Creating a logical volume


Architecture :

vikki_lvcreate

Step 1:

Creating physical volume

Following disk will be used to create the logical volume
/dev/sdb – 10GB
/dev/sdc – 10GB
/dev/sdd – 10GB
/dev/sde – 10GB

[root@server1 ~]# fdisk -l |grep “Disk /dev/”
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Disk /dev/sdc: 10.7 GB, 10737418240 bytes, 20971520 sectors
Disk /dev/sde: 10.7 GB, 10737418240 bytes, 20971520 sectors
Disk /dev/sdd: 10.7 GB, 10737418240 bytes, 20971520 sectors

 

[root@server1 ~]# pvcreate /dev/sdb /dev/sdc /dev/sdd /dev/sde
Physical volume “/dev/sdb” successfully created
Physical volume “/dev/sdc” successfully created
Physical volume “/dev/sdd” successfully created
Physical volume “/dev/sde” successfully created

Verify the physical volume

[root@server1 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 a– 10.00g 10.00g
/dev/sdc lvm2 a– 10.00g 10.00g
/dev/sdd lvm2 a– 10.00g 10.00g
/dev/sde lvm2 a– 10.00g 10.00g

 

Step 2:

Creating volume group(VG01)

[root@server1 ~]# vgcreate VG01 /dev/sdb /dev/sdc /dev/sdd /dev/sde
Volume group “VG01” successfully created
Verify the volume group
[root@server1 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VG01 4 0 0 wz–n- 39.98g 39.98g

 

Step 3:

Creating the logical volume(LV01)

[root@server1 ~]# lvcreate -L 25G -n LV01 VG01
Logical volume “LV01” createdVerify the Logical volume
[root@server1 ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
LV01 VG01 -wi-a—– 25.00g

 

[root@server1 ~]# lvdisplay
— Logical volume —
LV Path /dev/VG01/LV01
LV Name LV01
VG Name VG01
LV UUID qbz4nZ-Eo7g-GmMv-nGGF-MR2P-ENcP-YeoCSG
LV Write Access read/write
LV Creation host, time server1.vikki.in, 2016-05-09 23:20:23 +0530
LV Status available
# open 0
LV Size 25.00 GiB
Current LE 6400
Segments 3
Allocation inherit
Read ahead sectors auto
– currently set to 8192
Block device 253:0

 

Step 4:

Creating file system over logical volume

[root@server1 ~]# mkfs -t ext4 /dev/VG01/LV01
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1638400 inodes, 6553600 blocks
327680 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2155872256
200 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

 

Step 5:

Mounting the logical volume

[root@server1 ~]# mkdir /mount_point
[root@server1 ~]# mount /dev/VG01/LV01 /mount_point/
[root@server1 ~]# df -h /mount_point/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VG01-LV01 25G 45M 24G 1% /mount_point

Permanent mounting the logical volume

[root@server1 ~]# blkid /dev/mapper/VG01-LV01
/dev/mapper/VG01-LV01: UUID=”1a9851c8-5c0c-4dc7-a8df-81219a3eb53c” TYPE=”ext4″[root@server1 ~]# cat /etc/fstab |grep /mount_point
UUID=1a9851c8-5c0c-4dc7-a8df-81219a3eb53c /mount_point ext4 defaults 0 1

 

[root@server1 ~]# umount /mount_point/
[root@server1 ~]# mount -a
[root@server1 ~]# df -h /mount_point/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VG01-LV01 25G 45M 24G 1% /mount_point

Optional:

Logical volume can also created  based on number of physical extend
To check the size of physical extend

[root@server1 ~]# vgdisplay VG01 |grep “PE Size”
PE Size 4.00 MiB

Here it is 4MB . so to create a logical volume of 40MB we need 10 PE

Creating Logical volume with number of physical extend

[root@server1 ~]# lvcreate -l 10 -n LV02 VG01
Logical volume “LV02” created

 

[root@server1 ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
LV01 VG01 -wi-ao—- 25.00g
LV02 VG01 -wi-a—– 40.00m