Configuring Logical Volume Manager (LVM) [Red Hat]

Don't be shellfish...twitter Configuring Logical Volume Manager (LVM) [Red Hat]google Configuring Logical Volume Manager (LVM) [Red Hat]linkedin Configuring Logical Volume Manager (LVM) [Red Hat]stumbleupon Configuring Logical Volume Manager (LVM) [Red Hat]email Configuring Logical Volume Manager (LVM) [Red Hat]facebook Configuring Logical Volume Manager (LVM) [Red Hat]

lvm Configuring Logical Volume Manager (LVM) [Red Hat]In this post I am going to explain how to configure an Logical Volume Manager (LVM) on a Red Hat based system (Red Hat, Fedora, CentOS).

With LVM, we can configure logical volume (or partition) that can be resized. It means that you can extend or reduce the logical volume size without loosing data!

How is it organized?

To setup an LVM, we will need to create one or more Physical Volume (partition). You can use fdisk and this documentation. It’s necessary that physical volumes are from the same hard drive. So actually you can prepare one physical volume from sdA and another from sdB.

The next step is group them into a Volume Group which represent a “logical hard drive” :p. Its size is the sum of every physical volumes you put. So if you have sda1 with 1Gib and sdb4 with 3Gib as physical volume into the vg0 as volume group, vg0 will have 4Gib. Then logical volume will be created from the volume group vg0.

basic lvm volume Configuring Logical Volume Manager (LVM) [Red Hat]

basic LVM

How to create LVM ?

Prepare the Physical Volume

Make sure that there is no data in your partition. If you still have not prepared a partition have look at ‘how to use fdisk‘ . Then execute the following:

root@sigmoun-redhat ~] pvcreate /dev/sdaN

To display the physical volume execute the following:

root@sigmoun-redhat ~] pvdisplay /dev/sdaN

Create / Remove a Volume Group

Create

To create the volume group execute:

root@sigmoun-redhat ~] vgcreate vgname /dev/sdaN

To display the volume group execute:

root@sigmoun-redhat ~] vgdisplay /dev/vgname
Remove

To remove the volume group execute:

root@sigmoun-redhat ~] vgremove vgname

Resize Volume Group

Resizing a volume group only consist of add or removing physical volume to / from a volume group.

Extend Volume Group
root@sigmoun-redhat ~] vgextend /dev/vgname /dev/sdaN+1
Reduce Volume Group

Make sur the physical volume you remove from the volume group does not containt any data.

root@sigmoun-redhat ~] vgreduce vgname /dev/sdaN

Create / Remove Logical Volume

Create

We create the logical volume:

root@sigmoun-redhat ~] lvcreate -n lvname -L 2G vgname

Then we install a file system into the new logical volume:

root@sigmoun-redhat ~] mkfs.ext4 /dev/vgname/lvname

If you want to mount it:

root@sigmoun-redhat ~] mkdir /mounting_point
root@sigmoun-redhat ~] mount /dev/vgname/lvname /mounting_point

To display the logical volume execute the following:

root@sigmoun-redhat ~] lvdisplay /dev/vgname/lvname
Extend Logical Volume

We extend the lvname to 3G:

root@sigmoun-redhat ~] lvextend -L 3G /dev/vgname/lvname

Then we need format the added part and so it can be used:

root@sigmoun-redhat ~] resize2fs -p /dev/vgname/lvname
Reduce Logical Volume

Before reducing a logical volume we need to unmount it:

root@sigmoun-redhat ~] umount /mounting_point

We check the file system:

root@sigmoun-redhat ~] fsck -f /dev/vgname/lvname

Then and we inform the file system of the logical volume its new size (512M) with resize2fs

root@sigmoun-redhat ~] resi2fs -p /dev/vgname/lvname 512M

Finally we reduce the logical volume:

root@sigmoun-redhat ~] lvreduce -L 512M /dev/vgname/lvname
Remove

To remove a logical volume execute:

root@sigmoun-redhat ~] lvremove /dev/vgname/lvname

That’s it! LVM is something very interesting. It lets you have easly manage your disks and partition. It will be very interesting to use it with RAID…

Anyway, if you have any suggestion or comment please let me know and share it!

Don't be shellfish...twitter Configuring Logical Volume Manager (LVM) [Red Hat]google Configuring Logical Volume Manager (LVM) [Red Hat]linkedin Configuring Logical Volume Manager (LVM) [Red Hat]stumbleupon Configuring Logical Volume Manager (LVM) [Red Hat]email Configuring Logical Volume Manager (LVM) [Red Hat]facebook Configuring Logical Volume Manager (LVM) [Red Hat]

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Current ye@r *