Skip to content

A few more playing with LVM: creating, mounting and removing a partition

The way 1&1 provide their “cloud” (btw, it looks like my feeling about this meaningless word was right, after all ;)) is really unusual to me and gives me quite a few things to learn about. That’s how half a year ago I posted about extending and shrinking LVM volumes. It however had an important limitation: once the filesystem is extended, it’s in most cases not possible to shrink it, so you can forget about shrinking the volume unless you don’t mind losing the whole partition.
My workaround for that was just to increase volume size on a strict need-more-space basis, which of course leads to quite a massive waste of unused space. A few days ago, I finally searched a way to implement a better solution: creating a new LVM partition. So with all the unused space we can create a temporary partition that we can use to store temporary stuff, and when we need to expand the production partitions, we can just erase the temp partition, expand the prod partitions, then create a new temp partition over the remaining space.

The steps are actually fairly simple:

  • find out the name of your LVM volume(s) and group(s): pvs
  • let’s say you have a group named “vg00” with 50 GiB free space, and we want to create a volume named “espace1” which would take all this space. First we check what volumes are already in that group: lvdisplay /dev/vg00
    Then we create the “espace1” volume: lvcreate -L50G -nespace1 vg00
  • now we format it, say, in ext3: mkfs -t ext3 -m 0 -v /dev/vg00/espace1
    Note that the “-m 0” means that we claim back the 5% (“-m 5”) space usually reserved for root. This is good for a storage partition, but not a good idea for a system partition.
  • then we create the mounting point, for instance: mkdir /home/espace1
  • and all we have to do now is to mount it: mount -t ext3 /dev/vg00/espace1 /home/espace1

That’s it, your new partition is ready. You can also check out the results using df -h. You’ll probably want to make sure it’s automatically mounted at boot time, too: for this just add a line in /etc/fstab (nano /etc/fstab). For instance here’s our fstab file (note the last line with our new partition):

/dev/xvda1      /               ext3    defaults        1 1
/dev/xvda2      none            swap    sw
/dev/vg00/usr   /usr            xfs     defaults        0 2
/dev/vg00/var   /var            xfs     defaults        0 2
/dev/vg00/home  /home           xfs     defaults,usrquota       0 2
devpts          /dev/pts        devpts  gid=5,mode=620  0 0
none            /proc           proc    defaults        0 0
none            /tmp    tmpfs   defaults        0 0
/dev/vg00/espace1  /home/espace1    ext3   defaults     0 2

For some more details on the fstab file, see Tuxfiles – How to edit and understand /etc/fstab and Dushan888 – Configuring+Understanding ‘/etc/fstab’

Finally, to destroy it, you just need to unmount it first, so:
umount /dev/vg00/espace1 => unmount
lvremove /dev/vg00/espace1 => delete the volume

This time that’s all, the circle of life of the volume is complete 😉 Here are the sources I used, in the last one you’ll also find how to create the whole LVM thing, not just a volume within it like we did here:

Posted in Linux, servers.

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

or, reply to this post via trackback.

Sorry about the CAPTCHA that requires JS. If you really don't want to enable JS and still want to comment, you can send me your comment via e-mail and I'll post it for you.

Please solve the CAPTCHA below in order to fight spamWordPress CAPTCHA