Logical volume manager (LVM)

What is LVM ?

Logical volume manager (LVM) introduces an extra layer between the physical disks and the file system allowing file systems to be resized and moved easily and online without requiring a system-wide outage.

LVM is a tool for logical volume management which includes allocating disks, striping, mirroring and resizing logical volumes

 

Here there is two examples to practice LVM :

Example 1 :

Create the “LVM” with the name “source” by using 26PE’s from the volume group “open”. Consider the PE size as “8MB”. Mount it on /mnt/secret with filesystem vfat.

create a partition
# fdisk /dev/sda (n, p, 3, +300M, t, 8e , w)
Force reading partition table by the kernel
# partprobe /dev/sda
create a physical volume
# pvcreate /dev/sda3
create a volume group with a size of PE = 8M
# vgcreate –s 8M open /dev/sda3
creatie a logical volume from the volume group 26PE’s
# lvcreate –n source –l 26 open 
assign the vfat file system type to the logical volume
# mkfs.vfat /dev/open/source 
create the mount point
# mkdir /mnt/secret 
mounting the logical volume persistently
# vim /etc/fstab 

/dev/mapper/open-source /mnt/secret vfat defaults 1 2

# mount -a

 

Example 2 :

Resize the lvm “/dev/vgsrv/home” (/dev/myvol/vo) so that after reboot size should be in between 90MB to 120MB..

Show details about the logical volume
# lvdisplay /dev/vgsrv/home 
Show details about the volume group
# vgdisplay vgsrv 
Extend the logical group
# lvextend –L +volume_to_add /dev/vgsrv/home
Extend the file system
# mount | grep /dev/mapper/vgsrv-home (To show file system type)

# xfs_growfs file_system_name (if type of the file system is xfs)

# resize2fs logical_volume_name (if type of the file system is ext4)

 

Note: If we want to reduce the size of 100Mb

# umount /dev/vgsrv/home 

# Lvreduce –L 100M /dev/vgsrv/home -r

# mount /dev/vgsrv/home