[HowTo] Btrfs and Snapper

Difficulty: ★★★☆☆

How-To BTRFS and SNAPSHOTS for N@@bs

  1. Install system in BTRFS format on a sdd disk
  • Partitions
    • boot:
      • File System: FAT32
      • Mount point: /boot/efi
      • Size: 512M
      • Partition flags: EFI, BOOT
    • root:
      • File System: BTRFS
      • Mount point: /
      • Size: 48GB for normal user, 64GB for power user
      • Mount options: noatime,sdd,clear_cache,commit=120,compress=zstd,subvolid=256
    • home:
      • File System: BTRFS
      • Mount point: /home
      • Size: 64GB for small user, 128GB for power user, the rest of your disk -10% for super-user
      • Mount Options: noatime,sdd,clear_cache,commit=120,compress=zstd,subvolid=256
  • Subvolumes
    • @ /
    • @Ugin /home
  1. Snapper
  • Create config files for each Partition

    • We need root acces
    • snapper -c root create-config /
    • snapper -c home create-config /home
  • Config the snapper config files

    • We need root acces

    • The method is the same for any config file (I.E. / and /home)

    • nano /etc/snapper/configs/root

    • Set the variable ALLOW_USERS="@USER" in /etc/environment

    • Set limits for timeline cleanup to:

      #this is my own
      Hourly=“0”
      Daily=“2”
      Weekly=“4”
      Monthly=“12”
      Yearly=“1” 
      
  • Adding @USER permissions to the snapshots directories:

    chmod a+rw /.snapshots/
    chmod a+rw /home/.snapshots/
    
  • Enable and start snapper services:

    • We need root access

      systemctl start snapper-timeline.timer
      systemctl enable snapper-timeline.timer
      systemctl start snapper-cleanup.timer
      systemctl enable snapper-cleanup.timer
      
  • Enable grub-btrfs services

    • Install grub-btrfs:

      pamac install grub-btrfs
      
    • We need root acces

      systemctl start grub-btrfs.path
      systemctl enable grub-btrfs.path
      
  • List the snapshots created

    • As @USER

      snapper -c list
      
  • Create a snapshot manually:

    • As @USER

        snapper -c create -c timeline --description
      
  • Changing permissions of snapshots

    • By default all snapshots are set as Read-Only

    • Check snapshops permissions as @USER:

      btrfs property list -ts /.snapshots//snapshot/ # for @
      btrfs property list -ts /home/.snapshops//snapshot # for @Ugin
      
    • Changing snaphots permissions to Write

      • We need root acces

        btrfs property set -ts /.snapshots//snapshot/ ro false #for @
        btrfs property set -ts /home/.snaphots//snapshot/ ro false #for @Ugin
        

How-To Convert an ext2/3/4 filesystem in a BTRFS system

  1. Do a full backup of your system, / and /home with Timeshift or other application who use RSYNC
  2. Boot up with a live system
  3. Do the partitioning using btrfs; in my case, I created /boot/efi, / and /home
  • Checking subvolumes

    • We need root acces

      btrfs subvolume list
      
  • Mount / partition

    mount /dev/sdXN /mnt
    btrfs subvolume list /mnt
    
  1. Creating other subvolumes
  • Create BTRFS subvolume for /home

  • With our / partition mounted in /mnt, we’re going to delete the EXT4 /home folder

    rm -rf /mnt/home
    
  • Create the @Ugin subvolume

    btrfs subvolume create /mnt/@Ugin
    
  • Now we can mount the /home partition into the subvolume

    mount /dev/sdXN /mnt/@Ugin
    
  1. Restoring the backup

    • You could use any application or you could use rsync to do it.
  2. Edit /etc/fstab

  • Change the old UUID to the news, the partitions format and mount options

    sudo nano --backup /mnt/etc/fstab
    
  1. Reinstall Grub

    sudo update-grub
    

Source for documentation:
Btrfs Arch Wiki
Snapper Arch Wiki

9 Likes

Please have a look at my edits and disregard anything you don’t like… :wink: (:heart: and :+1: will remain in place even if you revert completely, but this way it’s easier on the :eyes:…)

2 Likes

Hi!
Like you said, It’s easy to see this way. Nothing to add, just Thanks!!!1

1 Like

Hi,

I have some issues with Snapper setup.
Atm I stucked here :

  • systemctl start grub-btrfs.path  1 ✘
    Failed to start grub-btrfs.path: Unit \x2esnapshots.mount not found.

Also can not create snapshot manually … What I did wrong ? :slight_smile:

A post was split to a new topic: BTRFS Snapper help needed

But this is old.
There is snapper GUI btrfs-assistant good for beginner, but it is still in development and testing.

Forum:

I tried it in Manjaro, it works fine with creating new snapshots and restoring snapshot via GUI.

  • One point is missing:
    Grub-btrfs can not boot any read-only snapshot.
    There is a trick:
    You need to edit /etc/mkinitcpio.conf to add grub-btrfs-overlayfs in HOOK, then you create a new read-only snapshot including the ability grub-btrfs-overlayfs to boot it into RAM like the behavior of Live USB/CD. Then you restore a snapshot.

Because .snapshots is the directory, but not subvolume. Try to create a new subvolume @snapshots then edit /etc/fstab to mount it with .snapshots

Total noob questions:

  1. What’s @Ugin? I tried googling but even on the wiki I couldn’t find anything about it.

  2. Is the /home partition necessary? I come from Garuda and I didn’t have a /home partition. My / usage is kinda unpredictable, especially with docker/podman/distrobox. Speaking of:

Current Subvolumes on Garuda
sudo btrfs subvolume list /mnt
ID 256 gen 187528 top level 5 path @
ID 257 gen 187528 top level 5 path @home
ID 258 gen 186167 top level 5 path @root
ID 259 gen 175719 top level 5 path @srv
ID 260 gen 187502 top level 5 path @cache
ID 261 gen 187528 top level 5 path @log
ID 262 gen 186845 top level 5 path @tmp
ID 263 gen 186610 top level 256 path .snapshots
ID 396 gen 179152 top level 256 path var/lib/docker/btrfs/subvolumes/21b99aa1976242e860da5be90a706225222041dc9d28e9a4aa2961878fd157df
ID 397 gen 10614 top level 256 path var/lib/docker/btrfs/subvolumes/ba18748cababfedc54a6e5c49b6609a93279574caa467421b61871cab5d1c0a0-init
ID 398 gen 10614 top level 256 path var/lib/docker/btrfs/subvolumes/ba18748cababfedc54a6e5c49b6609a93279574caa467421b61871cab5d1c0a0
ID 1392 gen 184269 top level 263 path .snapshots/1122/snapshot
ID 1393 gen 184271 top level 263 path .snapshots/1123/snapshot
ID 1394 gen 184275 top level 263 path .snapshots/1124/snapshot
ID 1395 gen 184276 top level 263 path .snapshots/1125/snapshot
ID 1396 gen 184280 top level 263 path .snapshots/1126/snapshot
ID 1397 gen 184281 top level 263 path .snapshots/1127/snapshot
ID 1398 gen 184284 top level 263 path .snapshots/1128/snapshot
ID 1399 gen 184285 top level 263 path .snapshots/1129/snapshot
ID 1400 gen 184335 top level 263 path .snapshots/1130/snapshot
ID 1401 gen 184337 top level 263 path .snapshots/1131/snapshot
ID 1402 gen 186271 top level 263 path .snapshots/1132/snapshot
ID 1403 gen 186274 top level 263 path .snapshots/1133/snapshot
ID 1404 gen 186569 top level 263 path .snapshots/1134/snapshot
ID 1405 gen 186570 top level 263 path .snapshots/1135/snapshot
ID 1406 gen 186607 top level 263 path .snapshots/1136/snapshot
ID 1407 gen 186608 top level 263 path .snapshots/1137/snapshot
  1. The suggested subvolumes is kinda different from what I saw on the Arch wiki and my own subvolumes. Plus, my Garuda one seems to account for docker as well?

  2. Do I have to do all these at install? At which point is it alright to install? After the first partition and subvolume creation?

  3. Is there a video or visual guide that does it that aren’t for manjaro-architect?

Sorry for the questions, but I am a total noob at btrfs. and not sure what a lot of it means because there’s a lot of jargon I’m still not familiar with (and probably won’t be until I’ve done the process because that’s how I learn best).

  1. @Ugin is just name which he typed himself what he wants. You do not need to know it.

  2. Yes, the subvolume @home is mounted to /home by default after installation .
    You can check the fstab file /etc/fstab

  3. You are using the default layout of Snapper, that is fine. You can use btrfs-assistant GUI that supports it well.

  4. These subvolumes are default by Garuda installation, they are ok, but not nice for me (IMO)

  5. I think there is no video.

1 Like

Docker automatically created its own subvolumes, if it detected BTRFS. That is Docker’s job.

If you turn off Docker service manually, then Docker’s subvolumes are gone.

1 Like