BTRFS and moving /home to subvolume, in need of a sanity check.

So I installed Debian 12 with btrfs and apparently it only uses a single subvolume rootfs. I would like to have my /home in a separate subvolume (and possibly /var too I guess) and with a flat subvolume structure. I started figuring out on how to do it and I feel like I’m not entirely sure yet so I need a sanity check.

Lots of comments online seem to use something like this method:


<span style="color:#323232;">cd /
</span><span style="color:#323232;">mv /home /home_old
</span><span style="color:#323232;">btrfs subvolume create home
</span><span style="color:#323232;">cp -a --reflink=always  /home_old/* /home/
</span>

But this would NOT create a flat subvolume structure, right? And you woul NOT need to modify fstab as the /home would be automatically mounted because it resides under rootfs actually because / is rootfs and not its parent?

If I want to actually have a flat structure, then I would first need to mount the actual parent subvolume (subvolumeid=5), cd into it, then create the home subvolume, copy everything from the current home directory into there, unmount, modify fstab to mount home, and delete the old stuff and reboot I guess.

Soo something like this:


<span style="color:#323232;">mkdir /mnt/tmp
</span><span style="color:#323232;">    Make a folder for mount
</span><span style="color:#323232;">mount -o subvolid=5 /dev/sdXX /mnt/tmp/
</span><span style="color:#323232;">    Mount the actual parent subvolume
</span><span style="color:#323232;">cd /mnt/tmp/
</span><span style="color:#323232;">    Here 'ls -a' would output 'rootfs' if I understood correctly
</span><span style="color:#323232;">btrfs subvolume create home
</span><span style="color:#323232;">    Create new subvolume, now being sibling of 'rootfs'
</span><span style="color:#323232;">cp -a --reflink=always  /home/* /mnt/tmp/home/
</span><span style="color:#323232;">    Copy old /home
</span><span style="color:#323232;">umount /mnt/tmp/
</span><span style="color:#323232;">    Don't need it anymore 
</span>

Then go to fstab, and do something like


<span style="color:#323232;">...
</span><span style="color:#323232;">UUID=  / btrfs  subvol=rootfs bunch_of_options_and_stuff
</span><span style="color:#323232;">...
</span><span style="color:#323232;">-> change into
</span><span style="color:#323232;">...
</span><span style="color:#323232;">UUID=  / btrfs  subvol=rootfs bunch_of_options_and_stuff
</span><span style="color:#323232;">UUID=  /home btrfs  subvol=home bunch_of_options_and_stuff
</span><span style="color:#323232;">...
</span>

Then just rm -rf /home/* (or just move to keep it as backup if something is fucked up) and reboot?

Does this sound about right?

Edit:

Everything went smoothly. Well just don’t fuck up fstab like I did. Decided not to make /var into a subvolume because not sure if you can do it the same way, thinking that logs etc are being written all the time so the gap between me copying everything to the subvolume, and eventually booting might make weird things but dunno. Also added compress=zstd into fstab mount options to reduce writes on the ssd.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • linux@lemmy.ml
  • localhost
  • All magazines
  • Loading…
    Loading the web debug toolbar…
    Attempt #