Extend Logical Volume In Ubuntu
So I installed my OS, started installing a bunch of packages. The application worked for a few weeks… then it no longer started. Looking at “df -H”, you can see:
Filesystem Size Used Available Use% Mounted on
udev 16G 0 16G 0% /dev
tmpfs 32G 1.7M 32G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 32G 32G 0M 100% /
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/loop0 87M 87M 0 100% /snap/core/4917
/dev/loop1 3.2M 3.2M 0 100% /snap/stress-ng/471
/dev/loop2 90M 90M 0 100% /snap/core/6130
/dev/sda2 976M 143M 766M 16% /boot
tmpfs 3.2G 0 3.2G 0% /run/user/1000
I know I created the VM with a 100 GB drive, but errors in the log and the output from “df -H”, you can see the disc is 100% in use.
It can be a bit tricky but if you understand that there are 3 parts, it’ll be much easier.
- Physical Volume (PV) => The physical space on a drive.
- Volume Group (VG) => An abstracted amount of drive space that can be split between multiple drives/devices.
- Logical Volume (LV) => The space that ubuntu “sees”
You’ll need to extend your VG all the way across your 1TB Drive (or extend however much you want), then extend the Logical Volume group to take up that space.
# We need to resize the logical volume to use all the existing and free space of the volume group
$ lvm
lvm> lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
lvm> exit
# And then, we need to resize the file system to use the new available space in the logical volume
$ resize2fs /dev/ubuntu-vg/ubuntu-lv
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 58
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 120784896 (4k) blocks long.
# Finally, you can check that you now have available space:
$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 786M 1.2M 785M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 100G 32G 68G 32% /
If you didn’t customize the LVM settings, the names for the volume group and logical volume should be the same as mine (ubuntu-vg
and ubuntu-lv
respectively).
If your partition is completely full, you could get a no space left
error when trying to resize the logical volume like:
lvm> lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
/etc/lvm/archive/.lvm_computer: write error failed: No space left on device
The easiest way to fix this is by removing apt
cache (it will get regenerated next time you do apt update
), which should give you more than enough space to complete the operation:
rm -rf /var/cache/apt/*
help from: https://askubuntu.com/users/46198/yorch from: here