1

I've set up a backup-server that creates daily BTRFS-snapshots of / in /backup/.

btrfs subvolume snapshot -r / /backup/$(date +%s)  # simplified example

I found this to be problematic because the snapshots get bloated by temporary volumes in /var/lib/docker. Now I'd like to create snapshots of /home only. But this does not work:

# btrfs subvolume snapshot -r /home /backup/$(date +%s)
ERROR: Not a Btrfs subvolume: Invalid argument

So I understand I need to make /home a subvolume. I'm unsure whether this means /home must be mounted separately. I've looked at other questions like How to make a btrfs snapshot? but they already have /home set up for this. How can I migrate this? What are the steps I need to take?

My current devices:

# blkid
/dev/sda1: UUID="39520d46-2e30-4b51-b093-2a3671eb8f52" TYPE="swap" PARTUUID="c9b515af-26c9-4809-aee1-680ca5ee7153"
/dev/sda2: UUID="3a994a01-9d92-4e67-8440-284ce24465f8" UUID_SUB="cbb73892-5f50-40f2-b411-37307bcbefc4" TYPE="btrfs" PARTUUID="462e3ffe-2c99-4481-89aa-b3f13f3985dc"
/dev/sdb: UUID="3a994a01-9d92-4e67-8440-284ce24465f8" UUID_SUB="b78ffe6c-c078-4cc5-b4c7-dd3874251394" TYPE="btrfs"
/dev/sda3: PARTUUID="63c9d4dd-0a85-40d6-9e10-3eaffcba4b49"

The / volume is mirrored on /dev/sda2 and /dev/sdb.

sba
  • 291

2 Answers2

2

You can't make a snapshot of a directory, but only a subvolume.

But it is quite easy to convert /home directory to a separate snapshot.

Let's say your / is /dev/sda2.

Create a backup of your system first in case you make a mistake!

To convert your /home to a subvolume boot from a LiveUSB and do this:

sudo mount /dev/sda2 /mnt
sudo btrfs sub create /mnt/@
sudo btrfs sub create /mnt/@home
sudo mv /home /mnt/@home
sudo mv / /mnt/@

Now you moved your / to the @ subvolume and /home to @home subvolume.

Now you need to edit /mnt/etc/fstab and add mount options to mount the volumes properly. Add subvol=@ to the line where the / is mounted. And create a similar line for /home like this:

UUID=3a994a01-9d92-4e67-8440-284ce24465f8 /               btrfs subvol=@ 0       0
UUID=3a994a01-9d92-4e67-8440-284ce24465f8 /home           btrfs subvol=@home 0       0

The last thing is to chroot to the system and update grub:

sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys  /mnt/sys
sudo chroot /mnt
sudo update-grub
exit
sudo umount /mnt

If you made everything right and I didn't make a mistake, you should reboot to a working system.

Pilot6
  • 92,041
0
a correction:

  $ sudo mv /home /mnt/@home

should read

  $ sudo mv /home/* /mnt/@home

otherwise you end up with

  $ ls -r/home
  home
  $ ls -r /home/home
  user1 user2 user2 ..

which will prevent GDM login..
jeorge
  • 1
  • 1