Resizing a LVM logical volume to the max

Dynamically modifiable partitions created by using LVM can span mutliple physical drives (PVs). Extending a logical volume (LV) to the maximum space available can be done online and therefore without any interruption of running tasks.

Currently the volume has an capacity of 1,73 TB as can be seen in the following output:

root@server:~# lvdisplay
 --- Logical volume ---
 LV Name /dev/tank0/lvol0
 VG Name tank0
 LV UUID NmxWAS-s18B-CbpD-1Pmv-kkOt-idfQ-mbf5QD
 LV Write Access read/write
 LV Status available
 # open 1
 LV Size 1.73 TB
 Current LE 454144
 Segments 1
 Allocation inherit
 Read ahead sectors auto - currently set to 256
 Block device 252:0 

The physical volume behind it has a capacity of 1,82 TB usable space:

root@server:~# pvdisplay
 --- Physical volume ---
 PV Name /dev/sde
 VG Name tank0
 PV Size 1.82 TB / not usable 1.09 MB
 Allocatable yes
 PE Size (KByte) 4096
 Total PE 476932
 Free PE 22788
 Allocated PE 454144
 PV UUID 2gS24Z-kT2s-Cgv4-0XvE-PISG-dFP0-nLfSTV

The most important line in this output is the line starting with "Free PE". The value behind it shows the number of physical extents available on this drive. This number is needed for the command that starts the expansion:
 

root@server:~# lvextend -l +22788 -A y /dev/tank0/lvol0

After this command has finished successfully the partition now already has a size of 1,82 TB- but the usable space still is only 1,73 TB.

root@server:~# lvdisplay
 --- Logical volume ---
 LV Name /dev/tank0/lvol0
 VG Name tank0
 LV UUID NmxWAS-s18B-CbpD-1Pmv-kkOt-idfQ-mbf5QD
 LV Write Access read/write
 LV Status available
 # open 1
 LV Size 1.82 TB
 Current LE 476932
 Segments 1
 Allocation inherit
 Read ahead sectors auto - currently set to 256
 Block device 252:0

The physical volume is filled up totally. There is no space left on the device anymore:

root@server:~# pvdisplay
 --- Physical volume ---
 PV Name /dev/sde
 VG Name tank0
 PV Size 1.82 TB / not usable 1.09 MB
 Allocatable yes (but full)
 PE Size (KByte) 4096
 Total PE 476932
 Free PE 0
 Allocated PE 476932 PV UUID 2gS24Z-kT2s-Cgv4-0XvE-PISG-dFP0-nLfSTV

Finally the filesystem has to be grown. If running an ext2/3/4 filesystem the command resize2fs does the job:

root@server:~# resize2fs /dev/mapper/tank0-lvol0
 resize2fs 1.41.9 (22-Aug-2009)
 Filesystem at /dev/mapper/tank0-lvol0 is mounted on /mnt/tank0; on-line resizing required
 old desc_blocks = 111, new_desc_blocks = 117
 Performing an on-line resize of /dev/mapper/tank0-lvol0 to 488378368 (4k) blocks.
The filesystem on /dev/mapper/tank0-lvol0 is now 488378368 blocks long.

That's it. Now the whole 1,83 TB are usable and available without any interruption.