Saturday, June 23, 2018

linux - fsck on LVM snapshots



I'm trying to do some file system checks using LVM snapshots of our Logical Volumes to see if any of them have dirty file systems.



The problem that I have is that our LVM only has one Volume Group with no available space. I was able to do fsck's on some of the logical volumes using a loopback file system. However my question is, is it possible to create a 200GB loopback file system, and saved it on the same partition/logical volume that I'll be taking a snapshot of? Is LVM smart enough to not take a snapshot copy of the actual snapshot?



[root@server z]# vgdisplay
--- Volume group ---
VG Name Web2-Vol
System ID

Format lvm2
Metadata Areas 1
Metadata Sequence No 29
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 6
Open LV 6
Max PV 0
Cur PV 1

Act PV 1
VG Size 544.73 GB
PE Size 4.00 MB
Total PE 139450
Alloc PE / Size 139450 / 544.73 GB
Free PE / Size 0 / 0
VG UUID BrVwNz-h1IO-ZETA-MeIf-1yq7-fHpn-fwMTcV


[root@server z]# df -h

Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.7G 3.6G 5.6G 40% /
/dev/sda1 251M 29M 210M 12% /boot
/dev/mapper/Web2--Vol-var
12G 1.1G 11G 10% /var
/dev/mapper/Web2--Vol-var--spool
12G 184M 12G 2% /var/spool
/dev/mapper/Web2--Vol-var--lib--mysql
30G 15G 14G 52% /var/lib/mysql
/dev/mapper/Web2--Vol-usr

13G 3.3G 8.9G 27% /usr
/dev/mapper/Web2--Vol-z
468G 197G 267G 43% /z
/dev/mapper/Web2--Vol-tmp
3.0G 76M 2.8G 3% /tmp
tmpfs 7.9G 92K 7.9G 1% /dev/shm


The logical volume in question is /dev/mapper/Web2--Vol-z. I'm afraid if I created the loopback file system in /dev/mapper/Web2--Vol-z and take a snapshot of it, the disk size will be trippled in size, thus running out of disk space available.


Answer





However my question is, is it possible to create a 200GB loopback file system,
and saved it on the same partition/logical volume that I'll be taking a snapshot of?




No if based on file on the same LV you are taking snapshot. The underlying block device will be constantly changing and will result in infinite loop terminated by loop device exhaustion.



You could, depending on amount of changes to the filesystems (and amount of available RAM and/or disk-space), either create a loop device on /dev/sda2 or on another LV or use ramdisk. However, the preferred way is to make some free space in the VG.



Also, make sure the snapshot is allocated on the temporary PV (pass the PV path to lvcreate) and no other data are saved there, or they will be lost. I am not sure the pvcreate and subsequent snapshot operation could be made a single atomic operation.

Ask on #lvm IRC channel on freenode.




Is LVM smart enough to not take a snapshot copy of the actual snapshot?




I would not say it is not smart enough, it is just not suitable for the usecase. It does know nothing about files or filesystems, works on block devices and snapshot just mirrors any modified block including loop file's.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...