blob: 73aa0022c19e0e539e98a3cfb919a6b40507b562 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#!/bin/bash
set -e
echo ">>> [snapshots-subvol] Running INSIDE target system"
ROOT_DEV="$(findmnt -no SOURCE / | sed 's/\[.*\]//')"
ROOT_FS="$(findmnt -no FSTYPE /)"
if [ "$ROOT_FS" != "btrfs" ]; then
echo ">>> [snapshots-subvol] Root is not btrfs (${ROOT_FS}), skipping."
exit 0
fi
if [ -d /.snapshots ] && findmnt -no SOURCE /.snapshots >/dev/null 2>&1; then
echo ">>> [snapshots-subvol] /.snapshots already mounted, skipping."
exit 0
fi
mkdir -p /mnt/topvol
mount -o subvolid=5 "${ROOT_DEV}" /mnt/topvol
if [ ! -d /mnt/topvol/@snapshots ]; then
btrfs subvolume create /mnt/topvol/@snapshots
echo ">>> [snapshots-subvol] Created @snapshots subvolume"
else
echo ">>> [snapshots-subvol] @snapshots subvolume already exists"
fi
umount /mnt/topvol
rmdir /mnt/topvol
mkdir -p /.snapshots
ROOT_UUID="$(blkid -s UUID -o value "${ROOT_DEV}")"
if ! grep -q '/.snapshots' /etc/fstab; then
echo "UUID=${ROOT_UUID} /.snapshots btrfs rw,noatime,compress=zstd:3,discard=async,space_cache=v2,subvol=/@snapshots 0 0" >> /etc/fstab
echo ">>> [snapshots-subvol] Added /.snapshots to fstab"
fi
mount /.snapshots
echo ">>> [snapshots-subvol] Done."
|