To start - check the partitions:
# cat /proc/partitions
major minor #blocks name
11 0 1920096 sr0
252 0 20971520 vda
252 1 1048576 vda1
252 2 19921920 vda2
8 16 1048576 sdb
8 0 1048576 sda
253 0 17821696 dm-0
253 1 2097152 dm-1
I have sda and sdb: both are 1 GB in size.# vgcreate vgstriped /dev/sda /dev/sdb
Physical volume "/dev/sda" successfully created.
Physical volume "/dev/sdb" successfully created.
Volume group "vgstriped" successfully created
Show what we have:
# pvs
PV VG Fmt Attr PSize PFree
/dev/sda vgstriped lvm2 a-- 1020.00m 1020.00m
/dev/sdb vgstriped lvm2 a-- 1020.00m 1020.00m
/dev/vda2 fedora_localhost-live lvm2 a-- <19.00g 0
Let's use lvcreate to create a striped logical volume named lvdata:
# lvcreate -L 1G -i2 -I64 -n lvdata vgstriped
Logical volume "lvdata" created.
Options:
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root fedora_localhost-live -wi-ao---- <17.00g
swap fedora_localhost-live -wi-ao---- 2.00g
lvdata vgstriped -wi-a----- 1.00g
If you want more information use lvdisplay command:
# lvdisplay /dev/vgstriped/lvdata
--- Logical volume ---
LV Path /dev/vgstriped/lvdata
LV Name lvdata
VG Name vgstriped
LV UUID 4beSCk-Zffc-dvRc-dRBm-zYex-ref6-ra06ZH
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2021-12-24 21:44:06 +0200
LV Status available
# open 0
LV Size 1.00 GiB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 512
Block device 253:2
likewise there are vgdisplay and pvdisplay commands.# mkfs.ext4 /dev/vgstriped/lvdata
mke2fs 1.45.5 (07-Jan-2020)
Discarding device blocks: done
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: 4f97cdad-a383-4b34-9e92-a6ca7d17d570
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
And now we have a filesystem, we can mount it:
# mount /dev/vgstriped/lvdata /mnt/
# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 970M 0 970M 0% /dev
tmpfs 990M 0 990M 0% /dev/shm
tmpfs 990M 1.5M 989M 1% /run
/dev/mapper/fedora_localhost--live-root 17G 7.2G 8.6G 46% /
tmpfs 990M 100K 990M 1% /tmp
/dev/vda1 976M 179M 731M 20% /boot
tmpfs 198M 96K 198M 1% /run/user/1000
/dev/sr0 1.9G 1.9G 0 100% /run/media/user/Fedora-WS-Live-32-1-6
/dev/mapper/vgstriped-lvdata 976M 2.6M 907M 1% /mnt
Let's copy some data to this mounted volume:
# cp -r /etc/[abc]* /mnt/
Now, we have some data in there:
# cd /mnt/
# ls
abrt alternatives at.deny bash_completion.d bluetooth ceph chrony.keys cron.d cron.monthly crypttab cupshelpers
adjtime anaconda audit bashrc brlapi.key chkconfig.d cifs-utils cron.daily crontab csh.cshrc lost+found
aliases anacrontab authselect bindresvport.blacklist brltty chromium cni cron.deny cron.weekly csh.login
alsa asound.conf avahi binfmt.d brltty.conf chrony.conf containers cron.hourly crypto-policies cups
One of benefits of working with LVM is that you can easily resize LVM volumes. If we type vgs:
# vgs
VG #PV #LV #SN Attr VSize VFree
fedora_localhost-live 1 2 0 wz--n- <19.00g 0
vgstriped 2 1 0 wz--n- 1.99g 1016.00m
we can see that we have VFree of approximately 1G in vgstriped.# lvresize --help
lvresize - Resize a logical volume
Resize an LV by a specified size.
lvresize -L|--size [+|-]Size[m|UNIT] LV
[ -l|--extents [+|-]Number[PERCENT] ]
[ -r|--resizefs ]
[ --poolmetadatasize [+]Size[m|UNIT] ]
[ COMMON_OPTIONS ]
[ PV ... ]
Resize an LV by specified PV extents.
lvresize LV PV ...
[ -r|--resizefs ]
[ COMMON_OPTIONS ]
Resize a pool metadata SubLV by a specified size.
lvresize --poolmetadatasize [+]Size[m|UNIT] LV_thinpool
[ COMMON_OPTIONS ]
[ PV ... ]
Common options for command:
[ -A|--autobackup y|n ]
[ -f|--force ]
[ -i|--stripes Number ]
[ -I|--stripesize Size[k|UNIT] ]
[ -n|--nofsck ]
[ --alloc contiguous|cling|cling_by_tags|normal|anywhere|inherit ]
[ --nosync ]
[ --noudevsync ]
[ --reportformat basic|json ]
[ --type linear|striped|snapshot|mirror|raid|thin|cache|vdo|thin-pool|cache-pool|vdo-pool ]
Common options for lvm:
[ -d|--debug ]
[ -h|--help ]
[ -q|--quiet ]
[ -v|--verbose ]
[ -y|--yes ]
[ -t|--test ]
[ --commandprofile String ]
[ --config String ]
[ --driverloaded y|n ]
[ --nolocking ]
[ --lockopt String ]
[ --longhelp ]
[ --profile String ]
[ --version ]
Use --longhelp to show all options and advanced commands.
options -l and -L allows you to specify the size that should be added. -l allows to specify the percentage of free extets, With -L you can use absolute number +200M for example. # lvresize -L +100M -r /dev/vgstriped/lvdata
Using stripesize of last segment 64.00 KiB
Rounding size (281 extents) up to stripe boundary size for segment (282 extents).
Size of logical volume vgstriped/lvdata changed from 1.00 GiB (256 extents) to 1.10 GiB (282 extents).
Logical volume vgstriped/lvdata successfully resized.
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/mapper/vgstriped-lvdata is mounted on /mnt; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mapper/vgstriped-lvdata is now 288768 (4k) blocks long.
Options used:
# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 970M 0 970M 0% /dev
tmpfs 990M 0 990M 0% /dev/shm
tmpfs 990M 1.5M 989M 1% /run
/dev/mapper/fedora_localhost--live-root 17G 7.2G 8.6G 46% /
tmpfs 990M 100K 990M 1% /tmp
/dev/vda1 976M 179M 731M 20% /boot
tmpfs 198M 96K 198M 1% /run/user/1000
/dev/sr0 1.9G 1.9G 0 100% /run/media/user/Fedora-WS-Live-32-1-6
/dev/mapper/vgstriped-lvdata 1.1G 7.1M 1000M 1% /mnt
How to create the snapshot.# lvcreate -s -n lvdata_snap -L 100M /dev/vgstriped/lvdata
Logical volume "lvdata_snap" created.
Options:
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root fedora_localhost-live -wi-ao---- <17.00g
swap fedora_localhost-live -wi-ao---- 2.00g
lvdata vgstriped owi-aos--- 1.10g
lvdata_snap vgstriped swi-a-s--- 100.00m lvdata 0.01
you can see that lvdata_snap with origin lvdata has been created.# cd /mnt/
# rm -rf b*
Now, let's unmount /mnt and mount the snapshot on /mnt:
# cd
# umount /mnt
# mount /dev/vgstriped/lvdata_snap /mnt/
And we will see that the files starting with b are still exists:
# cd /mnt/
# ls
abrt alternatives at.deny bash_completion.d bluetooth ceph chrony.keys cron.d cron.monthly crypttab cupshelpers
adjtime anaconda audit bashrc brlapi.key chkconfig.d cifs-utils cron.daily crontab csh.cshrc lost+found
aliases anacrontab authselect bindresvport.blacklist brltty chromium cni cron.deny cron.weekly csh.login
alsa asound.conf avahi binfmt.d brltty.conf chrony.conf containers cron.hourly crypto-policies cups
That is what happening in the snapshot. Now, in the background LVM is working on copying all deleted files from the original Logical Volume to the snapshot.# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root fedora_localhost-live -wi-ao---- <17.00g
swap fedora_localhost-live -wi-ao---- 2.00g
lvdata vgstriped owi-a-s--- 1.10g
lvdata_snap vgstriped swi-aos--- 100.00m lvdata 0.33
Previously the Data% was set to 0.01 and you can now see that it is set to something a lot higher.