First we gotta extend the logical volume, then extend the filesystem to fill the block device.
You can specify the size to extend the logical volume by:
$ lvextend --size +40G /dev/vg0/foo
Or the final size you want it to be extended to:
$ lvextend --size 120G /dev/vg0/foo
After you run it you’ll see this almost immediately:
Extending logical volume foo to 120.00 GB Logical volume foo successfully resized
You can check it with lvdisplay:
$ lvdisplay /dev/vg0/foo --- Logical volume --- LV Name /dev/vg0/foo VG Name vg0 LV UUID w2q9ZN-hKnN-CLGf-6Z5g-e1QZ-DCKX-1DYZvR LV Write Access read/write LV Status available # open 0 LV Size 120.00 GB Current LE 30720 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 254:85
To extend the underlying filesystem to fill the logical volume, you can first optionally unmount it:
$ umount /dev/vg0/foo
And also optionally run a check for any errors in the filesystem:
$ fsck -f /dev/vg0/foo
But it is super important to never run fsck on a mounted filesystem.
If you can’t unmount the filesystem (for customer/product related reasons or whatever), you can nowadays resize on a mounted filesystem if your kernel supports online resizing for filesystems mounted using ext3 and ext4. Use the resize2fs command, but beware, this will be a longrunning command (hours, days, even weeks), whose time it will take to finish depends on your device, your available resources and how much you want to extend by.
$ resize2fs /dev/vg0/foo
Definitely do not run this command 5 minutes before leaving work without something like screen, tmux or triggering it as a cronjob. If you cancel it, you will lose all the data on the storage device. Once you start it you need to wait for it to finish, so make sure you think about it before pressing the return key.
If it’s successful you’ll see this:
The filesystem on /dev/vg0/foo is now 31457280 blocks long.
You can also check:
$ df Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/vg0-foo 123854820 192188 117371688 1% /mnt