Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LVM snapshot of mounted filesystem

I'd like to programmatically make a snapshot of a live filesystem in Linux, preferably using LVM. I'd like not to unmount it because I've got lots of files opened (my most common scenario is that I've got a busy desktop with lots of programs).

I understand that because of kernel buffers and general filesystem activity, data on disk might be in some more-or-less undefined state.

Is there any way to "atomically" unmount an FS, make an LVM snapshot and mount it back? It will be ok if the OS will block all activity for few seconds to do this task. Or maybe some kind of atomic "sync+snapshot"? Kernel call?

I don't know if it is even possible...

like image 399
liori Avatar asked Dec 21 '09 13:12

liori


People also ask

How do I mount a snapshot in LVM?

In order to mount a LVM snapshot, you have to use the “mount” command, specify the full path to the logical volume and specify the mount point to be used. As an example, let's say that we want to mount the “/dev/vg_1/lvol0” to the “/mnt/lv_snapshot” mount point on our system.

What is snapshot on LVM?

A Logical Volume Manager (LVM) logical volume snapshot is a copy-on-write technology that monitors changes to an existing volume's data blocks so that when a write is made to one of the blocks, the block's value at the snapshot time is copied to a snapshot volume.

How much space does a LVM snapshot take?

Regarding the size of the snapshot, a maximum of 1 GiB of "data" may be changed in the original volume, so that the snapshot will remain useful. If more data is changed on the original volume, the snapshot will be destroyed and lost.

Where are LVM snapshots stored?

Upon RTFM, it appears that LVM snapshots are automatically stored in the same directory as the original logical volume. In my case, that would mean the /dev directory.


1 Answers

You shouldn't have to do anything for most Linux filesystems. It should just work without any effort at all on your part. The snapshot command itself hunts down mounted filesystems using the volume being snapshotted and calls a special hook that checkpoints them in a consistent, mountable state and does the snapshot atomically.

Older versions of LVM came with a set of VFS lock patches that would patch various filesystems so that they could be checkpointed for a snapshot. But with new kernels that should already be built into most Linux filesystems.

This intro on snapshots claims as much.

And a little more research reveals that for kernels in the 2.6 series the ext series of filesystems should all support this. ReiserFS probably also. And if I know the btrfs people, that one probably does as well.

like image 133
Omnifarious Avatar answered Oct 09 '22 01:10

Omnifarious