Jan 202016

My home Zabbix instance was running out of space today, so I had to resize the partition that it lived on so that it would last a few more days while I worked out how to migrate it from my VMWare host to my ProxMox host.

Resizing Hard Drive

First thing first, I needed to expand the HDD in the hypervisor.

After resizing the hard drive, you may to rescan the disk for Linux to recognise the new size.
The following command will rescan all the disks.

# for x in /sys/class/scsi_disk/*; do echo '1' > $x/device/rescan; done

If the disk is still the same size in fdisk, then you’ll need to reboot the server.

Resizing Partition

Depending on the partition layout, you will need to either resize 1 or 2 partitions, assuming that the partitions are at the end of the disk.
In layout 1, you’ll have just a single partition that is the LVM partition.
In layout 2, you’ll have an extended partition that contains the LVM partition.

The process to resize partitions are the same, except that in layout 2, you’ll need to resize 2 partitions, with the extended one being resized first so that it’s able to contain the LVM partition.

I’m using parted to resize my partitions in this case.
First up is to start parted on /dev/sda

# parted /dev/sda

I normally use Bytes as a unit, and then use the print free command to see where the partition needs to end to fill up the Free Space.

(parted) unit b
(parted) print free
Number Start End Size Type File system Flags
32256B 1048575B 1016320B Free Space
1 1048576B 255852543B 254803968B primary ext2 boot
255852544B 256900095B 1047552B Free Space
2 256900096B 53687091200B 53430191104B primary lvm
53687091201B 75161927679B 5369757696B Free Space

To resize it, a simple resizepart command is used.

(parted) resizepart 2 75161927679B

In the case of an extended partition containing the LVM partition, the command above just needs to be run against the 2 partition numbers, with the extended partition being extended first, and the LVM partition being extended second with the ending byte being one less than the extended partition.
In this example, partition 2 is the extended partition, and partition 5 is the LVM partition.

(parted) resizepart 2 75161927679B
(parted) resizepart 5 75161927678B

Resizing Physical Volume

After resizing the partition, you’ll need to resize the physical volume. This is as simple as running the following:

# pvresize /dev/sda2

Replace /dev/sda2 with the partition that has just been extended.

Resizing Logical Volume

Next, the logical volume will need to be resized with lvresize [lv path].
You can choose to resize to fill up the empty space, or you can select a specific size. In this example, I’ve resized the logical volume to use all available space.
Replace /dev/VolGroup/lv_root with the path of the logical volume that needs resizing.

# lvresize -l +100%FREE /dev/VolGroup/lv_root

You should see the following output once the logical volume is resized.

Size of logical volume VolGroup/lv_root changed from 48.54 GiB (12426 extents) to 68.54 GiB (17546 extents).
Logical volume lv_root successfully resized

Resize Filesystem

The last thing to do is to resize the filesystem. This can be done live on ext4 with the resize2fs tool.
Replace /dev/mapper/VolGroup-lv_root with the path to the filesystem that needs resizing.
If you’re unsure of the filesystem, lvscan will display the path to the filesystem.

# resize2fs /dev/mapper/VolGroup-lv_root

Once the resize is complete, you should be able to run a df and see the new filesystem size.
In my case, the filesystem was grown from 50G to almost 70G

# df -h
Filesystem Size Used Avail Use% Mounted on
68G 44G 20G 69% /


 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>