# LVM Snapshots with xfs

## BigBeer

I'm trying to do LVM snapshots with an xfs filesystem.

I do the following:

```

xfs_freeze -f /mnt/dir

lvcreate -L 1G -s -n snapshot1 /dev/vg1/lv-to-snapshot

```

It just hangs.. no output at all, can't kill the pid for lvcreate.

If I do a lvscan it hangs, but I can ctl-c out and I get this:

```

......

ACTIVE      '/dev/vg2/otherlvs' [size] inherit

CTL-c detected: giving up waiting for lock

/var/lock/lvm/V_vg1: flock failed: Interrupted system call

Can't lock vg1: skipping

```

Yes I have snapshoting enabled in kernel.

I am running gentoo-sources 2.6.15-r1

Am I missing something to taking the snapshots correctly?

----------

## BigBeer

I went to ~x86 for lvm2 to see if I could get some love.

Still nothing with lvm2-2.01.14

I guess I'll start playing with different kernels/fs next.

----------

## MrTV

Hi,

I am having the same problem on two separate the systems. They become totally locked, even hitting ctrl-c doesn't do anything.

system 1:

2.6.16-gentoo-r7

sys-fs/lvm2-2.02.06

system 2:

2.6.15-gentoo-r1

sys-fs/lvm2-2.01.09

I am going to update to the latest kernel on one system now to see if that helps. If you have any further experiences please post them.

TIA

Timo

----------

## Janne Pikkarainen

xfs + lvm2 + snapshots have been a shaky ground quite a long time. This bug is still in REOPENED state:

http://oss.sgi.com/bugzilla/show_bug.cgi?id=400

I don't know if it's actually fixed somewhere or not: anyway it seems that the bug is somehow related to LVM2 userland tools.

----------

## Sachankara

Unless you use LVM1, that is not the way you're supposed to do it (with XFS). This is how:

```
$ lvcreate -L512M -s -n home-backup /dev/volumegroup/home

$ mkdir /mnt/home-backup

$ mount /dev/volumegroup/home-backup /mnt/home-backup -o nouuid,ro

(Make the backup from /mnt/home-backup after this step)

$ umount /mnt/home-backup

$ lvremove /dev/volumegroup/home-backup

(When you've done the backup)
```

Notice that xfs_freeze is not used with LVM2 because it handles that itself. The mount options are also worth noticing.  :Smile: 

----------

## MrTV

Actually that was the way I was trying to do my backups before.

I am doing md5sum checks on all files to verify my backup. I found that some files fail the test (8 of more than 70000). Besides the md5sum checks, I compared the size of the files and it matches. cmp told me that the difference is only in the first byte. So I thought it could be a file system caching issue. First I stopped the services that write to those files. No difference. Then I inserted a "sync" command in my backup script just before doing the lvm snapshot and still became 2 errors. May sound strange to stop services and to do syncing while lvm snapshots shouldn't be affected by that.

Somehow I found xfs_freeze and the man page sounds promising. Unfortunately I experienced those system lock.

Btw, tried it again with kernel 2.6.17-gentoo-r4, sys-fs/xfsprogs-2.7.11, sys-fs/lvm2-2.02.06. Still the same.

Timo

----------

## MrTV

Hi,

I recompiled the whole system (with gcc-3.4.6-r1 and glibc-2.3.6-r4) and installed a newer lvm2 version (lvm2-2.02.07).

This time I opened two shells, one for entering the xfs_freeze commands and one for lvcreate. lvcreate -s hangs until I unfreeze the file system again. So the problem remains. It seems like the file system is "too frozen" that lvcreate could read it. Just like described in the bug's comment from above. But should lvm be independent of the file system? It is operating one layer beneath...

----------

## MrTV

Sachankara, 

you were right. LVM2 is said to be used without xfs_freeze. I found that the lvm howto was changed explicitly for that. But that doesn't explain the md5sum errors I get when comparing my backup files.  :Sad: 

----------

## Sachankara

 *MrTV wrote:*   

