How to extend a volume on LVM

2 minute read


Sometimes it is necessary to extend a logical volume, expanding the physical volume where it is hosted. If this is the case, you can follow this example extending a volume of 450 GB to 500 GB: First, Let’s check the disk geometry:

:~# fdisk -l /dev/sdb

Disk /dev/sdb: 483.2 GB, 483183820800 bytes
 255 heads, 63 sectors/track, 58743 cylinders, total 943718400 sectors
 Units = sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disk identifier: 0x0001178e

After expanding the volume you must make the system to rescan the volume:

:~# echo 1 > /sys/block/sdb/device/rescan

Then check the disk geometry one more time:

:~# fdisk -l /dev/sdb

Disk /dev/sdb: 536.9 GB, 536870912000 bytes
 255 heads, 63 sectors/track, 65270 cylinders, total 1048576000 sectors
 Units = sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disk identifier: 0x0001178e

As you can see, the disk size grew up but this is only known by the operating system, because the LVM still has the same information since the physical volume hasn’t been expanded yet:

:~# pvs
 PV VG Fmt Attr PSize PFree
 /dev/sda5 debian lvm2 a-- 3.76g 0
 /dev/sda6 debian lvm2 a-- 13.00g 0
 /dev/sdb svn_vg lvm2 a-- 450.00g 0

If you extend the physical volume with the following command:

:~# pvresize /dev/sdb
 Physical volume "/dev/sdb" changed
 1 physical volume(s) resized / 0 physical volume(s) not resized

And check the physical volume sizes you will see the added space:

:~# pvs
 PV VG Fmt Attr PSize PFree
 /dev/sda5 debian lvm2 a-- 3.76g 0
 /dev/sda6 debian lvm2 a-- 13.00g 0
 /dev/sdb svn_vg lvm2 a-- 500.00g 50.00g

Now you have to extend the logical volume and the system file size on the fly. You can do both actions using just one command:

:~# lvresize -r -L +50G /dev/mapper/svn_vg-svn

Extending logical volume svn to 500.00 GiB
 Logical volume svn successfully resized
 resize2fs 1.42.5 (29-Jul-2012)
 Filesystem at /dev/mapper/svn_vg-svn is mounted on /var/data/svn; on-line resizing required
 old_desc_blocks = 29, new_desc_blocks = 32
 Performing an on-line resize of /dev/mapper/svn_vg-svn to 131070976 (4k) blocks.
 The filesystem on /dev/mapper/svn_vg-svn is now 131070976 blocks long.

Finally, check the free space available to see the added 50 GB in the system file:

:~# df -h
 Filesystem Size Used Avail Use% Mounted on
 rootfs 993M 287M 655M 31% /
 udev 10M 0 10M 0% /dev
 tmpfs 397M 228K 397M 1% /run
 /dev/mapper/debian-root 993M 287M 655M 31% /
 tmpfs 5.0M 0 5.0M 0% /run/lock
 tmpfs 794M 0 794M 0% /run/shm
 /dev/sda1 228M 34M 183M 16% /boot
 /dev/mapper/debian-home 2.0G 39M 1.9G 3% /home
 /dev/mapper/debian-tmp 3.9G 7.1M 3.7G 1% /tmp
 /dev/mapper/debian-usr 2.0G 869M 1.1G 46% /usr
 /dev/mapper/debian-var 6.7G 2.1G 4.3G 33% /var
 /dev/mapper/svn_vg-svn 493G 432G 62G 88% /var/data/svn

Leave a Comment