Kirya [.net]

Last updated: Mar 24, 2008

Memo: Resizing logical volumes

Yesterday, my system refused to start properly: “No space left on device”

My root partition was full! After cleaning apt cache, the system was in order, but this could not be the permanent solution (less than 15% of my /home partition were used):

Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/hathor-root     6.6G  4.0G  2.3G  64% /
tmpfs                       507M     0  507M   0% /lib/init/rw
udev                         10M   60K   10M   1% /dev
tmpfs                       507M  8.0K  507M   1% /dev/shm
/dev/sda1                   236M   21M  203M  10% /boot
/dev/mapper/hathor-home     175G   20G  146G  13% /home

When I installed Debian using the latest d-i available at that time, I was proposed to use LVM, which I have accepted, even if I wasn’t sure it would be useful.

I thus decided to try and resize my logical volumes.

Here is what I have done:

Preparing the system

telinit 1
umount /home
e2fsck -f /dev/hathor/home

Note that hathor is the VG name chosen by the debian-installer (ie. the host name).

Reducing /home

When reducing a LV, the filesystem has to be shrinked first:

resize2fs /dev/hathor/home 170G

In this case, I reduce the system to 170GB.

Then, I had to reduce the LV:

lvreduce -L170g /dev/hathor/home

Extending /

Obviously, the root partition can’t be unmounted. On Debian systems, the default is to remount it as read-only, you can thus safely issue:

umount /

As my aim was to use all the free space in my VG, I had to use:

lvextend -l+100%FREE /dev/hathor/root

Then, the filesystem can be safely resized, after remount /:

mount -o remount /
resize2fs /dev/hathor/root

This time, no need to specify any size, as resize2fs will automatically use all the available space.

The results

Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/hathor-root      14G  4.0G  8.7G  32% /
tmpfs                       507M     0  507M   0% /lib/init/rw
udev                         10M   52K   10M   1% /dev
tmpfs                       507M  8.0K  507M   1% /dev/shm
/dev/sda1                   236M   21M  203M  10% /boot
/dev/mapper/hathor-home     168G   20G  141G  13% /home

I now have sufficient space available on my / ;)

About

You will find here some information about me and my different projects. I am involved in several open source projects, and try to promote Free software. This site is thus mainly dedicated to Free Software use on GNU/Linux systems. Please do not hesitate to contact me for any comments on this site.