Pages

Resizing extended partitions with GNU parted

This post will show how to resize an extended partition using GNU parted. There are many tools for partitioning available, but I wanted to use a tool which was by default installed in my test system (which runs CentOS Linux).

In summary "The GNU Parted program allows you to create, destroy, resize, move,and copy hard disk partitions. Parted can be used for creating space for new operating systems, reorganizing disk usage, and copying data to new hard disks."

On my test CentOS system I had three primary extended partitions created and one extended as below:
Model: ATA ST3500320AS (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number Start End Size Type File system Flags
1 32.3kB 535MB 535MB primary ext3 boot
2 535MB 11.0GB 10.5GB primary ext3
3 11.0GB 12.1GB 1078MB primary linux-swap
4 12.1GB 37.1GB 25.0GB extended
5 12.1GB 37.1GB 25.0GB logical lvm
As it's visible I had plenty of space on my hard drive (500GB), but I could use only approximately 7% (as I had 3 primary partitions and one extended there's no way in which I could create another partition).

Note: Extended partitions can be resized, so long as the new extended partition completely contains all logical partitions.

I wanted to resize my extended partition to 100GB so I could create additional logical partitions on it. For this there are two ways how to use parted:

1) Command line mode
#/sbin/parted /dev/sda resize 4 12.1GB 100GB
or
2) Interactive mode
#/sbin/parted /dev/sda
(parted) resize 4 12.1GB 100GB
The arguments are /dev/sda which is the device on which the partition to be manipulated is located, "resize" - to resize the partition, 4 - which partition to resize, the partition will start 12.1GB, and end 100GB from the beginning of the disk.

If the device (/dev/sda in my case) is not mentioned, parted will try to guess it (not a good option in some cases ;) ).

For a list of all arguments and capabilities of parted please go here.

Then we can have a look on what it actually did:
# parted /dev/sda print

Model: ATA ST3500320AS (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number Start End Size Type File system Flags
1 32.3kB 535MB 535MB primary ext3 boot
2 535MB 11.0GB 10.5GB primary ext3
3 11.0GB 12.1GB 1078MB primary linux-swap
4 12.1GB 100GB 87.9GB extended
5 12.1GB 37.1GB 25.0GB logical lvm

No comments: