Move a Linux installation using btrfs on the default subvolume (subvolid=0) to another subvolume
While not strictly necessary, you might want to do these steps in single user ("recovery") mode to avoid accidental data loss.
We'll create the layout we want in the default subvolume:
mkdir /subvolumes
btrfs subvolume snapshot / /subvolumes/root
mkdir /snapshots
/subvolumes/root
will be our new root filesystem, so don't make any changes to the filesystem one after this step.
Edit /subvolumes/root/etc/fstab
to make the system use the new root subvolume as root filesystem. For that, you'll need to modify it to include the subvol=/subvolumes/root
option.
Now we need to mount our new root filesystem somewhere in order to fix grub to point to the new subvolume:
mkdir /media/temporary
mount -o subvol=/subvolumes/root /dev/sdXX /media/temporary
cd /media/temporary
mount -o bind /dev dev
mount -o bind /sys sys
mount -o bind /proc proc
mount -o bind /boot boot # only necessary if you have a separate boot partition
chroot .
update-grub
exit
That's it. Reboot, and your root filesystem should be the new subvolume. If this succeeded, there shouldn't be any /snapshots
directory.
If you want, you may make a permanent mount point for the default subvolume:
mkdir /media/btrfs/root
then you can mount -o subvolid=0 /dev/sdXX /media/btrfs/root
to mount the default subvolume.
You can now safely delete the contents of the old root filesystem in the default subvolume.
cd /media/btrfs/root
rm -rf {dev,home,var,...}