Skip to content

Commit

Permalink
grub-btrfs: add custom kernel parameters option for snapshots
Browse files Browse the repository at this point in the history
Fix #214, #160

Signed-off-by: Pascal Jäger <[email protected]>
  • Loading branch information
Schievel1 committed Dec 6, 2022
1 parent f0ed56d commit 934ab21
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion 41_snapshots-btrfs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ boot_hs=$(${grub_probe} --device ${boot_device} --target="hints_string" 2>/dev/n
boot_fs=$(${grub_probe} --device ${boot_device} --target="fs" 2>/dev/null) # Type filesystem of boot device

## 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
Expand Down
9 changes: 8 additions & 1 deletion config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

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

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

# Additonal 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 seperated 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
Expand Down
8 changes: 6 additions & 2 deletions initramfs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
21 changes: 17 additions & 4 deletions manpages/grub-btrfs.8.man
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "grub-btrfs" "1"
.TH "grub-btrfs" "8"

.SH "NAME"
.PP
Expand Down Expand Up @@ -114,6 +114,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
Additonal 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
Expand Down Expand Up @@ -168,7 +179,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
Expand All @@ -183,9 +193,13 @@ 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
startup of the system.
.IP \(em 4
Default: “/boot/grub”
Default: $GRUB\d\s-2BTRFS\s+2\u\d\s-2GRUB\s+2\u\d\s-2DIRNAME\s+2\u
.IP \(em 4
<<<<<<< HEAD
Example: \fCGRUB_BTRFS_GBTRFS_DIRNAME="/.snapshots"\fP
=======
Example \fCGRUB_BTRFS_GBTRFS_DIRNAME="/boot/grub2"\fP
>>>>>>> e76cdc4 (grub-btrfs: add custom kernel parameters option for snapshots)

.SS "\fCGRUB_BTRFS_GBTRFS_SEARCH_DIRNAME\fP"
.PP
Expand All @@ -204,7 +218,6 @@ 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}”


.SS "\fCGRUB_BTRFS_MKCONFIG\fP"
.PP
Name/path of the command to generate the grub menu, used by “grub-btrfs.service”
Expand Down
8 changes: 8 additions & 0 deletions manpages/grub-btrfs.8.org
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,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~
Additonal 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~
Expand Down

0 comments on commit 934ab21

Please sign in to comment.