Description:
LVM is a tool for logical volume management, which includes allocating disks, striping, mirroring and resizing logical volumes. LVM allow you to manage disk space more effectively. 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.
Configure Logical Volume:
First create three partitions using fdisk or gdisk. In this example I have create 3 partition /dev/sda5, /dev/sdb1 and /dev/sdc1
After create partition need to convert to physical volume using below command:
# pvcreate /dev/sda5 /dev/sdb1 /dev/sdc1
Physical volume "/dev/sda5" successfully created
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdc1" successfully created
Once physical volume created you need to create volume group of all three partition using below command:
# vgcreate vg0 /dev/sda5 /dev/sdb1 /dev/sdc1
Volume group "vg0" successfully created
You can use the vgs command to display the attributes of the new volume group
Now you can create logical volume from volume group using below command:
# lvcreate –L 100 G –n lv0 vg0
Logical volume "lv0" created
Note : lv0 is logical volume name
Create a file system on the logical volume using below command
# mkfs –t ext4 /dev/vg0/lv0
Mount logical volume to directory
# mount /dev/vg0/lv0 /storage
Extending a logical volume:
Extend logical volume using below command.
# lvextend -L12G /dev/vg0/lv0
lvextend -- extending logical volume "/dev/vg0/lv0" to 12 GB
lvextend -- doing automatic backup of volume group "vg0"
lvextend -- logical volume "/dev/vg0/lv0" successfully extended
# lvextend -L+1G /dev/vg0/lv0
lvextend -- extending logical volume "/dev/vg0/lv0" to 13 GB
lvextend -- doing automatic backup of volume group "vg0"
lvextend -- logical volume "/dev/vg0/lv0" successfully extended
After you have extended the logical volume, it is necessary to increase the file system size to match.
# umount /dev/vg0/lv0
# resize2fs /dev/vg0/lv0
# mount /dev/vg0/lv0 /storage
Reducing a Logical Volume:
First, unmount partition using below command
# umount /storage
Check file system for error using e2fsck command
# e2fsck –f /dev/vg0/lv0
Note: In the above command e2fsck, we use the option ‘-f’ to forcefully check the file system, even if the file system is clean.
Reduce or Shrink the size of /storage to desire size
# resize2fs /dev/vg0/lv0 10G
Now reduce the size using lvreduce command.
# lvreduce -L 10G /dev/vg0/lv0
For the safer side, now check the reduced file system for errors
# e2fsck -f /dev/vg0/lv0
Mount the file system and verify its size.
# mount /dev/vg0/lv0 /storage
No comments:
Post a Comment