Or, just use LVM


Or just use LVM which removes the error-prone and nail-biting fdisk step:

  • Unmount filesystem.
  • Extend the logical volume:
    $ sudo lvextend -L2G /dev/vgname/lvname
  • fsck the filesystem:
    $ sudo fsck.ext3 -f /dev/vgname/lvname
  • Extend the filesystem:
    $ sudo resize2fs /dev/vgname/lvname
  • Mount it again.

Note a couple of things:

  • At no point did you have to delete a partition and create it again.
  • There was no need to remember any strange numbers, only the final size you wanted it to go to. This size could also have been specified as an offset: -L+2G extends the existing LV by 2GiB.
  • There is no need to remove the ext3 journal: a clean and unmounted ext3 filesystem has no journal anyway, that’s why the fsck step is done. resize2fs will tell you to do fsck if you don’t do it yourself anyway.

Also bear in mind that any logical volume can be extended as long as there are free extents available in the volume group. Whereas without LVM, it is hard to extend a partition in the middle of the disk.

Just some of the reasons why I think almost every Linux machine should use LVM.

Finally, I have heard that with recent kernels and e2fsprogs the resize2fs can be done on a mounted fs. I have not tried this though.

9 thoughts on “Or, just use LVM

  1. I’ve been using EVMS, a solution from IBM that is in Ubuntu by default and it’s even easier – apt-get install evms-ncurses and resizing a partition is just some menu options away.

  2. You can enlarge an ext2/3 filesystem while it is mounted, that is correct and works like a charm! Shrinking on the other hand is not possible

  3. Your three commands are nice, but I believe there’s a function within lvextend that will even resize the ext3 partition as well, doing things in the right order. So, that cuts it down to one command to do it all! Can’t find it using Google, but I know it exists, that’s how I extended my Xen array about 6 months ago!

  4. Adalbert, I’m not sure if Feisty’s installer would let you set that up. I only use Ubunty Edgy on my laptop at the moment and I had a hard time doing LVM in that installer; I set all the LVM up afterwards.

    Note that putting / on LVM requires you to use an initrd with the devicemapper and LVM support in it. You may have to regenerate your initrd for that to work.

    Personally I don’t put / on LVM because it makes life more difficult than the advantages are worth. With everything else (/usr, /var, /tmp, /home and so on) in their own LVs, root can be very small and little need to resize it.

Leave a Reply

Your email address will not be published. Required fields are marked *