0

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                       
/dev/loop0                                     
$ losetup --show -f snapshot                   
/dev/loop1                                     
$ 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?

Tom Hale
  • 28,728
  • 32
  • 139
  • 229
  • It may have something to do with the fact that you will lose the loopback device on reboot. – Raman Sailopal Oct 09 '17 at 09:30
  • @RamanSailopal [These scripts](https://www.reddit.com/r/linuxquestions/comments/4npllq/anyone_using_device_mapper_snapshots/d4fhn84/) use a loop device, so I don't believe it's that. – Tom Hale Oct 09 '17 at 09:57

1 Answers1

1

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.

Resources:

Tom Hale
  • 28,728
  • 32
  • 139
  • 229