2

I need to make an in-memory snapshot of a running mounted root filesystem.

The filesystem itself is on an lvm device, but there is zero free space in the VG and there is no way to expand it. However I have plenty of ram and I only need my snapshot to make a backup, and, maybe roll back to it. I don't care if the server reboots and "rolls back" to the snapshot. I am using device-mapper and not lvm2 because I didn't find a way to make it with lvm. So in DM terminology i need to make a snapshot-origin and a snapshot on top of it.

I have created an in-memory block device (linear on top of loop over file on tmpfs) for cow data and it works.

My problem is that my root fs device is two linear devices, not one:

root: 0 57000000 linear 8:48 2048
root: 57000000 160000000 linear 8:48 73869312
cow: 0 20971520 linear 7:2 0

(root is not the only LV in this vg, cow is my in-memory device)

I found a bunch of articles about doing this online, for example: https://wiki.gentoo.org/wiki/Device-mapper#Snapshot However I didn't find the proper syntax to make snapshot-origin on top of two or more linear device.

when I do it like this: dmsetup table root| sed 's~linear.*~snapshot-origin /dev/mapper/root~g'| dmsetup create snapshot-origin I get "command failed" and this in dmesg:

[ 2957.073592] device-mapper: table: 254:1: snapshot-origin: Cannot get target device
[ 2957.073595] device-mapper: ioctl: error adding target to table

When I use the same approach for a single linear device everything is fine.

Update:
I did an lvm snapshot on a same configuration, but with some space in the vg to take a peek on how does lvm handle this. Well it does, but i still don't get it how i do that manually (with my own cow device of cause).

The initial setup:

Root: 0 57090048 linear 8:48 2048
Root: 57090048 160571392 linear 8:48 73869312

This is what lvm does on lvcreate -s -L10G. So this is what i want to create manually:

Root--snap: 0 217661440 snapshot 254:1 254:4 P 8
Root-real: 0 57090048 linear 8:0 2048
Root-real: 57090048 160571392 linear 8:0 73869312
Root: 0 217661440 snapshot-origin 254:1
Root--snap-cow: 0 8388608 linear 8:0 57092096

As i understand from dm documentation and various articles one should start by marking the original device as snapshot-origin:

dmsetup -vvv create so --table '0 217661440 snapshot-origin /dev/mapper/Root'            
dm version   OF   [16384] (*1)
Udev cookie 0xd4d3634 (semid 12746752) created
Udev cookie 0xd4d3634 (semid 12746752) incremented to 1
Udev cookie 0xd4d3634 (semid 12746752) incremented to 2
Udev cookie 0xd4d3634 (semid 12746752) assigned to CREATE task(0) with flags DISABLE_LIBRARY_FALLBACK         (0x20)
dm create so  OF   [16384] (*1)
dm reload so  OF   [16384] (*1)
<backtrace>
Udev cookie 0xd4d3634 (semid 12746752) decremented to 1
Udev cookie 0xd4d3634 (semid 12746752) incremented to 2
Udev cookie 0xd4d3634 (semid 12746752) assigned to REMOVE task(2) with flags DISABLE_LIBRARY_FALLBACK         (0x20)
dm remove so  OF   [16384] (*1)
Udev cookie 0xd4d3634 (semid 12746752) decremented to 1
Udev cookie 0xd4d3634 (semid 12746752) waiting for zero
Udev cookie 0xd4d3634 (semid 12746752) destroyed
Command failed

Update2:

open("/dev/mapper/control", O_RDWR)     = 3
/...cut.../
write(1, "dm create ECS-LVRoot  OF   [1638"..., 40dm create ECS-LVRoot  OF   [16384] (*1)
) = 40
ioctl(3, DM_DEV_CREATE, 0x7f66e826f350) = -1 EBUSY (Device or resource busy)
write(1, "<backtrace>\n", 12<backtrace>
)           = 12
write(2, "Command failed\n", 15Command failed
)        = 15

Your Answer

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

Browse other questions tagged or ask your own question.