參考文檔: Linux命令大全
需求:測試環(huán)境虛擬機某個目錄下空間不足,準(zhǔn)備通過添加一塊磁盤,并將該目錄掛載到該磁盤
前面幾步在測試服務(wù)器上操作的,截圖困難,所以網(wǎng)上找了幾張設(shè)置圖
[root@node3 ~]# fdisk -lDisk /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000bd826 Device Boot Start End Blocks Id System/dev/sda1 * 2048 2099199 1048576 83 Linux/dev/sda2 2099200 1048575999 523238400 8e Linux LVM//新加的磁盤(100G)Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-home: 480.0 GB, 479954206720 bytes, 937410560 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes
[root@node3 ~]# fdisk /dev/sdbWelcome to fdisk (util-linux 2.23.2).Changes will remain in memory only, until you decide to write them.Be careful before using the write command.Device does not contain a recognized partition tableBuilding a new DOS disklabel with disk identifier 0x2890866a.
command (m for help): mCommand action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition //刪除現(xiàn)有分區(qū) l list known partition types m print this menu n add a new partition //添加新的分區(qū) o create a new empty DOS partition table p print the partition table //查看分區(qū)情況 q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only)
Command (m for help): pDisk /dev/sdb: 3221 MB, 3221225472 bytes255 heads, 63 sectors/track, 391 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sdb1 1 1 8001 8e Linux LVM/dev/sdb2 2 26 200812 83 Linux
Command (m for help): dPartition number (1-4): 1Command (m for help): dSelected partition 2
Command (m for help): pDisk /dev/sdb: 3221 MB, 3221225472 bytes255 heads, 63 sectors/track, 391 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id SystemCommand (m for help):
Command (m for help): nCommand action e extended p primary partition (1-4)p //建立主分區(qū)Partition number (1-4): 1 //分區(qū)號First cylinder (1-391, default 1): //分區(qū)起始位置Using default value 1last cylinder or size or sizeM or sizeK (1-391, default 391): 100 //分區(qū)結(jié)束位置,單位為扇區(qū)(磁盤扇區(qū)默認(rèn)是512Byte)Command (m for help): n //再建立一個分區(qū)Command action e extended p primary partition (1-4)p Partition number (1-4): 2 //分區(qū)號為2First cylinder (101-391, default 101):Using default value 101Last cylinder or size or sizeM or sizeK (101-391, default 391): 200M //分區(qū)結(jié)束位置,單位為M
Command (m for help): nCommand action e extended p primary partition (1-4)e //選擇擴展分區(qū)Partition number (1-4): 3First cylinder (126-391, default 126):Using default value 126Last cylinder or size or sizeM or sizeK (126-391, default 391)://剩下的空間都用做擴展分區(qū)Using default value 391
Command (m for help): pDisk /dev/sdb: 3221 MB, 3221225472 bytes255 heads, 63 sectors/track, 391 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sdb1 1 100 803218 83 Linux/dev/sdb2 101 125 200812 83 Linux/dev/sdb3 126 391 2136645 5 Extended
Command (m for help): nCommand action l logical (5 or over) p primary partition (1-4)l //選擇邏輯分區(qū)First cylinder (126-391, default 126):Using default value 126Last cylinder or size or sizeM or sizeK (126-391, default 391): 400M Command (m for help): nCommand action l logical (5 or over) p primary partition (1-4)lFirst cylinder (176-391, default 176):Using default value 176Last cylinder or size or sizeM or sizeK (176-391, default 391):Using default value 391
Command (m for help): pDisk /dev/sdb: 3221 MB, 3221225472 bytes255 heads, 63 sectors/track, 391 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sdb1 1 100 803218 83 Linux/dev/sdb2 101 125 200812 83 Linux/dev/sdb3 126 391 2136645 5 Extended/dev/sdb5 126 175 401593 83 Linux/dev/sdb6 176 391 1734988 83 LinuxCommand (m for help):
從上面的結(jié)果我們可以看到,在硬盤sdb我們建立了2個主分區(qū)(sdb1,sdb2),1個擴展分區(qū)(sdb3),2個邏輯分區(qū)(sdb5,sdb6)
注意:主分區(qū)和擴展分區(qū)的磁盤號位1-4,也就是說最多有4個主分區(qū)或者擴展分區(qū),邏輯分區(qū)開始的磁盤號為5,因此在這個實驗中試沒有sdb4的。
Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.
分區(qū)創(chuàng)建方式按照參考文檔的操作,但是我并沒有創(chuàng)建這么多分區(qū),100G全部創(chuàng)建了主分區(qū)即
/dev/sdb1
[root@node3 ~]# fdisk -lDisk /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000bd826 Device Boot Start End Blocks Id System/dev/sda1 * 2048 2099199 1048576 83 Linux/dev/sda2 2099200 1048575999 523238400 8e Linux LVMDisk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x2890866a Device Boot Start End Blocks Id System/dev/sdb1 2048 209715199 104856576 83 Linux //新的分區(qū)(sbd1:100G)Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-home: 480.0 GB, 479954206720 bytes, 937410560 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes
[root@node3 ~]# cat /proc/partitionsmajor minor #blocks name 8 0 524288000 sda 8 1 1048576 sda1 8 2 523238400 sda2 8 16 104857600 sdb 8 17 104856576 sdb1 11 0 1048575 sr0 253 0 52428800 dm-0 253 1 2097152 dm-1 253 2 468705280 dm-2
[root@node3 ~]# mkfs -t ext3 /dev/sdb1mke2fs 1.42.9 (28-Dec-2013)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks6553600 inodes, 26214144 blocks1310707 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=4294967296800 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872Allocating group tables: doneWriting inode tables: doneCreating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: done
#/usr/hdp/ 目錄要先存在[root@node3 ~]# mount /dev/sdb1 /usr/hdp/
[root@node3 usr]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/centos-root 50G 50G 20K 100% /devtmpfs 3.8G 0 3.8G 0% /devtmpfs 3.9G 0 3.9G 0% /dev/shmtmpfs 3.9G 12M 3.8G 1% /runtmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup/dev/sda1 1014M 142M 873M 14% /boot/dev/mapper/centos-home 447G 1018M 446G 1% /hometmpfs 781M 0 781M 0% /run/user/0/dev/sdb1 99G 60M 94G 1% /usr/hdp //掛載成功
[root@node3 /]# umount /dev/sdb1[root@node3 /]# df -kFilesystem 1K-blocks Used Available Use% Mounted on/dev/mapper/centos-root 52403200 52403180 20 100% /devtmpfs 3983896 0 3983896 0% /devtmpfs 3996168 0 3996168 0% /dev/shmtmpfs 3996168 11992 3984176 1% /runtmpfs 3996168 0 3996168 0% /sys/fs/cgroup/dev/sda1 1038336 145260 893076 14% /boot/dev/mapper/centos-home 468476420 1041428 467434992 1% /hometmpfs 799236 0 799236 0% /run/user/0
來源:https://www.icode9.com/content-3-413051.html取消掛載成功
還可以用umount /usr/hdp
取消掛載
聯(lián)系客服