Skip to content

Commit 934ab21

Browse files
committed
grub-btrfs: add custom kernel parameters option for snapshots
Fix #214, #160 Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
1 parent f0ed56d commit 934ab21

5 files changed

Lines changed: 40 additions & 8 deletions

File tree

41_snapshots-btrfs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ boot_hs=$(${grub_probe} --device ${boot_device} --target="hints_string" 2>/dev/n
121121
boot_fs=$(${grub_probe} --device ${boot_device} --target="fs" 2>/dev/null) # Type filesystem of boot device
122122

123123
## Parameters passed to the kernel
124-
kernel_parameters="$GRUB_CMDLINE_LINUX $GRUB_CMDLINE_LINUX_DEFAULT"
124+
kernel_parameters="$GRUB_CMDLINE_LINUX $GRUB_CMDLINE_LINUX_DEFAULT $GRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS"
125125
## Mount point location
126126
grub_btrfs_mount_point=$(mktemp -dt grub-btrfs.XXXXXXXXXX)
127127
## Class for theme

config

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
GRUB_BTRFS_VERSION=4.12-improve-config-2022-12-05T20:15:10+00:00
3+
GRUB_BTRFS_VERSION=4.12-improve-config-2022-12-06T21:56:44+00:00
44

55
# Disable grub-btrfs.
66
# Default: "false"
@@ -48,6 +48,13 @@ GRUB_BTRFS_VERSION=4.12-improve-config-2022-12-05T20:15:10+00:00
4848
# Default: ("")
4949
#GRUB_BTRFS_CUSTOM_MICROCODE=("custom-ucode.img" "custom-uc.img "custom_ucode.cpio")
5050

51+
# Additonal kernel command line parameters that should be passed to the kernel
52+
# when booting a snapshot.
53+
# For dracut based distros this could be useful to pass "rd.live.overlay.overlayfs=1"
54+
# or "rd.live.overlay.readonly=1" to the Kernel for booting snapshots read only.
55+
# Default: ""
56+
#GRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS="rd.live.overlay.overlayfs=1"
57+
5158
# Comma seperated mount options to be used when booting a snapshot.
5259
# They can be defined here as well as in the "/" line inside the respective snapshots'
5360
# "/etc/fstab" files. Mount options found in both places are combined, and this variable

initramfs/readme.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ You notice that the name of the `hook` must match the name of the 2 installed fi
3939
Re-generate your initramfs
4040
`mkinitcpio -P` (option -P means, all preset present in `/etc/mkinitcpio.d`)
4141

42+
#### Dracut based distros
43+
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.
44+
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.
45+
After changing this run `sudo /etc/grub.d/41_snapshots-btrfs` to generate a new snapshot-submenu with the parameter added.
46+
4247
#### Other distribution
43-
Refer to your distribution's documentation
44-
or contribute to this project to add a paragraph.
48+
Refer to your distribution's documentation or contribute to this project to add a paragraph.
4549
#

manpages/grub-btrfs.8.man

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "grub-btrfs" "1"
1+
.TH "grub-btrfs" "8"
22

33
.SH "NAME"
44
.PP
@@ -114,6 +114,17 @@ Example: \fCGRUB_BTRFS_NKERNEL=("kernel\-5.19.4\-custom" "vmlinux\-5.19.4\-custo
114114
\fCGRUB_BTRFS_NINIT=("initramfs\-5.19.4\-custom.img" "initrd\-5.19.4\-custom.img" "otherinit\-5.19.4\-custom.gz")\fP
115115
\fCGRUB_BTRFS_CUSTOM_MICROCODE=("custom\-ucode.img" "custom\-uc.img "custom_ucode.cpio")\fP
116116

117+
.SS "\fCGRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS\fP"
118+
.PP
119+
Additonal kernel command line parameters that should be passed to the kernelwhen
120+
booting a snapshot.
121+
For dracut based distros this could be useful to pass “rd.live.overlay.overlayfs=1”
122+
or “rd.live.overlay.readonly=1” to the Kernel for booting read only snapshots.
123+
.IP \(em 4
124+
Default: “”
125+
.IP \(em 4
126+
Example: \fCGRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS="rd.live.overlay.overlayfs=1"\fP
127+
117128
.SS "SNAPSHOT FILTERING"
118129
.SS "\fCGRUB_BTRFS_IGNORE_SPECIFIC_PATH\fP"
119130
.PP
@@ -168,7 +179,6 @@ Example: \fCGRUB_BTRFS_BOOT_DIRNAME="/"\fP
168179
.SS "\fCGRUB_BTRFS_GRUB_DIRNAME\fP"
169180
.PP
170181
Location of the folder containing the “grub.cfg” file.
171-
Used by grub-btrfs to save the file “grub-btrfs.cfg”.
172182
Might be grub2 on some systems.
173183
For example, on Fedora with EFI : “/boot/efi/EFI/fedora”
174184
.IP \(em 4
@@ -183,9 +193,13 @@ Some distributions (like OpenSuSE) store those file at the snapshot directory
183193
instead of boot. Be aware that this direcory must be available for grub during
184194
startup of the system.
185195
.IP \(em 4
186-
Default: “/boot/grub”
196+
Default: $GRUB\d\s-2BTRFS\s+2\u\d\s-2GRUB\s+2\u\d\s-2DIRNAME\s+2\u
187197
.IP \(em 4
198+
<<<<<<< HEAD
188199
Example: \fCGRUB_BTRFS_GBTRFS_DIRNAME="/.snapshots"\fP
200+
=======
201+
Example \fCGRUB_BTRFS_GBTRFS_DIRNAME="/boot/grub2"\fP
202+
>>>>>>> e76cdc4 (grub-btrfs: add custom kernel parameters option for snapshots)
189203

190204
.SS "\fCGRUB_BTRFS_GBTRFS_SEARCH_DIRNAME\fP"
191205
.PP
@@ -204,7 +218,6 @@ with `$\` before the `$`
204218
.IP \(em 4
205219
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}”
206220

207-
208221
.SS "\fCGRUB_BTRFS_MKCONFIG\fP"
209222
.PP
210223
Name/path of the command to generate the grub menu, used by “grub-btrfs.service”

manpages/grub-btrfs.8.org

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ Customs kernel, initramfs and microcodes that are not detected can be added in t
8383
~GRUB_BTRFS_NINIT=("initramfs-5.19.4-custom.img" "initrd-5.19.4-custom.img" "otherinit-5.19.4-custom.gz")~
8484
~GRUB_BTRFS_CUSTOM_MICROCODE=("custom-ucode.img" "custom-uc.img "custom_ucode.cpio")~
8585

86+
*** ~GRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS~
87+
Additonal kernel command line parameters that should be passed to the kernelwhen
88+
booting a snapshot.
89+
For dracut based distros this could be useful to pass "rd.live.overlay.overlayfs=1"
90+
or "rd.live.overlay.readonly=1" to the Kernel for booting read only snapshots.
91+
- Default: ""
92+
- Example: ~GRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS="rd.live.overlay.overlayfs=1"~
93+
8694
** SNAPSHOT FILTERING
8795

8896
*** ~GRUB_BTRFS_IGNORE_SPECIFIC_PATH~

0 commit comments

Comments
 (0)