Hello,
I have the following usecase: I’d like to be able to put my Btrfs snapshots taken with snapper on an external disk and then send them back when needed to do a snapper rollback.
I’ve no problem to send a Btrfs snapshot on an external disk then to send it back to the origin disk using btrfs send and btrfs receive commands.
The problem is I can’t boot a snapshot received from the external disk. I guess the problem comes from the subvolume UUIDs but I can’t be sure as I don’t know how grub handles Btrfs subvolumes exactly.
Here are the steps I’ve done:
- Install openSUSE Tumbleweed on a vm, default partitioning settings, except I didn’t create a separate XFS /home partition, it’s just another Btrfs subvolume:
# btrfs subvolume list -tuRq /
ID gen top level parent_uuid received_uuid uuid path
-- --- --------- ----------- ------------- ---- ----
257 184 5 - - c2c960f4-6f65-bf4c-8f0b-99eb73265b3b @
258 262 257 - - 2731a281-7a57-124c-a53a-a48c14e1f8fd @/.snapshots
259 264 258 c2c960f4-6f65-bf4c-8f0b-99eb73265b3b - 0a903510-4214-8540-b39f-7a3622ecb8a0 @/.snapshots/1/snapshot
260 184 257 - - ac4db657-8ef2-354d-9211-48d21f7a73da @/boot/grub2/i386-pc
261 184 257 - - 9b1425e5-2076-814f-acaa-0707725b47dd @/boot/grub2/x86_64-efi
262 281 257 - - f033239a-55e6-3f4a-a1a4-e1e428bcdaad @/home
263 184 257 - - 43632d0d-84ba-0a47-bfbc-9cfe63417cdf @/opt
264 184 257 - - ad53afd6-b8e8-8b45-9642-a6edfabb7717 @/srv
265 281 257 - - ef23a9c7-0880-f142-9dde-5d6494d85c4f @/tmp
266 184 257 - - a7a1de99-4f13-e744-8a6c-849f25379b6a @/usr/local
267 225 257 - - 94d0b4f5-c43a-6b48-9f7c-c1d7d5d96a5c @/var/cache
268 184 257 - - e526bc3f-081f-6349-a740-0f5ca5efdb00 @/var/crash
269 184 257 - - 80a2ec11-d9ca-fc4e-8468-9524b90f8f84 @/var/lib/libvirt/images
270 184 257 - - c0ccb002-d881-f543-9a02-347c10ebeefb @/var/lib/machines
271 184 257 - - 28e3e58e-6a55-3a40-b11b-d6099dd852d2 @/var/lib/mailman
272 184 257 - - 887aa3ce-aca0-b142-937c-06d2f2bf4d6b @/var/lib/mariadb
273 184 257 - - e052e57e-4a0b-6445-b00c-cb69b0a15d2e @/var/lib/mysql
274 184 257 - - 17979ee9-09e0-8040-9314-50b2cdaac363 @/var/lib/named
275 184 257 - - 3a633711-1ad5-164a-b7cc-fe8c5d41bc59 @/var/lib/pgsql
276 264 257 - - b73cacdf-88b9-4b4f-b666-f5f6251b4224 @/var/log
277 184 257 - - 9c473a03-2cad-4241-9b8a-6f44de4727d6 @/var/opt
278 281 257 - - c6e11bcc-974c-ed40-8527-e140ee02036c @/var/spool
279 230 257 - - 057c9b12-92bc-dc49-9769-e815fe391e37 @/var/tmp
#
- Create a snapshot with snapper
# snapper ls
Type | # | Pre # | Date | User | Cleanup | Description | User data
-------+---+-------+----------------------------------+-------------+----------+-----------------------+---------------------
single | 0 | | | root | | current |
single | 1 | | dim. 09 juil. 2017 15:48:53 CEST | root | | first root filesystem |
single | 2 | | dim. 09 juil. 2017 18:19:47 CEST | root | number | |
# btrfs subvolume list -tuRqs /
ID gen cgen top level otime parent_uuid received_uuid uuid path
-- --- ---- --------- ----- ----------- ------------- ---- ----
259 235 11 258 2017-07-09 15:48:53 c2c960f4-6f65-bf4c-8f0b-99eb73265b3b - 0a903510-4214-8540-b39f-7a3622ecb8a0 @/.snapshots/1/snapshot
294 235 235 258 2017-07-09 18:19:47 0a903510-4214-8540-b39f-7a3622ecb8a0 - 28e73373-4043-e449-9c09-b08b53ee043f @/.snapshots/2/snapshot
#
- Send the snapshot to an external disk (not really an external disk, just another virtual disk I added to the vm and mounted at /mnt):
# mkdir -p /mnt/2
# cp /.snapshots/2/info.xml /mnt/2
# btrfs send /.snapshots/2/snapshot | btrfs receive /mnt/2
# btrfs subvolume list -tuRq /mnt
ID gen top level parent_uuid received_uuid uuid path
-- --- --------- ----------- ------------- ---- ----
257 324 5 - - 9942db34-e2f7-1c41-a6d4-53962633c538 @
282 322 257 - 28e73373-4043-e449-9c09-b08b53ee043f ac2a7ecd-e3c0-e242-b313-9f2690528fea 2/snapshot
#
- Delete the snapshot on the origin disk:
# snapper delete 2
#
- Send the snapshot from the external disk back to the origin:
# mkdir -p /.snapshots/2
# cp /mnt/2/info.xml /.snapshots/2
# btrfs send /mnt/2/snapshot | btrfs receive /.snapshots/2
# btrfs subvolume list -tuRq /
ID gen top level parent_uuid received_uuid uuid path
-- --- --------- ----------- ------------- ---- ----
257 184 5 - - c2c960f4-6f65-bf4c-8f0b-99eb73265b3b @
258 262 257 - - 2731a281-7a57-124c-a53a-a48c14e1f8fd @/.snapshots
259 264 258 c2c960f4-6f65-bf4c-8f0b-99eb73265b3b - 0a903510-4214-8540-b39f-7a3622ecb8a0 @/.snapshots/1/snapshot
260 184 257 - - ac4db657-8ef2-354d-9211-48d21f7a73da @/boot/grub2/i386-pc
261 184 257 - - 9b1425e5-2076-814f-acaa-0707725b47dd @/boot/grub2/x86_64-efi
262 281 257 - - f033239a-55e6-3f4a-a1a4-e1e428bcdaad @/home
263 184 257 - - 43632d0d-84ba-0a47-bfbc-9cfe63417cdf @/opt
264 184 257 - - ad53afd6-b8e8-8b45-9642-a6edfabb7717 @/srv
265 281 257 - - ef23a9c7-0880-f142-9dde-5d6494d85c4f @/tmp
266 184 257 - - a7a1de99-4f13-e744-8a6c-849f25379b6a @/usr/local
267 225 257 - - 94d0b4f5-c43a-6b48-9f7c-c1d7d5d96a5c @/var/cache
268 184 257 - - e526bc3f-081f-6349-a740-0f5ca5efdb00 @/var/crash
269 184 257 - - 80a2ec11-d9ca-fc4e-8468-9524b90f8f84 @/var/lib/libvirt/images
270 184 257 - - c0ccb002-d881-f543-9a02-347c10ebeefb @/var/lib/machines
271 184 257 - - 28e3e58e-6a55-3a40-b11b-d6099dd852d2 @/var/lib/mailman
272 184 257 - - 887aa3ce-aca0-b142-937c-06d2f2bf4d6b @/var/lib/mariadb
273 184 257 - - e052e57e-4a0b-6445-b00c-cb69b0a15d2e @/var/lib/mysql
274 184 257 - - 17979ee9-09e0-8040-9314-50b2cdaac363 @/var/lib/named
275 184 257 - - 3a633711-1ad5-164a-b7cc-fe8c5d41bc59 @/var/lib/pgsql
276 264 257 - - b73cacdf-88b9-4b4f-b666-f5f6251b4224 @/var/log
277 184 257 - - 9c473a03-2cad-4241-9b8a-6f44de4727d6 @/var/opt
278 281 257 - - c6e11bcc-974c-ed40-8527-e140ee02036c @/var/spool
279 230 257 - - 057c9b12-92bc-dc49-9769-e815fe391e37 @/var/tmp
295 279 258 - 28e73373-4043-e449-9c09-b08b53ee043f f1d2d421-e0d4-4242-830b-13491c5f863e @/.snapshots/2/snapshot
- Regenerate grub-snapshot.cfg:
# /usr/lib/snapper/plugins/grub --refresh
# cat /.snapshots/2/grub-snapshot.cfg
if -f "/.snapshots/2/snapshot/boot/grub2/grub.cfg" ]; then
snapshot_found=true
saved_subvol=$btrfs_subvol
menuentry " openSUSE Tumbleweed (4.11.8-1,2017-07-09T16:19)" "/.snapshots/2/snapshot" "/@/.snapshots/2/snapshot" {
btrfs_subvol="$3"
extra_cmdline="rootflags=subvol=$3"
export extra_cmdline
snapshot_num=2
export snapshot_num
configfile "$2/boot/grub2/grub.cfg"
btrfs_subvol=$saved_subvol
}
fi
# cat /.snapshots/grub-snapshot.cfg
if -z "$extra_cmdline" ]; then
submenu "Start bootloader from a read-only snapshot" {
if -f "/.snapshots/2/grub-snapshot.cfg" ]; then
source "/.snapshots/2/grub-snapshot.cfg"
fi
if x$snapshot_found != xtrue ]; then
submenu "Not Found" { true; }
fi
}
fi
#
- Reboot
- On grub, select “boot from read-only snapshot” then select snapshot 2; Nothing happens.
If I create other snapshots they are bootable, but snapshot 2 isn’t. I mean I see the entry in grub but I can’t enter it, I just stay at the list of bootable snapshots.
As I said, I think the problem may come from the UUIDs. When I create more snapshots, I see they all have their parent UUID set to the UUID of /.snapshots/1/snapshot (first root filesystem snapper says).
But when the snapshot is sent with btrfs send, the received snapshot:
- has no parent UUID; I guess it’s the reason why it’s not seen as a snapshot (not listed with option -s of btrfs subvolume list
). - gets a received UUID, which is the UUID (or the received UUID if any) of the sent snapshot - gets a new UUID
I know there is a -p option to btrfs send for incremental backup; But it doesn’t make sense to me to do a btrfs send -p /.snapshots/1/snapshot /.snapshots/2/snapshot | … as there is nothing on /mnt side. Anyway command is refused because /.snapshots/1/snapshot is not read-only.
Do you see the reason why I can’t enter the snapshot entry in grub? Do you think it’s related to UUIDs or it’s something different? Do you know how to realize my usecase?