It worked, let me share my .txt file for you guys, it has everything I know so far…
This .txt file is far from complete, there is still a lot to learn…
Especial thanks to @ricklinux, @dalto and @pebcak who helped me a lot
The instrctuions below are for BTRFS filesystem, snapper usage for snapshots management, and snapper-rollback or rollback through Live USB.
Intended for single disk only which means no RAID instructions.
If you are reading this before installing the system, I suggest you to follow the procedures to have a separate @snapshots subvolume and have the suggested filesystem layout as Calamares itself won't do it for you.
This is required for snapper-rollback to work.
https://wiki.archlinux.org/title/Snapper#Suggested_filesystem_layout
This is only valid for endeavouros-2021.08.27-x86_64.iso or previous, as we don't know yet how the next Calamares fstab and mount.conf will be.
*** Installation and configuration
** LIVEUSB STEP #1
edit /etc/calamares/modules/mount.conf
Add these to the end of the file: (Make sure it is written exactly as the already existings mountpoints).
- mountPoint: /.snapshots
subvolume: /@snapshots
Now, it also has been recommended by the EnOS community, to change the compression from LZO to ZSTD:
** LIVEUSB STEP #2
edit /etc/calamares/modules/fstab.conf
Change the mountOptions for btrfs compression field from lzo to zstd as per below:
mountOptions:
ssdExtraMountOptions:
btrfs: compress=zstd
Then install the system, once it's finished, proceed below:
# pacman -S snapper
Configuration of snapper and mount point
It is assumed that the subvolume @ is mounted at root /. It is also assumed that /.snapshots is not mounted and does not exist as folder, this can be ensured by the commands:
# umount /.snapshots
# rm -r /.snapshots
Then create a new configuration for /. Snapper create-config automatically creates a subvolume .snapshots with the root subvolume @ as its parent, that is not needed for the suggested filesystem layout, and can be deleted.
# snapper -c root create-config /
# btrfs subvolume delete /.snapshots
Delete subvolume (no-commit): '//.snapshots'
After deleting the subvolume, recreate the directory /.snapshots.
# mkdir /.snapshots
Now mount @snapshots to /.snapshots. Where # is the BTRFS root partition.
# mount -o subvol=@snapshots /dev/sda# /.snapshots
To make this mount permanent, add an entry to your fstab.
Or if you have an existing fstab entry remount the snapshot subvolume:
# mount -a
# chmod 750 /.snapshots/
Give the folder 750 permissions.
This will make all snapshots that snapper creates be stored outside of the @ subvolume, so that @ can easily be replaced anytime without losing the snapper snapshots.
** SNAPPER configuration steps for @ (/).
# sudo snapper -c root create-config / (if you edited mount.conf in calamares and performed all the steps above, this is not needed, jump to next step).
# systemctl enable --now snapper-timeline.timer
# systemctl enable --now snapper-cleanup.timer
** Set snapshot limits
Now that snapper is installed and partially configured, you can change the snapshot limits and snapshot and cleanup frequencies.
As per Arch Wiki, the default settings will keep 10 hourly, 10 daily, 10 monthly and 10 yearly snapshots. You may want to change this in the configuration, especially on busy subvolumes like /
Here is an example section of a configuration named config with only 5 hourly snapshots, 7 daily ones, no monthly and no yearly ones:
/etc/snapper/configs/root
TIMELINE_MIN_AGE="1800"
TIMELINE_LIMIT_HOURLY="5"
TIMELINE_LIMIT_DAILY="7"
TIMELINE_LIMIT_WEEKLY="0"
TIMELINE_LIMIT_MONTHLY="0"
TIMELINE_LIMIT_YEARLY="0"
*** SNAPPER useful commands:
- List snapper configs
snapper list-configs
- List snapshots for a config where config_name is the name of the configuration:
snapper -c config_name list
- Delete a snapshot:
snapper -c root delete N (config is the name of the config and N is the number of the snapshot)
snapper -c root delete 65 70 (delete snapshot 65 and 70)
snapper -c root delete 65-70 (delete snapshot from 65 to 70)
Note: When deleting a pre snapshot, you should always delete its corresponding post snapshot and vice versa.
- Remove a config from snapper:
The sequence of the commands here is very important.
$ snapper -c config_name list
$ snapper -c config_name delete 3-18 (3-18 is the range from 3 to 18)
$ snapper -c config_name delete-config
- Remove root config from snapper cannot be done as described in the previous section, follows below how to accomplish it:
$ cd /etc/snapper/configs/
# rm root
edit /etc/conf.d/snapper and remove root from the quotes of SNAPPER_CONFIGS="root"
- Create a snapshot:
To take a snapshot of a subvolume manually, do:
# snapper -c config create --description desc
The above command does not use any cleanup algorithm, so the snapshot is stored permanently or until deleted.
To set a cleanup algorithm, use the -c flag after create and choose either number, timeline, pre, or post. number sets snapper to periodically remove snapshots that have exceeded a set number in the configuration file. For example, to create a snaphot that uses the number algorithm for cleanup do:
# snapper -c config create -c number
- Restore a snapshot Using snapper-rollback: (Suggested SNAPPER filesystem layout required) Live USB boot not required.
Find the device used for the root partition through:
$ mount | grep btrfs
Configure snapper-rollback
Edit /etc/snapper-rollback.conf and add to the end of the file:
dev = /dev/sda#
Where # is the number of the drive for the root partition
Then, to rollback, find out which snapshot you want to rollback to (snapper -c root list) and then issue the following command:
# snapper-rollback #
Where # is the number of the snapshot you want to rollback to.
- Restore a snapshot: (Default calaremes filesystem layout) Live USB boot required.
List which snapshot you will be using
# snapper -c root list
Boot to live USB
Mount BTRFS partition:
# mount /dev/sda# /mnt (should be the BTRFS volume used for root, /)
# mv /mnt/@ /mnt/@old
# btrfs subvolume snapshot /mnt/@old/.snaphots/#/snapshot /mnt/@
Where # is the number of the snapper snapshot you wish to restore. Your / has now been restored to the previous snapshot.
# mv /mnt/@old/.snapshots /mnt/@/.
# btrfs subvolume delete /mnt/@old - Optional, to remove the current broken snapshot
Now just simply reboot.
- Restore a snapshot: (Suggested SNAPPER filesystem layout) Live USB boot required.
List which snapshot you will be using
# snapper -c root list
Boot to live USB
Mount BTRFS partition:
# mount /dev/sda# /mnt (# should be the BTRFS volume used for root, /)
# mv /mnt/@ /mnt/@old
# btrfs subvolume snapshot /mnt/@snapshots/#/snapshot /mnt/@
Where # is the number of the snapper snapshot you wish to restore. Your / has now been restored to the previous snapshot.
# btrfs subvolume delete /mnt/@old - Optional, to remove the current broken snapshot
Now just simply reboot.
*** BTRFS useful commands:
- List subvolumes:
# btrfs subvolume list /
- List subvolumes, print the parent ID
# btrfs subvolume list -p /
- Count snapshots:
# btrfs subvolume list -ts / | wc -l
- Display disk usage:
# btrfs filesystem usage /
$ btrfs filesystem df /
- List of all the btrfs filesystems on the systems and which devices they include
# btrfs filesystem show
- List details about a subvolume (using root in the example below)
# btrfs subvolume show /
- Create subvolume
# btrfs subvolume create /path/dir
- Delete subvolume
# btrfs subvolume delete /path/dir
- Change a snapshot from ro (read only), to read and write: where # is the number of the snapshot, useful for deleting files from snapshots and other actions.
Verify status:
$ btrfs property get /.snapshots/#/snapshot
ro=true
Change to rw:
# btrfs property set /.snapshots/#/snapshot ro false
Fallback to ro:
# btrfs property set /.snapshots/#/snapshot ro true
You can now modify files in /path/to/.snapshots/<snapshot_num>/snapshot like normal. You can use a shell loop to work on your snapshots in bulk.
*** Tips:
** Preventing slowdowns
- updatedb
By default, updatedb (see mlocate) will also index the .snapshots directory created by snapper, which can cause serious slowdown and excessive memory usage if you have many snapshots. You can prevent updatedb from indexing over it by editing:
/etc/updatedb.conf
PRUNENAMES = ".snapshots"
** Access for non-root users
Each config is created with the root user, and by default, only root can see and access it.
To be able to list the snapshots for a given config for a specific user, simply change the value of ALLOW_USERS in your /etc/snapper/configs/config file. You should now be able to run snapper -c config list as a normal user.
Eventually, you want to be able to browse the .snapshots directory with a user, but the owner of this directory must stay root. Therefore, you should change the group owner by a group containing the user you are interested in, such as users for example:
# chmod a+rx .snapshots
# chown :users .snapshots
*** BTRFS Maintanance:
- SCRUB /
I personally prefer to run scrub manually, note that a scrub in / works at filesystem level, so all subvolumes included, I suggest to run it once per month.
# btrfs scrub start /
# btrfs scrub status /
- TRIM (SSD), don't forget to enable TRIM in fstab (discard=async), or enable periodic fstrim.timer as per below:
- Enable timer
# systemctl enable --now fstrim.timer
# systemctl status fstrim.timer
- Start fstrim manually
# systemctl start fstrim.service
# systemctl status fstrim.service
- If you are using the provided systemd timers, you can edit them to change the snapshot and cleanup frequency.
- snapper-timeline.timer
# systemctl edit snapper-timeline.timer
to revert changes:
# systemctl revert snapper-timeline.timer
When editing snapper-cleanup.timer, you need to change OnUnitActiveSec. (I prefer 12h period, default is 24h).
to revert changes:
# systemctl revert snapper-timeline.timer
*** Troubleshooting
- Orphaned snapshots causing wasted disk space
It is possible for snapshots to get 'lost', where they still exist on disk but are not tracked by snapper. This can result in a large amount of wasted, unaccounted-for disk space. To check for this, compare the output of
# snapper -c <config> list
to
# btrfs subvolume list -o <parent subvolume>/.snapshots (sudo btrfs subvolume list -o /.snapshots/ to check root)
Any subvolume in the second list which is not present in the first is an orphan and can be deleted manually.
- Balance:
Balance on a single-device filesystem a balance may be also useful for (temporarily) reducing the amount of allocated but unused (meta)data chunks.
This will run on filesystem level, thus all subvolumes included.
# btrfs balance start /
- Checksum hardware acceleration
CRC32 is a new instruction in Intel SSE4.2. To verify if Btrfs checksum is hardware accelerated:
# dmesg | grep crc32c
[ 3.630588] Btrfs loaded, crc32c=crc32c-intel, zoned=yes
If you see crc32c=crc32c-generic, it is probably because your root partition is Btrfs, and you will have to compile crc32c-intel into the kernel to make it work. Putting crc32c-intel into mkinitcpio.conf does not work.
- Check the mount options to confirm if everything is correct:
$ mount | grep btrfs
- Check if the SSD optimizations were set:
# dmesg | grep ssd
Useful links:
https://forum.endeavouros.com/t/first-try-with-btrfs-questions/17353/2
https://btrfs.wiki.kernel.org/index.php/Gotchas#Fragmentation
https://wiki.archlinux.org/title/Snapper#Creating_a_new_configuration
https://wiki.archlinux.org/title/Btrfs
https://btrfs.wiki.kernel.org/index.php/FAQ#Is_Btrfs_optimized_for_SSD.3F
https://man.archlinux.org/man/btrfs.5#MOUNT_OPTIONS
https://wiki.archlinux.org/title/Btrfs#Creating_a_subvolume
https://bbs.archlinux.org/viewtopic.php?id=194491
https://wiki.archlinux.org/title/Systemd#Editing_provided_units
https://wiki.archlinux.org/title/Systemd/Timers
https://github.com/jrabinow/snapper-rollback