Compare commits

...

36 Commits

Author SHA1 Message Date
github-actions[bot]
6845af429b chore: bump version to master-2026-05-31T15:55:08+00:00 2026-05-31 15:55:08 +00:00
Antynea
4a0a27bef1 Fix OpenRC command for adding grub-btrfsd to startup
Fixes #427 
Replace `rc-config add` with `rc-update add` in the README.
2026-05-31 17:55:01 +02:00
github-actions[bot]
474771981f chore: bump version to master-2026-05-30T19:22:48+00:00 2026-05-30 19:22:48 +00:00
Antynea
e929a4b010 Use print_info for "Detecting snapshots" message
The "Detecting snapshots ..." message was still a bare printf and bypassed the logging helpers added in #435.
Use print_info so it carries the "grub-btrfs:" prefix; 
the trailing newline is handled by the helper.
2026-05-30 21:22:41 +02:00
github-actions[bot]
eb87f5101f chore: bump version to master-2026-05-30T13:43:14+00:00 2026-05-30 13:43:14 +00:00
Antynea
aea2b0aa1c #423 remove unneeded log messages (#435)
* Refactor error handling to logging functions
2026-05-30 15:43:07 +02:00
github-actions[bot]
85589d735a chore: bump version to master-2026-05-30T12:41:03+00:00 2026-05-30 12:41:03 +00:00
Antynea
141c795a1d Update checkout action to version 4 2026-05-30 14:40:54 +02:00
github-actions[bot]
7306aad97d chore: bump version to master-2026-05-30T12:36:21+00:00 2026-05-30 12:36:21 +00:00
Antynea
3162276a22 Update GitHub Actions to use checkout@v4 2026-05-30 14:36:14 +02:00
github-actions[bot]
3979c534f4 chore: bump version to master-2026-05-30T12:33:43+00:00 2026-05-30 12:33:43 +00:00
Antynea
4e12747226 Update GitHub Actions to use checkout@v4 2026-05-30 14:33:34 +02:00
github-actions[bot]
d785137f55 chore: bump version to 2026-05-30 12:13:48 +00:00
Sneed
b5670caba5 fixed typo - added "$" to pidfile (#434)
Added "$" to {RC_SVCNAME} to ensure pid file is grub-btrfsd.pid and not "{RC_SVCNAME}.pid"
2026-05-30 14:13:41 +02:00
github-actions[bot]
4669f59d47 chore: bump version to 2026-05-30 12:07:59 +00:00
Antynea
531f3676b7 Fix typo
Fix typo
2026-05-30 14:07:52 +02:00
github-actions[bot]
efece5eeb2 chore: bump version to 2026-05-23 08:55:16 +00:00
kennethso168
fe2028b623 Add more information for booting read-only snapshots on Dracut distros (#431)
Adapted from https://github.com/Antynea/grub-btrfs/issues/399#issuecomment-4478211233
2026-05-23 10:55:09 +02:00
github-actions[bot]
aeda46c2a0 chore: bump version to 2026-05-22 11:33:41 +00:00
Antynea
8fb00c532a Modify bump-version workflow for versioning
Update version retrieval method and remove fetch-tags.
2026-05-22 13:33:34 +02:00
github-actions[bot]
97ae2976f9 chore: bump version to 2026-05-22 11:29:30 +00:00
Antynea
86345e0d38 Modify versioning in bump-version-on-merge workflow
Removed fetching tags when checking out the master branch and updated version format to exclude the latest tag.
2026-05-22 13:29:22 +02:00
github-actions[bot]
5b567255e3 chore: bump version to 2026-05-10 10:13:56 +00:00
Reynegton Pinheiro Nunes
a181e2ca41 feat: add auto-detection for Fedora distribution (#428)
Fedora uses non-standard paths and command names for GRUB (e.g., /boot/grub2 instead of /boot/grub, and grub2-mkconfig).
This change adds a conditional block to detect Fedora via /etc/fedora-release and automatically sets the appropriate variables, improving the out-of-the-box experience for Fedora users.
2026-05-10 12:13:50 +02:00
github-actions[bot]
a79c9cc42c chore: bump version to 2026-05-10 10:12:40 +00:00
Antynea
88e8b4ae97 Add condition to skip action for bot commits 2026-05-10 12:12:32 +02:00
github-actions[bot]
004fe0aae4 chore: bump version to 2026-05-10 10:10:14 +00:00
Antynea
828f593f6f Add workflow to bump version on merge to master 2026-05-10 12:10:01 +02:00
Antynea
b8e6deaafd Add workflow to bump version on tag push 2026-05-10 12:07:00 +02:00
Jalopy
7e8a45ca9c Fix boot_uuid_subvolume fallback (#415)
Fix regression affecting systems where boot directory is not a Btrfs subvolume.
2026-02-19 09:21:08 +01:00
Jalopy
14fa71c994 add support for detached LUKS header and UUID fallbacks (#378)
Two hard failures prevented 41-snapshots-btrfs from generating a
snapshot submenu when the root LUKS header is detached and cryptdevice=
uses a /dev/disk/by-id path:

* grub-probe --target=fs_uuid aborted on detached headers.
* grep-based extraction of UUID from GRUB_CMDLINE_LINUX_DEFAULT failed
  when cryptdevice= did not contain “UUID=…”.

This patch:

1. Wraps grub-probe in a try/blkid/lsblk cascade that always returns the
   filesystem UUID or prints a clear error.
2. Replaces the fixed “cryptomount -u $(grep …UUID=…)” line with logic
   that:
   • accepts both UUID=… and /dev/disk/by-id/… syntaxes,
   • resolves paths to a canonical UUID with blkid,
   • emits ‘cryptomount -u <uuid>’ when possible,
   • falls back to ‘cryptomount -a’ only if no UUID can be extracted.
3. Keeps the previous behavior unchanged for unencrypted systems or for
   installations that already worked.

Result: snapshot menu is produced and boots correctly on standard
(setup with inline header), detached-header, and by-id configurations;
no regression for existing users.
2026-01-02 10:52:31 +01:00
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
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
10 changed files with 247 additions and 38 deletions

View File

@@ -0,0 +1,34 @@
name: Bump version on merge
on:
push:
branches:
- master
permissions:
contents: write
jobs:
bump-version:
name: Bump version in config
runs-on: ubuntu-latest
if: github.actor != 'github-actions[bot]'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: master
- name: Update version in config
run: |
version="master-$(date -u -Iseconds)"
sed -i "s/GRUB_BTRFS_VERSION=.*/GRUB_BTRFS_VERSION=${version}/" config
echo "VERSION=${version}" >> $GITHUB_ENV
- name: Commit updated config
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add config
git commit -m "chore: bump version to ${{ env.VERSION }}"
git push origin master

31
.github/workflows/bump-version.yml vendored Normal file
View File

@@ -0,0 +1,31 @@
name: Bump version on tag
on:
push:
tags:
- '*'
permissions:
contents: write
jobs:
bump-version:
name: Bump version in config
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: master
- name: Update version in config
run: |
sed -i "s/GRUB_BTRFS_VERSION=.*/GRUB_BTRFS_VERSION=${{ github.ref_name }}/" config
- name: Commit updated config
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add config
git commit -m "chore: bump version to ${{ github.ref_name }}"
git push origin master

View File

@@ -14,9 +14,8 @@ jobs:
codespell:
name: Check for spelling errors
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Codespell
uses: codespell-project/actions-codespell@v2

View File

@@ -44,12 +44,21 @@ grub_btrfs_config="${sysconfdir}/default/grub-btrfs/config"
[ -f "$grub_btrfs_config" ] && . "$grub_btrfs_config"
[ -f "${sysconfdir}/default/grub" ] && . "${sysconfdir}/default/grub"
## Error Handling
## Logging
print_info()
{
printf "grub-btrfs: %s\n" "$*" >&2
}
print_warning()
{
printf "grub-btrfs: Warning: %s\n" "$*" >&2
}
print_error()
{
local err_msg="$*"
local bug_report="If you think an error has occurred, please file a bug report at \"https://github.com/Antynea/grub-btrfs\""
printf "%s\n" "${err_msg}" "${bug_report}" >&2 ;
printf "grub-btrfs: Error: %s\n" "$*" "${bug_report}" >&2
exit 0
}
@@ -75,12 +84,12 @@ while getopts :V-: opt; do
done
## Exit the script, if:
[ "$(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
[ "$(echo "$GRUB_BTRFS_DISABLE" | tr '[:upper:]' '[:lower:]')" = 'true' ] && { print_info "GRUB_BTRFS_DISABLE is set to true (default=false)"; exit 0; }
if ! type btrfs >/dev/null 2>&1; then print_info "btrfs-progs isn't installed"; exit 0; 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"
[[ "$(btrfs filesystem df / 2>&1)" == *"not a btrfs filesystem"* ]] && print_error "Root filesystem isn't btrfs"
[[ "$(btrfs filesystem df / 2>&1)" == *"not a btrfs filesystem"* ]] && { print_info "Root filesystem isn't btrfs"; exit 0; }
printf "Detecting snapshots ...\n" >&2 ;
print_info "Detecting snapshots ..."
## Submenu name
distro=$(awk -F "=" '/^NAME=/ {gsub(/"/, "", $2); print $2}' /etc/os-release) # escape '
@@ -107,20 +116,85 @@ esac
if [ -n "${GRUB_BTRFS_PROTECTION_AUTHORIZED_USERS}" ] ; then
protection_authorized_users="--users ${GRUB_BTRFS_PROTECTION_AUTHORIZED_USERS} "
fi
## 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 '
# 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_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
# -----------------------------------------------------------
# ---------- Root partition ----------
root_device="$(${grub_probe} --target=device /)" # e.g. /dev/mapper/enc
root_uuid="$(${grub_probe} --device "${root_device}" --target=fs_uuid 2>/dev/null)" || true
# Fallback when grub-probe fails (encrypted container, detached header…)
if [ -z "$root_uuid" ]; then
root_uuid="$(blkid -s UUID -o value "${root_device}" 2>/dev/null)"
fi
[ -z "$root_uuid" ] && print_error "Cannot determine UUID of ${root_device}"
# Root subvolume UUID
root_uuid_subvolume="$(btrfs subvolume show / 2>/dev/null | \
awk -F':' '/^\s*UUID/ {gsub(/^[ \t]+/, "", $2); print $2}')"
[ -z "$root_uuid_subvolume" ] && print_error "UUID of the root subvolume is not available"
# ---------- Boot partition ----------
boot_device="$(${grub_probe} --target=device "${boot_directory}")" # e.g. /dev/sdb1
boot_uuid="$(${grub_probe} --device "${boot_device}" --target=fs_uuid 2>/dev/null)" || true
# Fallback for boot UUID
if [ -z "$boot_uuid" ]; then
boot_uuid="$(blkid -s UUID -o value "${boot_device}" 2>/dev/null)"
fi
[ -z "$boot_uuid" ] && print_error "Cannot determine UUID of ${boot_device}"
# If /boot is not a Btrfs subvolume, reuse root subvol UUID
boot_uuid_subvolume="$(
btrfs subvolume show "${boot_directory}" 2>/dev/null | \
awk -F':' '/^\s*UUID/ {gsub(/^[ \t]+/, "", $2); print $2; exit}'
)"
[ -z "$boot_uuid_subvolume" ] && boot_uuid_subvolume="$root_uuid_subvolume"
# Extra data for GRUB commands
boot_hs="$(${grub_probe} --device "${boot_device}" --target=hints_string 2>/dev/null)"
boot_fs="$(${grub_probe} --device "${boot_device}" --target=fs 2>/dev/null)"
# -----------------------------------------------------------
## Enable LUKS encrypted devices support
case "$(echo "$GRUB_BTRFS_ENABLE_CRYPTODISK" | tr '[:upper:]' '[:lower:]')" in
true)
list_insmods=(
"insmod gzio"
"insmod part_gpt"
"insmod cryptodisk"
"insmod luks"
"insmod gcry_rijndael"
"insmod gcry_rijndael"
"insmod gcry_sha256"
"insmod ${boot_fs}"
)
# Extract the <source> field of cryptdevice=<source>:<name>[:header]
crypt_source="$(printf '%s %s\n' "$GRUB_CMDLINE_LINUX_DEFAULT" "$GRUB_CMDLINE_LINUX" \
| grep -o -P 'cryptdevice=\K[^:]+' || true)"
# Turn the source into a UUID that cryptomount -u understands
crypt_uuid=""
if [[ "$crypt_source" =~ ^UUID=.* ]]; then # already UUID=…
crypt_uuid="${crypt_source#UUID=}"
elif [[ "$crypt_source" == /dev/* ]]; then # path → resolve → blkid
real_dev=$(readlink -f "$crypt_source" 2>/dev/null || true)
[ -b "$real_dev" ] && crypt_uuid=$(blkid -s UUID -o value "$real_dev" 2>/dev/null || true)
fi
# Emit the proper cryptomount command
if [[ "$crypt_uuid" =~ ^[0-9a-fA-F-]{36}$ ]]; then
list_insmods+=("cryptomount -u ${crypt_uuid}")
else
# last-resort: scan all crypto containers (works but a bit slower)
list_insmods+=("cryptomount -a")
fi
;;
*)
list_insmods=("insmod ${boot_fs}")
;;
esac
## Parameters passed to the kernel
kernel_parameters="$GRUB_CMDLINE_LINUX $GRUB_CMDLINE_LINUX_DEFAULT $GRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS"
@@ -218,13 +292,22 @@ 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}"\""
@@ -259,7 +342,12 @@ 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}"\""
@@ -318,7 +406,7 @@ snapshot_list()
# 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"}')"
@@ -455,12 +543,8 @@ 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
for oiucode in ${GRUB_EARLY_INITRD_LINUX_STOCK} ; do
oiucode="${boot_dir}/${oiucode}"
[ ! -f "${oiucode}" ] && continue;
list_ucode+=("$oiucode")
done
@@ -531,6 +615,7 @@ 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
@@ -610,7 +695,7 @@ 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."
print_info "No snapshots found."; exit 0
fi
# Move "grub-btrfs.new" to "grub-btrfs.cfg"
header_menu

View File

@@ -240,7 +240,7 @@ sudo rc-service grub-btrfsd start
To activate it during system startup, run:
```bash
sudo rc-config add grub-btrfsd default
sudo rc-update add grub-btrfsd default
```
##### 💼 Snapshots not in `/.snapshots` for OpenRC
@@ -274,6 +274,10 @@ After that, the daemon should be restarted with:
sudo rc-service grub-btrfsd restart
```
##### 🔒 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.
- - -
### Troubleshooting
If you experience problems with grub-btrfs don't hesitate [to file an issue](https://github.com/Antynea/grub-btrfs/issues/new/choose).

16
config
View File

@@ -1,7 +1,15 @@
#!/usr/bin/env bash
GRUB_BTRFS_VERSION=4.13-yabsnap_info_support-2024-03-06T13:43:57+00:00
GRUB_BTRFS_VERSION=master-2026-05-31T15:55:08+00:00
# Distribution specific auto-detection (e.g. Fedora)
if [ -f /etc/fedora-release ]; then
GRUB_BTRFS_GRUB_DIRNAME="/boot/grub2"
GRUB_BTRFS_GBTRFS_DIRNAME="/boot/grub2"
GRUB_BTRFS_MKCONFIG="grub2-mkconfig"
GRUB_BTRFS_SCRIPT_CHECK="grub2-script-check"
fi
# Disable grub-btrfs.
# Default: "false"
@@ -74,7 +82,7 @@ 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:
@@ -158,3 +166,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

@@ -5,7 +5,7 @@
name="grub-btrfs daemon"
command="/usr/bin/grub-btrfsd"
command_args="$optional_args ${snapshots}"
pidfile="/run/{RC_SVCNAME}.pid"
pidfile="/run/${RC_SVCNAME}.pid"
command_background=true
depend() {

View File

@@ -40,8 +40,39 @@ 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.
Distributions that use Dracut to make their initramfs (many of the Fedora based Distros) have to include the `overlayfs` module into the initramfs and 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.
1. Include `overlayfs` module into dracut
```bash
echo 'add_dracutmodules+=" overlayfs "' | sudo tee /etc/dracut.conf.d/overlayfs.conf
```
2. Fix for dracut <109
Unfortunately, dracut version <109 has a bug that prevents overlayfs mount from properly working. [A fix has been committed into dracut version 109](https://github.com/dracut-ng/dracut-ng/commit/deeb670c28d12a478bbea95e29677e436d1912fb). If you are still on version < 109, instead of editing `/usr/lib/dracut/modules.d/70overlayfs/mount-overlayfs.sh` directly on your system, which will get overwritten on updates to the dracut package, we can duplicate the whole module with a lower priority number and carry out the patch there. As explained in this [very old notes about dracut](https://wwoods.fedorapeople.org/doc/dracut-notes.html):
> dracut refuses to overwrite files when installing things into the initramfs, so things installed by the the lower numbered modules have priority over the higher ones.
```bash
sudo cp -r /usr/lib/dracut/modules.d/70overlayfs /usr/lib/dracut/modules.d/69overlayfs
sudoedit /usr/lib/dracut/modules.d/69overlayfs/mount-overlayfs.sh
```
Edit the file as per [the commit](https://github.com/dracut-ng/dracut/commit/deeb670c28d12a478bbea95e29677e436d1912fb)
3. Regenerate the initramfs
```
# for current kernel's initramfs
sudo dracut -f
# for all kernels
sudo dracut -f --regenerate-all
```
4. Add kernel parameter and regenerate grub snapshot-submenu
Grub-btrfs provides the variable `GRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS` in `/etc/default/grub-btrfs/config` 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

View File

@@ -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

View File

@@ -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~