I am trying to create a dmsetup snapshot device be able to rollback changes made by fsck.

I think I'm calling dmsetup incorrectly. Here's an example:

$ truncate -s 4096 real snapshot               
$ losetup --show -f real                       
$ losetup --show -f snapshot                   
$ sudo dmsetup -v create snapdev --table '0 8 snapshot /dev/loop0 /dev/loop1 P 1'
device-mapper: reload ioctl on snapdev  failed: Input/output error
Command failed

The two spaces after snapdev in the error message are slightly weird.

However, if I change the P for persistent to N for non-persistent, everything is ok:

$ sudo dmsetup -v create snapdev --table '0 8 snapshot /dev/loop0 /dev/loop1 N 1'
Name:              snapdev
State:             ACTIVE
Read Ahead:        256
Tables present:    LIVE
Open count:        0
Event number:      0
Major, minor:      254, 4
Number of targets: 1

What am I doing wrong?

  • It may have something to do with the fact that you will lose the loopback device on reboot. – Raman Sailopal Oct 9 '17 at 9:30
  • @RamanSailopal These scripts use a loop device, so I don't believe it's that. – Tom Hale Oct 9 '17 at 9:57

To be used for a persistent snapshot, the first few blocks of the device need to be \0. This example zeros out the first 32 blocks.

The bytes SnAp\001 are written to the beginning of a persistent snap device.

The first block of the underlying device maps to block 16 of a persistent snapshot device. (Data starts at byte offset 8192 or 0x2000).

A snapshot device needs to be an (unspecified) minimum size. 4MB is sufficient.


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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