> Sachankara, 
> 
> you were right. LVM2 is said to be used without xfs_freeze. I found that the lvm howto was changed explicitly for that. But that doesn't explain the md5sum errors I get when comparing my backup files. 

 Did you use the right mount options (ro and nouuid) and did you perform the backup from the newly mounted partition and not the usual one?

----------

## MrTV

 *Sachankara wrote:*   

> Did you use the right mount options (ro and nouuid) and did you perform the backup from the newly mounted partition and not the usual one?

 

Yes, I mounted ro,nouuid and yes I rsynced from the right partition.

----------

## Sachankara

 *MrTV wrote:*   

>  *Sachankara wrote:*   Did you use the right mount options (ro and nouuid) and did you perform the backup from the newly mounted partition and not the usual one? 
> 
> Yes, I mounted ro,nouuid and yes I rsynced from the right partition.

 Late answer: That's strange. It workes for me. For example: 

```
$ lvcreate -L1G -s -nhome-backup /dev/vg1/home

$ mount /dev/vg1/home-backup /mnt/temp

$ cd /

$ find /mnt/temp/ -type f -exec md5sum {} >> /tmp/md5sum1 \;

(Use the computer for a couple of hours here)

$ md5sum -c /tmp/md5sum1 | grep -v OK

(No changes in the snapshot)

$ find /mnt/temp/ -type f -exec md5sum {} >> /tmp/md5sum2 \;;

$ diff -u /tmp/md5sum1 /tmp/md5sum2

(No changes reported)
```

----------

## MrTV

 *Sachankara wrote:*   

> Late answer: That's strange. It workes for me. For example: 
> 
> ```
> $ lvcreate -L1G -s -nhome-backup /dev/vg1/home
> 
> ...

 

You are doing the md5sum check against the same data. This is not what I do.  What I do is more like so:

```
$ lvcreate -L1G -s -nhome-backup /dev/vg1/home

$ mount /dev/vg1/home-backup /mnt/temp

$ rsync -aHRx --delete --delete-excluded --numeric-ids /mnt/temp/ /mnt/backup/

$ cd /mnt/temp

$ find ./ -type f -exec md5sum {} >> /tmp/md5sum1 \;

$ cd /mnt/backup

$ md5sum -c /tmp/md5sum1 | grep -v OK

```

Errors are not reported (or at least I haven't seen any yet) if I do mkfs.xfs on the /mnt/backup partition just before the first rsync. Errors show up after say the 2nd or 3rd time I do the rsync. I must add that I do rsyncs according to http://www.mikerubel.org/computers/rsync_snapshots/. And the errors become fewer, if I do sync; sync; sync right before I do lvcreate -s.  It feels like if the file system was maiden-like, it is ok. And if the file system becomes more and more used, the errors show up. Just like a dirty buffer, that wasn't written cleanly to the disk.

----------

## Sachankara

You missed the fact that I did one md5sum control first, then another several hours later and then compared the two md5sums. If the mounted snapshot wouldn't have contained exactly the same files as before, one would have noticed it.

----------

## MrTV

 *Sachankara wrote:*   

> You missed the fact that I did one md5sum control first, then another several hours later and then compared the two md5sums. If the mounted snapshot wouldn't have contained exactly the same files as before, one would have noticed it.

 

I noticed that. But you still do the check against the same data/partition. Of course one could assume that the change could also happen there. But as it didn't (as you found out) thats not the problem.

The problem is, that the rsynced data on /mnt/backup are not the same as on /mnt/temp. but they should be! You would assume that rsync provides an exact copy of the source, don't you?

----------

## Sachankara

 *MrTV wrote:*   

> The problem is, that the rsynced data on /mnt/backup are not the same as on /mnt/temp. but they should be! You would assume that rsync provides an exact copy of the source, don't you?

 Yes, one would, but if you try the same thing as I did and it works the same way as it did for me, then you can rule out the snapshot as being the problem. Perhaps the problem lies in rsync or in the partition you sync to? Perhaps rsync "works in mysterious ways" on XFS? :/

----------

