Перейти к содержанию

Resize partition to maximum using parted in non-interactive mode

  1. Make sure that OS is aware of the disk size increase since the last scan(reboot):
# echo 1 > /sys/block/sda/device/rescan
  1. Check that there is free space available after the last partition:
# parted -s -a opt /dev/sda "print free"
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  1075MB  1074MB  primary  xfs          boot
 2      1075MB  32.2GB  31.1GB  primary               lvm
        32.2GB  53.7GB  21.5GB           Free Space
  1. Resize last partition to the maximum available disk space:
# parted -s -a opt /dev/sda "resizepart 2 100%"
# echo $?
0

This operation doesn’t have any indication of it’s success except the exit code.

  1. You can verify that partition size was increased by repeating:
# parted -s -a opt /dev/sda "print free"
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  1075MB  1074MB  primary  xfs          boot
 2      1075MB  53.7GB  52.6GB  primary               lvm

As a bonus you can fit all this into one command line(don’t miss step 0):

# parted -s -a opt /dev/sda "print free" "resizepart 2 100%" "print free"
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  1075MB  1074MB  primary  xfs          boot
 2      1075MB  32.2GB  31.1GB  primary               lvm
        32.2GB  53.7GB  21.5GB           Free Space

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

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  1075MB  1074MB  primary  xfs          boot
 2      1075MB  53.7GB  52.6GB  primary               lvm