Using parted to Manage Disk on Linux

List disk information.

~]# parted -l
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 64.4GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 1049kB 211MB 210MB fat16 EFI System Partition boot
2 211MB 1285MB 1074MB xfs
3 1285MB 64.4GB 63.1GB lvm


Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-home: 18.6GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number Start End Size File system Flags
1 0.00B 18.6GB 18.6GB xfs


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-swap: 6442MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number Start End Size File system Flags
1 0.00B 6442MB 6442MB linux-swap(v1)


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-root: 38.1GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number Start End Size File system Flags
1 0.00B 38.1GB 38.1GB xfs


~]# parted /dev/sdb print
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags

Make disk label gpt.

~]# parted /dev/sdb mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
Information: You may need to update /etc/fstab.

Make disk label msdos.

~]# parted /dev/sdb mklabel msdos
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
Information: You may need to update /etc/fstab.

Create a lvm primary partition.

~]# parted /dev/sdb mkpart primary 0% 100% toggle 1 lvm
Information: You may need to update /etc/fstab.

~]# parted /dev/sdb print
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 1049kB 21.5GB 21.5GB primary lvm

Create a xfs primary partition.

~]# parted /dev/sdb mkpart primary xfs 0% 100%
Information: You may need to update /etc/fstab.

~]# parted /dev/sdb print
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 1049kB 21.5GB 21.5GB primary

Remove a partition.

~]# parted /dev/sdb rm 1
Error: Partition(s) 1 on /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
old partition(s) will remain in use. You should reboot now before making further changes.
Ignore/Cancel? i
Information: You may need to update /etc/fstab.