Extend a root LVM partition online, extendlvm
There is also a quick remedy for the emergency situation when your root partition runs out of disk space. there is a feature specific to ext3 and ext4 that can help the goal of resolving the full disk situation. unless explicitly changed during filesystem creation, both by default reserve five percent (5%) of a volume capacity to the superuser (root ).
1 # df -Th 2 Filesystem Type Size Used Avail Use% Mounted on 3 /dev/mapper/vg_main-lv_root 4 ext4 8.4G 8.0G 952K 100% / 5 tmpfs tmpfs 499M 0 499M 0% /dev/shm 6 /dev/vda1 ext4 485M 33M 428M 8% /boot 7 8 # dumpe2fs /dev/vg_main/lv_root | grep 'Reserved block count' 9 dumpe2fs 1.41.12 (17-May-2010)10 Reserved block count: 111513
It turned out 111513 of 4 kb blocks were reserved for the superuser, which was exactly five percent of the volume capacity.
How to enable it?
1 # tune2fs -m 0 /dev/vg_main/lv_root 2 tune2fs 1.41.12 (17-May-2010)3 Setting reserved blocks percentage to 0% (0 blocks)4 # df -Th5 Filesystem Type Size Used Avail Use% Mounted on6 /dev/mapper/vg_main-lv_root7 ext4 8.4G 8.0G 437M 95% /8 tmpfs tmpfs 499M 0 499M 0% /dev/shm9 /dev/vda1 ext4 485M 33M 428M 8% /boot
Now that we have some free space on the root partition to work on we can extend the LVM partition:
Create a new partition of appropriate size using fdisk
1 fdisk /dev/sdb1
This is a key sequence on the keyboard to create a new LVM type (8e) partition:
N, p, 1, enter (accept default first sector), enter (accept default last sector), t, 8e, w
Create a new Physical Volume
1 # pvcreate /dev/sdb12 Writing physical volume data to disk "/dev/sdb1"3 Physical volume "/dev/sdb1" successfully created
Extend a Volume Group
1 # vgextend vg_main /dev/sdb12 Volume group "vg_main" successfully extended
Extend your LVM
-Extend the size of your LVM by the amount of free space on PV
1 # lvextend /dev/vg_main/lv_root /dev/sdb12 Extending logical volume lv_root to 18.50 GiB3 Logical volume lv_root successfully resized
-Or with a given size
1 lvextend -L +10G /dev/vg_main/lv_root
Finally resize the file system on-line
1 # resize2fs /dev/vg_main/lv_root2 resize2fs 1.41.12 (17-May-2010)3 Filesystem at /dev/vg_main/lv_root is mounted on /; on-line resizing required4 old desc_blocks = 1, new_desc_blocks = 25 Performing an on-line resize of /dev/vg_main/lv_root to 4850688 (4k) blocks.6 The filesystem on /dev/vg_main/lv_root is now 4850688 blocks long.
-Or useXfs_growfsFor xfs file system
1 # xfs_growfs /dev/vg_main/lv_root
Now we can set the reserved blocks back to the default percentage-5%
1 # tune2fs -m 5 /dev/mapper/vg_main-lv_root2 Results:3 4 # df -Th5 Filesystem Type Size Used Avail Use% Mounted on6 /dev/mapper/vg_main-lv_root7 ext4 19G 8.0G 9.4G 46% /8 tmpfs tmpfs 499M 0 499M 0% /dev/shm9 /dev/vda1 ext4 485M 33M 428M 8% /boot