LVM (Logical Volume Management)
LVM is a tool for logical volume management which is used to allocating disks, mirroring and resizing logical volumes.Logical volume management is widely used technique for deploying logical rather than physical storage.
With LVM we can create logical partitions that can span across one or more physical hard drives. First, the hard drives are divided into physical volumes, then those physical volumes are combined together to create the volume group and finally the logical volumes are created from volume group.
Steps for creating LVM partitions:-
- Login with root user.
- Use â€œfdiskâ€ command to create and manage partitions.
To view existing partitions use â€œfdisk -lâ€
Now according to the space available in particular hard disk, create different partitions.
For creating partitions use â€œfdisk<physical hard disk>â€
e.g.:- #fdiskÂ /dev/sda
- Press n to create new disk partition,
- Press p for primary disk partition,
- Press 1 to denote 1st partition,
- Press enter twice for taking all space from physical hard disk that we entered,
- Press t for changing its type to lvmlinux,
- Press 8e for lvmlinux,
- Finally press w to save and come out
- Use â€œpartxâ€ command for telling kernel about new partition.
â€œpartx<path of new partition>â€
e.g. #partx /dev/sda7
Creating Physical Volume
Use â€œpvcreateâ€ command for creating physical volume.
â€œpvdisplayâ€ for display all physical volume information.
Creating Volume Group
â€œvgcreateÂ vgnameÂ pvnameâ€
- This will create the volume group with specified physical volume. The size of the vg is the sum of the size of different pvâ€™s associated.
- #vgcreate vg0Â /dev/sda7
- To show all volume group information.
Creating logical volume
Use â€œlvcreateâ€ command for creating logical volume.
â€œlvcreate –size<specify size>â€“n lvnameÂ vgnameâ€
#lvcreateÂ â€“size +2GÂ -nÂ lvÂ /dev/vg0
This command will create a logical volume of size 2GB that will be taken from volume group vg0.
Next step is to format the logical volume to support linux file system.
â€œmkfs.ext4 <path of lv>â€
Finally mount the logical volume into lvm partition.
Before mounting create a mount point
Mount point created as /lvm
#mountÂ /dev/vg0/lvÂ /lvm
This will mount the logical volume.