Logical Volume Manager Cheatsheet

Today I got a new harddisk, so it was finally time for me to have an in depth look at LVM. I use it to combine two harddisks /dev/sdg1 and /dev/sdb1 into one volume group ext_vg which contains one big logical volume /dev/ext_vg/ext. In short, my 250GB and 500GB harddisks are used in one big 750GB ext3 mount point.

I followed the excellent LVM Tutorial, and was surprised how easy everything goes. Here is a short cheat sheet of the important commands (take care to exchange the partition/volume names if you use this):

Installation

I use Ubuntu, so this is a piece of cake:

There is also a GUI available, but I found the command line tools are very easy to use so there is no real need. I wouldn’t use EVMS as it is not supported in Ubuntu 7.10 and may cause problems.

Create a New Filesystem

First I create the physical volume on the partition sdg1, create a new volume group ext_vg that contains this physical volume, and create a new logical volume of size 450GB within the volume group. Finally create the filesystem (disabled reservation space, see Get More Space Out of Your ext3 Partition).

Show Status

Each LVM layer has its corresponding command to get information about the metadata:

Mount via fstab

I use the filesystem mainly for data, so allowing just rw is enough (no executables allowed). noatime allows quicker access.

Resize

It is even possible to do an online resize of the system, wohoo 🙂 This extends the logical volume by 200MB.

You can watch the resize process going on with df -h.

Add Another Partition to the Logical Volume

To add another partition and use up all the available space in the logical volume, first add the physical volume to the volume group, then use pvdisplay to find out the total available number of free PE (add the numbers from the physical volumes), then use lvextend to use up all this available space.

That’s it! Any questions? please post.

8 Comments on "Logical Volume Manager Cheatsheet"

Notify of
avatar
Christian
Guest

Thanks Martin, that was just what I was looking for 🙂 I had been too lazy about it to bother to figure it out :shame: But now I can safely say goodbye to runlevel 5
:byebye:

Martin Ankerl
Guest

Hi christian, glad you like it 🙂 Using only command line tools for LVM is really quite easy, the only obstactle is reading through the manual (which is very good).

Christian
Guest

Martin,

one usefull addition could be to mention certain switches when creating LV:
lvcreate -l 100%VG -n mynew_lv mynew_vg

The -l switch has some meta options for adding 100% of the Volume Group (VG), or 100%FREE to allocate all of the free space.

Otherwise you have to figure out how many extends a volume has or how much left, etc. These meta option are much easier to remember (at least for me)
🙂

thanks again!

trackback

[…] Logical Volume Manager Cheat Sheet […]

Andrea
Guest

Great tutorial,

I found it very (very!!!) useful!

Thanks

Heston Holtmann
Guest

Nice summary… but how would you move a Logical Volume from one VG to a completely different VG?

I thought it would be possible with the `pvmove` command but it appears to only work for moving Physical Extents of a LV from one VG device to another.

trackback

[…] you want to find out some more commands here you find a very nice LVM tutorial I've consulted […]

trackback

[…] Logical Volume Manager Cheatsheet | Martin AnkerlFeb 5, 2008 … I wouldn’t use EVMS as it is not supported in Ubuntu 7.10 and may … numbers from the physical volumes), then use lvextend to use up all this … […]

wpDiscuz