Categories
Linux/BSD

On resizing filesystems and LVM2 logical volumes

I’ve been using Debian squeeze/sid for a while now (with apt-pinning) and for the past few days I’ve been facing the “no space left to write” problem. I used the default LVM2-based disk partitioning scheme offered by the Debian installer. I thought it was okay to have a 6.5G root partition and the rest for the swap and my home partitions. Looks like 6.5G wasn’t enough for me. And the root and home partitions used the ext4(!) file-systems.

Now, here’s how you go about reducing your home’s size and increasing your root’s size.

  1. Reduce the filesystem size of the partition which has enough free space to spare using resize2fs.
  2. Then reduce the logical volume in which this filesystem resides using lvreduce.
  3. Now extend the logical volume in which the “starving” filesystem resides  using lvextend by the same amount you used in step 2.
  4. Then simply issue resize2fs /dev/VGNAME/LVNAME which should simply fill up the unallocated space in the logical volume it resides.
  5. (optional), if your reduced filesystem doesn’t mount due to a block-size mismatch, e2fsck it and apply step 4. to it.

Glad that it all worked out fine. I didn’t have to use a live cd to do this (was too lazy for that anyway). I dropped into a vt, unmounted my home (which has the “important” data) and performed steps 1 and 2 on it. My root was still mounted while I did steps 3 and 4 on it.