Compare commits

...

74 Commits

Author SHA1 Message Date
Wayne Galen
2fcfbe9676 Ignore Podman container images (#380)
Same basic pattern as with Docker, but Podman uses a slightly different
path for this
2025-09-17 07:41:59 +02:00
TNE
9e171282da Get default early initrd list from GRUB_EARLY_INITRD_LINUX_STOCK (#389)
This mimics the behavior of grub more precisely

Fixes #388
2025-09-17 07:41:05 +02:00
cip91sk
b509fcaf61 add support for booting snapshots on LUKS encrypted disk (#333)
* add support for booting snapshots on LUKS encrypted disk

* documentation for booting from LUKS encrypted devices

* better detecting cryptdevice UUID
2025-01-06 08:11:45 +01:00
Pascal J
f682e17b30 Merge pull request #321 from StollD/set-subvolid
Add support for GRUB patches from SUSE
2024-04-08 17:02:40 +02:00
Pascal J
72a3dc092b Merge pull request #325 from aidan-gibson/master
Fix RAID
2024-03-27 18:16:20 +01:00
Aidan Gibson
6cb200a50b Fix RAID 2024-03-24 19:11:54 -07:00
Dorian Stoll
ece8d87151 Add support for GRUB patches from SUSE
Some GRUBs out there (Fedora, openSUSE) have an option that makes all
paths relative to the default subvolume of the filesystem. This can be
used to include /boot in your snapshots and roll them back without
having to regenerate grub.cfg.

However, enabling that option will break grub-btrfs, because loading the
kernel from a different snapshot requires the paths to be absolute.

To make this work, GRUB has to be told explicitly to access the root
subvolume when booting to a snapshot.
2024-03-10 12:56:37 +01:00
Pascal J
346a9868b8 Merge pull request #318 from expoodo/yabsnap_info_support
add support for yabsnap snapshot information
2024-03-06 14:48:24 +01:00
Pascal Jäger
b8465d14db fix spelling 2024-03-06 14:43:57 +01:00
Pascal J
0bc09317d8 Merge branch 'master' into yabsnap_info_support 2024-03-06 14:41:49 +01:00
Pascal J
94d742d1d4 Merge pull request #311 from bastien-roucaries/fix_bashism
Fix bashism
2024-03-06 14:24:44 +01:00
Pascal Jäger
363d7da3a7 fix typo uper -> upper 2024-03-06 14:23:26 +01:00
expoodo
585268dad7 Merge branch 'Antynea:master' into yabsnap_info_support 2024-02-19 15:18:18 -05:00
expoodo
34b54de71c removed redundant array slice 2024-02-19 15:16:26 -05:00
expoodo
a8713bbd0b mention yabsnap 2024-02-19 15:12:38 -05:00
Pascal Jäger
ac45f09af3 do not install compressed manpages
Fix #317

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2024-02-19 14:59:57 +01:00
expoodo
d41991979e add support for yabsnap snapshots info 2024-02-18 20:24:13 -05:00
Pascal J
99fc835e9c Merge pull request #305 from felixonmars/patch-1
Update Arch Linux package URL in README.md
2024-01-29 10:45:04 +01:00
Pascal J
5e608f8d96 Merge pull request #309 from yarikoptic/enh-codespell
Add codespell support (config, workflow to alert on new typos) + make it fix typos
2024-01-29 10:44:42 +01:00
Bastien Roucariès
465b56107f Add double quote if needed 2024-01-27 17:42:06 +00:00
Bastien Roucariès
7aa227b378 Fix 41_snapshots-btrs bashish [[ ]] 2024-01-27 17:38:55 +00:00
Yaroslav Halchenko
4ff82352bb Fix indentation after codespell 2023-12-21 19:25:54 -05:00
Yaroslav Halchenko
98a5bbe8c5 [DATALAD RUNCMD] run codespell throughout fixing typo automagically
=== Do not change lines below ===
{
 "chain": [],
 "cmd": "codespell -w",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [],
 "outputs": [],
 "pwd": "."
}
^^^ Do not change lines above ^^^
2023-12-21 19:25:13 -05:00
Yaroslav Halchenko
abd2889464 [DATALAD RUNCMD] Do interactive fixing of some ambigous typos
=== Do not change lines below ===
{
 "chain": [],
 "cmd": "codespell -w -i 3 -C 2 ./grub-btrfsd",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [],
 "outputs": [],
 "pwd": "."
}
^^^ Do not change lines above ^^^
2023-12-21 19:25:10 -05:00
Yaroslav Halchenko
25a9876ad4 Add rudimentary codespell config 2023-12-21 19:24:42 -05:00
Yaroslav Halchenko
d82ee289c3 Add github action to codespell master on push and PRs 2023-12-21 19:24:13 -05:00
Felix Yan
ef150c17bb Update Arch Linux package URL in README.md
The old URL returns 404 now.
2023-11-21 16:42:56 +02:00
Brian Morison
490720a13c Update grub-btrfsd (#289)
fix grub.cfg path in grub submenu creation
2023-07-26 21:18:10 +02:00
Pascal J
ade5a91d55 fix #285 (#287) 2023-06-05 08:55:44 +02:00
Pascal Jäger
9a8a1b7d50 fix #278
Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2023-04-28 18:26:25 +02:00
Pascal J
d51c96433c Remove openrc instructions for updating at system boot/ shutdown 2023-04-13 10:54:03 +02:00
Dan MacDonald
f461ea9cf1 More improvements to the README (#276)
* More improvements to the README

* Fix typo in README

* Adjust README according to Pascal's advice
2023-04-13 10:52:24 +02:00
Dan MacDonald
85571aab62 Correct first sentence of README 2023-04-11 08:52:34 +02:00
Dan MacDonald
2bbfddc46a Several edits and tweaks to the README 2023-04-11 08:52:34 +02:00
Pascal Jäger
3ce858f18d grub-btrfsd: refactor whole script
Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2023-04-05 18:05:29 +02:00
Pascal Jäger
dd96f22888 grub-btrfsd: Check if all dirs exist
Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2023-04-05 17:26:58 +02:00
Pascal Jäger
35429e02a4 grub-btrfsd: Kill process group on SIGTERM/ SIGINT
Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2023-04-05 17:10:49 +02:00
Pascal Jäger
04958d6e0b grub-btrfsd: Start subdaemon when --timeshift-auto
Fix #272

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2023-04-05 17:09:30 +02:00
Pascal Jäger
c6550d0d96 grub-btrfs: unquote snap variable
Fix #273

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2023-04-05 13:40:40 +02:00
Pascal Jäger
c7d4bbbe45 Makefile: don't delete temp dir after installation
Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2023-03-26 21:50:48 +02:00
Pascal Jäger
09a2a55ee4 Makefile: make docs installation optional
Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2023-03-26 21:39:51 +02:00
Pascal Jäger
8105a2edf7 grub-btrfsd: watch more than one snapshot dir
Fix #262

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2023-03-26 21:08:16 +02:00
Pascal Jäger
879bec3697 grub-btrfsd: watch snapshots directory recursively
Fix: #262

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2023-03-26 20:44:50 +02:00
Pascal Jäger
e2937f6bff grub-btrfs: update comments
Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2023-03-26 19:46:23 +02:00
Pascal Jäger
ec5ff8b4bc grub-btrfs: get back the grub_btrfs_search_directory functionality
Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2023-03-26 19:46:05 +02:00
Pascal Jäger
1556c345da grub-btrfs: Do root fs detection with btrfs progs
Fix: #266 #255

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2023-03-26 19:44:56 +02:00
Pascal Jäger
8028a4376a grub-btrfsd: change condition to run script
Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2023-03-26 18:56:35 +02:00
Pascal Jäger
0745117a76 Makefile: add variable GRUB_UPDATE_EXCLUDE
Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2023-03-26 18:56:35 +02:00
Kevin Chevreuil - Kaisen
2032502e09 Makefile: add an if statement for RHEL distribs based 2023-03-26 18:56:35 +02:00
Kevin Chevreuil - Kaisen
1d53472569 41_snapshots-btrfs: Create a bkp file. Delete the .new when no snapshots found. 2023-03-26 18:56:35 +02:00
Kevin Chevreuil - Kaisen
8ea8046887 Update the Makefile 2023-03-26 18:56:35 +02:00
Kevin Chevreuil - Kaisen
7586639f48 Auto execute the grub-mkconfig command at the installation 2023-03-26 18:56:35 +02:00
Kevin Chevreuil - Kaisen
5ce2dfa640 Only recreation of the submenu 2023-03-26 18:56:35 +02:00
Kevin Chevreuil - Kaisen
44c9cd16d0 Dynamic GRUB entry 2023-03-26 18:56:35 +02:00
Kevin Chevreuil - Kaisen
934a4a38e6 Force the deletion of the grub-btrfs.cfg file 2023-03-26 18:56:35 +02:00
Pascal J
87f030f6e8 Merge pull request #245 from Antynea/improve-config
Add kernel command line for snapshots as config parameter
2023-01-22 20:10:16 +01:00
Pascal J
1d33404c78 Merge branch 'master' into improve-config 2023-01-22 20:07:54 +01:00
Pascal Jäger
89ef805e81 grub-btrfsd: do no append with += to optional args
This does not work anymore, but it should be similar to the systemd
service file anyway, where things are just written in one line.

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2022-12-10 22:20:15 +01:00
Pascal Jäger
e03e87dd64 grub-btrfsd: Use bash as interpreter
Fix: #248

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2022-12-07 15:01:10 +01:00
Pascal Jäger
f131c38300 manpages: correct some minor things
Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2022-12-06 23:10:24 +01:00
Pascal Jäger
934ab213b0 grub-btrfs: add custom kernel parameters option for snapshots
Fix #214, #160

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2022-12-06 22:56:44 +01:00
Pascal Jäger
f0ed56d242 grub-btrfs: Improve variable defaults
Fix #244

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2022-12-06 22:55:51 +01:00
Pascal Jäger
29ec43e9a6 grub-btrfsd: Fix non POSIX redirect
Squashed commit of the following:

commit d75feb59f4
Author: Pascal J <pascal.jaeger@leimstift.de>
Date:   Sun Dec 4 22:07:01 2022 +0100

    grub-btrsd: update shebang

commit a64379789c
Author: Pavin Joseph <pavinjosdev@gmail.com>
Date:   Sun Dec 4 22:52:31 2022 +0530

    Update grub-btrfsd

commit fe42568785
Author: Pavin Joseph <pavinjosdev@gmail.com>
Date:   Sun Dec 4 04:07:05 2022 +0530

    Update grub-btrfsd

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2022-12-04 22:11:00 +01:00
Kevin Chevreuil - Kaisen
6980771cd2 Don't display warnings when the mount command is used 2022-11-29 14:47:18 +01:00
Pascal Jäger
bc167ffe00 Readme: added instructions for --timeshift-old
Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2022-11-26 17:59:38 +01:00
Pascal Jäger
b661e4e03f Merge branch 'fix-snap-dir-check' 2022-11-26 17:46:45 +01:00
Pascal Jäger
f594a56232 Merge branch 'improve-version-generation' 2022-11-26 17:44:06 +01:00
Pascal Jäger
fe48642596 Merge branch 'make-prefix-configurable' 2022-11-26 17:38:15 +01:00
Pascal Jäger
e3d0792a74 Post release version bump
Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2022-11-26 15:10:28 +01:00
Pascal Jäger
efc4657aab grub-btrfsd: fixed message about flag dependencies
Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2022-11-26 15:06:44 +01:00
Pascal Jäger
9e34f53ef8 Readme: discribe new version generation
Fix #237

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2022-11-26 15:03:10 +01:00
Pascal Jäger
6f154329c7 grub-btrfsd: fix if...else in daemon
add description of feature in manpage
fix non sh compatible commands in daemon

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2022-11-26 10:06:19 +01:00
Pascal Jäger
4942989d7f grub-btrfsd: add flag or old timeshift
Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2022-11-25 16:58:07 +01:00
Pascal Jäger
91c4aac82c grub-btrfsd: make dir check of snapshots dir a warning
Bug #234

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
2022-11-25 08:52:49 +01:00
17 changed files with 1084 additions and 524 deletions

6
.codespellrc Normal file
View File

@@ -0,0 +1,6 @@
[codespell]
skip = .git,*.pdf,*.svg,go.sum,.codespellrc
check-hidden = true
# ignore-regex =
# ist -- unfortunate variable
ignore-words-list = ist

22
.github/workflows/codespell.yml vendored Normal file
View File

@@ -0,0 +1,22 @@
---
name: Codespell
on:
push:
branches: [master]
pull_request:
branches: [master]
permissions:
contents: read
jobs:
codespell:
name: Check for spelling errors
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Codespell
uses: codespell-project/actions-codespell@v2

View File

@@ -20,14 +20,16 @@
# - Automatically generate grub.cfg if you use the provided systemd service.
#
# Installation:
# - Refer to https://github.com/Antynea/grub-btrfs#installation-
# - Refer to https://github.com/Antynea/grub-btrfs#%EF%B8%8F-installation
#
# Customization:
# You have the possibility to modify many parameters in /etc/default/grub-btrfs/config.
# Read more here https://github.com/Antynea/grub-btrfs#installation- an in the manpage
# 'man grub-btrfs'
#
# Automatically update Grub
# If you would like grub-btrfs menu to automatically update when a snapshot is created or deleted:
# - Refer to https://github.com/Antynea/grub-btrfs#automatically-update-grub.
# - Refer to https://github.com/Antynea/grub-btrfs#-automatically-update-grub-upon-snapshot.
#
# Special thanks for assistance and contributions:
# - My friends
@@ -39,8 +41,8 @@ set -e
sysconfdir="/etc"
grub_btrfs_config="${sysconfdir}/default/grub-btrfs/config"
[[ -f "$grub_btrfs_config" ]] && . "$grub_btrfs_config"
[[ -f "${sysconfdir}/default/grub" ]] && . "${sysconfdir}/default/grub"
[ -f "$grub_btrfs_config" ] && . "$grub_btrfs_config"
[ -f "${sysconfdir}/default/grub" ] && . "${sysconfdir}/default/grub"
## Error Handling
print_error()
@@ -73,15 +75,15 @@ while getopts :V-: opt; do
done
## Exit the script, if:
[[ "${GRUB_BTRFS_DISABLE,,}" == "true" ]] && print_error "GRUB_BTRFS_DISABLE is set to true (default=false)"
[ "$(echo "$GRUB_BTRFS_DISABLE" | tr '[:upper:]' '[:lower:]')" = 'true' ] && print_error "GRUB_BTRFS_DISABLE is set to true (default=false)"
if ! type btrfs >/dev/null 2>&1; then print_error "btrfs-progs isn't installed"; fi
[[ -f "${GRUB_BTRFS_MKCONFIG_LIB:-/usr/share/grub/grub-mkconfig_lib}" ]] && . "${GRUB_BTRFS_MKCONFIG_LIB:-/usr/share/grub/grub-mkconfig_lib}" || print_error "grub-mkconfig_lib couldn't be found"
[[ "$(${grub_probe} --target="fs" / 2>/dev/null)" != "btrfs" ]] && print_error "Root filesystem isn't btrfs"
[ -f "${GRUB_BTRFS_MKCONFIG_LIB:-/usr/share/grub/grub-mkconfig_lib}" ] && . "${GRUB_BTRFS_MKCONFIG_LIB:-/usr/share/grub/grub-mkconfig_lib}" || print_error "grub-mkconfig_lib couldn't be found"
[[ "$(btrfs filesystem df / 2>&1)" == *"not a btrfs filesystem"* ]] && print_error "Root filesystem isn't btrfs"
printf "Detecting snapshots ...\n" >&2 ;
## Submenu name
distro=$(awk -F "=" '/^NAME=/ {gsub(/"/, "", $2); print $2}' /etc/os-release)
distro=$(awk -F "=" '/^NAME=/ {gsub(/"/, "", $2); print $2}' /etc/os-release) # escape '
submenuname=${GRUB_BTRFS_SUBMENUNAME:-"${distro:-Linux} snapshots"}
## Limit snapshots to show in the Grub menu (default=50)
limit_snap_show="${GRUB_BTRFS_LIMIT:-50}"
@@ -92,12 +94,12 @@ grub_directory=${GRUB_BTRFS_GRUB_DIRNAME:-"/boot/grub"}
## Customize BOOT directory, where kernels/initrams/microcode is saved.
boot_directory=${GRUB_BTRFS_BOOT_DIRNAME:-"/boot"}
## Customize GRUB-BTRFS.cfg directory, where "grub-btrfs.cfg" file is saved
grub_btrfs_directory=${GRUB_BTRFS_GBTRFS_DIRNAME:-"/boot/grub"}
grub_btrfs_directory=${GRUB_BTRFS_GBTRFS_DIRNAME:-${grub_directory}}
## Customize directory where "grub-btrfs.cfg" file is searched for by grub
grub_btrfs_search_directory=${GRUB_BTRFS_GBTRFS_SEARCH_DIRNAME:-"\${prefix}"}
## Password protection management for submenu
# Protection support for submenu (--unrestricted)
case "${GRUB_BTRFS_DISABLE_PROTECTION_SUBMENU,,}" in
case "$(echo "$GRUB_BTRFS_DISABLE_PROTECTION_SUBMENU" | tr '[:upper:]' '[:lower:]')" in
true) unrestricted_access_submenu="--unrestricted ";;
*) unrestricted_access_submenu=""
esac
@@ -106,22 +108,41 @@ if [ -n "${GRUB_BTRFS_PROTECTION_AUTHORIZED_USERS}" ] ; then
protection_authorized_users="--users ${GRUB_BTRFS_PROTECTION_AUTHORIZED_USERS} "
fi
## Probe informations of Root and Boot devices
## Probe information of Root and Boot devices
# Probe info "Root partition"
root_device=$(${grub_probe} --target=device /) # Root device
root_uuid=$(${grub_probe} --device ${root_device} --target="fs_uuid" 2>/dev/null) # UUID of the root device
root_uuid_subvolume=$(btrfs subvolume show / 2>/dev/null) || print_error "UUID of the root subvolume is not available"; # If UUID of root subvolume is not available, then exit
root_uuid_subvolume=$(awk -F":" 'match($1, /(^[ \t]+UUID)/) {sub(/^[ \t]+/, "", $2); print $2}' <<< "$root_uuid_subvolume") # UUID of the root subvolume
root_uuid_subvolume=$(awk -F":" 'match($1, /(^[ \t]+UUID)/) {sub(/^[ \t]+/, "", $2); print $2}' <<< "$root_uuid_subvolume") # UUID of the root subvolume '
# Probe info "Boot partition"
boot_device=$(${grub_probe} --target=device ${boot_directory}) # Boot device
boot_uuid=$(${grub_probe} --device ${boot_device} --target="fs_uuid" 2>/dev/null) # UUID of the boot device
boot_uuid_subvolume=$(btrfs subvolume show "$boot_directory" 2>/dev/null) || boot_uuid_subvolume=" UUID: $root_uuid_subvolume"; # If boot folder isn't a subvolume, then UUID=root_uuid_subvolume
boot_uuid_subvolume=$(awk -F":" 'match($1, /(^[ \t]+UUID)/) {sub(/^[ \t]+/, "", $2); print $2}' <<< "$boot_uuid_subvolume") # UUID of the boot subvolume
boot_uuid_subvolume=$(awk -F":" 'match($1, /(^[ \t]+UUID)/) {sub(/^[ \t]+/, "", $2); print $2}' <<< "$boot_uuid_subvolume") # UUID of the boot subvolume '
boot_hs=$(${grub_probe} --device ${boot_device} --target="hints_string" 2>/dev/null) # hints string
boot_fs=$(${grub_probe} --device ${boot_device} --target="fs" 2>/dev/null) # Type filesystem of boot device
# Enable LUKS encrypted devices support
case "$(echo "$GRUB_BTRFS_ENABLE_CRYPTODISK" | tr '[:upper:]' '[:lower:]')" in
true)
list_insmods=()
list_insmods+=("insmod gzio")
list_insmods+=("insmod part_gpt")
list_insmods+=("insmod cryptodisk")
list_insmods+=("insmod luks")
list_insmods+=("insmod gcry_rijndael")
list_insmods+=("insmod gcry_rijndael")
list_insmods+=("insmod gcry_sha256")
list_insmods+=("insmod ${boot_fs}")
list_insmods+=("cryptomount -u $(echo $GRUB_CMDLINE_LINUX_DEFAULT | grep -o -P '(?<=cryptdevice=UUID=).*(?=:cryptdev)')")
;;
*)
list_insmods=("insmod ${boot_fs}")
;;
esac
## Parameters passed to the kernel
kernel_parameters="$GRUB_CMDLINE_LINUX $GRUB_CMDLINE_LINUX_DEFAULT"
kernel_parameters="$GRUB_CMDLINE_LINUX $GRUB_CMDLINE_LINUX_DEFAULT $GRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS"
## Mount point location
grub_btrfs_mount_point=$(mktemp -dt grub-btrfs.XXXXXXXXXX)
## Class for theme
@@ -130,7 +151,7 @@ CLASS="--class snapshots --class gnu-linux --class gnu --class os"
oldIFS=$IFS
## Detect uuid requirement (lvm,btrfs...)
check_uuid_required() {
if [ "x${root_uuid}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
if [ "${root_uuid}" = "" ] || [ "${GRUB_DISABLE_LINUX_UUID}" = "true" ] \
|| ! test -e "/dev/disk/by-uuid/${root_uuid}" \
|| ( test -e "${root_device}" && uses_abstraction "${root_device}" lvm ); then
LINUX_ROOT_DEVICE=${root_device}
@@ -148,7 +169,7 @@ detect_rootflags()
unmount_grub_btrfs_mount_point()
{
if [[ -d "$grub_btrfs_mount_point" ]]; then
if [ -d "$grub_btrfs_mount_point" ]; then
local wait=true
local wait_max=0
printf "Unmount %s .." "$grub_btrfs_mount_point" >&2;
@@ -158,7 +179,7 @@ if [[ -d "$grub_btrfs_mount_point" ]]; then
if umount "$grub_btrfs_mount_point" >/dev/null 2>&1; then
wait=false # umount successful
printf " Success\n" >&2;
elif [[ $wait_max = 10 ]]; then
elif [ $wait_max -eq 10 ]; then
printf "\nWarning: Unable to unmount %s in %s\n" "$root_device" "$grub_btrfs_mount_point" >&2;
break;
else
@@ -170,9 +191,9 @@ if [[ -d "$grub_btrfs_mount_point" ]]; then
printf " Success\n" >&2;
fi
done
if [[ "$wait" != true ]]; then
if [ "$wait" != true ]; then
if ! rm -d "$grub_btrfs_mount_point" >/dev/null 2>&1; then
printf "Unable to delete %s: Device or ressource is busy\n" "$grub_btrfs_mount_point" >&2;
printf "Unable to delete %s: Device or resource is busy\n" "$grub_btrfs_mount_point" >&2;
fi
fi
fi
@@ -191,10 +212,10 @@ make_menu_entries()
entry "submenu '${title_menu}' {
submenu '${title_submenu}' { echo }"
for k in "${name_kernel[@]}"; do
[[ ! -f "${boot_dir}"/"${k}" ]] && continue;
[ ! -f "${boot_dir}"/"${k}" ] && continue;
kversion=${k#*"-"}
for i in "${name_initramfs[@]}"; do
if [[ "${name_initramfs}" != "x" ]] ; then
if [ "${name_initramfs}" != "x" ] ; then
# prefix_i=${i%%"-"*}
suffix_i=${i#*"-"}
# alt_suffix_i=${i##*"-"}
@@ -205,7 +226,7 @@ make_menu_entries()
else continue;
fi
for u in "${name_microcode[@]}"; do
if [[ "${name_microcode}" != "x" ]] ; then
if [ "${name_microcode}" != "x" ] ; then
entry "
menuentry ' "${k}" & "${i}" & "${u}"' ${CLASS} "\$menuentry_id_option" 'gnulinux-snapshots-$boot_uuid' {"
else
@@ -216,17 +237,26 @@ make_menu_entries()
if [ x\$feature_all_video_module = xy ]; then
insmod all_video
fi
set gfxpayload=keep
insmod ${boot_fs}
set gfxpayload=keep"
for j in "${insmods[@]}"; do
entry "\
${j}"
done
entry "\
if [ x\$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root ${boot_hs} ${boot_uuid}
else
search --no-floppy --fs-uuid --set=root ${boot_uuid}
fi"
if [ "${SUSE_BTRFS_SNAPSHOT_BOOTING:-"false"}" = "true" ]; then
entry "\
set btrfs_subvolid=5"
fi
entry "\
echo 'Loading Snapshot: "${snap_date_trim}" "${snap_dir_name_trim}"'
echo 'Loading Kernel: "${k}" ...'
linux \"${boot_dir_root_grub}/"${k}"\" root="${LINUX_ROOT_DEVICE}" ${kernel_parameters} ${rootflags}subvol=\""${snap_dir_name_trim}"\""
if [[ "${name_microcode}" != "x" ]] ; then
if [ "${name_microcode}" != "x" ] ; then
entry "\
echo 'Loading Microcode & Initramfs: "${u}" "${i}" ...'
initrd \"${boot_dir_root_grub}/"${u}"\" \"${boot_dir_root_grub}/"${i}"\""
@@ -240,7 +270,7 @@ make_menu_entries()
done
else
for u in "${name_microcode[@]}"; do
if [[ "${name_microcode}" != "x" ]] ; then
if [ "${name_microcode}" != "x" ] ; then
entry "
menuentry ' "${k}" & "${u}"' ${CLASS} "\$menuentry_id_option" 'gnulinux-snapshots-$boot_uuid' {"
else
@@ -257,11 +287,16 @@ make_menu_entries()
search --no-floppy --fs-uuid --set=root ${boot_hs} ${boot_uuid}
else
search --no-floppy --fs-uuid --set=root ${boot_uuid}
fi"
if [ "${SUSE_BTRFS_SNAPSHOT_BOOTING:-"false"}" = "true" ]; then
entry "\
set btrfs_subvolid=5"
fi
entry "\
echo 'Loading Snapshot: "${snap_date_trim}" "${snap_dir_name_trim}"'
echo 'Loading Kernel: "${k}" ...'
linux \"${boot_dir_root_grub}/"${k}"\" root="${LINUX_ROOT_DEVICE}" ${kernel_parameters} ${rootflags}subvol=\""${snap_dir_name_trim}"\""
if [[ "${name_microcode}" != "x" ]] ; then
if [ "${name_microcode}" != "x" ] ; then
entry "\
echo 'Loading Microcode: "${u}" ...'
initrd \"${boot_dir_root_grub}/"${u}"\""
@@ -295,7 +330,7 @@ snapshot_list()
IFS=$'\n'
for snap in $(btrfs subvolume list -sa "${btrfs_subvolume_sort}" /); do # Parse btrfs snapshots
IFS=$oldIFS
snap=($snap)
snap=(${snap})
local path_snapshot=${snap[@]:13:${#snap[@]}}
if [ "$path_snapshot" = "DELETED" ]; then continue; fi # Discard deleted snapshots
[[ ${path_snapshot%%"/"*} == "<FS_TREE>" ]] && path_snapshot=${path_snapshot#*"/"} # Remove the "<FS_TREE>" string at the beginning of the path
@@ -303,7 +338,7 @@ snapshot_list()
# ignore specific path during run "grub-mkconfig"
if [ -n "${GRUB_BTRFS_IGNORE_SPECIFIC_PATH}" ] ; then
for isp in "${GRUB_BTRFS_IGNORE_SPECIFIC_PATH[@]}" ; do
[[ "${path_snapshot}" == "${isp}" ]] && continue 2;
[ "${path_snapshot}" = "${isp}" ] && continue 2;
done
fi
if [ -n "${GRUB_BTRFS_IGNORE_PREFIX_PATH}" ] ; then
@@ -311,30 +346,38 @@ snapshot_list()
[[ "${path_snapshot}" == "${isp}"/* ]] && continue 2;
done
fi
[[ ! -d "$grub_btrfs_mount_point/$path_snapshot/boot" ]] && continue; # Discard snapshots without /boot folder
[ ! -d "$grub_btrfs_mount_point/$path_snapshot/boot" ] && continue; # Discard snapshots without /boot folder
# Parse Snapper & timeshift informations
# Parse Snapper & timeshift & yabsnap information
local type_snapshot="N/A"
local description_snapshot="N/A"
# path to yabsnap snapshot meta data
local yabsnap_info="$grub_btrfs_mount_point/${path_snapshot%"/"*}/$(echo "${snap[13]}" | awk -F'/' '{print $3 "-meta.json"}')"
if [[ -s "$grub_btrfs_mount_point/${path_snapshot%"/"*}/$snapper_info" ]] ; then
type_snapshot=$(awk -F"<|>" 'match($2, /^type/) {print $3}' "$grub_btrfs_mount_point/${path_snapshot%"/"*}/$snapper_info") # search matching string beginning "type"
description_snapshot=$(awk -F"<|>" 'match($2, /^description/) {print $3}' "$grub_btrfs_mount_point/${path_snapshot%"/"*}/$snapper_info") # search matching string beginning "description"
elif [[ -s "$grub_btrfs_mount_point/${path_snapshot%"/"*}/$timeshift_info" ]] ; then
type_snapshot=$(awk -F" : " 'match($1, /^[ \t]+"tags"/) {gsub(/"|,/,"");print $2}' "$grub_btrfs_mount_point/${path_snapshot%"/"*}/$timeshift_info") # search matching string beginning "tags"
description_snapshot=$(awk -F" : " 'match($1, /^[ \t]+"comments"/) {gsub(/"|,/,"");print $2}' "$grub_btrfs_mount_point/${path_snapshot%"/"*}/$timeshift_info") # search matching string beginning "comments"
description_snapshot=$(awk -F" : " 'match($1, /^[ \t]+"comments"/) {gsub(/"|,/,"");print $2}' "$grub_btrfs_mount_point/${path_snapshot%"/"*}/$timeshift_info") # search matching string beginning "comments" fix '
elif [[ -s $yabsnap_info ]] ; then
type_snapshot=$(grep -P '^\s*"trigger"' $yabsnap_info | awk -F'"' '{print $4}') # search matching string beginning "trigger"
description_snapshot=$(grep -P '^\s*"comment"' $yabsnap_info | awk -F'"' '{print $4}') # search matching string beginning "comment"
fi
[[ -z "$type_snapshot" ]] && type_snapshot=("N/A")
[[ -z "$description_snapshot" ]] && description_snapshot=("N/A")
[ -z "$type_snapshot" ] && type_snapshot=("N/A")
[ -z "$description_snapshot" ] && description_snapshot=("N/A")
# ignore specific {type,tag,description} of snapshot during run "grub-mkconfig"
if [ -n "${GRUB_BTRFS_IGNORE_SNAPSHOT_TYPE}" ] ; then
for ist in "${GRUB_BTRFS_IGNORE_SNAPSHOT_TYPE[@]}" ; do
[[ "${type_snapshot}" == "${ist}" ]] && continue 2;
[ "${type_snapshot}" = "${ist}" ] && continue 2;
done
fi
if [ -n "${GRUB_BTRFS_IGNORE_SNAPSHOT_DESCRIPTION}" ] ; then
for isd in "${GRUB_BTRFS_IGNORE_SNAPSHOT_DESCRIPTION[@]}" ; do
[[ "${description_snapshot}" == "${isd}" ]] && continue 2;
[ "${description_snapshot}" = "${isd}" ] && continue 2;
done
fi
@@ -349,21 +392,21 @@ snapshot_list()
local max_date_length=0
for i in "${date_snapshots[@]}"; do
local length="${#i}"
[[ "$length" -gt "$max_date_length" ]] && max_date_length=$length
[ "$length" -gt "$max_date_length" ] && max_date_length=$length
done
# Find max length of a snapshot name, needed for pretty formatting
local max_path_length=0
for i in "${path_snapshots[@]}"; do
local length="${#i}"
[[ "$length" -gt "$max_path_length" ]] && max_path_length=$length
[ "$length" -gt "$max_path_length" ] && max_path_length=$length
done
# Find max length of a snapshot type, needed for pretty formatting
local max_type_length=0
for i in "${type_snapshots[@]}"; do
local length="${#i}"
[[ "$length" -gt "$max_type_length" ]] && max_type_length=$length
[ "$length" -gt "$max_type_length" ] && max_type_length=$length
done
# Find max length of a snapshot description, needed for pretty formatting
@@ -404,14 +447,14 @@ detect_kernel()
for okernel in "${boot_dir}"/vmlinuz-* \
"${boot_dir}"/vmlinux-* \
"${boot_dir}"/kernel-* ; do
[[ ! -f "${okernel}" ]] && continue;
[ ! -f "${okernel}" ] && continue;
list_kernel+=("$okernel")
done
# Custom name kernel in "GRUB_BTRFS_NKERNEL"
if [ -n "${GRUB_BTRFS_NKERNEL}" ] ; then
for ckernel in "${boot_dir}/${GRUB_BTRFS_NKERNEL[@]}" ; do
[[ ! -f "${ckernel}" ]] && continue;
[ ! -f "${ckernel}" ] && continue;
list_kernel+=("$ckernel")
done
fi
@@ -425,14 +468,14 @@ detect_initramfs()
for oinitramfs in "${boot_dir}"/initrd.img-* \
"${boot_dir}"/initramfs-* \
"${boot_dir}"/initrd-* ; do
[[ ! -f "${oinitramfs}" ]] && continue;
[ ! -f "${oinitramfs}" ] && continue;
list_initramfs+=("$oinitramfs")
done
# Custom name initramfs in "GRUB_BTRFS_NINIT"
if [ -n "${GRUB_BTRFS_NINIT}" ] ; then
for cinitramfs in "${boot_dir}/${GRUB_BTRFS_NINIT[@]}" ; do
[[ ! -f "${cinitramfs}" ]] && continue;
[ ! -f "${cinitramfs}" ] && continue;
list_initramfs+=("$cinitramfs")
done
fi
@@ -445,13 +488,9 @@ detect_microcode()
list_ucode=()
# Original intel/amd microcode (auto-detect)
# See "https://www.gnu.org/software/grub/manual/grub/html_node/Simple-configuration.html"
for oiucode in "${boot_dir}"/intel-uc.img \
"${boot_dir}"/intel-ucode.img \
"${boot_dir}"/amd-uc.img \
"${boot_dir}"/amd-ucode.img \
"${boot_dir}"/early_ucode.cpio \
"${boot_dir}"/microcode.cpio; do
[[ ! -f "${oiucode}" ]] && continue;
for oiucode in ${GRUB_EARLY_INITRD_LINUX_STOCK} ; do
oiucode="${boot_dir}/${oiucode}"
[ ! -f "${oiucode}" ] && continue;
list_ucode+=("$oiucode")
done
@@ -507,7 +546,7 @@ boot_bounded()
# Initialize menu entries
IFS=$'\n'
for item in $(snapshot_list); do
[[ ${limit_snap_show} -le 0 ]] && break; # fix: limit_snap_show=0
[ "${limit_snap_show}" -le 0 ] && break; # fix: limit_snap_show=0
IFS=$oldIFS
parse_snapshot_list
boot_dir="$grub_btrfs_mount_point/$snap_dir_name_trim$boot_directory"
@@ -521,14 +560,15 @@ boot_bounded()
detect_rootflags
title_format
boot_dir_root_grub="$(make_system_path_relative_to_its_root "${boot_dir}")" # convert "boot_directory" to root of GRUB (e.g /boot become /)
insmods=("${list_insmods[@]##*"/"}")
make_menu_entries
# show snapshot found during run "grub-mkconfig"
if [[ "${GRUB_BTRFS_SHOW_SNAPSHOTS_FOUND:-"true"}" = "true" ]]; then
if [ "${GRUB_BTRFS_SHOW_SNAPSHOTS_FOUND:-"true"}" = "true" ]; then
printf "Found snapshot: %s\n" "$item" >&2 ;
fi
# Limit snapshots found during run "grub-mkconfig"
count_limit_snap=$((1+count_limit_snap))
[[ $count_limit_snap -ge $limit_snap_show ]] && break;
[ "$count_limit_snap" -ge "$limit_snap_show" ] && break;
done
IFS=$oldIFS
}
@@ -548,59 +588,72 @@ boot_separate()
# Initialize menu entries
IFS=$'\n'
for item in $(snapshot_list); do
[[ ${limit_snap_show} -le 0 ]] && break; # fix: limit_snap_show=0
[ "${limit_snap_show}" -le 0 ] && break; # fix: limit_snap_show=0
IFS=$oldIFS
parse_snapshot_list
detect_rootflags
title_format
make_menu_entries
# show snapshot found during run "grub-mkconfig"
if [[ "${GRUB_BTRFS_SHOW_SNAPSHOTS_FOUND:-"true"}" = "true" ]]; then
if [ "${GRUB_BTRFS_SHOW_SNAPSHOTS_FOUND:-"true"}" = "true" ]; then
printf "Found snapshot: %s\n" "$item" >&2 ;
fi
# Limit snapshots found during run "grub-mkconfig"
count_limit_snap=$((1+count_limit_snap))
[[ $count_limit_snap -ge $limit_snap_show ]] && break;
[ "$count_limit_snap" -ge "$limit_snap_show" ] && break;
done
IFS=$oldIFS
}
rm -f "$grub_btrfs_directory/grub-btrfs.new"
> "$grub_btrfs_directory/grub-btrfs.new" # Create a "grub-btrfs.new" file in "grub_btrfs_directory"
true > "$grub_btrfs_directory/grub-btrfs.new" # Create a "grub-btrfs.new" file in "grub_btrfs_directory"
# Create a backup of the "$grub_btrfs_directory/grub-btrfs.cfg" file if exist
if [ -e "$grub_btrfs_directory/grub-btrfs.cfg" ]; then
mv -f "$grub_btrfs_directory/grub-btrfs.cfg" "$grub_btrfs_directory/grub-btrfs.cfg.bkp"
fi
# Create mount point then mounting
[[ ! -d $grub_btrfs_mount_point ]] && mkdir -p "$grub_btrfs_mount_point"
mount -o ro,subvolid=5 /dev/disk/by-uuid/"$root_uuid" "$grub_btrfs_mount_point/"
[ ! -d "$grub_btrfs_mount_point" ] && mkdir -p "$grub_btrfs_mount_point"
mount -o ro,subvolid=5 /dev/disk/by-uuid/"$root_uuid" "$grub_btrfs_mount_point/" > /dev/null
trap "unmount_grub_btrfs_mount_point" EXIT # unmounting mount point on EXIT signal
count_warning_menuentries=0 # Count menuentries
count_limit_snap=0 # Count snapshots
check_uuid_required
# Detects if /boot is a separate partition
[[ "${GRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION,,}" == "true" ]] && printf "Override boot partition detection : enable \n" >&2 && boot_separate;
if [[ "$root_uuid" != "$boot_uuid" ]] || [[ "$root_uuid_subvolume" != "$boot_uuid_subvolume" ]]; then boot_separate ; else boot_bounded ; fi
# Show warn, menuentries exceeds 250 entries
[[ $count_warning_menuentries -ge 250 ]] && printf "Generated %s total GRUB entries. You might experience issues loading snapshots menu in GRUB.\n" "${count_warning_menuentries}" >&2 ;
# Show total found snapshots
if [[ "${GRUB_BTRFS_SHOW_TOTAL_SNAPSHOTS_FOUND:-"true"}" = "true" && -n "${count_limit_snap}" && "${count_limit_snap}" != "0" ]]; then
printf "Found %s snapshot(s)\n" "${count_limit_snap}" >&2 ;
fi
# if no snapshot found, exit
if [[ "${count_limit_snap}" = "0" || -z "${count_limit_snap}" ]]; then
print_error "No snapshots found."
fi
# Make a submenu in GRUB (grub.cfg) and move "grub-btrfs.new" to "grub-btrfs.cfg"
header_menu
if "${bindir}/${GRUB_BTRFS_SCRIPT_CHECK:-grub-script-check}" "$grub_btrfs_directory/grub-btrfs.new"; then
cat "$grub_btrfs_directory/grub-btrfs.new" > "$grub_btrfs_directory/grub-btrfs.cfg"
rm -f "$grub_btrfs_directory/grub-btrfs.new"
cat << EOF
[ "$(echo "$GRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION}" | tr '[:upper:]' '[:lower:]')" = "true" ] && printf "Override boot partition detection : enable \n" >&2 && boot_separate;
if [ "$root_uuid" != "$boot_uuid" ] || [ "$root_uuid_subvolume" != "$boot_uuid_subvolume" ]; then boot_separate ; else boot_bounded ; fi
# Make a submenu in GRUB (grub.cfg)
cat << EOF
if [ ! -e "${grub_btrfs_search_directory}/grub-btrfs.cfg" ]; then
echo ""
else
submenu '${submenuname}' ${protection_authorized_users}${unrestricted_access_submenu}{
configfile "${grub_btrfs_search_directory}/grub-btrfs.cfg"
}
fi
EOF
# Show warn, menuentries exceeds 250 entries
[ $count_warning_menuentries -ge 250 ] && printf "Generated %s total GRUB entries. You might experience issues loading snapshots menu in GRUB.\n" "${count_warning_menuentries}" >&2 ;
# Show total found snapshots
if [ "${GRUB_BTRFS_SHOW_TOTAL_SNAPSHOTS_FOUND:-"true"}" = "true" ] && [ -n "${count_limit_snap}" ] && [ "${count_limit_snap}" != "0" ]; then
printf "Found %s snapshot(s)\n" "${count_limit_snap}" >&2 ;
fi
# if no snapshot found, delete the "$grub_btrfs_directory/grub-btrfs.new" file and the "$grub_btrfs_directory/grub-btrfs.cfg.bkp" file and exit
if [ "${count_limit_snap}" = "0" ] || [ -z "${count_limit_snap}" ]; then
rm -f "$grub_btrfs_directory/grub-btrfs.new" "$grub_btrfs_directory/grub-btrfs.cfg.bkp"
print_error "No snapshots found."
fi
# Move "grub-btrfs.new" to "grub-btrfs.cfg"
header_menu
if "${bindir}/${GRUB_BTRFS_SCRIPT_CHECK:-grub-script-check}" "$grub_btrfs_directory/grub-btrfs.new"; then
cat "$grub_btrfs_directory/grub-btrfs.new" > "$grub_btrfs_directory/grub-btrfs.cfg"
rm -f "$grub_btrfs_directory/grub-btrfs.new" "$grub_btrfs_directory/grub-btrfs.cfg.bkp"
else
print_error "Syntax errors were detected in generated ${grub_btrfs_directory}/grub-btrfs.new file. Old grub-btrfs.cfg (if present) was not replaced."
if [ -e "$grub_btrfs_directory/grub-btrfs.cfg.bkp" ]; then
mv -f "$grub_btrfs_directory/grub-btrfs.cfg.bkp" "$grub_btrfs_directory/grub-btrfs.cfg"
fi
print_error "Syntax errors were detected in generated ${grub_btrfs_directory}/grub-btrfs.new file. The old grub-btrfs.cfg file (if present) have been restored."
fi
# warn when this script is run but there is no entry in grub.cfg
grep "snapshots-btrfs" "${grub_directory}/grub.cfg" || printf "\nWARNING: '%s' needs to run at least once to generate the snapshots (sub)menu entry in grub the main menu. \
grep "snapshots-btrfs" "${grub_directory}/grub.cfg" >/dev/null 2>&1 || printf "\nWARNING: '%s' 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.\n\n" "${GRUB_BTRFS_MKCONFIG:-grub-mkconfig}" >&2 ;

View File

@@ -5,6 +5,12 @@ INITCPIO ?= false
SYSTEMD ?= true
OPENRC ?= false
BOOT_DIR_DEBIAN ?= /boot/grub
BOOT_DIR_FEDORA ?= /boot/grub2
GRUB_UPDATE_EXCLUDE ?= false
INSTALL_DOCS ?= true
SHARE_DIR = $(DESTDIR)$(PREFIX)/share
LIB_DIR = $(DESTDIR)$(PREFIX)/lib
BIN_DIR = $(DESTDIR)$(PREFIX)/bin
@@ -12,6 +18,7 @@ MAN_DIR = $(SHARE_DIR)/man
TEMP_DIR = ./temp
.PHONY: install uninstall clean help
install:
@@ -31,14 +38,18 @@ install:
@echo
@echo " For further information visit https://github.com/Antynea/grub-btrfs or read the man page: 'man grub-btrfs'"
@echo
@rm -rf "${TEMP_DIR}"
@mkdir "${TEMP_DIR}"
@chmod 777 ${TEMP_DIR}
@cp manpages/grub-btrfs.8.man ${TEMP_DIR}/grub-btrfs.8
@bzip2 ${TEMP_DIR}/grub-btrfs.8
@install -Dm644 -t "${MAN_DIR}/man8" "${TEMP_DIR}/grub-btrfs.8.bz2"
@if test "$(INSTALL_DOCS)" = true; then \
echo "Installing manpages..."; \
install -Dm644 -t "${MAN_DIR}/man8" "${TEMP_DIR}/grub-btrfs.8"; \
fi
@cp manpages/grub-btrfsd.8.man ${TEMP_DIR}/grub-btrfsd.8
@bzip2 ${TEMP_DIR}/grub-btrfsd.8
@install -Dm644 -t "${MAN_DIR}/man8" "${TEMP_DIR}/grub-btrfsd.8.bz2";
@if test "$(INSTALL_DOCS)" = true; then \
install -Dm644 -t "${MAN_DIR}/man8" "${TEMP_DIR}/grub-btrfsd.8"; \
fi
@install -Dm755 -t "$(DESTDIR)/etc/grub.d/" 41_snapshots-btrfs
@install -Dm644 -t "$(DESTDIR)/etc/default/grub-btrfs/" config
@install -Dm744 -t "$(BIN_DIR)/" grub-btrfsd;
@@ -59,10 +70,20 @@ install:
install -Dm644 "initramfs/Arch Linux/overlay_snap_ro-install" "$(LIB_DIR)/initcpio/install/grub-btrfs-overlayfs"; \
install -Dm644 "initramfs/Arch Linux/overlay_snap_ro-hook" "$(LIB_DIR)/initcpio/hooks/grub-btrfs-overlayfs"; \
fi
@install -Dm644 -t "$(SHARE_DIR)/licenses/$(PKGNAME)/" LICENSE
@install -Dm644 -t "$(SHARE_DIR)/doc/$(PKGNAME)/" README.md
@install -Dm644 "initramfs/readme.md" "$(SHARE_DIR)/doc/$(PKGNAME)/initramfs-overlayfs.md"
@rm -rf "${TEMP_DIR}"
@if test "$(INSTALL_DOCS)" = true; then \
echo "Installing docs..."; \
install -Dm644 -t "$(SHARE_DIR)/licenses/$(PKGNAME)/" LICENSE; \
install -Dm644 -t "$(SHARE_DIR)/doc/$(PKGNAME)/" README.md; \
install -Dm644 "initramfs/readme.md" "$(SHARE_DIR)/doc/$(PKGNAME)/initramfs-overlayfs.md"; \
fi
@if command -v grub-mkconfig > /dev/null && [ -e "$(BOOT_DIR_DEBIAN)/grub.cfg" ] && test "$(GRUB_UPDATE_EXCLUDE)" = false; then \
echo "Updating the GRUB menu..."; \
grub-mkconfig -o "$(BOOT_DIR_DEBIAN)/grub.cfg"; \
fi
@if command -v grub2-mkconfig > /dev/null && [ -e "$(BOOT_DIR_FEDORA)/grub.cfg" ] && test "$(GRUB_UPDATE_EXCLUDE)" = false; then \
echo "Updating the GRUB menu..."; \
grub2-mkconfig -o "$(BOOT_DIR_FEDORA)/grub.cfg"; \
fi
uninstall:
@echo "Uninstalling grub-btrfs"
@@ -94,6 +115,14 @@ uninstall:
@rmdir --ignore-fail-on-non-empty "$(SHARE_DIR)/doc/$(PKGNAME)/" || :
@rmdir --ignore-fail-on-non-empty "$(SHARE_DIR)/licenses/$(PKGNAME)/" || :
@rmdir --ignore-fail-on-non-empty "$(DESTDIR)/etc/default/grub-btrfs" || :
@if command -v grub-mkconfig > /dev/null && [ -e "$(BOOT_DIR_DEBIAN)/grub.cfg" ] && test "$(GRUB_UPDATE_EXCLUDE)" = false; then \
echo "Updating the GRUB menu..."; \
grub-mkconfig -o "$(BOOT_DIR_DEBIAN)/grub.cfg"; \
fi
@if command -v grub2-mkconfig > /dev/null && [ -e "$(BOOT_DIR_FEDORA)/grub.cfg" ] && test "$(GRUB_UPDATE_EXCLUDE)" = false; then \
echo "Updating the GRUB menu..."; \
grub2-mkconfig -o "$(BOOT_DIR_FEDORA)/grub.cfg"; \
fi
clean:
@echo "Deleting ./temp"
@@ -108,14 +137,17 @@ help:
@echo " uninstall"
@echo " help"
@echo
@echo " parameter | type | description | defaults"
@echo " ----------+------+--------------------------------+----------------------------"
@echo " DESTDIR | path | install destination | <unset>"
@echo " PREFIX | path | system tree prefix | '/usr'"
@echo " SHARE_DIR | path | shared data location | '\$$(DESTDIR)\$$(PREFIX)/share'"
@echo " LIB_DIR | path | system libraries location | '\$$(DESTDIR)\$$(PREFIX)/lib'"
@echo " PKGNAME | name | name of the ditributed package | 'grub-btrfs'"
@echo " INITCPIO | bool | include mkinitcpio hook | false"
@echo " SYSTEMD | bool | include unit files | true"
@echo " OPENRC | bool | include OpenRc daemon | false"
@echo " parameter | type | description | defaults"
@echo " --------------------+------+-------------------------------------------------------+----------------------------"
@echo " DESTDIR | path | install destination | <unset>"
@echo " PREFIX | path | system tree prefix | '/usr'"
@echo " BOOT_DIR_DEBIAN | path | boot data location (Debian, Ubuntu, Gentoo, Arch...) | '/boot/grub'"
@echo " BOOT_DIR_FEDORA | path | boot data location (Fedora, RHEL, CentOS, Rocky...) | '/boot/grub2'"
@echo " SHARE_DIR | path | shared data location | '\$$(DESTDIR)\$$(PREFIX)/share'"
@echo " LIB_DIR | path | system libraries location | '\$$(DESTDIR)\$$(PREFIX)/lib'"
@echo " PKGNAME | name | name of the distributed package | 'grub-btrfs'"
@echo " INITCPIO | bool | include mkinitcpio hook | false"
@echo " SYSTEMD | bool | include unit files | true"
@echo " OPENRC | bool | include OpenRc daemon | false"
@echo " GRUB_UPDATE_EXCLUDE | bool | Do not update grub after installation | false"
@echo

281
README.md
View File

@@ -6,33 +6,32 @@
##### BTC donation address: `1Lbvz244WA8xbpHek9W2Y12cakM6rDe5Rt`
- - -
### 🔎 Description:
Improves grub by adding "btrfs snapshots" to the grub menu.
grub-btrfs improves the grub bootloader by adding a btrfs snapshots sub-menu, allowing the user to boot into snapshots.
You can boot your system on a "snapshot" from the grub menu.
Supports manual snapshots, snapper, timeshift ...
grub-btrfs supports manual snapshots as well as snapper, timeshift, and yabsnap created snapshots.
##### Warning: booting on read-only snapshots can be tricky
##### Warning: booting read-only snapshots can be tricky
If you choose to do it, `/var/log` or even `/var` must be on a separate subvolume.
Otherwise, make sure your snapshots are writable.
If you wish to use read-only snapshots, `/var/log` or even `/var` must be on a separate subvolume.
Otherwise, make sure your snapshots are writable.
See [this ticket](https://github.com/Antynea/grub-btrfs/issues/92) for more info.
This project includes its own solution.
This project includes its own solution.
Refer to the [documentation](https://github.com/Antynea/grub-btrfs/blob/master/initramfs/readme.md).
- - -
### ✨ What features does grub-btrfs have?
* Automatically list snapshots existing on root partition (btrfs).
* Automatically detect if `/boot` is in separate partition.
* Automatically detect kernel, initramfs and Intel/AMD microcode in `/boot` directory on snapshots.
* Automatically create corresponding "menuentry" in `grub.cfg`
* Automatically detect the type/tags and descriptions/comments of Snapper/Timeshift snapshots.
* Automatically lists snapshots existing on the btrfs root partition.
* Automatically detect if `/boot` is in a separate partition.
* Automatically detect kernel, initramfs and Intel/AMD microcode in `/boot` directory within snapshots.
* Automatically create corresponding menu entries in `grub.cfg`
* Automatically detect the type/tags/triggers and descriptions/comments of Snapper/Timeshift/Yabsnap snapshots.
* Automatically generate `grub.cfg` if you use the provided Systemd/ OpenRC service.
- - -
### 🛠️ Installation:
#### Arch Linux
The package is available in the community repository [grub-btrfs](https://archlinux.org/packages/community/any/grub-btrfs/)
The package is available in the extra repository [grub-btrfs](https://archlinux.org/packages/extra/any/grub-btrfs/)
```
pacman -S grub-btrfs
```
@@ -56,118 +55,89 @@ Emerge grub-btrfs via
```
apt install grub-btrfs
```
Booting into read-only snapshots is fully supported when choosing "btrfs" as file system during a standard Kali Linux installation following [this walk-through](https://www.kali.org/docs/installation/btrfs/).
Booting into read-only snapshots is fully supported when choosing btrfs as the file system during a standard Kali Linux installation following [this walk-through](https://www.kali.org/docs/installation/btrfs/).
#### Manual
* Run `make install` or look into Makefile for instructions on where to put each file.
#### Manual installation
* Run `make install`
* Run `make help` to check what options are available.
* Dependencies:
* [btrfs-progs](https://archlinux.org/packages/core/x86_64/btrfs-progs/)
* [grub](https://archlinux.org/packages/core/x86_64/grub/)
* [bash >4](https://archlinux.org/packages/core/x86_64/bash/)
* [gawk](https://archlinux.org/packages/core/x86_64/gawk/)
* (only when using the daemon)[inotify-tools](https://archlinux.org/packages/community/x86_64/inotify-tools/)
* (only when using the grub-btrfsd daemon)[inotify-tools](https://archlinux.org/packages/extra/x86_64/inotify-tools/)
- - -
### 📚 Usage
After installation the grub main menu needs to be generated to make a menuentry for the snapshots sub menu. Depending on the Linux distribution the commands for that are different:
### 📚 Manual usage of grub-btrfs
To manually generate grub snapshot entries you can run `sudo /etc/grub.d/41_snapshots-btrfs` which updates `grub-btrfs.cfg`. You then need to regenerate the GRUB configuration by running one of the following commands:
* On **Arch Linux** or **Gentoo** use `grub-mkconfig -o /boot/grub/grub.cfg`.
* On **Fedora** use `grub2-mkconfig -o /boot/grub2/grub.cfg`
* On **Debian-like** distribution `update-grub` is an alias to `grub-mkconfig ...`
* On **Debian and Ubuntu based** distributions `update-grub` is a script that runs `grub-mkconfig ...`
Once the entry for the sub menu was generated grub-btrfs puts the actual sub menu into the file grub-btrfs.cfg. So to generate snapshot entries in the sub menu it is usually enough to run only the script with `sudo /etc/grub.d/41_snapshots-btrfs`.
Read further below on how to automate this process.
This process can be automated to occur whenever you create or delete snapshots but this process is slightly different depending upon your distributions choice on init system. See the relevant instructions for your init system below.
### ⚙️ Customization:
You have the possibility to modify many parameters in `/etc/default/grub-btrfs/config`.
You have the possibility to modify many parameters in `/etc/default/grub-btrfs/config`.
For further information see [config file](https://github.com/Antynea/grub-btrfs/blob/master/config) or `man grub-btrfs`
#### Warning:
Some file locations and command names differ from distribution to distribution. Initially the configuration is set up to work with Arch and Gentoo (and many other distributions) out of the box, which are using the `grub-mkconfig` command.
However, Fedora for example uses a different command, `grub2-mkconfig`.
Edit `GRUB_BTRFS_MKCONFIG` variable in `/etc/default/grub-btrfs/config` file to reflect this. (e.g. `GRUB_BTRFS_MKCONFIG=/sbin/grub2-mkconfig` for Fedora)
However Fedora, for example, uses a different command, `grub2-mkconfig`.
Edit the `GRUB_BTRFS_MKCONFIG` variable in `/etc/default/grub-btrfs/config` file to reflect this. (e.g. `GRUB_BTRFS_MKCONFIG=/sbin/grub2-mkconfig` for Fedora)
On most distributions and installs, the grub installation resides in `/boot/grub`. If grub is installed in a different place, change the variable `GRUB_BTRFS_MKCONFIG` in the config file accordingly. For Fedora this is `GRUB_BTRFS_GRUB_DIRNAME="/boot/grub2"`. Also the command to check the grub scripts is different on some system, for Fedora it is `GRUB_BTRFS_SCRIPT_CHECK=grub2-script-check`
On most distributions, the grub installation resides in `/boot/grub`. If grub is installed in a different place, change the variable `GRUB_BTRFS_MKCONFIG` in the config file accordingly. For Fedora this is `GRUB_BTRFS_GRUB_DIRNAME="/boot/grub2"`. The command to check the grub scripts is different on some system, for Fedora it is `GRUB_BTRFS_SCRIPT_CHECK=grub2-script-check`
#### Customization of the grub-btrfsd daemon
Grub-btrfs comes with a daemon script that automatically updates the grub menu when it sees a snapshot being created or deleted in a directory it is given via command line.
Grub-btrfs comes with a daemon script that automatically updates the grub menu when it sees a snapshot being created or deleted in a directory it is given via command line. You must install `inotify-tools` before you can use grub-btrfsd.
The daemon can be configured by passing different command line arguments to it.
The arguments are:
* `SNAPSHOTS_DIR`
This argument specifies the path where grub-btrfsd looks for newly created snapshots and snapshot deletions. It is usually defined by the program used to make snapshots.
E.g. for Snapper this would be `/.snapshots`
The available arguments are:
* `SNAPSHOTS_DIRS`
This argument specifies the (space separated) paths where grub-btrfsd looks for newly created snapshots and snapshot deletions. It is usually defined by the program used to make snapshots.
E.g. for Snapper or Yabsnap this would be `/.snapshots`. It is possible to define more than one directory here, all directories will inherit the same settings (recursive etc.).
This argument is not necessary to provide if `--timeshift-auto` is set.
* `-c / --no-color`
Disable colors in output.
* `-l / --log-file`
This arguments specifies a file where grub-btrfsd should write log messages.
* `-r / --recursive`
Watch the snapshots directory recursively
* `-s / --syslog`
* `-o / --timeshift-old`
Look for snapshots in `/run/timeshift/backup/timeshift-btrfs` instead of `/run/timeshift/$PID/backup/timeshift-btrfs.` This is to be used for Timeshift versions <22.06. You must also use `--timeshift-auto` if using this option.
* `-t / --timeshift-auto`
This is a flag to activate the auto detection of the path where Timeshift stores snapshots. Newer versions (>=22.06) of Timeshift mount their snapshots to `/run/timeshift/$PID/backup/timeshift-btrfs`. Where `$PID` is the process ID of the currently running Timeshift session. The PID is changing every time Timeshift is opened. grub-btrfsd can automatically take care of the detection of the correct PID and directory if this flag is set. In this case the argument `SNAPSHOTS_DIR` has no effect.
This is a flag to activate the auto-detection of the path where Timeshift stores snapshots. Newer versions (>=22.06) of Timeshift mount their snapshots to `/run/timeshift/$PID/backup/timeshift-btrfs`. Where `$PID` is the process ID of the currently running Timeshift session. The PID changes every time Timeshift is opened. grub-btrfsd can automatically take care of the detection of the correct PID and directory if this flag is set. In this case the argument `SNAPSHOTS_DIRS` has no effect.
* `-v / --verbose`
Let the log of the daemon be more verbose
* `-h / --help`
Displays a short help message.
- - -
##### Systemd instructions
To edit the arguments that are passed to the daemon, use
```bash
sudo systemctl edit --full grub-btrfsd
```
after that the Daemon must be restarted with
```bash
sudo systemctl restart grub-btrfsd
```
It is also possible to start the daemon without using systemd for troubleshooting purposes for example. If you want to do this, a running daemon should be stopped with
```bash
sudo systemctl stop grub-btrfsd
```
Then the daemon can be manually run and played around with using the command `/usr/bin/grub-btrfsd`.
For additional information on the daemon script and its arguments, run `grub-btrfsd -h` and see `man grub-btrfsd`
- - -
##### OpenRC instructions
To edit the arguments that are passed to the daemon edit the file `/etc/conf.d/grub-btrfsd`.
After that restart the daemon with
```
sudo rc-service grub-btrfsd restart
```
It is also possible to start the daemon without using OpenRC for troubleshooting purposes for example. If you want to do this, a running daemon should be stopped with
```bash
sudo rc-service grub-btrfsd stop
```
Then the daemon can be manually run and played around with using the command `grub-btrfsd`.
For additional information on daemon script and its arguments, run `grub-btrfsd -h` and see `man grub-btrfsd`
### 🪀 Automatically update grub upon snapshot creation or deletion
Grub-btrfsd is a daemon that watches the snapshot directory for you and updates the grub menu automatically every time a snapshot is created or deleted.
By default this daemon watches the directory `/.snapshots` for changes (creation or deletion of snapshots) and triggers the grub menu creation and re-installation of grub if any changes are noticed.
Therefore, if Snapper or Yabsnap is used with its default directory, the daemon can just be started and nothing needs to be configured. See the instructions below to configure grub-btrfsd for use with Timeshift or when using an alternative snapshots directory with Snapper/Yabsnap.
- - -
### 🪀 Automatically update grub upon snapshot
Grub-btrfsd is a daemon daemon that watches the snapshot directory for you and updates the grub menu automatically every time a snapshot is created or deleted.
By default this daemon watches the directory `/.snapshots` for changes (creation or deletion of snapshots) and triggers the grub menu creation if a snapshot is found.
Therefore, if Snapper is used with its default directory, the daemon can just be started and nothing needs to be configured. For other configurations like Timeshift, or Snapper with a different directory, see further below.
- - -
#### SystemD instructions
To start the daemon run
#### grub-btrfsd systemd instructions
To start the daemon run:
```bash
sudo systemctl start grub-btrfsd
```
To activate it during system startup, run
To activate it during system startup, run:
```bash
sudo systemctl enable grub-btrfsd
```
##### 💼 Snapshots not in `/.snapshots`
NOTE: This works also for Timeshift versions < 22.06, the path to watch would be `/run/timeshift/backup/timeshift-btrfs/snapshots`.
By default the daemon is watching the directory `/.snapshots`. If the daemon should watch a different directory, it can be edited with
##### 💼 Snapshots not in `/.snapshots` when using systemd
By default the daemon is watching the directory `/.snapshots`. If the daemon should watch a different directory, it can be edited with:
```bash
sudo systemctl edit --full grub-btrfsd
```
What should be edited is the `/.snapshots`-part in the line that says `ExecStart=/usr/bin/grub-btrfsd --syslog /.snapshots`.
So this is what the file should look afterwards:
You need to edit the `/.snapshots` part in the line that says `ExecStart=/usr/bin/grub-btrfsd --syslog /.snapshots`.
This is what the file should look like afterwards:
``` bash
[Unit]
Description=Regenerate grub-btrfs.cfg
@@ -180,46 +150,47 @@ Environment="PATH=/sbin:/bin:/usr/sbin:/usr/bin"
# Load environment variables from the configuration
EnvironmentFile=/etc/default/grub-btrfs/config
# Start the daemon, usage of it is:
# grub-btrfsd [-h, --help] [-t, --timeshift-auto] [-l, --log-file LOG_FILE] SNAPSHOTS_DIR
# SNAPSHOTS_DIR Snapshot directory to watch, without effect when --timeshift-auto
# grub-btrfsd [-h, --help] [-t, --timeshift-auto] [-l, --log-file LOG_FILE] SNAPSHOTS_DIRS
# SNAPSHOTS_DIRS Snapshot directories to watch, without effect when --timeshift-auto
# Optional arguments:
# -t, --timeshift-auto Automatically detect Timeshifts snapshot directory
# -o, --timeshift-old Activate for timeshift versions <22.06
# -l, --log-file Specify a logfile to write to
# -v, --verbose Let the log of the daemon be more verbose
# -s, --syslog Write to syslog
ExecStart=/usr/bin/grub-btrfsd --syslog /path/to/your/snapshot/directory
ExecStart=/usr/bin/grub-btrfsd --syslog /.snapshots
[Install]
WantedBy=multi-user.target
```
When done, the service should be restarted with
When done, the service should be restarted with:
``` bash
sudo systemctl restart grub-btrfsd
```
##### 🌟 Timeshift >= version 22.06
Newer Timeshift versions create a new directory named after their process ID in `/run/timeshift` every time they are started. The PID is going to be different every time.
Therefore the daemon can not simply watch a directory, it watches `/run/timeshift` first, if a directory is created it gets Timeshifts current PID, then watches a directory in that newly created directory from Timeshift.
Anyhow, to activate this mode of the daemon, `--timeshift-auto` must be passed to the daemon as a command line argument.
##### 🌟 Using Timeshift with systemd
Newer Timeshift versions (>= 22.06) create a new directory named after their process ID in `/run/timeshift` every time they are started. The PID will be different every time.
Therefore the daemon cannot simply watch a directory. It monitors `/run/timeshift` and if a directory is created it gets Timeshifts current PID then watches a directory in that newly created directory from Timeshift.
To activate this mode of the daemon, `--timeshift-auto` must be passed to the daemon as a command line argument.
To pass `--timeshift-auto` to grub-btrfsd, the .service-file of grub-btrfsd can be edited with
To pass `--timeshift-auto` to grub-btrfsd, the .service file of grub-btrfsd can be edited with
```bash
sudo systemctl edit --full grub-btrfsd
```
The line that says
The line that contains:
```bash
ExecStart=/usr/bin/grub-btrfsd /.snapshots --syslog
```
should be edited into
Should be modified to read:
``` bash
ExecStart=/usr/bin/grub-btrfsd --syslog --timeshift-auto
```
So the file looks like this, afterwards:
The modified file should look like this:
``` bash
[Unit]
Description=Regenerate grub-btrfs.cfg
@@ -232,8 +203,8 @@ Environment="PATH=/sbin:/bin:/usr/sbin:/usr/bin"
# Load environment variables from the configuration
EnvironmentFile=/etc/default/grub-btrfs/config
# Start the daemon, usage of it is:
# grub-btrfsd [-h, --help] [-t, --timeshift-auto] [-l, --log-file LOG_FILE] SNAPSHOTS_DIR
# SNAPSHOTS_DIR Snapshot directory to watch, without effect when --timeshift-auto
# grub-btrfsd [-h, --help] [-t, --timeshift-auto] [-l, --log-file LOG_FILE] SNAPSHOTS_DIRS
# SNAPSHOTS_DIRS Snapshot directories to watch, without effect when --timeshift-auto
# Optional arguments:
# -t, --timeshift-auto Automatically detect Timeshifts snapshot directory
# -l, --log-file Specify a logfile to write to
@@ -245,7 +216,13 @@ ExecStart=/usr/bin/grub-btrfsd --syslog --timeshift-auto
WantedBy=multi-user.target
```
When done, the service must be restarted with
If you are using an older release of Timeshift (before 22.06), you also need to add `--timeshift-old` so that your ExecStart line would look like:
```
ExecStart=/usr/bin/grub-btrfsd --syslog --timeshift-auto --timeshift-old
```
When done, the service must be restarted with:
``` bash
sudo systemctl restart grub-btrfsd
```
@@ -254,116 +231,59 @@ Note:
You can view your change with `systemctl cat grub-btrfsd`.
To revert all the changes use `systemctl revert grub-btrfsd`.
##### ❇️ Automatically update grub upon restart/boot:
[Look at this comment](https://github.com/Antynea/grub-btrfs/issues/138#issuecomment-766918328)
Currently not implemented
- - -
#### OpenRC instructions
To start the daemon run
#### grub-btrfsd OpenRC instructions
To start the daemon run:
```bash
sudo rc-service grub-btrfsd start
```
To activate it during system startup, run
To activate it during system startup, run:
```bash
sudo rc-config add grub-btrfsd default
```
##### 💼 Snapshots not in `/.snapshots`
NOTE: This works also for Timeshift versions < 22.06, the path to watch would be `/run/timeshift/backup/timeshift-btrfs/snapshots`.
##### 💼 Snapshots not in `/.snapshots` for OpenRC
By default the daemon is watching the directory `/.snapshots`. If the daemon should watch a different directory, it can be edited by passing different arguments to it.
Arguments are passed to grub-btrfsd via the file `/etc/conf.d/grub-btrfsd`.
The variable `snapshots` defines, where the daemon will watch for snapshots.
The variable `snapshots` defines the path the daemon will monitor for snapshots.
After editing, the file should look like this:
``` bash
# Copyright 2022 Pascal Jaeger
# Distributed under the terms of the GNU General Public License v3
## Where to locate the root snapshots
#snapshots="/.snapshots" # Snapper in the root directory
#snapshots="/run/timeshift/backup/timeshift-btrfs/snapshots" # Timeshift < v22.06
snapshots="/path/to/your/snapshot/directory"
## Optional arguments to run with the daemon
# Possible options are:
# -t, --timeshift-auto Automatically detect Timeshifts snapshot directory for timeshift >= 22.06
# -l, --log-file Specify a logfile to write to
# -v, --verbose Let the log of the daemon be more verbose
# -s, --syslog Write to syslog
# Uncomment the line to activate the option
optional_args+="--syslog " # write to syslog by default
#optional_args+="--timeshift-auto "
#optional_args+="--log-file /var/log/grub-btrfsd.log "
#optional_args+="--verbose "
```
After that, the daemon should be restarted with
``` bash
sudo rc-service grub-btrfsd restart
```
##### 🌟 Timeshift >= version 22.06
Arguments are passed to grub-btrfsd via the file `/etc/conf.d/grub-btrfsd`.
The variable `optional_args` defines, which optional arguments get passed to the daemon.
Uncomment `#optional_args+="--timeshift-auto "` to pass the command line option `--timeshift-auto` to it.
After the change, the file should look like this:
(Note that there is no need to comment out the `snapshots` variable. It is ignored when `--timeshift-auto` is active.)
``` bash
# Copyright 2022 Pascal Jaeger
# Distributed under the terms of the GNU General Public License v3
## Where to locate the root snapshots
snapshots="/.snapshots" # Snapper in the root directory
#snapshots="/run/timeshift/backup/timeshift-btrfs/snapshots" # Timeshift < v22.06
## Optional arguments to run with the daemon
# Append options to this like this:
# optional_args="--syslog --timeshift-auto --verbose"
# Possible options are:
# -t, --timeshift-auto Automatically detect Timeshifts snapshot directory for timeshift >= 22.06
# -o, --timeshift-old Look for snapshots in directory of Timeshift <v22.06 (requires --timeshift-auto)
# -l, --log-file Specify a logfile to write to
# -v, --verbose Let the log of the daemon be more verbose
# -s, --syslog Write to syslog
# Uncomment the line to activate the option
optional_args+="--syslog " # write to syslog by default
optional_args+="--timeshift-auto "
#optional_args+="--log-file /var/log/grub-btrfsd.log "
#optional_args+="--verbose "
optional_args="--syslog"
```
After that, the daemon should be restarted with
After that, the daemon should be restarted with:
``` bash
sudo rc-service grub-btrfsd restart
sudo rc-service grub-btrfsd restart
```
##### ❇️ Automatically update grub upon restart/boot:
If you would like the grub-btrfs menu to automatically update on system restart/ shutdown, just add the following script as `/etc/local.d/grub-btrfs-update.stop`:
```bash
#!/usr/bin/env bash
##### 🔒 Snapshots on LUKS encrypted devices
By default, grub-btrfs generates entries that does not load modules for dealing with encrypted devices.
Enable the `GRUB_BTRFS_ENABLE_CRYPTODISK` variable in `/etc/default/grub-btrfs/config` to load said modules and then execute the steps to mount encrypted root after selecting the snapshot.
description="Update the grub btrfs snapshots menu"
name="grub-btrfs-update"
depend()
{
use localmount
}
bash -c 'if [ -s "${GRUB_BTRFS_GRUB_DIRNAME:-/boot/grub}/grub-btrfs.cfg" ]; then /etc/grub.d/41_snapshots-btrfs; else {GRUB_BTRFS_MKCONFIG:-grub-mkconfig} -o {GRUB_BTRFS_GRUB_DIRNAME:-/boot/grub}/grub.cfg; fi'
```
Make your script executable with `sudo chmod a+x /etc/local.d/grub-btrfs-update.stop`.
* The extension `.stop` at the end of the filename indicates to the locald-daemon that this script should be run at shutdown.
If you want to run the menu update on system startup instead, rename the file to `grub-btrfs-update.start`
* Works for Snapper and Timeshift
- - -
### Troubleshooting
If there are problems don't hesitate [to file an issue](https://github.com/Antynea/grub-btrfs/issues/new/choose).
If you experience problems with grub-btrfs don't hesitate [to file an issue](https://github.com/Antynea/grub-btrfs/issues/new/choose).
#### Version
To help the best we would like to know the version of grub-btrfs used. Please run
#### What version of grub-btrfs am I running?
When requesting help or reporting bugs in grub-btrfs, please run:
``` bash
sudo /etc/grub.d/41_snapshots-btrfs --version
```
@@ -371,18 +291,37 @@ or
``` bash
sudo /usr/bin/grub-btrfsd --help
```
to get the currently running version of grub-btrfs.
to get the currently running version of grub-btrfs and include this information in your ticket.
#### Verbose mode of the daemon
If you have problems with the daemon, you can run it with the `--verbose`-flag. To do so you can run
#### Running grub-btrfsd in verbose mode
If you have problems with the daemon, you can run it with the `--verbose`-flag. To do so you can run:
``` bash
sudo /usr/bin/grub-btrfsd --verbose --timeshift-auto` (for timeshift)
# or
sudo /usr/bin/grub-btrfsd /.snapshots --verbose` (for snapper)
sudo /usr/bin/grub-btrfsd /.snapshots --verbose` (for snapper/yabsnap)
```
Or pass `--verbose` to the daemon using the Systemd .service-file or the OpenRC conf.d file respectively. (see Daemon installation instructions how to do that)
Or pass `--verbose` to the daemon using the Systemd .service file or the OpenRC conf.d file respectively.
For additional information on the daemon and its arguments, run `grub-btrfsd -h` or `man grub-btrfsd`
- - -
### Development
Grub-btrfs uses a rudimentary system of automatic versioning to tell apart different commits. This is helpful when users report problems and it is not immediately clear what version they are using.
We therefore have the following script in `.git/hooks/pre-commit`:
``` bash
#!/bin/sh
echo "Doing pre commit hook with version bump"
version="$(git describe --tags --abbrev=0)-$(git rev-parse --abbrev-ref HEAD)-$(date -u -Iseconds)"
echo "New version is ${version}"
sed -i "s/GRUB_BTRFS_VERSION=.*/GRUB_BTRFS_VERSION=${version}/" config
git add config
```
This automatically sets the version in the `config`-file to `[lasttag]-[branch-name]-[current-date-in-UTC]`.
In order to create a Tag we don't want to have this long version. In this case we set the version manually in `config` and commit with `git commit --no-verify`. This avoids running the hook.
### Special thanks for assistance and contributions
* [Maxim Baz](https://github.com/maximbaz)
* [Schievel1](https://github.com/Antynea/grub-btrfs/discussions/173#discussioncomment-1438790)

30
config
View File

@@ -1,6 +1,7 @@
#!/usr/bin/env bash
GRUB_BTRFS_VERSION=4.12-make-prefix-configurable-2022-11-26T14:14:00+00:00
GRUB_BTRFS_VERSION=4.13-yabsnap_info_support-2024-03-06T13:43:57+00:00
# Disable grub-btrfs.
# Default: "false"
@@ -48,7 +49,14 @@ GRUB_BTRFS_VERSION=4.12-make-prefix-configurable-2022-11-26T14:14:00+00:00
# Default: ("")
#GRUB_BTRFS_CUSTOM_MICROCODE=("custom-ucode.img" "custom-uc.img "custom_ucode.cpio")
# Comma seperated mount options to be used when booting a snapshot.
# Additional kernel command line parameters that should be passed to the kernel
# when booting a snapshot.
# For dracut based distros this could be useful to pass "rd.live.overlay.overlayfs=1"
# or "rd.live.overlay.readonly=1" to the Kernel for booting snapshots read only.
# Default: ""
#GRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS="rd.live.overlay.overlayfs=1"
# Comma separated mount options to be used when booting a snapshot.
# They can be defined here as well as in the "/" line inside the respective snapshots'
# "/etc/fstab" files. Mount options found in both places are combined, and this variable
# takes priority over `fstab` entries.
@@ -66,13 +74,15 @@ GRUB_BTRFS_IGNORE_SPECIFIC_PATH=("@")
# Any path starting with the specified string will be ignored.
# e.g : if `prefix path` = @, all snapshots beginning with "@/..." will be ignored.
# Default: ("var/lib/docker" "@var/lib/docker" "@/var/lib/docker")
GRUB_BTRFS_IGNORE_PREFIX_PATH=("var/lib/docker" "@var/lib/docker" "@/var/lib/docker")
GRUB_BTRFS_IGNORE_PREFIX_PATH=("var/lib/docker" "@var/lib/docker" "@/var/lib/docker" "var/lib/containers" "@var/lib/containers" "@/var/lib/containers")
# Ignore specific type/tag of snapshot during run "grub-mkconfig".
# For snapper:
# Type = single, pre, post.
# For Timeshift:
# Tag = boot, ondemand, hourly, daily, weekly, monthly.
# For yabsnap:
# Trigger = S, I, U.
# Default: ("")
#GRUB_BTRFS_IGNORE_SNAPSHOT_TYPE=("")
@@ -88,9 +98,7 @@ GRUB_BTRFS_IGNORE_PREFIX_PATH=("var/lib/docker" "@var/lib/docker" "@/var/lib/doc
#GRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION="true"
# Location of the folder containing the "grub.cfg" file.
# Use by grub-btrfs to save the file "grub-btrfs.cfg".
# Might be grub2 on some systems.
# For example, on Fedora with EFI : "/boot/efi/EFI/fedora"
# Default: "/boot/grub"
#GRUB_BTRFS_GRUB_DIRNAME="/boot/grub2"
@@ -100,15 +108,15 @@ GRUB_BTRFS_IGNORE_PREFIX_PATH=("var/lib/docker" "@var/lib/docker" "@/var/lib/doc
#GRUB_BTRFS_BOOT_DIRNAME="/boot"
# Location where grub-btrfs.cfg should be saved.
# Some distributions (like OpenSuSE) store those file at the snapshot directory
# instead of boot. Be aware that this direcory must be available for grub during
# Some distributions (like OpenSuSE) store those files at the snapshot directory
# instead of boot. Be aware that this directory must be available for grub during
# startup of the system.
# Default: "/boot/grub"
# Default: $GRUB_BTRFS_GRUB_DIRNAME
#GRUB_BTRFS_GBTRFS_DIRNAME="/boot/grub"
# Location of the directory where Grub searches for the grub-btrfs.cfg file.
# Some distributions (like OpenSuSE) store those file at the snapshot directory
# instead of boot. Be aware that this direcory must be available for grub during
# instead of boot. Be aware that this directory must be available for grub during
# startup of the system.
# Default: "\${prefix}" # This is a grub variable that resolves to where grub is
# installed. (like /boot/grub, /boot/efi/grub)
@@ -150,3 +158,7 @@ GRUB_BTRFS_IGNORE_PREFIX_PATH=("var/lib/docker" "@var/lib/docker" "@/var/lib/doc
# doesn't work if GRUB_BTRFS_PROTECTION_AUTHORIZED_USERS isn't empty
# Default: "false"
#GRUB_BTRFS_DISABLE_PROTECTION_SUBMENU="true"
# Enable booting from snapshots stored on LUKS encrypted devices
# Default: "false"
#GRUB_BTRFS_ENABLE_CRYPTODISK="true"

View File

@@ -1,16 +1,15 @@
#!/bin/sh
# Copyright 2022 Pascal Jaeger
#!/usr/bin/env bash
# Copyright 2023 Pascal Jaeger
# Distributed under the terms of the GNU General Public License v3
# Update GRUB when new BTRFS snapshots are created.
# init
timeshift_pid=-1
watchtime=0
logfile=0
snapshots=-1
timeshift_auto=false
verbose=false
syslog=false
sighandler() {
trap '""' SIGINT SIGTERM
vlog "Parent $$: Received signal SIGINT/ SIGTERM"
kill 0
wait
exit 0
}
setcolors() {
if [ "${1}" = true ]; then
@@ -20,239 +19,322 @@ setcolors() {
RESET=$'\033[0m'
fi
if [ "${1}" = false ]; then
GREEN=$'\033[0;0m'
RED=$'\033[0;0m'
CYAN=$'\033[;0m'
RESET=$'\033[0m'
GREEN=$'\033[0;0m'
RED=$'\033[0;0m'
CYAN=$'\033[;0m'
RESET=$'\033[0m'
fi
}
setcolors true # normally we want colors
sysconfdir="/etc"
grub_btrfs_config="${sysconfdir}/default/grub-btrfs/config"
# source config file
[[ -f "$grub_btrfs_config" ]] && . "$grub_btrfs_config"
[[ -f "${sysconfdir}/default/grub" ]] && . "${sysconfdir}/default/grub"
print_help() {
echo "${CYAN}[?] Usage:"
echo "${0##*/} [-h, --help] [-c, --no-color] [-l, --log-file LOG_FILE] [-s, --syslog] [-t, --timeshift-auto] [-v, --verbose] SNAPSHOTS_DIR"
echo
echo "SNAPSHOTS_DIR Snapshot directory to watch, without effect when --timeshift-auto"
echo
echo "Optional arguments:"
echo "-c, --no-color Disable colors in output"
echo "-l, --log-file Specify a logfile to write to"
echo "-s, --syslog Write to syslog"
echo "-t, --timeshift-auto Automatically detect Timeshifts snapshot directory"
echo "-v, --verbose Let the log of the daemon be more verbose"
echo "-h, --help Display this message"
echo
echo "Version ${GRUB_BTRFS_VERSION}${RESET}"
echo "${CYAN}[?] Usage:"
echo "${0##*/} [-h, --help] [-c, --no-color] [-l, --log-file LOG_FILE] [-r, --recursive] [-s, --syslog] [-t, --timeshift-auto] [-v, --verbose] SNAPSHOTS_DIRS"
echo
echo "SNAPSHOTS_DIRS Snapshot directories to watch, without effect when --timeshift-auto"
echo
echo "Optional arguments:"
echo "-c, --no-color Disable colors in output"
echo "-l, --log-file Specify a logfile to write to"
echo "-r, --recursive Watch snapshots directory recursively"
echo "-s, --syslog Write to syslog"
echo "-o, --timeshift-old Look for snapshots in directory of Timeshift <v22.06 (requires --timeshift-auto)"
echo "-t, --timeshift-auto Automatically detect Timeshifts snapshot directory"
echo "-v, --verbose Let the log of the daemon be more verbose"
echo "-h, --help Display this message"
echo
echo "Version ${GRUB_BTRFS_VERSION}${RESET}"
}
log() {
echo "${2}"$1"${RESET}"
if [ ${syslog} = true ]; then
logger -p user.notice -t ${0##*/}"["$$"]" "$1"
logger -p user.notice -t ${0##*/}"["$$"]" "$1"
fi
if [ ${#logfile} -gt 1 ]; then
echo "$(date) ${1}" >> ${logfile}
echo "$(date) ${1}" >> "${logfile}"
fi
}
vlog() {
if [ ${verbose} = true ]; then
echo "${2}"$1"${RESET}"
if [ ${syslog} = true ]; then
logger -p user.notice -t ${0##*/} "$1"
fi
if [ ${#logfile} -gt 1 ]; then
echo "$(date) ${1}" >> ${logfile}
fi
echo "${2}"$1"${RESET}"
if [ ${syslog} = true ]; then
logger -p user.notice -t ${0##*/} "$1"
fi
if [ ${#logfile} -gt 1 ]; then
echo "$(date) ${1}" >> "${logfile}"
fi
fi
}
err() {
echo "${2}"${1}"${RESET}" >&2
if [ ${syslog} = true ]; then
logger -p user.error -t ${0##*/} "$1"
fi
if [ ${#logfile} -gt 1 ]; then
echo "$(date) error: ${1}" >> ${logfile}
fi
echo "${2}"${1}"${RESET}" >&2
if [ ${syslog} = true ]; then
logger -p user.error -t ${0##*/} "$1"
fi
if [ ${#logfile} -gt 1 ]; then
echo "$(date) error: ${1}" >> "${logfile}"
fi
}
# parse arguments
while getopts :l:ctvsh-: opt; do
case "$opt" in
-)
case "${OPTARG}" in
no-color)
parse_arguments() {
while getopts :l:ctvrsh-: opt; do
case "$opt" in
-)
case "${OPTARG}" in
no-color)
setcolors false
;;
log-file)
logfile="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
timeshift-auto)
timeshift_auto=true
;;
timeshift-old)
timeshift_old=true
;;
verbose)
verbose=true
;;
recursive)
recursive=true
;;
syslog)
syslog=true
;;
help)
print_help
exit 0
;;
*)
if [ "$OPTERR" = 1 ] && [ "${optspec:0:1}" != ":" ]; then
err "[!] Unknown option --${OPTARG}" "${RED}" >&2
echo
fi
print_help
exit 1
;;
esac;;
c)
setcolors false
;;
log-file)
logfile="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
l)
logfile="${OPTARG}"
;;
timeshift-auto)
t)
timeshift_auto=true
;;
verbose)
o)
timeshift_old=true
;;
v)
verbose=true
;;
syslog)
r)
recursive=true
;;
s)
syslog=true
;;
help)
h)
print_help
exit 0
;;
*)
if [ "$OPTERR" = 1 ] && [ "${optspec:0:1}" != ":" ]; then
err "[!] Unknown option --${OPTARG}" "${RED}" >&2
echo
if [ "$OPTERR" = 1 ] || [ "${optspec:0:1}" = ":" ]; then
err "[!] Non-option argument: '-${OPTARG}'" "${RED}" >&2
echo
fi
print_help
exit 1
;;
esac;;
c)
setcolors false
;;
l)
logfile="${OPTARG}"
;;
t)
timeshift_auto=true
;;
v)
verbose=true
;;
s)
syslog=true
;;
h)
print_help
exit 0
;;
*)
if [ "$OPTERR" = 1 ] || [ "${optspec:0:1}" = ":" ]; then
err "[!] Non-option argument: '-${OPTARG}'" "${RED}" >&2
echo
fi
print_help
exit 1
;;
esac
done
shift $(( OPTIND - 1 ))
esac
done
}
snapshots="${1}"
checks() {
# check if inotify exists, see issue #227
if ! command -v inotifywait >/dev/null 2>&1; then
err "[!] inotifywait was not found, exiting. Is inotify-tools installed?" "${RED}" >&2
exit 1
fi
# check if inotify exists, see issue #227
if ! command -v inotifywait &> /dev/null; then
err "[!] inotifywait was not found, exiting. Is inotify-tools installed?" "${RED}" >&2
exit 1
fi
if [ ${timeshift_auto} = false ] && [ ${timeshift_old} = true ]; then
err "[!] Flag --timeshift-old requires flag --timeshift-auto" "${RED}" >&2
exit 1
fi
if [ ${#logfile} -gt 1 ]; then
touch "${logfile}"
echo "GRUB-BTRFSD log $(date)" >> "${logfile}"
fi
log "grub-btrfsd starting up..." "${GREEN}"
if [ ${verbose} = true ]; then
inotify_qiet_flag=""
else
inotify_qiet_flag=" -q -q "
fi
vlog "Arguments:"
vlog "Snapshot directory: $snapshots"
vlog "Timestift autodetection: $timeshift_auto"
vlog "Logfile: $logfile"
if ! [ -d "$snapshots" ] && ! [ ${timeshift_auto} = true ]; then
err "[!] No directory found at ${snapshots}" "${RED}" >&2
err "[!] Please specify a valid snapshot directory" "${RED}" >&2
exit 1
fi
if [ ${timeshift_auto} = true ]; then
watchtime=15
[ -d /run/timeshift ] || mkdir /run/timeshift
else
watchtime=0
fi
create_grub_menu() {
# create the grub submenu of the whole grub menu, depending on wether the submenu already exists
# and gives feedback if it worked
if [ -s "${GRUB_BTRFS_GRUB_DIRNAME:-/boot/grub}/grub-btrfs.cfg" ]; then
if /etc/grub.d/41_snapshots-btrfs; then
log "Grub submenu recreated" "${GREEN}"
else
err "[!] Error during grub submenu creation (grub-btrfs error)" "${RED}"
fi
else
if ${GRUB_BTRFS_MKCONFIG:-grub-mkconfig} -o ${GRUB_BTRFS_GRUB_DIRNAME:-/boot/grub}/grub.cfg; then
log "Grub menu recreated" "${GREEN}"
else
err "[!] Error during grub menu creation (grub/ grub-btrfs error)" "${RED}"
fi
if ! [ ${timeshift_auto} = true ]; then
for snapdir in "${snapdirs[@]}"
do
if ! [ -d ${snapdir} ]; then
err "[!] No directory found at ${snapdir}" "${RED}" >&2
err "[!] Please specify a valid snapshot directory" "${RED}" >&2
exit 1
fi
done
fi
}
# start the actual daemon
vlog "Snapshot dir watchtimeout: $watchtime"
vlog "Entering infinite while" "${GREEN}"
while true; do
runs=false
if [ ${timeshift_auto} = true ] && ! [ "${timeshift_pid}" -gt 0 ] ; then
# watch the timeshift folder for a folder that is created when timeshift starts up
sleep 1 # for safety so the outer while is not going crazy
if [ "${timeshift_pid}" -eq -2 ]; then
log "detected timeshift shutdown"
fi
timeshift_pid=$(ps ax | awk '{sub(/.*\//, "", $5)} $5 ~ /timeshift/ {print $1}')
if [ "${#timeshift_pid}" -gt 0 ]; then
snapshots="/run/timeshift/${timeshift_pid}/backup/timeshift-btrfs/snapshots"
log "detected running Timeshift at daemon startup, PID is: $timeshift_pid"
vlog "new snapshots directory is $snapshots"
else
log "Watching /run/timeshift for timeshift to start"
inotifywait ${inotify_qiet_flag} -e create -e delete /run/timeshift && {
sleep 1
timeshift_pid=$(ps ax | awk '{sub(/.*\//, "", $5)} $5 ~ /timeshift/ {print $1}')
snapshots="/run/timeshift/${timeshift_pid}/backup/timeshift-btrfs/snapshots"
log "detected Timeshift startup, PID is: $timeshift_pid" "${CYAN}"
vlog "new snapshots directory is $snapshots" "${CYAN}"
(create_grub_menu) # create the grub menu once immidiatly in a forking process. Snapshots from commandline using timeshift --create need this
}
fi
runs=false
else
while [ -d "$snapshots" ]; do
# watch the actual snapshots folder for a new snapshot or a deletion of a snapshot
if [ ${runs} = false ] && [ ${verbose} = false ]; then
log "Watching $snapshots for new snapshots..." "${CYAN}"
else
vlog "Watching $snapshots for new snapshots..." "${CYAN}"
fi
runs=true
inotifywait ${inotify_qiet_flag} -e create -e delete -e unmount -t "$watchtime" "$snapshots" && {
log "Detected snapshot creation/ deletion, recreating Grub menu" "${CYAN}"
sleep 5
create_grub_menu
}
sleep 1
done
timeshift_pid=-2
setup() {
if [ ${#logfile} -gt 1 ]; then
touch "${logfile}"
echo "GRUB-BTRFSD log $(date)" >> "${logfile}"
fi
if ! [ ${timeshift_auto} = true ] && ! [ -d "${snapshots}" ] ; then # in case someone deletes the snapshots folder (in snapper mode) to prevent the while loop from going wild
break
fi
done
exit 0 # tradition is tradition
if [ ${verbose} = true ]; then
inotify_qiet_flag=""
else
inotify_qiet_flag=" -q -q "
fi
if [ ${recursive} = true ]; then
inotify_recursive_flag=" -r "
else
inotify_recursive_flag=""
fi
if [ ${timeshift_auto} = true ]; then
watchtime=15
[ -d /run/timeshift ] || mkdir /run/timeshift
else
watchtime=0
fi
}
create_grub_menu() {
# create the grub submenu of the whole grub menu, depending on whether the submenu already exists
# and gives feedback if it worked
if grep "snapshots-btrfs" "${GRUB_BTRFS_GRUB_DIRNAME:-/boot/grub}"/grub.cfg; then
if /etc/grub.d/41_snapshots-btrfs; then
log "Grub submenu recreated" "${GREEN}"
else
err "[!] Error during grub submenu creation (grub-btrfs error)" "${RED}"
fi
else
if ${GRUB_BTRFS_MKCONFIG:-grub-mkconfig} -o "${GRUB_BTRFS_GRUB_DIRNAME:-/boot/grub}"/grub.cfg; then
log "Grub menu recreated" "${GREEN}"
else
err "[!] Error during grub menu creation (grub/ grub-btrfs error)" "${RED}"
fi
fi
}
set_snapshot_dir() {
# old timeshift has it's snapshot dir in a different location
if [ "${timeshift_old}" = true ]; then
snapdir="/run/timeshift/backup/timeshift-btrfs/snapshots"
else
snapdir="/run/timeshift/${timeshift_pid}/backup/timeshift-btrfs/snapshots"
fi
}
daemon_function() {
trap 'vlog "$BASHPID: Received SIGINT/ SIGTERM"; exit 0' SIGINT SIGTERM
# start the actual daemon
snapdir=$1
vlog "Subdaemon function started, PID: $BASHPID" "${GREEN}"
vlog "${BASHPID}: Entering infinite while for $snapdir" "${GREEN}"
vlog "${BASHPID}: Snapshot dir watchtimeout: $watchtime"
while true; do
runs=false
if [ ${timeshift_auto} = true ] && ! [ "${timeshift_pid}" -gt 0 ] ; then
# watch the timeshift folder for a folder that is created when timeshift starts up
sleep 1 # for safety so the outer while is not going crazy
if [ "${timeshift_pid}" -eq -2 ]; then
log "${BASHPID}: detected timeshift shutdown"
fi
timeshift_pid=$(ps ax | awk '{sub(/.*\//, "", $5)} $5 ~ /timeshift/ {print $1}')
if [ "${#timeshift_pid}" -gt 0 ]; then
set_snapshot_dir
log "${BASHPID}: detected running Timeshift at daemon startup, PID is: $timeshift_pid"
vlog "${BASHPID}: new snapshots directory is $snapdir"
else
log "Watching /run/timeshift for timeshift to start"
inotifywait ${inotify_qiet_flag} -e create -e delete /run/timeshift && {
sleep 1
timeshift_pid=$(ps ax | awk '{sub(/.*\//, "", $5)} $5 ~ /timeshift/ {print $1}')
set_snapshot_dir
log "${BASHPID}: detected Timeshift startup, PID is: $timeshift_pid" "${CYAN}"
vlog "${BASHPID}: new snapshots directory is $snapdir" "${CYAN}"
(create_grub_menu) # create the grub menu once immediately in a forking process. Snapshots from commandline using timeshift --create need this
}
fi
runs=false
else
while [ -d "$snapdir" ]; do
# watch the actual snapshots folder for a new snapshot or a deletion of a snapshot
if [ ${runs} = false ] && [ ${verbose} = false ]; then
log "${BASHPID}: Watching $snapdir for new snapshots..." "${CYAN}"
else
vlog "${BASHPID}: Watching $snapdir for new snapshots..." "${CYAN}"
fi
runs=true
inotifywait ${inotify_qiet_flag} ${inotify_recursive_flag} -e create -e delete -e unmount -t "$watchtime" "$snapdir" && {
log "${BASHPID}: Detected snapshot creation/ deletion, recreating Grub menu" "${CYAN}"
sleep 5
create_grub_menu
}
sleep 1
done
timeshift_pid=-2
fi
if ! [ ${timeshift_auto} = true ] && ! [ -d "${snapdir}" ] ; then # in case someone deletes the snapshots folder (in snapper mode) to prevent the while loop from going wild
break
fi
done
}
main() {
# init
timeshift_pid=-1
watchtime=0
logfile=0
snapshots=-1
timeshift_auto=false
timeshift_old=false
verbose=false
syslog=false
recursive=false
trap sighandler SIGINT SIGTERM
setcolors true # normally we want colors
sysconfdir="/etc"
grub_btrfs_config="${sysconfdir}/default/grub-btrfs/config"
# source config file
[ -f "$grub_btrfs_config" ] && . "$grub_btrfs_config"
[ -f "${sysconfdir}/default/grub" ] && . "${sysconfdir}/default/grub"
parse_arguments "${@}"
shift $(( OPTIND - 1 ))
snapdirs=( "${@}" )
vlog "Arguments:"
vlog "Snapshot directories: ${snapdirs[*]}"
vlog "Timestift autodetection: $timeshift_auto"
vlog "Timeshift old: $timeshift_old"
vlog "Logfile: $logfile"
vlog "Recursive: $recursive"
checks
setup
log "grub-btrfsd starting up..." "${GREEN}"
if [ ${timeshift_auto} = true ] ; then
daemon_function "timeshift" &
else
# for all dirs that got passed to the script, start a new fork with that dir
for snapdir in "${snapdirs[@]}"
do
vlog "starting daemon watching $snapdir..."
daemon_function "${snapdir}" &
done
fi
wait # wait for forks to finish, kill child forks if SIGTERM is sent
exit 0
}
main "${@}"

View File

@@ -1,4 +1,4 @@
# Copyright 2022 Pascal Jaeger
# Copyright 2023 Pascal Jaeger
# Distributed under the terms of the GNU General Public License v3
## Where to locate the root snapshots
@@ -6,13 +6,12 @@ snapshots="/.snapshots" # Snapper in the root directory
#snapshots="/run/timeshift/backup/timeshift-btrfs/snapshots" # Timeshift < v22.06
## Optional arguments to run with the daemon
# Append options to this like this:
# optional_args="--syslog --timeshift-auto --verbose"
# Possible options are:
# -t, --timeshift-auto Automatically detect Timeshifts snapshot directory for timeshift >= 22.06
# -o, --timeshift-old Look for snapshots in directory of Timeshift <v22.06 (requires --timeshift-auto)
# -l, --log-file Specify a logfile to write to
# -v, --verbose Let the log of the daemon be more verbose
# -s, --syslog Write to syslog
# Uncomment the line to activate the option
optional_args+="--syslog " # write to syslog by default
#optional_args+="--timeshift-auto "
#optional_args+="--log-file /var/log/grub-btrfsd.log "
#optional_args+="--verbose "
optional_args="--syslog"

View File

@@ -1,5 +1,5 @@
#!/sbin/openrc-run
# Copyright 2021 Pascal Jaeger
# Copyright 2023 Pascal Jaeger
# Distributed under the terms of the GNU General Public License v3
name="grub-btrfs daemon"

View File

@@ -9,10 +9,11 @@ Environment="PATH=/sbin:/bin:/usr/sbin:/usr/bin"
# Load environment variables from the configuration
EnvironmentFile=/etc/default/grub-btrfs/config
# Start the daemon, usage of it is:
# grub-btrfsd [-h, --help] [-t, --timeshift-auto] [-l, --log-file LOG_FILE] SNAPSHOTS_DIR
# SNAPSHOTS_DIR Snapshot directory to watch, without effect when --timeshift-auto
# grub-btrfsd [-h, --help] [-t, --timeshift-auto] [-l, --log-file LOG_FILE] SNAPSHOTS_DIRS
# SNAPSHOTS_DIRS Snapshot directories to watch, without effect when --timeshift-auto
# Optional arguments:
# -t, --timeshift-auto Automatically detect Timeshifts snapshot directory
# -o, --timeshift-old Activate for timeshift versions <22.06
# -l, --log-file Specify a logfile to write to
# -v, --verbose Let the log of the daemon be more verbose
# -s, --syslog Write to syslog

View File

@@ -39,7 +39,11 @@ You notice that the name of the `hook` must match the name of the 2 installed fi
Re-generate your initramfs
`mkinitcpio -P` (option -P means, all preset present in `/etc/mkinitcpio.d`)
#### Dracut based distros
Distributions that use Dracut to make their initramfs (many of the Fedora based Distros) simply have to pass either `rd.live.overlay.readonly=1` (to boot into the snapshot read only) or `rd.live.overlay.overlayfs=1` (to act like a livedisk, that is files can be changed but changes will be lost on the next boot) to their kernel command line in grub.
Grub-btrfs provides the variable `GRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS` to add any command to the kernel command line. Set it to `GRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS="rd.live.overlay.overlayfs=1"` to make snapshots immutable when booted into.
After changing this run `sudo /etc/grub.d/41_snapshots-btrfs` to generate a new snapshot-submenu with the parameter added.
#### Other distribution
Refer to your distribution's documentation
or contribute to this project to add a paragraph.
Refer to your distribution's documentation or contribute to this project to add a paragraph.
#

View File

@@ -1,4 +1,4 @@
.TH "grub-btrfs" "8"
.TH "grub-btrfs" "8"
.SH "NAME"
.PP
@@ -82,7 +82,7 @@ Example: \fCGRUB_BTRFS_SHOW_SNAPSHOTS_FOUND="false"\fP
.SS "\fCGRUB_BTRFS_ROOTFLAGS\fP"
.PP
Comma seperated mount options to be used when booting a snapshot.
Comma separated mount options to be used when booting a snapshot.
They can be defined here as well as in the “/” line inside the respective snapshots
“/etc/fstab” files. Mount options found in both places are combined, and this variable
takes priority over `fstab` entries.
@@ -102,6 +102,14 @@ Default: “false”
.IP \(em 4
Example: \fCGRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION="true"\fP
.SS "\GRUB_BTRFS_ENABLE_CRYPTODISK\fP"
.PP
Enable booting from snapshots stored on LUKS encrypted devices
.IP \(em 4
Default: “false”
.IP \(em 4
Example: \GRUB_BTRFS_ENABLE_CRYPTODISK="true"\fP
.SS "CUSTOM KERNELS"
.SS "\fCGRUB_BTRFS_NKERNEL\fP / \fCGRUB_BTRFS_NINIT\fP / \fCGRUB_BTRFS_CUSTOM_MICROCODE\fP"
.PP
@@ -114,6 +122,17 @@ Example: \fCGRUB_BTRFS_NKERNEL=("kernel\-5.19.4\-custom" "vmlinux\-5.19.4\-custo
\fCGRUB_BTRFS_NINIT=("initramfs\-5.19.4\-custom.img" "initrd\-5.19.4\-custom.img" "otherinit\-5.19.4\-custom.gz")\fP
\fCGRUB_BTRFS_CUSTOM_MICROCODE=("custom\-ucode.img" "custom\-uc.img "custom_ucode.cpio")\fP
.SS "\fCGRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS\fP"
.PP
Additional kernel command line parameters that should be passed to the kernelwhen
booting a snapshot.
For dracut based distros this could be useful to pass “rd.live.overlay.overlayfs=1”
or “rd.live.overlay.readonly=1” to the Kernel for booting read only snapshots.
.IP \(em 4
Default: “”
.IP \(em 4
Example: \fCGRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS="rd.live.overlay.overlayfs=1"\fP
.SS "SNAPSHOT FILTERING"
.SS "\fCGRUB_BTRFS_IGNORE_SPECIFIC_PATH\fP"
.PP
@@ -168,7 +187,6 @@ Example: \fCGRUB_BTRFS_BOOT_DIRNAME="/"\fP
.SS "\fCGRUB_BTRFS_GRUB_DIRNAME\fP"
.PP
Location of the folder containing the “grub.cfg” file.
Used by grub-btrfs to save the file “grub-btrfs.cfg”.
Might be grub2 on some systems.
For example, on Fedora with EFI : “/boot/efi/EFI/fedora”
.IP \(em 4
@@ -180,18 +198,18 @@ Example: \fCGRUB_BTRFS_GRUB_DIRNAME="/boot/grub2"\fP
.PP
Location where grub-btrfs.cfg should be saved.
Some distributions (like OpenSuSE) store those file at the snapshot directory
instead of boot. Be aware that this direcory must be available for grub during
instead of boot. Be aware that this directory must be available for grub during
startup of the system.
.IP \(em 4
Default: “/boot/grub”
Default: \fC$GRUB_BTRFS_GRUB_DIRNAME\fP
.IP \(em 4
Example GRUB\d\s-2BTRFS\s+2\u\d\s-2GBTRFS\s+2\u\d\s-2DIRNAME\s+2\u=“/boot/grub”
Example: \fCGRUB_BTRFS_GBTRFS_DIRNAME="/.snapshots"\fP
.SS "\fCGRUB_BTRFS_GBTRFS_SEARCH_DIRNAME\fP"
.PP
Location of the directory where Grub searches for the grub-btrfs.cfg file.
Some distributions (like OpenSuSE) store those file at the snapshot directory
instead of boot. Be aware that this direcory must be available for grub during
instead of boot. Be aware that this directory must be available for grub during
startup of the system.
.IP \(em 4
Default: “\${prefix}” (This is a grub variable that resolves to where grub is
@@ -202,8 +220,7 @@ NOTE: If variables of grub are used here like ${prefix}, they need to be escaped
.PP
with `$\` before the `$`
.IP \(em 4
Example: GRUB\d\s-2BTRFS\s+2\u\d\s-2GBTRFS\s+2\u\d\s-2SEARCH\s+2\u\d\s-2DIRNAME\s+2\u=“\${prefix}
Example: \fCGRUB_BTRFS_GBTRFS_SEARCH_DIRNAME="\${prefix}"\fP
.SS "\fCGRUB_BTRFS_MKCONFIG\fP"
.PP
@@ -243,7 +260,9 @@ and this comment \fIhttps://github.com/Antynea/grub-btrfs/issues/95#issuecomment
Add authorized usernames separate by comma (userfoo,userbar).
When Grubs password protection is enabled, the superuser is authorized by default, it is not necessary to add it
.IP \(em 4
Default: “- Example: \fCGRUB_BTRFS_PROTECTION_AUTHORIZED_USERS="userfoo,userbar"\fP
Default: “
.IP \(em 4
Example: \fCGRUB_BTRFS_PROTECTION_AUTHORIZED_USERS="userfoo,userbar"\fP
.SS "\fCGRUB_BTRFS_DISABLE_PROTECTION_SUBMENU\fP"
.PP

View File

@@ -1,6 +1,6 @@
#+title: grub-btrfs
#+author: Pascal Jaeger
#+man_class_option: :sectionid 8
#+MAN_CLASS_OPTIONS: :section-id "8"
* NAME
grub-btrfs - Automatically add btrfs-Snapshots as a Grub submenu
@@ -58,7 +58,7 @@ Show snapshots found during run "grub-mkconfig"
- Example: ~GRUB_BTRFS_SHOW_SNAPSHOTS_FOUND="false"~
*** ~GRUB_BTRFS_ROOTFLAGS~
Comma seperated mount options to be used when booting a snapshot.
Comma separated mount options to be used when booting a snapshot.
They can be defined here as well as in the "/" line inside the respective snapshots'
"/etc/fstab" files. Mount options found in both places are combined, and this variable
takes priority over `fstab` entries.
@@ -73,6 +73,11 @@ Change to "true" if your boot partition is not detected as separate.
- Default: "false"
- Example: ~GRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION="true"~
*** ~GRUB_BTRFS_ENABLE_CRYPTODISK~
Enable booting from snapshots stored on LUKS encrypted devices
- Default: "false"
- Example: ~GRUB_BTRFS_ENABLE_CRYPTODISK="true"~
** CUSTOM KERNELS
*** ~GRUB_BTRFS_NKERNEL~ / ~GRUB_BTRFS_NINIT~ / ~GRUB_BTRFS_CUSTOM_MICROCODE~
@@ -83,6 +88,14 @@ Customs kernel, initramfs and microcodes that are not detected can be added in t
~GRUB_BTRFS_NINIT=("initramfs-5.19.4-custom.img" "initrd-5.19.4-custom.img" "otherinit-5.19.4-custom.gz")~
~GRUB_BTRFS_CUSTOM_MICROCODE=("custom-ucode.img" "custom-uc.img "custom_ucode.cpio")~
*** ~GRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS~
Additional kernel command line parameters that should be passed to the kernelwhen
booting a snapshot.
For dracut based distros this could be useful to pass "rd.live.overlay.overlayfs=1"
or "rd.live.overlay.readonly=1" to the Kernel for booting read only snapshots.
- Default: ""
- Example: ~GRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS="rd.live.overlay.overlayfs=1"~
** SNAPSHOT FILTERING
*** ~GRUB_BTRFS_IGNORE_SPECIFIC_PATH~
@@ -123,7 +136,6 @@ Used by "grub-btrfs" to detect the boot partition and the location of kernels, i
*** ~GRUB_BTRFS_GRUB_DIRNAME~
Location of the folder containing the "grub.cfg" file.
Used by grub-btrfs to save the file "grub-btrfs.cfg".
Might be grub2 on some systems.
For example, on Fedora with EFI : "/boot/efi/EFI/fedora"
- Default: "/boot/grub"
@@ -132,25 +144,27 @@ For example, on Fedora with EFI : "/boot/efi/EFI/fedora"
*** ~GRUB_BTRFS_GBTRFS_DIRNAME~
Location where grub-btrfs.cfg should be saved.
Some distributions (like OpenSuSE) store those file at the snapshot directory
instead of boot. Be aware that this direcory must be available for grub during
instead of boot. Be aware that this directory must be available for grub during
startup of the system.
- Default: "/boot/grub"
- Example GRUB_BTRFS_GBTRFS_DIRNAME="/boot/grub"
- Default: ~$GRUB_BTRFS_GRUB_DIRNAME~
- Example: ~GRUB_BTRFS_GBTRFS_DIRNAME="/.snapshots"~
*** ~GRUB_BTRFS_GBTRFS_SEARCH_DIRNAME~
Location of the directory where Grub searches for the grub-btrfs.cfg file.
Some distributions (like OpenSuSE) store those file at the snapshot directory
instead of boot. Be aware that this direcory must be available for grub during
instead of boot. Be aware that this directory must be available for grub during
startup of the system.
- Default: "\${prefix}" (This is a grub variable that resolves to where grub is
installed. (like /boot/grub, /boot/efi/grub))
- NOTE: If variables of grub are used here like ${prefix}, they need to be escaped
with `\` before the `$`
- Example: GRUB_BTRFS_GBTRFS_SEARCH_DIRNAME="\${prefix}"
- Example: ~GRUB_BTRFS_GBTRFS_SEARCH_DIRNAME="\${prefix}"~
*** ~GRUB_BTRFS_MKCONFIG~
Name/path of the command to generate the grub menu, used by "grub-btrfs.service"
Name/path of the command to generate the grub menu, used by
#+BEGIN_MAN
.BR grub-btrfsd (8)
#+END_MAN
Might be 'grub2-mkconfig' on some systems (e.g. Fedora)
Default paths are /sbin:/bin:/usr/sbin:/usr/bin, if your path is missing, report it on the upstream project.
You can use the name of the command only or full the path.
@@ -177,7 +191,8 @@ Refer to the Grub documentation https://www.gnu.org/software/grub/manual/grub/gr
and this comment https://github.com/Antynea/grub-btrfs/issues/95#issuecomment-682295660
Add authorized usernames separate by comma (userfoo,userbar).
When Grub's password protection is enabled, the superuser is authorized by default, it is not necessary to add it
- Default: "- Example: ~GRUB_BTRFS_PROTECTION_AUTHORIZED_USERS="userfoo,userbar"~
- Default: ""
- Example: ~GRUB_BTRFS_PROTECTION_AUTHORIZED_USERS="userfoo,userbar"~
*** ~GRUB_BTRFS_DISABLE_PROTECTION_SUBMENU~
Disable authentication support for submenu of Grub-btrfs only (--unrestricted)

View File

@@ -1,4 +1,4 @@
.TH "grub-btrfsd" "8"
.TH "grub-btrfsd" "8"
.SH "NAME"
.PP
@@ -9,7 +9,7 @@ when a new btrfs snapshot is created.
.SH "SYNOPSIS"
.PP
\fCgrub\-btrfsd [\-h, \-\-help] [\-c, \-\-no\-color] [\-l, \-\-log\-file LOG_FILE] [\-s, \-\-syslog] [\-t, \-\-timeshift\-auto] [\-v, \-\-verbose] SNAPSHOTS_DIR\fP
\fCgrub\-btrfsd [\-h, \-\-help] [\-c, \-\-no\-color] [\-l, \-\-log\-file LOG_FILE] [\-r, \-\-recursive] [\-s, \-\-syslog] [\-t, \-\-timeshift\-auto] [\-o, \-\-timeshift\-old] [\-v, \-\-verbose] SNAPSHOTS_DIRS\fP
.SH "DESCRIPTION"
.PP
@@ -17,10 +17,11 @@ Grub-btrfsd is a shell script which is meant to be run as a daemon.
Grub-btrfsd watches a directory where btrfs-snapshots are created or deleted via inotifywait and runs grub-mkconfig (if grub-mkconfig never ran before since grub-btrfs was installed) or \fC/etc/grub.d/41_snapshots\-btrfs\fP (when grub-mkconfig ran before with grub-btrfs installed) when something in that directory changes.
.SH "OPTIONS"
.SS "\fCSNAPSHOTS_DIR\fP"
.SS "\fCSNAPSHOTS_DIRS\fP"
.PP
This argument specifies the path where grub-btrfsd looks for newly created snapshots and snapshot deletions. It is usually defined by the program used to make snapshots.
E.g. for Snapper this would be \fC/.snapshots\fP
This argument specifies the (space separated) paths where grub-btrfsd looks for newly created snapshots and snapshot deletions. It is usually defined by the program used to make snapshots.
E.g. for Snapper this would be \fC/.snapshots\fP. It is possible to define more than one directory here, all directories will inherit the same settings (recursive etc.).
This argument is not necessary to provide if \fC\-\-timeshift\-auto\fP is set.
.SS "\fC\-c / \-\-no\-color\fP"
.PP
@@ -30,13 +31,21 @@ Disable colors in output.
.PP
This arguments specifies a file where grub-btrfsd should write log messages.
.SS "\fC\-r / \-\-recursive\fP"
.PP
Watch snapshot directory recursively
.SS "\fC\-s / \-\-syslog\fP"
.PP
Write to syslog
.SS "\fC\-t / \-\-timeshift\-auto\fP"
.PP
This is a flag to activate the auto detection of the path where Timeshift stores snapshots. Newer versions (>=22.06) of Timeshift mount their snapshots to \fC/run/timeshift/$PID/backup/timeshift\-btrfs\fP. Where \fC$PID\fP is the process ID of the currently running Timeshift session. The PID is changing every time Timeshift is opened. grub-btrfsd can automatically take care of the detection of the correct PID and directory if this flag is set. In this case the argument \fCSNAPSHOTS_DIR\fP has no effect.
This is a flag to activate the auto detection of the path where Timeshift stores snapshots. Newer versions (>=22.06) of Timeshift mount their snapshots to \fC/run/timeshift/$PID/backup/timeshift\-btrfs\fP. Where \fC$PID\fP is the process ID of the currently running Timeshift session. The PID is changing every time Timeshift is opened. grub-btrfsd can automatically take care of the detection of the correct PID and directory if this flag is set. In this case the argument \fCSNAPSHOTS_DIRS\fP has no effect.
.SS "\fC\-o / \-\-timeshift\-old\fP"
.PP
Look for snapshots in \fC/run/timeshift/backup/timeshift\-btrfs\fP instead of \fC/run/timeshift/$PID/backup/timeshift\-btrfs\fP. This is to be used for Timeshift versions <22.06.
.SS "\fC\-v / \-\-verbose\fP"
.PP
@@ -46,8 +55,6 @@ Let the log of the daemon be more verbose
.PP
Displays a short help message.
.SH "CONFIGURATION"
.PP
The daemon is usually configured via the file \fC/etc/conf.d/grub\-btrfsd\fP on openrc-init systems and \fCsudo systemctl edit \-\-full grub\-btrfsd\fP on systemd systems. In this file the arguments (See OPTIONS), that OpenRC passes to the daemon when it is started, can be configured.

View File

@@ -1,6 +1,6 @@
#+title: grub-btrfsd
#+author: Pascal Jaeger
#+man_class_option: :sectionid 8
#+MAN_CLASS_OPTIONS: :section-id "8"
* NAME
grub-btrfsd - An OpenRC daemon to automatically update the grub menu with
@@ -10,16 +10,17 @@ grub-btrfsd - An OpenRC daemon to automatically update the grub menu with
when a new btrfs snapshot is created.
* SYNOPSIS
~grub-btrfsd [-h, --help] [-c, --no-color] [-l, --log-file LOG_FILE] [-s, --syslog] [-t, --timeshift-auto] [-v, --verbose] SNAPSHOTS_DIR~
~grub-btrfsd [-h, --help] [-c, --no-color] [-l, --log-file LOG_FILE] [-r, --recursive] [-s, --syslog] [-t, --timeshift-auto] [-o, --timeshift-old] [-v, --verbose] SNAPSHOTS_DIRS~
* DESCRIPTION
Grub-btrfsd is a shell script which is meant to be run as a daemon.
Grub-btrfsd watches a directory where btrfs-snapshots are created or deleted via inotifywait and runs grub-mkconfig (if grub-mkconfig never ran before since grub-btrfs was installed) or ~/etc/grub.d/41_snapshots-btrfs~ (when grub-mkconfig ran before with grub-btrfs installed) when something in that directory changes.
* OPTIONS
** ~SNAPSHOTS_DIR~
This argument specifies the path where grub-btrfsd looks for newly created snapshots and snapshot deletions. It is usually defined by the program used to make snapshots.
E.g. for Snapper this would be ~/.snapshots~
** ~SNAPSHOTS_DIRS~
This argument specifies the (space separated) paths where grub-btrfsd looks for newly created snapshots and snapshot deletions. It is usually defined by the program used to make snapshots.
E.g. for Snapper this would be ~/.snapshots~. It is possible to define more than one directory here, all directories will inherit the same settings (recursive etc.).
This argument is not necessary to provide if ~--timeshift-auto~ is set.
** ~-c / --no-color~
Disable colors in output.
@@ -27,11 +28,17 @@ Disable colors in output.
** ~-l / --log-file~
This arguments specifies a file where grub-btrfsd should write log messages.
** ~-r / --recursive~
Watch snapshot directory recursively
** ~-s / --syslog~
Write to syslog
** ~-t / --timeshift-auto~
This is a flag to activate the auto detection of the path where Timeshift stores snapshots. Newer versions (>=22.06) of Timeshift mount their snapshots to ~/run/timeshift/$PID/backup/timeshift-btrfs~. Where ~$PID~ is the process ID of the currently running Timeshift session. The PID is changing every time Timeshift is opened. grub-btrfsd can automatically take care of the detection of the correct PID and directory if this flag is set. In this case the argument ~SNAPSHOTS_DIR~ has no effect.
This is a flag to activate the auto detection of the path where Timeshift stores snapshots. Newer versions (>=22.06) of Timeshift mount their snapshots to ~/run/timeshift/$PID/backup/timeshift-btrfs~. Where ~$PID~ is the process ID of the currently running Timeshift session. The PID is changing every time Timeshift is opened. grub-btrfsd can automatically take care of the detection of the correct PID and directory if this flag is set. In this case the argument ~SNAPSHOTS_DIRS~ has no effect.
** ~-o / --timeshift-old~
Look for snapshots in ~/run/timeshift/backup/timeshift-btrfs~ instead of ~/run/timeshift/$PID/backup/timeshift-btrfs~. This is to be used for Timeshift versions <22.06.
** ~-v / --verbose~
Let the log of the daemon be more verbose
@@ -39,8 +46,6 @@ Let the log of the daemon be more verbose
** ~-h / --help~
Displays a short help message.
* CONFIGURATION
The daemon is usually configured via the file ~/etc/conf.d/grub-btrfsd~ on openrc-init systems and ~sudo systemctl edit --full grub-btrfsd~ on systemd systems. In this file the arguments (See OPTIONS), that OpenRC passes to the daemon when it is started, can be configured.

280
temp/grub-btrfs.8 Normal file
View File

@@ -0,0 +1,280 @@
.TH "grub-btrfs" "8"
.SH "NAME"
.PP
grub-btrfs - Automatically add btrfs-Snapshots as a Grub submenu
.SH "SYNOPSIS"
.PP
\fC/etc/grub.d/41_snapshots\-btrfs [\-V, \-\-version]\fP
.SH "DESCRIPTION"
.PP
Improves grub by adding “btrfs snapshots” to the grub menu.
.PP
You can boot your system on a “snapshot” from the grub menu.
Supports manual snapshots, snapper and timeshift.
Features of grub-btrfs:
.IP \(em 4
Automatically list snapshots existing on root partition (btrfs).
.IP \(em 4
Automatically detect if /boot is in separate partition.
.IP \(em 4
Automatically detect kernel, initramfs and intel/amd microcode in /boot directory on snapshots.
.IP \(em 4
Automatically create corresponding “menuentry” in grub.cfg
.IP \(em 4
Automatically detect the type/tags and descriptions/comments of snapper/timeshift snapshots.
.IP \(em 4
Automatically generate grub.cfg if you use the provided systemd service.
.SH "CONFIGURATION"
.PP
grub-btrfs is configured via the file \fC/etc/default/grub\-btrfs/config\fP.
Possible options are:
.SS "GENERAL"
.SS "\fCGRUB_BTRFS_DISABLE\fP"
.PP
Disable grub-btrfs if true.
.IP \(em 4
Default: “false”
.IP \(em 4
Example: \fCGRUB_BTRFS_DISABLE="true"\fP
.SS "\fCGRUB_BTRFS_TITLE_FORMAT\fP"
.PP
The snapshot entries submenu in Grub are added according to this line. It is possible to change to order of the fields.
.IP \(em 4
Default: (“date” “snapshot” “type” “description”)
.IP \(em 4
Example: \fCGRUB_BTRFS_TITLE_FORMAT=("date" "snapshot" "type" "description")\fP
.SS "\fCGRUB_BTRFS_LIMIT\fP"
.PP
Maximum number of snapshots in the GRUB snapshots sub menu.
.IP \(em 4
Default: “50”
.IP \(em 4
Example: \fCGRUB_BTRFS_LIMIT="50"\fP
.SS "\fCGRUB_BTRFS_SUBVOLUME_SORT\fP"
.PP
Sort the found subvolumes by “ogeneration” or “generation” or “path” or “rootid”.
.IP \(em 4
See Sorting section in
.BR btrfs-subvolume (8)
.PP
“-rootid” means list snapshot by new ones first.
.IP \(em 4
Default: “-rootid”
.IP \(em 4
Example: \fCGRUB_BTRFS_SUBVOLUME_SORT="+ogen,\-gen,path,rootid"\fP
.SS "\fCGRUB_BTRFS_SHOW_SNAPSHOTS_FOUND\fP"
.PP
Show snapshots found during run “grub-mkconfig”
.IP \(em 4
Default: “true”
.IP \(em 4
Example: \fCGRUB_BTRFS_SHOW_SNAPSHOTS_FOUND="false"\fP
.SS "\fCGRUB_BTRFS_ROOTFLAGS\fP"
.PP
Comma separated mount options to be used when booting a snapshot.
They can be defined here as well as in the “/” line inside the respective snapshots
“/etc/fstab” files. Mount options found in both places are combined, and this variable
takes priority over `fstab` entries.
NB: Do NOT include “subvol=...” or “subvolid=...” here.
.IP \(em 4
Default: “”
.IP \(em 4
Example: \fCGRUB_BTRFS_ROOTFLAGS="space_cache,commit=10,norecovery"\fP
.SS "\fCGRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION\fP"
.PP
By default “grub-btrfs” automatically detects your boot partition,
either located at the system root or on a separate partition or in a subvolume,
Change to “true” if your boot partition is not detected as separate.
.IP \(em 4
Default: “false”
.IP \(em 4
Example: \fCGRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION="true"\fP
.SS "CUSTOM KERNELS"
.SS "\fCGRUB_BTRFS_NKERNEL\fP / \fCGRUB_BTRFS_NINIT\fP / \fCGRUB_BTRFS_CUSTOM_MICROCODE\fP"
.PP
By default, “grub-btrfs” automatically detects most existing kernels, initramfs and microcode.
Customs kernel, initramfs and microcodes that are not detected can be added in these variables.
.IP \(em 4
Default: (“”)
.IP \(em 4
Example: \fCGRUB_BTRFS_NKERNEL=("kernel\-5.19.4\-custom" "vmlinux\-5.19.4\-custom")\fP
\fCGRUB_BTRFS_NINIT=("initramfs\-5.19.4\-custom.img" "initrd\-5.19.4\-custom.img" "otherinit\-5.19.4\-custom.gz")\fP
\fCGRUB_BTRFS_CUSTOM_MICROCODE=("custom\-ucode.img" "custom\-uc.img "custom_ucode.cpio")\fP
.SS "\fCGRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS\fP"
.PP
Additional kernel command line parameters that should be passed to the kernelwhen
booting a snapshot.
For dracut based distros this could be useful to pass “rd.live.overlay.overlayfs=1”
or “rd.live.overlay.readonly=1” to the Kernel for booting read only snapshots.
.IP \(em 4
Default: “”
.IP \(em 4
Example: \fCGRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS="rd.live.overlay.overlayfs=1"\fP
.SS "SNAPSHOT FILTERING"
.SS "\fCGRUB_BTRFS_IGNORE_SPECIFIC_PATH\fP"
.PP
Ignore specific path during run “grub-mkconfig”.
Only exact paths are ignored.
e.g : if `specific path` = @, only `@` snapshot will be ignored.
.IP \(em 4
Default: (“@”)
.IP \(em 4
Example: \fCGRUB_BTRFS_IGNORE_SPECIFIC_PATH=("@home")\fP
.SS "\fCGRUB_BTRFS_IGNORE_PREFIX_PATH\fP"
.PP
Ignore prefix path during run “grub-mkconfig”.
Any path starting with the specified string will be ignored.
e.g : if `prefix path` = @, all snapshots beginning with “@/...” will be ignored.
.IP \(em 4
Default: (“var/lib/docker” “@var/lib/docker” “@/var/lib/docker”)
.IP \(em 4
Example: \fCGRUB_BTRFS_IGNORE_PREFIX_PATH=("var/lib/docker" "@var/lib/docker" "@/var/lib/docker")\fP
.SS "\fCGRUB_BTRFS_IGNORE_SNAPSHOT_TYPE\fP"
.PP
Ignore specific type/tag of snapshot during run “grub-mkconfig”.
For snapper:
Type = single, pre, post.
For Timeshift:
Tag = boot, ondemand, hourly, daily, weekly, monthly.
.IP \(em 4
Default: (“”)
.IP \(em 4
Example: \fCGRUB_BTRFS_IGNORE_SNAPSHOT_TYPE=("ondemand")\fP
.SS "\fCGRUB_BTRFS_IGNORE_SNAPSHOT_DESCRIPTION\fP"
.PP
Ignore specific description of snapshot during run “grub-mkconfig”.
.IP \(em 4
Default: (“”)
.IP \(em 4
Example: \fCGRUB_BTRFS_IGNORE_SNAPSHOT_DESCRIPTION=("timeline")\fP
.SS "DISTRIBUTION DEPENDENT SETTINGS"
.SS "\fCGRUB_BTRFS_BOOT_DIRNAME\fP"
.PP
Location of kernels/initramfs/microcode.
Used by “grub-btrfs” to detect the boot partition and the location of kernels, initramfs and microcodes.
.IP \(em 4
Default: “/boot”
.IP \(em 4
Example: \fCGRUB_BTRFS_BOOT_DIRNAME="/"\fP
.SS "\fCGRUB_BTRFS_GRUB_DIRNAME\fP"
.PP
Location of the folder containing the “grub.cfg” file.
Might be grub2 on some systems.
For example, on Fedora with EFI : “/boot/efi/EFI/fedora”
.IP \(em 4
Default: “/boot/grub”
.IP \(em 4
Example: \fCGRUB_BTRFS_GRUB_DIRNAME="/boot/grub2"\fP
.SS "\fCGRUB_BTRFS_GBTRFS_DIRNAME\fP"
.PP
Location where grub-btrfs.cfg should be saved.
Some distributions (like OpenSuSE) store those file at the snapshot directory
instead of boot. Be aware that this directory must be available for grub during
startup of the system.
.IP \(em 4
Default: \fC$GRUB_BTRFS_GRUB_DIRNAME\fP
.IP \(em 4
Example: \fCGRUB_BTRFS_GBTRFS_DIRNAME="/.snapshots"\fP
.SS "\fCGRUB_BTRFS_GBTRFS_SEARCH_DIRNAME\fP"
.PP
Location of the directory where Grub searches for the grub-btrfs.cfg file.
Some distributions (like OpenSuSE) store those file at the snapshot directory
instead of boot. Be aware that this directory must be available for grub during
startup of the system.
.IP \(em 4
Default: “\${prefix}” (This is a grub variable that resolves to where grub is
.PP
installed. (like /boot/grub, /boot/efi/grub))
.IP \(em 4
NOTE: If variables of grub are used here like ${prefix}, they need to be escaped
.PP
with `$\` before the `$`
.IP \(em 4
Example: \fCGRUB_BTRFS_GBTRFS_SEARCH_DIRNAME="\${prefix}"\fP
.SS "\fCGRUB_BTRFS_MKCONFIG\fP"
.PP
Name/path of the command to generate the grub menu, used by “grub-btrfs.service”
Might be grub2-mkconfig on some systems (e.g. Fedora)
Default paths are /sbin:/bin:/usr/sbin:/usr/bin, if your path is missing, report it on the upstream project.
You can use the name of the command only or full the path.
.IP \(em 4
Default: grub-mkconfig
.IP \(em 4
Example: \fCGRUB_BTRFS_MKCONFIG=/sbin/grub2\-mkconfig\fP
.SS "\fCGRUB_BTRFS_SCRIPT_CHECK\fP"
.PP
Name of grub-script-check command, used by “grub-btrfs”
Might be grub2-script-check on some systems (e.g. Fedora)
.IP \(em 4
Default: grub-script-check
.IP \(em 4
Example: \fCGRUB_BTRFS_SCRIPT_CHECK=grub2\-script\-check\fP
.SS "\fCGRUB_BTRFS_MKCONFIG_LIB\fP"
.PP
Path of grub-mkconfig\d\s-2lib\s+2\u file, used by “grub-btrfs”
Might be /usr/share/grub2/grub-mkconfig\d\s-2lib\s+2\u on some systems (e.g. Opensuse)
.IP \(em 4
Default: /usr/share/grub/grub-mkconfig\d\s-2lib\s+2\u
.IP \(em 4
Example: \fCGRUB_BTRFS_MKCONFIG_LIB=/usr/share/grub2/grub\-mkconfig_lib\fP
.SS "SECURITY"
.SS "\fCGRUB_BTRFS_PROTECTION_AUTHORIZED_USERS\fP"
.PP
Password protection management for submenu, snapshots
Refer to the Grub documentation \fIhttps://www.gnu.org/software/grub/manual/grub/grub.html#Authentication-and-authorisation\fP
and this comment \fIhttps://github.com/Antynea/grub-btrfs/issues/95#issuecomment-682295660\fP
Add authorized usernames separate by comma (userfoo,userbar).
When Grubs password protection is enabled, the superuser is authorized by default, it is not necessary to add it
.IP \(em 4
Default: “”
.IP \(em 4
Example: \fCGRUB_BTRFS_PROTECTION_AUTHORIZED_USERS="userfoo,userbar"\fP
.SS "\fCGRUB_BTRFS_DISABLE_PROTECTION_SUBMENU\fP"
.PP
Disable authentication support for submenu of Grub-btrfs only (--unrestricted)
does not work if GRUB\d\s-2BTRFS\s+2\u\d\s-2PROTECTION\s+2\u\d\s-2AUTHORIZED\s+2\u\d\s-2USERS\s+2\u is not empty
.IP \(em 4
Default: “false”
.IP \(em 4
Example: \fCGRUB_BTRFS_DISABLE_PROTECTION_SUBMENU="true"\fP
.SH "FILES"
.PP
/etc/default/grub-btrfs/config
.SH "SEE ALSO"
.IR btrfs (8)
.IR btrfs-subvolume (8)
.IR grub-btrfsd (8)
.IR grub-mkconfig (8)
.SH "COPYRIGHT"
.PP
Copyright (c) 2022 Pascal Jäger

84
temp/grub-btrfsd.8 Normal file
View File

@@ -0,0 +1,84 @@
.TH "grub-btrfsd" "8"
.SH "NAME"
.PP
grub-btrfsd - An OpenRC daemon to automatically update the grub menu with
.BR grub-btrfs (8)
.PP
when a new btrfs snapshot is created.
.SH "SYNOPSIS"
.PP
\fCgrub\-btrfsd [\-h, \-\-help] [\-c, \-\-no\-color] [\-l, \-\-log\-file LOG_FILE] [\-r, \-\-recursive] [\-s, \-\-syslog] [\-t, \-\-timeshift\-auto] [\-o, \-\-timeshift\-old] [\-v, \-\-verbose] SNAPSHOTS_DIRS\fP
.SH "DESCRIPTION"
.PP
Grub-btrfsd is a shell script which is meant to be run as a daemon.
Grub-btrfsd watches a directory where btrfs-snapshots are created or deleted via inotifywait and runs grub-mkconfig (if grub-mkconfig never ran before since grub-btrfs was installed) or \fC/etc/grub.d/41_snapshots\-btrfs\fP (when grub-mkconfig ran before with grub-btrfs installed) when something in that directory changes.
.SH "OPTIONS"
.SS "\fCSNAPSHOTS_DIRS\fP"
.PP
This argument specifies the (space separated) paths where grub-btrfsd looks for newly created snapshots and snapshot deletions. It is usually defined by the program used to make snapshots.
E.g. for Snapper this would be \fC/.snapshots\fP. It is possible to define more than one directory here, all directories will inherit the same settings (recursive etc.).
This argument is not necessary to provide if \fC\-\-timeshift\-auto\fP is set.
.SS "\fC\-c / \-\-no\-color\fP"
.PP
Disable colors in output.
.SS "\fC\-l / \-\-log\-file\fP"
.PP
This arguments specifies a file where grub-btrfsd should write log messages.
.SS "\fC\-r / \-\-recursive\fP"
.PP
Watch snapshot directory recursively
.SS "\fC\-s / \-\-syslog\fP"
.PP
Write to syslog
.SS "\fC\-t / \-\-timeshift\-auto\fP"
.PP
This is a flag to activate the auto detection of the path where Timeshift stores snapshots. Newer versions (>=22.06) of Timeshift mount their snapshots to \fC/run/timeshift/$PID/backup/timeshift\-btrfs\fP. Where \fC$PID\fP is the process ID of the currently running Timeshift session. The PID is changing every time Timeshift is opened. grub-btrfsd can automatically take care of the detection of the correct PID and directory if this flag is set. In this case the argument \fCSNAPSHOTS_DIRS\fP has no effect.
.SS "\fC\-o / \-\-timeshift\-old\fP"
.PP
Look for snapshots in \fC/run/timeshift/backup/timeshift\-btrfs\fP instead of \fC/run/timeshift/$PID/backup/timeshift\-btrfs\fP. This is to be used for Timeshift versions <22.06.
.SS "\fC\-v / \-\-verbose\fP"
.PP
Let the log of the daemon be more verbose
.SS "\fC\-h / \-\-help\fP"
.PP
Displays a short help message.
.SH "CONFIGURATION"
.PP
The daemon is usually configured via the file \fC/etc/conf.d/grub\-btrfsd\fP on openrc-init systems and \fCsudo systemctl edit \-\-full grub\-btrfsd\fP on systemd systems. In this file the arguments (See OPTIONS), that OpenRC passes to the daemon when it is started, can be configured.
.SS "NOTES"
.PP
A common configuration for Snapper would be to set \fCSNAPSHOTS_DIR\fP to \fC/.snapshots\fP and not to set \fC\-\-timeshift\-auto\fP.
For Timeshift \fC\-\-timeshift\-auto\fP is set to true and \fCSNAPSHOTS_DIR\fP can be left as is.
.SH "FILES"
.PP
\fC/etc/conf.d/grub\-btrfsd\fP
\fC/usr/lib/systemd/system/grub\-btrfsd.service\fP
.SH "SEE ALSO"
.IR btrfs (8)
.IR btrfs-subvolume (8)
.IR grub-btrfsd (8)
.IR grub-mkconfig (8)
.IR inotifywait (1)
.IR openrc (8)
.IR rc-service (8)
.IR timeshift (1)
.SH "COPYRIGHT"
.PP
Copyright (c) 2022 Pascal Jäger