# Using parted to Manage Disk on Linux

parted-3.1-28 without resizepart, parted-3.1-29 with resizepart

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 partition.

~]# parted /dev/sdb mkpart data01 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               data01  lvm

Create the new partition.

~]# parted /dev/sdb mkpart data01 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               data01

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.

# Expand Partition

Ⅰ. parted-3.1-29 with resizepart.

~]# parted /dev/sdb print
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number  Start   End     Size    File system  Name  Flags
 1      1049kB  53.7GB  53.7GB  xfs          cell
~]# for i in /sys/class/scsi_device/*; do echo 1 > ${i}/device/rescan; done
~]# parted /dev/sdb print
Error: The backup GPT table is not at the end of the disk, as it should be.  This might mean that another operating system believes the
disk is smaller.  Fix, by moving the backup to the end (and removing the old backup)?
Fix/Ignore/Cancel? Fix
Warning: Not all of the space available to /dev/sdb appears to be used, you can fix the GPT to use all of the space (an extra 104857600
blocks) or continue with the current setting?
Fix/Ignore? Fix
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number  Start   End     Size    File system  Name  Flags
 1      1049kB  53.7GB  53.7GB  xfs          cell
~]# umount /dev/sdb1
~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number  Start   End     Size    File system  Name  Flags
 1      1049kB  53.7GB  53.7GB  xfs          cell
(parted) unit s
(parted) p free
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 209715200s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number  Start       End         Size        File system  Name  Flags
        34s         2047s       2014s       Free Space
 1      2048s       104855551s  104853504s  xfs          cell
        104855552s  209715166s  104859615s  Free Space
(parted) resizepart 1
End?  [104855551s]? 209715166s
(parted) p
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 209715200s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number  Start  End         Size        File system  Name  Flags
 1      2048s  209715166s  209713119s  xfs          cell
(parted) q
Information: You may need to update /etc/fstab.
~]# parted /dev/sdb print
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number  Start   End    Size   File system  Name  Flags
 1      1049kB  107GB  107GB  xfs          cell
~]# xfs_growfs /dev/sdb1
meta-data=/dev/sdb1              isize=256    agcount=4, agsize=3276672 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=13106688, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=6399, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13106688 to 26214139

Ⅱ. parted-3.1-28 without resizepart.

~]# parted /dev/sdb print
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number  Start   End     Size    File system  Name  Flags
 1      1049kB  53.7GB  53.7GB  xfs          cell
~]# umount /dev/sdb1
~]# parted /dev/sdb rm 1
Information: You may need to update /etc/fstab.
~]# parted /dev/sdb mkpart cell xfs 0% 100%
Information: You may need to update /etc/fstab.
~]# parted /dev/sdb print
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number  Start   End    Size   File system  Name  Flags
 1      1049kB  107GB  107GB  xfs          cell
~]# xfs_growfs /dev/sdb1
meta-data=/dev/sdb1              isize=256    agcount=4, agsize=3276672 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=13106688, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=6399, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13106688 to 26213888
Edited on