Version 2 (modified by Ross, 10 years ago) (diff)


How to extend a logical volume on a KVM guest

Sometimes a file system on our guests fill up, meaning that data cannot be written to parts of the file system. For example, vg_stone0-var will have no remaining space making it impossible to write to the /var directory.

Step One: figure out file system and logical volume size

In order to determine if this is the case, you can run

# df -h

The output will look like this:

0 stone:~# df -h
Filesystem            Size  Used Avail Use% Mounted on
                      3.8G  957M  2.7G  27% /
tmpfs                1007M     0 1007M   0% /lib/init/rw
udev                 1001M  108K 1001M   1% /dev
tmpfs                1007M     0 1007M   0% /dev/shm
/dev/vda1             236M   22M  202M  10% /boot
                      961M   19M  894M   3% /tmp
                      6.9G  4.6G  2.1G  69% /var
                       30G   24G  4.3G  85% /home
0 stone:~# 

If the fifth column says 100% then the file system is full. In order to check if any space exists on the logical volume, you can run:

# lvdisplay

The output should look something like this.

0 stone:~# lvdisplay /dev/vg_stone0/var
  --- Logical volume ---
  LV Name                /dev/vg_stone0/var
  VG Name                vg_stone0
  LV UUID                quZZX4-zRSb-sGyH-1V1b-nBx9-A2rX-oGau0V
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                7.00 GiB
  Current LE             1792
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3
0 stone:~# 

You will want to check the LV Size and make sure it's the same size as the df -h command above. If it's larger than the output of df -h, then more space has been allotted to the drive and you can skip to step 3.

If you've determined that the LV Size needs extending from the proceeding step, you'll need to check and see if the volume group has available space:

0 stone:~# vgs
  VG        #PV #LV #SN Attr   VSize  VFree
  vg_stone0   1   5   0 wz--n- 49.76g 7.52g
0 stone:~# 

If you do not see enough VFree space, you'll need to follow the instructions on extend-disk-on-kvm-guest.

Step Two: Extend the logical volume

Once you've done that, then execute the following command for the logical volume.

# lvextend --size 10GB /dev/mapper/vg_stone0-var

Make sure that the number after --size is the total size of the logical volume you want.

Step Three: Extend the file system

Once you've extended the logical volume, you need to extend the file system as well. The following command will extend the file system.

resize2fs /dev/mapper/LVNAME

You may be asked to run e2fsck when running the above command. If so run:

e2fsck /dev/mapper/LVNAME

When running this command, you may be asked to allow e2fsck to fix parts of the file system. Generally, you should answer yes to such requests.

Then rerun resize2fs command. If it succeeds, you should have extended the logical volume. Repeat Step One and make sure everything looks correct.

Something's not Right

If you have done all of the above and the file system seems to be acting in an unusual manner. You may need to run fsck to fix the file system. The easiest way to accomplish this is to restart the guest with a -F option.

NOTE: This is the desperate response approach.

# shutdown -hF now