You are not logged in.

#1 2025-07-23 17:30:04

fiwlt
Member
Registered: 2025-07-23
Posts: 2

[SOLVED] Creating BTRFS subvolumes for timeshift retroactively

Hello All,

installed Arch yesterday on a btrfs partition without a proper subvolume layout. I'm trying to create a layout now so timeshift can be used for snapshotting.
I've read https://wiki.archlinux.org/title/Timeshift, but from what I understand about btrfs subvolumes atm, there seem to be steps missing, or I don't understand correctly. Either way, maybe I can expand the stub with a solution/verbose explanation.
Following the wiki page:
as I do not have a separate /home partition, I just create a subvolume for / with:

# btrfs subvolume create /@

which creates the following file:

% ls -l / |grep @
drwxr-xr-x   1 root root    0 Jul 23 17:32 @

and brtfs subvolume list:

# btrfs subvolume list -t /
ID      gen     top level       path
--      ---     ---------       ----
256     1256    5               var/lib/portables
257     1256    5               var/lib/machines
259     1373    5               @

Then I edit /etc/fstab and change subvol=/ for root / to subvol=/@ and reboot.

After a reboot, root still seems to be unchanged:

% mount | grep 'on / '
/dev/nvme0n1p5 on / type btrfs (rw,relatime,ssd,discard=async,space_cache=v2,subvolid=5,subvol=/)

Doing a quick test with timeshift, snapshotting does not seem to work:

  1. # touch /test

  2. create snapshot with timeshift

  3. # rm /test

  4. restore snapshot with timeshift

  5. /test was not restored

From what I understand there seem to be at least two steps missing:

  1. Populate the empty subvolume /@ with the contents of the top-level subvolume /

  2. Either change the default subvolume to /@ or boot with rootflags=subvol=/@ (last option seems preferable for figuring out the right approach)

Step 2 will not work without step 1, because subvolume /@ is empty and does not contain initrd.

I'm unsure on how to achieve step 1. Most reasonable approach i've found so far involves creating subvolume /@ by snapshotting top-level /:

# btrfs subvolume snapshot / /@

Is this approach just plain stupid? Drawbacks? A better approach? I guess for creating @home I will really have to move the files into it from /home.


Thanks for reading,
- fiwlt

Last edited by fiwlt (2025-07-26 12:21:47)

Offline

#2 2025-07-26 12:21:09

fiwlt
Member
Registered: 2025-07-23
Posts: 2

Re: [SOLVED] Creating BTRFS subvolumes for timeshift retroactively

Think I solved it, at least for this install. Marking as solved.

The following steps are for my installation only. It's not optimized and YMMV.

Solution

First, edit /etc/fstab (/@ -> /, /@home -> /home). Then create the new root subvolume /@ by snapshotting the existing one:

btrfs subvolume snapshot / /@

In new root, empty /home so there's an empty dir to mount home at:

rm -rf /@/home/*

Create a subvolume for home in the old/top-level root:

btrfs subvolume create /@home

Copy everything from the existing home directory into the @home subvolume. Use reflink to not waste space. I worked while logged into a user account and wasn't able to copy the Baloo index + lock file. Better do this while logged out of user accounts with root.

cp -a --reflink /home/. /@home/.

Then reboot with kernel parameter "rootflags=subvol=/@". Add the parameter by editing the boot entry in grub menu on boot. Check if everything works and looks OK (e.g. mount points reference the new subvolumes, timeshift works).

Make the rootflags kernel parameter permanent by running grub-install. This should automatically add the kernel parameter "rootflags=subvol=@", no need to edit "/etc/default/grub" and run grub-mkconfig!

Next Steps

I'll try to get a discussion going on https://wiki.archlinux.org/title/Timeshift to expand the stub. What's on the configuration section there doesn't work for existing installations.

For my next installation I plan to follow a similar approach, but I want to make the list of packages that is installed on top-level root before the snapshot a lot smaller, core repos only if possible. With a custom grub boot entry, the top-level root should work as a "factory reset" option to create a "forever system" that only needs to be installed once. With a smaller list of packages, update intervals for the factory install can hopefully be extended with less risk of breakage. Still a lot to figure out for this to work though.

Offline

Board footer

Powered by FluxBB