Playing with btrfs.
I set up an Arch Linux VM that boots from a btrfs subvolume.
Unfortunately, I could not get syslinux to boot directly from btrfs. I
needed a separate /boot partition, formatted as ext4. It looks like
this:
vda 254:0 0 10G 0 disk
|-vda1 254:1 0 250M 0 part /boot
`-vda2 254:2 0 9.8G 0 part /
"/" is a btrfs subvolume called "root":
# btrfs subvolume list -p /
ID 257 gen 29 parent 5 top level 5 path root
ID 259 gen 24 parent 257 top level 257 path var/lib/machines
I needed to add "rootflags=subvol=root" to my kernel parameters.
That subvolume "var/lib/machines" is automatically created by systemd
[1].
Now, for a start, I was primarily interested in snapshots and snapshot
recovery. Creating a read-only snapshot of the entire file system was
pretty easy:
# btrfs subvolume snapshot -r / /rootbackup
Next, I set up a second Arch Linux VM with btrfs. I connected both VMs
using a bridge, so they can talk via SSH. I then sent the snapshot
over SSH to the second VM:
# btrfs send /rootbackup | ssh 10.1.2.3 btrfs receive /backup
This created a new subvolume on my second VM:
# btrfs subvolume list -p /
...
ID 262 gen 73 parent 257 top level 257 path backup/rootbackup
So far, so good. To simulate a complete data loss, I simply created a
third VM from scratch. It's empty, so I booted from the Arch Linux
installation ISO. I created a new partition table on the empty drive,
a new ext4 file system for /boot and a new btrfs file system.
Restoring the backup of my root subvolume was pretty easy:
# ssh 10.1.2.3 btrfs send /backup/rootbackup | btrfs receive /mnt
# mv /mnt/rootbackup /mnt/root
# btrfs property set -ts /mnt/root ro false
It took me a moment, though, to find that last command. Without it,
you get a read-only subvolume which is not very handy.
Since /boot is a separate partition which has not been backed up, I
needed to recreate it (after I mounted the "root" subvolume at /mnt).
I also had to reinstall the bootloader to my MBR/VBR.
# arch-chroot /mnt
# pacman -S syslinux linux
# syslinux-install_update -i -a -m
# (edit /boot/syslinux/syslinux.cfg)
And that's it. Lo and behold, the system boots. Very nice.
Having a separate /boot is not so comfortable. But it's ok. I could
live with that.
It'll still take some time until I'm confident enough to use btrfs on
real systems. But so far, I like it.
____________________
1.
https://cgit.freedesktop.org/systemd/systemd/commit/?id=113b3fc1a8061f4a24dd0db74e9a3cd0083b2251