1。本地查看fdisk-l#真实设备cat/proc/partition#系统可识别设备blkid#系统可用设备df#系统挂载的设备[root@march~]#dfFilesystem1K-blocksUsedAvailableUse%Mountedon/dev/vda387091202980288572883235%/devtmpfs49392004939200%/devtmpfs5084561605082961%/dev/shmtmpfs50845671445013122%/runtmpfs50845605084560%/sys/fs/cgroup/dev/vda12013881417325965671%/boottmpfs10169281016841%/run/user/42tmpfs10169281016841%/devices挂载和卸载1.设备名/dev/hd0##表示IDE设备,即并口硬盘,是一个老式硬盘/dev/xdx#/dev/sda/dev/sdb..../dev/sr0#光驱/dev/mapper/*#虚拟设备2.设备挂载mount设备挂载点mount/dev/sdb1/mnt#将sdb1挂载到mntumount/mnt|/dev/sdb1#卸载mount-oro/devsdb1/mnt#只读挂载mount#查看挂载信信息mount-oremount,rw/dev/sdb1|/mnt#重新读写mount[root@foundation22~]#umount/mnt/umount:/mnt:targetisbusy.(在某些情况下,有关使用该设备的进程的有用信息可通过lsof(8)或fuser(1)找到)方法:打开另一个SHELL窗口,vim/mnt/filesolution1fuser-kvm/mntumount/mntsolution2lsof/mnt[root@foundation22~]#lsof/mntlsof:WARNING:can'tstat()fuse.gvfsd-fusefilesystem/run/user/1000/gvfs输出信息可能不完整。COMMANDPIDUSERFDTYPEDEVICESIZE/OFFNODENAMEvim3500kiosk4uREG8,17122882137/mnt/.file.swp[root@foundation22~]#kill-93500[root@foundation22~]#umount/mnt3。磁盘分区1.硬盘0磁道1扇区512字节记录的信息如下512=446+64+2mbr:主引导记录,负责从活动分区加载,运行系统引导程序mpt:分区表,包括4个分区表项,每个分区表项长16字节,共64字节。55aa:结束标志字4.分区步骤1.fdisk-l#查看分区2.创建主分区[root@localhost~]#fdisk/dev/vdbCommand(mforhelp):mCommandactionatoggleabootableflagbeditbsddisklabelc切换dos兼容性标志d删除一个分区#deleteg创建一个新的空GPT分区表G创建一个IRIX(SGI)分区表l列出已知的分区类型m打印此菜单n添加一个新分区#newo创建一个新的清空DOS分区表p打印分区表#显示分区信息q退出而不保存更改#退出s创建一个新的空Sun磁盘标签t更改分区的系统ID#修改分区IDu更改显示/输入单位v验证分区表w写入表到磁盘并退出#Savepartitionlabelinformationtohardwarexextrafunctionality(expertsonly)Command(mforhelp):n#NewPartitiontype:pprimary(0primary,0extended,4free)eextendedSelect(defaultp):p#主分区分区号(1-4,default1):#idDefaultFirstsector(2048-20971519,default2048):#PartitionstartUsingdefaultvalue2048最后一个扇区,+sectorsor+size{K,M,G}(2048-20971519,default20971519):+500M#PartitionsizePartition1oftypeLinuxandofsize500MiBissetCommand(mforhelp):p#显示信息Disk/dev/vdb:10.7GB,10737418240bytes,20971520sectorsUnits=sectorsof1*512=512bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDisklabeltype:dosDiskidentifier:0xed32f7e0DeviceBootStartEndBlocksIdSystem/dev/vdb120481026047583200寻求帮助):wqThe分区表已更改!调用ioctl()重新读取分区表。正在同步磁盘。当已建立3个主分区时命令(m求助):n分区类型:p主(3个主,0个扩展,1个空闲)eextendedSelect(defaulte):e#Createextendedpartition选择分区4第一个扇区(3074048-20971519,default3074048):使用默认值3074048Lastsector,+sectorsor+size{K,M,G}(3074048-20971519,default20971519):Usingdefaultvalue20971519Partition4oftypeExtendedandofsize8.5GiBissetCommand(mforhelp):pDisk/dev/vdb:10.7GB,10737418240bytes,20971520sectorsUnits=sectorsof1*512=512bytes扇区大小(逻辑/物理):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDisklabeltype:dosDiskidentifier:0xed32f7e0DeviceBootStartEndBlocksIdSystem/dev/vdb12048102604751200083Linux/dev/vdb21026048205004751200083Linux/dev/vdb32050048307404751200083Linux/dev/vdb430740482097151989487365Extended#把所有空间都给ExtendedCommand(mforhelp):wqThepartitiontablehasbeenaltered!Callingioctl()tore-readpartitiontable.5.给设备安装文件系统[root@localhost~]#mount/dev/vdb1/mnt/挂载:/dev/vdb1写保护,挂载只读mount:unknownfilesystemtype'(null)'formattingbyext3rhel5andpreviousversions,supportsupto32TBfilesystemand2Tfiles,actual2TBfilesystem,16Gfilesext4rhel61EB16TBxfsrhel718EB9EB7G/s4G/smkfs.xfs/dev/vdb1#将硬盘格式化为xfsmount/dev/vdb1/mnt#临时挂载vim/etc/fstab#开机自动挂载分区设备是否挂载点文件系统挂载参数备份或未检测/dev/vdb1/mntxfsdefaults00mount-aerror:[root@localhost~]#vim/etc/fstab/dev/vdb1/mntxfsdefaults00[root@localhost~]#rebootpartprobe#同步分区表cat/proc/partitionsrestart时,虚拟机出错-->输入PASSWD-->vim/etc/fstab#/dev/vdb1/mntxfsdefauts00-->reboot6.swap分区管理1.swap创建分区并设置分区标签82mkswap/dev/vdb6#formatswapon-a/dev/vdb6#startswapon-s#displayswapinformation[root@localhost~]#swapon-sFilenameTypeSizeUsedPriority/dev/vdb6分区10485720-1vim/etc/fstab#永久挂载在swap分区/dev/sdv6swapswapdefaults002.swap分区删除vim/etc/fstabswapoff/dev/vdb6swapon-s7.配额是给分区的mkdir/publicnew/etc/vdb7mkfs.xfs/etc/vdb7mount-ousrquota/dev/vdb7/public/chmod777/publicedquota-ustudent#设置用户配额student用户(uid1000)的磁盘配额:文件系统块softhardinodesofthard/dev/vdb60020480100vim/etc/fstab#Permanentquota/dev/vdb7/publicxfsdefaults,usrquota00Test:[root@localhost~]#su-studentLastlogin:WedAug122:52:55EDT2018onpts/0[student@localhost~]$ddif=/dev/zeroof=/public/studentfilebs=1Mcount=1010+0recordsin10+0recordsout10485760bytes(10MB)已复制,0.00694435s,1.5GB/s[student@localhost~]$ddif=/dev/zeroof=/public/studentfilebs=1Mcount=100dd:errorwriting'/public/studentfile':Disk超出配额21+0条记录in20+0条记录out20971520字节(21MB)已复制,0.224504s,93.4MB/s[student@localhost~]$du-sh/public/studentfile20M/public/studentfile8.磁盘加密新分区/dev/vdb8partprobe[root@localhost~]#ll/dev/vdb8brw-rw----.1rootdisk253,24Aug323:36/dev/vdb8cryptsetupluksFormat/dev/vdb8#encrypt/dev/vdb8cryptsetupopen/dev/vdb8sheen#打开加??密设备端口,命名为sheenmkfs.xfs/dev/mapper/sheen#/etc/mapper虚拟设备mount/dev/mapper/sheen/mnt/#mounttouch/mnt/file{1..10}umount/mnt/cryptsetupclosesheen#关闭加密设备端口cryptsetupopen/dev/vdb8sheenmount/dev/mapper/sheen/mnt/ls/mnt/[root@localhost~]#ll/dev/vdb8brw-rw----.1rootdisk253,23Aug123:24/dev/vdb7[root@localhost~]#cryptsetupluksFormat/dev/vdbwarnning!"============="这将覆盖/dev/vdb7不可撤销。你确定吗?(Typeuppercaseyes):YESEnterpassphrase:Verifypassphrase:[root@localhost~]#cryptsetupopen/dev/vdb8sheenEnterpassphrasefor/dev/vdb8:[root@localhost~]#ll/dev/folders/sheenlrwxrwxrwx。1rootroot7Aug123:25/dev/folders/sheen->../dm-0[root@localhost~]#mount/dev/folders/sheen/mnt/[root@localhost~]#touch/mnt/file{1..4}[root@localhost~]#ls/mnt/file1file2file4[root@localhost~]#umount/mnt/[root@localhost~]#ls/mnt/[root@localhost~]#cryptsetupclosesheen[root@localhost~]#ls/mnt/[root@localhost~]#cryptsetupopen/dev/vdb8sheenEnterpassphrasefor/dev/vdb8:[root@localhost~]#cryptsetupopen/dev/vdb8sheenEnter/dev/vdb8的密码:[root@localhost~]#ls/mnt/[root@localhost~]#mount/dev/folders/sheen/mnt/[root@localhost~]#ls/mnt/file1file2file3file4默认设置vim/etc/fstab/dev/folders/sheen/mntxfsdefaults00vim/etc/crypttabsheen/dev/vdb8/root/sheenkeysvim/root/sheenkeyssheenstar13cryptsetupluxAddKey/dev/vdbkeysprotection/sheenEnabledrebootdf
