Created
April 18, 2024 08:15
-
-
Save CodaBool/fcb7142ea14a58b4efa874f417d35298 to your computer and use it in GitHub Desktop.
Notes on Setting up BTRFS with rollbacks on Arch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# assumes you are using btrfs with the default subvolumes | |
# assumes you are using grub as your boot loader | |
# inotify-tools is not needed on all machines | |
# you can skip and check logs of grub-btrfsd after starting the | |
# service and it will tell you if inotify-tools is needed | |
paru -S snapper snap-pac grub-btrfs snapper-rollback inotify-tools | |
sudo su | |
cd / | |
# snapper defaults are weird | |
# we need to remove the .snapshots folder to create a config | |
umount .snapshots | |
rm -r .snapshots | |
# create a config for root | |
snapper -c root create-config / | |
# adding -p because I am not sure if this is needed here but doesn't hurt | |
mkdir -p .snapshots | |
# no need to edit /etc/fstab since it should still be in there | |
# we can just remount it | |
mount -a | |
# you can safely remove the .snapshots subvolume | |
# since there is a subvolume called @.snapshots by default | |
btrfs sub delete .snapshots | |
# add "wheels" to group and set schedule | |
# https://wiki.archlinux.org/title/snapper#Set_snapshot_limits | |
nano /etc/snapper/configs/root | |
# start your engines | |
sudo systemctl enable --now grub-btrfsd | |
sudo systemctl enable --now snapper-timeline.timer | |
sudo systemctl enable --now snapper-cleanup.timer | |
# did I mention these things have weird defaults | |
btrfs sub set-default 256 / | |
# add a hook to allow changing the read only file system to write when rolling back | |
# this may not be necessary since there seems to be a hook you could use instead | |
# https://wiki.archlinux.org/title/snapper#Booting_into_read-only_snapshots | |
wget https://raw.githubusercontent.com/Antynea/grub-btrfs/master/initramfs/Arch%20Linux/overlay_snap_ro-install -O /etc/initcpio/install/snap-hook | |
wget https://raw.githubusercontent.com/Antynea/grub-btrfs/master/initramfs/Arch%20Linux/overlay_snap_ro-hook -O /etc/initcpio/hooks/snap-hook | |
# add "snap-hook" to the hooks | |
nano /etc/mkinitcpio.conf | |
mkinitcpio -P | |
# change "@snapshots" to "@.snapshots" | |
# uncomment and set your root device id on the last line | |
nano /etc/snapper-rollback.conf | |
mount -a | |
# to help preserve my SSD lifespan there are a few additional things I did | |
# 1. enabled compression on all btrfs mounts in /etc/fstab with "compress=zstd" (the default level 3 is good) | |
# 2. I added subvolumes `/var/cache`, `/var/lib/docker`, `/var/lib/flatpak`. Since those folders would bloat up my rollback root snapshots | |
# I used a script to allow me to create subvolumes for busy folders here: | |
# https://gist.github.com/zatricky/b195b474ed5f3c3c4c57e878eef4f0f5 | |
# Make sure to add the new subvolume to /etc/fstab e.g. ... subvol=/@/var/cache | |
# 3. edit /usr/lib/systemd/system/snapper-timeline.timer to weekly so less snapshots need to be made |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment