Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have Windows 7 installed on one of my disks. I want to boot this Windows system in my Xen HVM, but I do not want the changes to be permanent. So I want to create a snapshot of my Windows 7 partition. I checked with LVM, but it seems LVM can only create snapshot for LV it created. I am looking for a more general snapshot method.

share|improve this question
up vote 2 down vote accepted

You can use the lower level dmsetup command to direct the kernel device mapper to create a snapshot. If you are otherwise using LVM aside from the Windows partition, then create a logical volume to use as the backing store of the snapshot.

lvcreate -n store -L 10g vg
echo 0 `blockdev --getsz /dev/sda1` snapshot-origin /dev/sda1 | dmsetup create origin
echo 0 `blockdev --getsz /dev/sda1` snapshot /dev/mapper/origin /dev/mapper/vg-store N 128 | dmsetup create snap

Now you can point xen to /dev/mapper/snap instead of /dev/sda1 and any changes it makes will be discarded when you finish and use dmsetup remove to remove the snap and origin devices, and lvremove to remove the store volume.

If you aren't using LVM then you will need another partition or loop device to use as the backing store instead.

share|improve this answer
Thanks a lot. I tried to google about dmsetup snapshot, but I can only find articles talking about dmsetup in general. Do you happen to know where I can find detailed description about the snapshot feature of dmsetup? – davidshen84 Mar 30 '12 at 1:59
@davidshen84, In the kernel source tree under Documentation/device-mapper/snapshot.txt. – psusi Mar 30 '12 at 13:41

LiveCDs tend to do something like this. They have a read-only image from the CDROM and then overlay with a RAMdisk.

The filesystem in question is UnionFS. An alternative would be AuFS, but they should both be easy.

I'd tinker with it in a VM first before running it against something you care about.

share|improve this answer
UnionFS and AuFS both work by implementing a copy-on-write. Also they dont work with block devices, only filesystems. – Patrick Mar 29 '12 at 3:20
I checked both, none is applicable. KVM supports snapshot itself. I wish Xen has a similar feature. – davidshen84 Mar 29 '12 at 7:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.