Create and remove physical volumes, assign physical volumes to volume groups, and create and delete logical volumes (LVM) Part II

LVM Diagram

For this exercise, we will start with this partition table:

# fdisk -l /dev/vdb
Disk /dev/vdb: 2254 MB, 2254858240 bytes, 4404020 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x3faed0a2
Device Boot Start End Blocks Id System
/dev/vdb1 2048 514047 256000 8e Linux LVM
/dev/vdb2 514048 1026047 256000 8e Linux LVM
/dev/vdb3 1026048 1538047 256000 8e Linux LVM
/dev/vdb4 1538048 4404019 1432986 5 Extended
/dev/vdb5 1540096 2052095 256000 8e Linux LVM

Create the physical volumes:

# pvcreate /dev/vdb{1,2,3,5,}
Physical volume "/dev/vdb1" successfully created.
Physical volume "/dev/vdb2" successfully created.
Physical volume "/dev/vdb3" successfully created.
Physical volume "/dev/vdb5" successfully created.

Create the volume group vg1:

# pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 myvg1 lvm2 a-- 6.00g 4.00m
/dev/vdb1 lvm2 --- 250.00m 250.00m
/dev/vdb2 lvm2 --- 250.00m 250.00m
/dev/vdb3 lvm2 --- 250.00m 250.00m
/dev/vdb5 lvm2 --- 250.00m 250.00m

# vgcreate vg1 /dev/vdb1 /dev/vdb2
Volume group "vg1" successfully created

# vgs
VG #PV #LV #SN Attr VSize VFree
myvg1 1 2 0 wz--n- 6.00g 4.00m
vg1 2 0 0 wz--n- 496.00m 496.00m

# vgdisplay vg1
--- Volume group ---
VG Name vg1
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 496.00 MiB
PE Size 4.00 MiB

Total PE 124
Alloc PE / Size 0 / 0
Free PE / Size 124 / 496.00 MiB
VG UUID H5xfdb-W8gj-woUO-nRzU-eWrQ-b1hd-qj4Wak

Create the volume group vg2 with a size of 16 MB:

# pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 myvg1 lvm2 a-- 6.00g 4.00m
/dev/vdb1 vg1 lvm2 a-- 248.00m 248.00m
/dev/vdb2 vg1 lvm2 a-- 248.00m 248.00m
/dev/vdb3 lvm2 --- 250.00m 250.00m
/dev/vdb5 lvm2 --- 250.00m 250.00m

# vgcreate vg2 -s 16M /dev/vdb3 /dev/vdb5
Volume group "vg2" successfully created

# vgs
VG #PV #LV #SN Attr VSize VFree
myvg1 1 2 0 wz--n- 6.00g 4.00m
vg1 2 0 0 wz--n- 496.00m 496.00m
vg2 2 0 0 wz--n- 480.00m 480.00m

# vgdisplay vg2
--- Volume group ---
VG Name vg2
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 480.00 MiB
PE Size 16.00 MiB

Total PE 30
Alloc PE / Size 0 / 0
Free PE / Size 30 / 480.00 MiB
VG UUID if1oYq-oCBz-bR0Y-Q4t1-1wsT-Tnud-fgMez3

For VG vg1, create the logical volume lv01(100 MB) and lv02(20 LE):

# lvcreate vg1 -n lv01 -L 100M
Logical volume "lv01" created.

# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root myvg1 -wi-ao---- 5.29g
swap myvg1 -wi-ao---- 716.00m
lv01 vg1 -wi-a----- 100.00m

# lvcreate vg1 -n lv02 -l 20
Logical volume "lv02" created.

# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root myvg1 -wi-ao---- 5.29g
swap myvg1 -wi-ao---- 716.00m
lv01 vg1 -wi-a----- 100.00m
lv02 vg1 -wi-a----- 80.00m

For VG vg2, create the logical volume lv03(20 LE) and lv04(100 MB):

# lvcreate vg2 -n lv03 -l 20
Logical volume "lv03" created.

# lvcreate vg2 -n lv04 -L 100M
Rounding up size to full physical extent 112.00 MiB
Logical volume "lv04" created.

# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root myvg1 -wi-ao---- 5.29g
swap myvg1 -wi-ao---- 716.00m
lv01 vg1 -wi-a----- 100.00m
lv02 vg1 -wi-a----- 80.00m
lv03 vg2 -wi-a----- 320.00m
lv04 vg2 -wi-a----- 112.00m

And we format these volumes as ext4:

# mkfs.ext4 /dev/vg1/lv01
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

[root@cliente1 dev]# mkfs.ext4 /dev/vg1/lv02
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
20480 inodes, 81920 blocks
4096 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33685504
10 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

[root@cliente1 dev]# mkfs.ext4 /dev/vg2/lv03
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
81920 inodes, 327680 blocks
16384 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33947648
40 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

[root@cliente1 dev]# mkfs.ext4 /dev/vg2/lv04
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
28672 inodes, 114688 blocks
5734 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33685504
14 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

[root@cliente1 dev]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root myvg1 -wi-ao---- 5.29g
swap myvg1 -wi-ao---- 716.00m
lv01 vg1 -wi-a----- 100.00m
lv02 vg1 -wi-a----- 80.00m
lv03 vg2 -wi-a----- 320.00m
lv04 vg2 -wi-a----- 112.00m

and check the new volumes created with blkid command:

 # blkid | grep vg
/dev/mapper/myvg1-root: UUID="a2069214-b13a-4afb-95a8-69fedb70b3d1" TYPE="xfs"
/dev/mapper/myvg1-swap: UUID="9ae5b86c-6b97-47dc-bb56-c17a234e8907" TYPE="swap"
/dev/mapper/vg1-lv01: UUID="d759a731-780d-443a-8aad-b63d873080af" TYPE="ext4"
/dev/mapper/vg1-lv02: UUID="73e5ac3d-9036-4bdd-a90a-65763f756166" TYPE="ext4"
/dev/mapper/vg2-lv03: UUID="51df1b35-1f8e-40ea-a2c7-ae90aa3fc842" TYPE="ext4"
/dev/mapper/vg2-lv04: UUID="5b641810-5d4c-4ffb-afc5-dad4776c11ad" TYPE="ext4"

Now create the mount points:

# mkdir /mnt/{lv01,lv02,lv03,lv04}
[root@cliente1 dev]# cd /mnt/
[root@cliente1 mnt]# ll
total 0
drwxr-xr-x. 2 root root 6 Jun 14 20:03 lv01
drwxr-xr-x. 2 root root 6 Jun 14 20:03 lv02
drwxr-xr-x. 2 root root 6 Jun 14 20:03 lv03
drwxr-xr-x. 2 root root 6 Jun 14 20:03 lv04

And mount these volumes (or fs):

Copy the output of the blkid | grep vg command, and edit the fstab file with that information:

/etc/fstab file

Finally, we check and mount all :

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/myvg1-root 5.3G 3.0G 2.4G 57% /
devtmpfs 905M 0 905M 0% /dev
tmpfs 920M 188K 920M 1% /dev/shm
tmpfs 920M 8.9M 911M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
/dev/vda1 1014M 173M 842M 17% /boot
tmpfs 184M 4.0K 184M 1% /run/user/42
tmpfs 184M 24K 184M 1% /run/user/1000
tmpfs 184M 0 184M 0% /run/user/0

[root@cliente1 mnt]# mount -a

[root@cliente1 mnt]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/myvg1-root 5.3G 3.0G 2.4G 57% /
devtmpfs 905M 0 905M 0% /dev
tmpfs 920M 188K 920M 1% /dev/shm
tmpfs 920M 8.9M 911M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
/dev/vda1 1014M 173M 842M 17% /boot
tmpfs 184M 4.0K 184M 1% /run/user/42
tmpfs 184M 24K 184M 1% /run/user/1000
tmpfs 184M 0 184M 0% /run/user/0
/dev/mapper/vg1-lv01 93M 1.6M 85M 2% /mnt/lv01
/dev/mapper/vg1-lv02 74M 1.6M 67M 3% /mnt/lv02
/dev/mapper/vg2-lv03 302M 2.1M 280M 1% /mnt/lv03
/dev/mapper/vg2-lv04 105M 1.6M 96M 2% /mnt/lv04

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *