Skip to content

Commit

Permalink
fix(arch): set up Btrfs system snapshots
Browse files Browse the repository at this point in the history
Signed-off-by: Chris1320 <chris1320@protonmail.com>
  • Loading branch information
Chris1320 committed Nov 22, 2024
1 parent 0aded4f commit 30f2f2b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
11 changes: 6 additions & 5 deletions Operating Systems/Arch Linux/Contents/Environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ During the installation I've configured my machine to have the following disk pa

If your machine has a RAM size of 8GB or lower, I recommend that you create a separate partition for [ZRAM](https://wiki.archlinux.org/title/Zram), `/dev/sdaX`, as its backing device. `/dev/sdaY` will be a [Btrfs filesystem](https://wiki.archlinux.org/title/Btrfs) with the following subvolumes:

| Subvolume | Description |
| ----------------- | ------------------------------------------- |
| `/mnt/@` | The root partition |
| `/mnt/@home` | The home partition |
| `/mnt/@snapshots` | The partition where snapshots will be saved |
| Subvolume | Description |
| ----------------- | ---------------------------------- |
| `/mnt/@` | The root partition |
| `/mnt/@home` | The home partition |
| `/mnt/@var_log` | The partition for system logs |
| `/mnt/@snapshots` | The partition for system snapshots |

> [!ERROR] Important Note
>
Expand Down
18 changes: 3 additions & 15 deletions Operating Systems/Arch Linux/Contents/Manual Customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,26 +603,14 @@ paru -S obs-studio v4l2loopback-dkms v4l2loopback-utils
## Btrfs Snapshots

Since we have set up our system to use Btrfs with a `@snapshots` subvolume, we will use [Snapper](https://snapper.io/) to create snapshots and [Btrfs Assistant](https://gitlab.com/btrfs-assistant/btrfs-assistant) as the frontend. [snap-pac](https://github.com/wesbarnett/snap-pac) is installed to create Btrfs snapshots before and after Pacman operations.
We will use [Snapper](https://snapper.io/) to create snapshots and [Btrfs Assistant](https://gitlab.com/btrfs-assistant/btrfs-assistant) as the frontend. [snap-pac](https://github.com/wesbarnett/snap-pac) is installed to create Btrfs snapshots before and after Pacman operations.

```bash
paru -S snapper snap-pac btrfs-assistant inotify-tools
systemctl enable snapper-boot.timer
```

To use `grub-btrfsd.service`, we'll have to edit the service to point to `/snapshots`.

```bash
sudo systemctl edit --full grub-btrfsd.service
```

Find the line where it shows:

```toml
ExecStart=/usr/bin/grub-btrfsd --syslog /.snapshots
```

and replace `/.snapshots` to `/snapshots`. Save and close the file and then run the following command to enable the service:
To use `grub-btrfsd.service`, run the following command to enable the service:

```bash
systemctl enable grub-btrfsd.service
Expand All @@ -638,7 +626,7 @@ After saving and closing the file, run `mkinitcpio -P`.

### Setting Up Snapper

Start Btrfs Assistant and go to the *Snapper Settings* tab. Click *New* and name it `root` with backup path `/`. Enable *timeline snaphots*, adjust the snapshot retention times, and click *Save*. Click *New* again and name it `home` with backup path `/home`, enable *timeline snaphots*, adjust the snapshot retention times, and click *Save*. Lastly, enable *timeline*, *cleanup*, and *boot* in *systemd Unit Settings* section.
Start Btrfs Assistant and go to the *Snapper Settings* tab. Click *New* and name it `root` with backup path `/`. Enable *timeline snaphots*, adjust the snapshot retention times, and click *Save*. Enable *timeline*, *cleanup*, and *boot* in *systemd Unit Settings* section.

## Ricing Up GRUB

Expand Down
4 changes: 3 additions & 1 deletion Operating Systems/Arch Linux/Contents/System Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ mount --mkdir /dev/sdaY /mnt
# Create Btrfs subvolumes
btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home
btrfs subvolume create /mnt/@var_log
btrfs subvolume create /mnt/@snapshots

# Unmount /mnt
Expand All @@ -97,7 +98,8 @@ umount /mnt
# Mount the partitions in their respective mountpoints.
mount --mkdir -o noatime,compress-force=zstd:3,subvol=@ /dev/sdaY /mnt
mount --mkdir -o noatime,compress-force=zstd:3,subvol=@home /dev/sdaY /mnt/home
mount --mkdir -o noatime,compress-force=zstd:3,subvol=@snapshots /dev/sdaY /mnt/snapshots
mount --mkdir -o noatime,compress-force=zstd:3,subvol=@var_log /dev/sdaY /mnt/var/log
mount --mkdir -o noatime,compress-force=zstd:3,subvol=@snapshots /dev/sdaY /mnt/.snapshots
mount --mkdir /dev/sda2 /mnt/boot
mount --mkdir /dev/sda1 /mnt/boot/efi
```
Expand Down

0 comments on commit 30f2f2b

Please sign in to comment.