This is another article I’ve written some years ago (2003-09-29, original URL). It used to be quite popular, so I’ve decided to recover it and publish it again here:
I want to do a consistent snapshot of my /home, which is an XFS filesystem created on an LVM logical volume:
# grep home /etc/mtab
/dev/vg01/lvhome /home xfs rw,noatime 0 0
# lvdisplay /dev/vg01/lvhome
--- Logical volume ---
LV Name /dev/vg01/lvhome
VG Name vg01
LV Write Access read/write
LV Status available
LV # 2
# open 1
LV Size 800 MB
Current LE 200
Allocated LE 200
Allocation next
Read ahead sectors 1024
Block device 58:1
In order to get a consistent image of the filesystem in the snapshot, we need to freeze it, so the log jornal is flushed and no more accesses are done to it.
So the idea is : freeze, take snapshot and then unfreeze (see xfs_freeze(8))
# xfs_freeze -f /home
# lvcreate -l 30 -n lvsnap_home -s /dev/vg01/lvhome
# xfs_freeze -u /home
I’ve created the snapshot with 30 extents which is ~15% of the original LV.
Now we can mount the snapshot, and for example make a backup of the filesystem while users can continue to work.
# mount /dev/vg01/lvsnap_home /mnt/tmp/
mount: block device /dev/vg01/lvsnap_home is write-protected, mounting read-only
mount: wrong fs type, bad option, bad superblock on /dev/vg01/lvsnap_home,
or too many mounted file systems
The mount error message is a little confusing, but looking at console messages or syslog, we can see the explaination:
kernel: XFS: Filesystem lvm(58,2) has duplicate UUID - can't mount
Uff… actually we are in trouble: as expected, the snapshot is an image of the orginal filesystem, so it also has it UUID.
The solution could be:
# xfs_admin -U generate /dev/vg01/lvsnap_home
But it can’t be done because the snapshot is read-only.
NOTE: i’ve read that there is a LVM kernel patch and userland tools patch for mounting a LVM snapshot r/w, but i’ve not seen it.
Actually i’ve found the solution in Documentation/filesystems/xfs.txt: using the nouuid option of mount:
# mount -o ro,nouuid /dev/vg01/lvsnap_home /mnt/tmp/
That’s it:
alegrome:~# df /home /mnt/tmp/
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vg01/lvhome 814400 201508 612892 25% /home
/dev/vg01/lvsnap_home 814400 201504 612896 25% /mnt/tmp
UPDATED (Sat, 31 Mar 2007 14:40:59 +0200):
This article works for LVM10. It may be obsolete when you use LVM2, as it seems that LVM2 snapshots are R/W by default now.

Recent Comments