I have a debian installation on a virtual machine with a btrfs filesystem at /dev/vda2
. A subvolume named @
is mounted at / and @home
is mounted at /home.
My aim is to do a clean reinstall of the OS while keeping the files in @home
. The problem is that formatting the btrfs partition in the installer will clear all files, not just those in the @
subvolume. The solution is to pursuade the debian installer to install into a new subvolume on the btrfs partition.
There is probably a better way but this is how I did it. I have only done this with VMs so YMMV, buyer beware etc. All commands should be run as root.
mount -o subvolid=5 /dev/vda2 /mnt
btrfs subvolume create /mnt/@new
btrfs subvolume set-default /mnt/@new
umount /mnt
systemctl poweroff
Begin a normal reinstall from the debian installer CD/USB. When partioning the disk, select the existing btrfs partition as root. Do not format the btrfs partition. The installer should detect the default @new
btrfs subvolume and complete the install as normal.
Boot into the reinstalled system. You can check that you have booted the @new
subvolume by entering the mount
command. The output should include a line for the subvolume mounted at root that looks something like the line shown below. However, @home
subvolume is not mounted.
/dev/vda2 at / type btrfs (rw,relatime,space_cache,subvolid=261,subvol=@new)
mount -o subvolid=5 /dev/vda2 /mnt
btrfs subvolume delete /mnt/@
mv /mnt/@new /mnt/@
btrfs subvolume set-default /mnt/@
umount /mnt
grub-install /dev/vda
update-grub
@home
subvolume, which should look something like the entry below. UUID=0123456789-abcdef... /home btrfs defaults,subvol=@home 0 0
You can now reboot into your reinstalled system and find your home directory still intact.
This solution achieved my aim of reinstalling while retaining the files in my home directory. However, it does rely on there being enough space in the btrfs partition to temporarily hold two root subvolumes.