Moving home partition to a btrfs subvolume

Thanks both @dalto and @FGD for your input. I managed to solve the problem as @dalto specified. I don´t know what went wrong the first times I tried to send/receive. Maybe it had to do with the fact I had just cleaned caches using Stacer and had done a balance (using the recommend command by @tbg applied to /home).

The steps I followed and what I learned:

BACKUP YOUR DATA

  1. Create a read-only snapshot of my /home btrfs partition (lesson: the filesystem volume is itself a subvolume) called home-transfer. This needs to be created inside the same device:
    # btrfs subvolume snapshot -r /home /home/home-transfer
    Only read-only subvolumes can be send/received across devices.

  2. Mount the (hidden) top level volume of the system by mounting the corresponding device or partition (in my case this is /dev/nvme0n1p3):
    # mkdir /mnt/btrfs && mount /dev/nvme0n1p3 /mnt/btrfs/
    We do this so we can access the top level and keep a consistent (flat) subvolume layout. It’s still hard to wrap my head around the possibility of mounting the very filesystem being used on a directory inside itself. Even weirder was that this filesystem wasn’t actually mounted, but a subvolume of it on /. A filesystem can be mounted on multiple directories with no issues, as mentioned in the man page of mount:

    The same filesystem may be mounted more than once, and in some cases (e.g., network filesystems) the same filesystem may be mounted on the same mountpoint
    multiple times.

  3. Transfer the subvolume (across devices), placing it at the top level:
    # btrfs send /home/home-transfer | btrfs receive /mnt/btrfs/
    Confirm the operation with
    # btrfs subvolume list /

  4. Now create a writable snapshot of the transfered subvolume called @home:
    # btrfs subvolume snapshot /mnt/btrfs/home-transfer /mnt/btrfs/@home
    Its good time now to delete the read-only snapshot:
    # btrfs subvolume delete /mnt/btrfs/home-transfer

  5. Then modify the fstab accordingly. I changed the/home mount point line so the UUID pointed to the same device as the other system subvolumes, instead of my original /home partition UUID, and added the option subvol=@home. Not without making a backup file before:
    # cp /etc/fstab /etc/fstab.bak

  6. Then $ reboot to the new configuration. Everything should be working as nothing had happened.

  7. Now we can clean our mess by removing the auxiliary mounting directory and backup fstab:
    # rmdir /mnt/btrfs && rm /etc/fstab.bak

I still have to erase the now obsolete partition and grow my system’s partition, but this is no issue.
Thanks for all your help.

PS, after mounting the top level subvolume I discovered a timeshift-btrfs directory with some old snapshot’s json files, which I deleted at once.

Reference: Btrfs subvolumes and snapshots

3 Likes