Logical Volume Manager(LVM), allows users to create logical volumes using one or more physical hard disks. LVM volumes can be created on both software RAID partitions and standard partitions residing on a single disk. Volumes can also be extended on the fly, providing greater flexibility to systems as requirements change.
There are some useful utilities to view information about LVM:
- pvdisplay: shows information about Physical Volumes
- vgdisplay: shows information about Volume Groups
- lvdisplay: shows information about Logical Volumes
This command will install LVM package and its dependency. “apt-get install lvm2”.
Then Create a new partition type Linux LVM.
Follow this procedure:
Make sure you don’t already have an existing /dev/sdb before issuing the commands below. You could lose some data if you issue those commands on a non-empty disk.
Enter this Fdisk /dev/sdb command and press enter. If you know the procedure move on by typing n (next) then p (primary) give enter two times to select default value.
Now you will have a new partition type “Linux” now we have to change the type to Linux LVM. Again press t to list the types then press 8e and enter, now we have Changed type of partition ‘Linux’ to ‘Linux LVM’.
To write this changes, press w and give enter.
Create the physical volume with this command “sudo pvcreate /dev/sdb”
To check the created physical volume pvdisplay:
Now we have to create volume group.
To create volume group, use this command vgcreate /dev/vg0 /dev/sdb1 (vg0 is volume name you can set as your wish)
To check the created Volume Group vgdisplay:
Now create logical volume:
To create Logical volume use this command lvcreate -L 10G -n lv0 /dev/vg0 (Here 10G is the size of the disk we want to create and lv0 is Logical Volume name and /dev/vg0 is Volume Group path)
To check the created Logical Volume vgdisplay
Now we format the partition using this command: mkfs.ext4 /dev/vg0/lv0
Then create a directory in root and mount on it.
To check or list all physical volumes (PV) created for volume group (VG) in the current system.
To dynamically add more physical volume (PV), i.e. through new hard disk or disk partition, to an existing volume group (VG) in online mode. You’ll have to manually execute vgextend after pvcreate command that creates LVM physical volume (PV).
Removing a logical volume
A logical volume must be closed before it can be removed:
umount /dev/dev/vg0/lv0
Then run this command to remove logical volume.
lvremove /dev/vg0/lv0
Conclusion:
Logical Volume Manager (LVM) is very useful for partitioning a running machine. No need of live cd or shutting down the machine.
Follow our Twitter and Facebook feeds for new releases, updates, insightful posts and more.