Skip to content

Commit d68fdf5

Browse files
authored
Adds a new config variable "GRUB_BTRFS_ROOTFLAGS" (#133)
Script: Improves the rootflags option in the kernel command line: - Remove "rw" flag. - Parse fstab mountoptions and add them to rootflags: Adds functionality to read in snapshot specific mount flags from the respective fstab and uses them in combination with the new config option, while the latter is prioritized. Both places can, but don't need to define mount flags. If either of them doesn't, it will simply not be taken into account. Config file: Adds a new config variable "GRUB_BTRFS_ROOTFLAGS": - The new variable is used to include user-defined rootflags in the kernel command line of generated snapshot bootmenu entries. See config file for more infos.
1 parent 87168d2 commit d68fdf5

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

41_snapshots-btrfs

+12-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ else
115115
LINUX_ROOT_DEVICE=UUID=${root_uuid}
116116
fi
117117
}
118+
## Detect rootflags
119+
detect_rootflags()
120+
{
121+
local fstabflags=$(grep -oE '^\s*[^#][[:graph:]]+\s+/\s+btrfs\s+[[:graph:]]+' "${gbgmp}/${snap_dir_name}/etc/fstab" \
122+
| sed -E 's/^.*[[:space:]]([[:graph:]]+)$/\1/;s/,?subvol(id)?=[^,$]+//g;s/^,//')
123+
rootflags="rootflags=${fstabflags:+$fstabflags,}${GRUB_BTRFS_ROOTFLAGS:+$GRUB_BTRFS_ROOTFLAGS,}"
124+
}
118125

119126
### Error Handling
120127
print_error()
@@ -183,7 +190,7 @@ make_menu_entries()
183190
fi
184191
echo 'Loading Snapshot: "${snap_date_time}" "${snap_dir_name}"'
185192
echo 'Loading Kernel: "${k}" ...'
186-
linux \"${boot_dir_root_grub}/"${k}"\" root="${LINUX_ROOT_DEVICE}" rw ${kernel_parameters} rootflags=subvol=\""${snap_dir_name}"\""
193+
linux \"${boot_dir_root_grub}/"${k}"\" root="${LINUX_ROOT_DEVICE}" ${kernel_parameters} ${rootflags}subvol=\""${snap_dir_name}"\""
187194
if [[ "${name_microcode}" != "x" ]] ; then
188195
entry "\
189196
echo 'Loading Microcode & Initramfs: "${u}" "${i}" ...'
@@ -417,6 +424,8 @@ boot_bounded()
417424
detect_kernel
418425
if [ -z "${list_kernel}" ]; then continue; fi
419426
name_kernel=("${list_kernel[@]##*"/"}")
427+
# Detect rootflags
428+
detect_rootflags
420429
# Initramfs (Original + custom initramfs)
421430
detect_initramfs
422431
if [ -z "${list_initramfs}" ]; then continue; fi
@@ -472,6 +481,8 @@ boot_separate()
472481
snap_dir_name="$(trim "$snap_dir_name")"
473482
snap_date_time="$(echo "$item" | cut -d' ' -f1-2)"
474483
snap_date_time="$(trim "$snap_date_time")"
484+
# Detect rootflags
485+
detect_rootflags
475486
# show snapshot found during run "grub-mkconfig"
476487
if [[ "${GRUB_BTRFS_SHOW_SNAPSHOTS_FOUND:-"true"}" = "true" ]]; then
477488
printf "Found snapshot: %s\n" "$item" >&2 ;

config

+8
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@
5454
# Default: ("")
5555
#GRUB_BTRFS_CUSTOM_MICROCODE=("custom-ucode.img" "custom-uc.img "custom_ucode.cpio")
5656

57+
# Comma seperated mount options to be used when booting a snapshot.
58+
# They can be defined here as well as in the "/" line inside the respective snapshots'
59+
# "/etc/fstab" files. Mount options found in both places are combined, and this variable
60+
# takes priority over `fstab` entries.
61+
# NB: Do NOT include "subvol=..." or "subvolid=..." here.
62+
# Default: ""
63+
#GRUB_BTRFS_ROOTFLAGS="space_cache,commit=10,norecovery"
64+
5765
# Ignore specific path during run "grub-mkconfig".
5866
# Only exact paths are ignored.
5967
# e.g : if `specific path` = @, only `@` snapshot will be ignored.

0 commit comments

Comments
 (0)