Or, just use LVM

Steven,

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 Responses to “Or, just use LVM”

  1. Here we are now, entertain us » Uncategorized Says:

    [...] Partitioning Bring your system into the circa 1999 era and make your system use LVM to manage partitions. Span across multiple drives, stripe, and resize with ease. [...]

  2. Ubuntu | Steven Harms: Uncategorized Says:

    [...] Partitioning Bring your system into the circa 1999 era and make your system use LVM to manage partitions. Span across multiple drives, stripe, and resize with ease. [...]

  3. Tassos Bassoukos Says:

    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.

  4. Floris Says:

    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

  5. Matthew Walster Says:

    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!

  6. Adalbert Says:

    would even be a useful tip if feisty would boot with root on lv at all

  7. Andy Says:

    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.

  8. bigredradio Says:

    There are a couple of filesystems that allow for online (hot) resizing.

    # Reiserfs
    resize_reiserfs -f /dev/myvg/homevol

    # XFS
    xfs_growfs /home

    # JFS
    mount -o remount,resize /home

    Blatantly stolen info from http://tldp.org/HOWTO/LVM-HOWTO/extendlv.html

  9. Federico Says:

    LVM is 2007, ZFS is the future. Unfortunately it seems that we, linux user, aren’t in that future…

Leave a Reply