This article describes a basic logic behind a Linux logical volume manager by showing real examples of configuration and usage. Although Debian Linux will be used for this tutorial, you can also apply the same command line syntax with other Linux distributions such as Red Hat, Mandriva, SuSe Linux and others.

This is what we are going to do

Create Partitions

For this Linux lvm example you need an unpartitioned hard disk /dev/sdb. First you need to create physical volumes. To do this you need partitions or a whole disk. It is possible to run pvcreate command on /dev/sdb, but I prefer to use partitions and from partitions I later create physical volumes.

Use your preferred partitioning tool to create partitions. In this example I have used cfdisk.

Create Virtual Group

At this stage you need to create a virtual group which will serve as a container for your physical volumes. To create a virtual group with the name "mynew_vg" which will include /dev/sdb1 partition, you can issue the following linux command:

# vgcreate mynew_vg /dev/sdb1

To include both partitions at once you can use this command:

# vgcreate mynew_vg /dev/sdb1 /dev/sdb2

Feel free to add new physical volumes to a virtual group by using the vgextend command.

# vgextend mynew_vg /dev/sdb2

Create Logical Volumes

From your big cake (virtual group) you can cut pieces (logical volumes) which will be treated as a partitions for your linux system. To create a logical volume, named "vol01", with a size of 400 MB from the virtual group "mynew_vg" use the following linux command:

create a logical volume of size 400 MB -L 400

create a logical volume of size 4 GB -L 4G

# lvcreate -L 400 -n vol01 mynew_vg

With a following example you will create a logical volume with a size of 1GB and with the name vol02:

# lvcreate -L 1000 -n vol02 mynew_vg

Note the free size in virtual group.

Create File system on logical volumes

The logical volume is almost ready to use. All you need to do is to create a filesystem.:

# mkfs.ext3 -m 0 /dev/mynew_vg/vol01

the -m option specifies the percentage reserved for the super-user, set this to 0 if you wish not to waste any space, the default is 5%.

Edit /etc/fstab

Add an entry for your newly created logical volume into /etc/fstab

Mount logical volumes

Before you mount do not forget to create a mount point.

# mkdir /home/foobar

Extend logical volume

The biggest advantage of logical volume manager is that you can extend your logical volumes any time you are running out of the space. To increase the size of a logical volume by another 800 MB you can run this command:

# lvextend -L +800 /dev/mynew_vg/vol01

The command above does not actually increase the physical size of volume, to do that you need to:

# resize2fs /dev/mynew_vg/vol01

Look at the figure below to see what problems you may encounter when extending a volume:

Remove logical volume

The command lvremove can be used to remove logical volumes. Make sure that before you attempt to remove logical volumes your logical volume does not have any valuable data stored on it, moreover, make sure the volume is unmounted.

# lvdisplay

# lvremove /dev/mynew_vg/vol02

ARE YOU LOOKING FOR A LINUX JOB?Submit your RESUME or create a JOB ALERT on LinuxCareers.com job portal.

DO YOU NEED ADDITIONAL HELP?Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in:

Comments and Discussions

SUPPORT US

LinuxConfig.org team is determined to provide you with simple to follow Linux tutorials, various tips, tricks and programming guides as well as with GNU/Linux system administration tutorials in general to help you to learn Linux faster and use it with ease.

Donations

Bitcoin (BTC) Address:1PyYJEVtxkokkYtLkRw9BA7Fr4xEAXJn3U

Litecoin (LTC) Address:LXvDNUcdKuh3Svge358rNanXfXMKcPkxCo

Thank You

Write For Us

LinuxConfig is looking for a technical writer(s) geared towards GNU/Linux and FLOSS technologies. Your articles will feature various GNU/Linux configuration tutorials and FLOSS technologies used in combination with GNU/Linux operating system.

When writing your articles you will be expected to be able to keep up with a technological advancement regarding the above mentioned technical area of expertise. You will work independently and be able to produce at minimum 2 technical articles a month.