$ sudo parted /dev/sdb GNU parted 3.2 Using/dev/sdb Welcome to GNU parted! Type 'help'toview a list of commands. (parted) mklabel msdos (parted) unit GB (parted) mkpart Partition type? primary/extended? primary File system type? [ext2]? ext4 Start? 0.00GB End? 10.00GB (parted) print Model: ATA VBOX HARDDISK (scsi) Disk /dev/sdb: 53.7GB Sector size (logical/physical): 512B/512B PartitionTable: msdos Disk Flags:
Number StartEnd Size Type File system Flags 10.00GB 10.0GB 10.0GB primary ext4 lba
(parted) quit Information: You may need toupdate/etc/fstab.
$ sudo parted /dev/sdb resizepart 333.0GB Information: You may need toupdate /etc/fstab.
运行下列命令来确认分区是否已经扩容。可以看到,分区 3 已经从 8GB 增加到 13GB。
1 2 3 4 5 6 7 8 9 10 11 12 13
$ sudo parted /dev/sdb print Model: ATA VBOX HARDDISK (scsi) Disk /dev/sdb: 53.7GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags:
Number Start EndSizeTypeFile system Flags 11049kB 10.0GB 9999MB primary ext4 210.0GB 20.0GB 9999MB primary ext4 320.0GB 33.0GB 13.0GB primary ext4
重新调整文件系统大小。
1 2 3 4 5
$ sudo resize2fs /dev/sdb3 resize2fs 1.43.4 (31-Jan-2017) Resizing the filesystemon /dev/sdb3 to 3173952 (4k) blocks. The filesystemon /dev/sdb3 is now 3173952 (4k) blocks long.
$ sudo parted /dev/sdb rm 3 Warning: Partition /dev/sdb3 is being used. Are you sure you want tocontinue? Yes/No? Yes Error: Partition(s) 3on /dev/sdb have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the oldpartition(s) will remain in use. You should reboot now before making further changes. Ignore/Cancel? Ignore Information: You may need toupdate /etc/fstab.
我们也可以用下列的命令检查。可以看到,分区 3 已经被成功移除。
1 2 3 4 5 6 7 8 9 10 11 12
$ sudo parted /dev/sdb print Model: ATA VBOX HARDDISK (scsi) Disk /dev/sdb: 53.7GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags:
Number Start EndSizeTypeFile system Flags 11049kB 10.0GB 9999MB primary ext4 210.0GB 20.0GB 9999MB primary ext4
$ sudo parted /dev/sdb set2 lvm on Information: You may need toupdate /etc/fstab.
我们可以列出分区来验证这次的更改。
1 2 3 4 5 6 7 8 9 10 11 12
$ sudo parted /dev/sdb print Model: ATA VBOX HARDDISK (scsi) Disk /dev/sdb: 53.7GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags:
Number Start EndSizeTypeFile system Flags 11049kB 10.0GB 9999MB primary ext4 210.0GB 20.0GB 9999MB primary ext4 lvm
如果你想知道可用的标志,只需要用如下的命令。
1 2 3 4 5 6 7
$ (parted) help set set NUMBER FLAG STATE change the FLAG onpartition NUMBER
NUMBER is the partition number used by Linux. On MS-DOS disk labels, the primary partitions number from1to4, logical partitions from5 onwards. FLAG is one of: boot, root, swap, hidden, raid, lvm, lba, hp-service, palo, prep, msftres, bios_grub, atvrecv, diag, legacy_boot, msftdata, irst, esp STATE is one of: on, off
$ sudo parted GNU parted 3.2 Using /dev/sda Welcome to GNU parted! Type'help'toview a list of commands. (parted) help align-checkTYPE N checkpartition N forTYPE(min|opt) alignment help [COMMAND] print general help, or help on COMMAND mklabel,mktable LABEL-TYPEcreate a new disklabel (partitiontable) mkpart PART-TYPE [FS-TYPE] STARTEND make a partition name NUMBER NAMEnamepartition NUMBER asNAME print [devices|free|list,all|NUMBER] display the partitiontable, available devices, free space, allfound partitions, or a particular partition quit exit program rescue STARTEND rescue a lost partition near STARTandEND resizepart NUMBER END resize partition NUMBER rm NUMBER deletepartition NUMBER select DEVICE choose the device to edit disk_set FLAG STATE change the FLAG on selected device disk_toggle [FLAG] toggle the state of FLAG on selected device set NUMBER FLAG STATE change the FLAG onpartition NUMBER toggle [NUMBER [FLAG]] toggle the state of FLAG onpartition NUMBER unit UNIT set the default unit to UNIT version display the version number and copyright information of GNU parted (parted) quit