PV, VG, LM exercise lsblk vgcreate lvcreate mkfs.xfs lvs vgs vgextend
we can resize root filesystem with LVM running it
fdsik /dev/sdc
Disk /dev/sdc: 10.7 GB, 10737418240 bytes, 20971520 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: 0xcbbe4aaa
Device Boot Start End Blocks Id System
/dev/sdc1 2048 104447 51200 83 Linux
/dev/sdc2 104448 186367 40960 83 Linux
/dev/sdc3 186368 595967 204800 8e Linux LVM
Command (m for help): w
partprobe /dev/sdc
=========================
[root@localhost ~]# cat /proc/partitions
major minor #blocks name
8 0 41943040 sda
...
...
8 32 10485760 sdc
8 33 51200 sdc1
8 34 40960 sdc2
8 35 204800 sdc3
11 0 8086528 sr0
253 0 38789120 dm-0
253 1 2097152 dm-1
253 2 94208 dm-2
[root@localhost ~]#
[root@localhost ~]# mkfs.xfs /dev/vgwhatever/lvmyvol
meta-data=/dev/vgwhatever/lvmyvol isize=512 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]#
fdsik /dev/sdc
Disk /dev/sdc: 10.7 GB, 10737418240 bytes, 20971520 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: 0xcbbe4aaa
Device Boot Start End Blocks Id System
/dev/sdc1 2048 104447 51200 83 Linux
/dev/sdc2 104448 186367 40960 83 Linux
/dev/sdc3 186368 595967 204800 8e Linux LVM
Command (m for help): w
partprobe /dev/sdc
=========================
[root@localhost ~]# cat /proc/partitions
major minor #blocks name
8 0 41943040 sda
...
...
8 32 10485760 sdc
8 33 51200 sdc1
8 34 40960 sdc2
8 35 204800 sdc3
11 0 8086528 sr0
253 0 38789120 dm-0
253 1 2097152 dm-1
253 2 94208 dm-2
[root@localhost ~]#
==========================
[root@localhost ~]# lsblk
...
...
sdc 8:32 0 10G 0 disk
├─sdc1 8:33 0 50M 0 part /sdcmount
├─sdc2 8:34 0 40M 0 part /lsdc
└─sdc3 8:35 0 200M 0 part
sr0 11:0 1 7.7G 0 rom /run/media/bit/CentOS 7 x86_64
[root@localhost ~]#
==========================
[root@localhost ~]# pvcreate /dev/sdc3
(optional step)
if you run vgcreate it will automatically create physical volume
WARNING: swap signature detected on /dev/sdc3 at offset 4086. Wipe it? [y/n]: y
Wiping swap signature on /dev/sdc3.
Physical volume "/dev/sdc3" successfully created.
[root@localhost ~]#
==========================
[root@localhost ~]# vgcreate vgwhatever /dev/sdc3
Volume group "vgwhatever" successfully created
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
cl 1 2 0 wz--n- 39.00g 4.00m
vg_sdbmount 1 1 0 wz--n- 96.00m 4.00m
vgwhatever 1 0 0 wz--n- 196.00m 196.00m
[root@localhost ~]#
==========================
[root@localhost ~]# lvcreate -n lvmyvol -L 100M vgwhatever
Logical volume "lvmyvol" created.
[root@localhost ~]#
==========================
meta-data=/dev/vgwhatever/lvmyvol isize=512 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]#
==========================
lvs — report information about logical volumes
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root cl -wi-ao---- 36.99g
swap cl -wi-ao---- 2.00g
lv_sdb vg_sdbmount -wi-a----- 92.00m
lvmyvol vgwhatever -wi-a----- 100.00m
[root@localhost ~]#
lvs — report information about logical volumes
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root cl -wi-ao---- 36.99g
swap cl -wi-ao---- 2.00g
lv_sdb vg_sdbmount -wi-a----- 92.00m
lvmyvol vgwhatever -wi-a----- 100.00m
[root@localhost ~]#
==========================
[root@localhost ~]# mkdir /hallo; mount /dev/vgwhatever/lvmyvol /hallo
[root@localhost ~]# mount | grep my
/dev/mapper/vgwhatever-lvmyvol on /hallo type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
[root@localhost ~]#
===========================
[root@localhost ~]# cd /hallo/
[root@localhost hallo]# dd if=/dev/zero of=bigfile
dd: writing to ‘bigfile’: No space left on device
187329+0 records in
187328+0 records out
95911936 bytes (96 MB) copied, 0.360617 s, 266 MB/s
[root@localhost hallo]#
==========================
[root@localhost hallo]# df -hk
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/cl-root 38770180 4735892 34034288 13% /
devtmpfs 488984 0 488984 0% /dev
tmpfs 499968 156 499812 1% /dev/shm
tmpfs 499968 7236 492732 2% /run
tmpfs 499968 0 499968 0% /sys/fs/cgroup
/dev/sr0 8086368 8086368 0 100% /run/media/bit/CentOS 7 x86_64
/dev/mapper/vgwhatever-lvmyvol 98980 98960 20 100% /hallo
[root@localhost hallo]#
/dev/mapper/vgwhatever-lvmyvol - mapper word is how the kernel sees
===========================
Logical volumes need space from in volume group
To add space to volume group, we need space in physical group
check free volume group
[root@localhost hallo]# vgs
VG #PV #LV #SN Attr VSize VFree
cl 1 2 0 wz--n- 39.00g 4.00m
vg_sdbmount 1 1 0 wz--n- 96.00m 4.00m
vgwhatever 1 1 0 wz--n- 196.00m 96.00m
[root@localhost hallo]#
===========================
If there is no free space, we have to run
pvcreate and vgextend commands as well
===========================
[root@localhost hallo]# lvextend -L +50M -r /dev/vgwhatever/lvmyvol
Rounding size to boundary between physical extents: 52.00 MiB.
Size of logical volume vgwhatever/lvmyvol changed from 100.00 MiB (25 extents) to 152.00 MiB (38 extents).
Logical volume vgwhatever/lvmyvol successfully resized.
meta-data=/dev/mapper/vgwhatever-lvmyvol isize=512 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 25600 to 38912
===============================
[root@localhost hallo]# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vgwhatever-lvmyvol 149M 97M 52M 66% /hallo
[root@localhost hallo]#
Comments
Post a Comment