What are the advantages of LVM?

Dick Davies rasputnik at gmail.com
Sat May 20 20:03:32 UTC 2006


On 20/05/06, David M <lists2006 at viewport.ukfsn.org> wrote:

> The LVM setup decided to set up a volume group for /, and another one
> for swap, each of which contained a partition for / and swap
> respectively. This was followed by stern warnings about how these were
> permanent group settings which could not then ever be changed.

Last time I tried, it made two *logical volumes* (for / and swap as you say),
but both in the same volume group.

Don't remember that warning, but that's not the case - you'll be able to resize
both of those, but not / without booting off a live CD or similar
(see below).

> So, I decided to try to split / into / and /home, but found I was unable
> to do this: I couldn't resize the / partition (which is what I thought
> was the point of LVM?), so I'm a bit perplexed as to what I would
> actually have gained with LVM: I thought it was supposed to allow more
> flexibility in resizing partitions?

The point of LVM is to abstract away your disks into 'storage', which you can
work with more flexibly than disks allow.

The trouble is, / is mounted. The usual drill to split up running
logical volumes
(LVs) is:

1.  shrink the filesystem on the LV
2. resize the LV (freeing space in the volume group)
3. use the spare space in the VG to make a new LV
4. Treat the LV like any other new disk partition
   (mkfs it, mount it and start using it)

Trouble is that you need to unmount the filesystem to resize it (at
least to shrink
it). But that's a problem with Linux filesystems, not LVM (XFS filesystems,
for example, can't be shrunk at all).

It's generally best with LVM to start with conservatively-sized
partitions - most
decent filesystems can be grown while the filesystem is still mounted
(I like reiserfs, but that's mainly personal taste).
Keep a few Gb in reserve in the volume group, and the next time a large
ISO is 50% downloading and you notice /home is 98% full, you'll be
glad you did :)

Say I want to grow /usr.

    rasputnik at hypnotoad:~$ df -h /usr
    Filesystem                    Size  Used Avail Use% Mounted on
    /dev/mapper/chunk-usr   2.6G  1.9G  630M  76% /usr

Check I've got some free space in that volume group:

    rasputnik at hypnotoad:~$ sudo vgs
      VG    #PV #LV #SN Attr   VSize  VFree
      chunk   2   9   0 wz--n- 17.76G     5.56G

Cool, 5Gb to free up. First, I add a few hundred Mb to the logical volume
(the 'device'):

    rasputnik at hypnotoad:~$ sudo lvextend -L +400M /dev/chunk/usr
      Extending logical volume usr to 2.90 GB
      Logical volume usr successfully resized

Now I can grow the filesystem. No need to umount (thanks Hans!):

    rasputnik at hypnotoad:~$ sudo resize_reiserfs -s +400M /dev/chunk/usr
    resize_reiserfs 3.6.19 (2003 www.namesys.com)
            resize_reiserfs: On-line resizing finished successfully.

Et voila! Space for more junk.

    rasputnik at hypnotoad:~$ df -h /usr
    Filesystem                   Size  Used Avail Use% Mounted on
    /dev/mapper/chunk-usr  3.0G  1.9G  1.1G  66% /usr

I wroteup what else I like about it at

  http://number9.hellooperator.net/articles/2005/10/10/loveit-very-much

-- 
Rasputin :: Jack of All Trades - Master of Nuns
http://number9.hellooperator.net/




More information about the ubuntu-users mailing list