This is currently a work in progress!!!!!
This project is not finish and still in development use at your own RISK!!!
Using the arch live iso
BTRFS, Snapper, btrfs-grub, snap-pac
Snapper is a tool for managing BTRFS snapshots. It can create and restore snapshots, and provides scheduled auto-snapping. Snap-pac provides a Pacman hook that uses Snapper to create pre- and post- BTRFS snapshots triggered by use of the package manager.
Snapshots can be created manualy or whit the Timeline scheduler. it will also prune the timeline and install snapshot automaticaly when they reach the posted threshold that you set in the config.
which can be found:
/etc/snapper/configs/root
- Install the OS of choice:
- Create the Additional Subvolumes
- Install and Configure Snapper
- Intstall and Configure Grub-Btrfs
- Create a system Root Snapshot and set tit as default
- Test Snapper
- Enable automatic Timeline Snapshots
sudo systemctl enable --now grub-btrfsd
sudo grub-mkconfig -o /boot/grub/grub.cfg
WARNING: 'grub-mkconfig' needs to run at least once to generate the snapshots (sub)menu entry in grub the main menu. After that this script can run alone to generate the snapshot entries.
sudo btrfs property get /.snapshots/1/snapshot
## or ( sudo btrfs prop get -ts / )
sudo btrfs property set /.snapshots /1/snapshot ro false
1- = the snapshot that is currently booted in.
sudo btrfs subvol get-defualt /
sudo btrfs subvol list /
btrfs subvolume set-default 263 /
As you can see, the /.snapshots/1/snapshot subvolume is also visible as snapshot #1 in snapper. The asterisk (*) indicates that this snapshot is the default and is currently active.
snapper list-configs
snapper delete-config
snapper get-config
snapper list
snapper -c root create -d "***Initial Manual snapshot***"
btrfs subvolume delete /.snapshots/1/snapshot
btrfs subvolume delete /.snapshots
sudo btrfs subvolume list /
sudo btrfs subvolume show /
snapper status 2..3
sudo snapper undochange 2..3
sudo snapper undochange 3..2
snapper diff 3..0 /etc/hosts
sudo snapper undochange 3..0 /etc/hosts
snapper -c root create -t pre -c number -d 'Pre Color Picker'
snapper -c root create -t post --pre-number 4 -c number -d 'Post Color Picker'
snapper -c root delete 4-7
snapper -c home delete 1-2
sudo snapper rollback
sudo reboot
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
sudo btrfs filesystem du -s --human-readable /.snapshots/*/snapshot
snapper delete 1
snapper delete 3-4
Providing there is no snapshot/1 Create a directory named /.snapshots/1
sudo mkdir -v /.snapshots/1
sudo cp -v /.snapshots/2/info.xml /.snapshots/1/
<?xml version="1.0"?>
<snapshot>
<type>single</type>
<num>1</num>
<date>2024-04-26 15:18:14</date>
<description>new root subvolume</description>
</snapshot>
sudo btrfs subvolume snapshot /.snapshots/2/snapshot /.snapshots/1/snapshot
sudo btrfs inspect-internal rootid /.snapshots/1/snapshot
Output: #> 276
Using subvolid 276, set the /.snapshots/1/snapshot subvolume as the default subvolume for the root (/)
sudo btrfs subvolume set-default 276 /
sudo reboot
sudo btrfs subvolume get-default /
sudo btrfs property get -ts /
snapper ls
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
sudo snapper -c home set-config TIMELINE_CREATE=no
sudo systemctl enable --now snapper-timeline.timer
sudo systemctl enable --now snapper-cleanup.timer
echo 'PRUNENAMES = ".snapshots"' | sudo tee -a /etc/updatedb.conf
paru -S update-grub sudo update-grub
- snap-pac — Makes pacman automatically use snapper to create pre/post snapshots like openSUSE's YaST. Uses pacman hooks.
- grub-btrfs — Includes a daemon (grub-btrfsd) that can be enabled via systemctl to look for new snapshots and automatically includes them in the GRUB menu.
Snapper includes a rollback tool, but on Arch systems the preferred method is a manual rollback.
After booting into a snapshot mounted rw courtesy of overlayfs, mount the toplevel subvolume (subvolid=5). That is, omit any subvolid or subvol mount flags (example: an encrypted device map labelled cryptdev) ...
sudo mount /dev/mapper/cryptdev /mnt
Move the broken @ subvolume out of the way ...
sudo mv /mnt/@ /mnt/@.broken
Or simply delete the subvolume ...
sudo btrfs subvolume delete /mnt/@
Find the number of the snapshot that you want to recover ...
sudo grep -r '<date>' /mnt/@snapshots/*/info.xml
[...]
/.snapshots/8/info.xml: <date>2022-08-20 15:21:53</date>
/.snapshots/9/info.xml: <date>2022-08-20 15:22:39</date>
Create a read-write snapshot of the read-only snapshot taken by Snapper ...
sudo btrfs subvolume snapshot /mnt/@snapshots/number/snapshot /mnt/@
Where number is the snapshot you wish to restore as the new @.
Unmount /mnt.
Reboot and rollback!
inotify-tools ?? Do I need this
snap-pac-grub
btrfs-asssitant
More information can be found in the arch wiki:
https://wiki.archlinux.org/title/snapper
Reference info:
- https://www.lorenzobettini.it/2022/07/timeshift-and-grub-btrfs-in-linux-arch/
- https://wiki.archlinux.org/title/Btrfs
- https://www.youtube.com/watch?v=aAAUU3t55YQ
- https://www.lorenzobettini.it/2023/03/snapper-and-grub-btrfs-in-arch-linux/
- https://www.dwarmstrong.org/archlinux-install/
- https://www.dwarmstrong.org/btrfs-snapshots-rollbacks/