diff --git a/41_snapshots-btrfs b/41_snapshots-btrfs index 8429267..7c64801 100755 --- a/41_snapshots-btrfs +++ b/41_snapshots-btrfs @@ -91,6 +91,10 @@ btrfs_subvolume_sort="--sort=${GRUB_BTRFS_SUBVOLUME_SORT:-"-rootid"}" 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"} +## 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 @@ -177,7 +181,7 @@ fi ## Create entry entry() { - echo "$@" >> "$grub_directory/grub-btrfs.new" + echo "$@" >> "$grub_btrfs_directory/grub-btrfs.new" } ## menu entries @@ -494,7 +498,7 @@ header_menu() local lenght_title_column_right=$(((${#var}-lenght_title_column_left)+1)) #+1 is necessary for extra "|" character header_entry+=$(printf "%${lenght_title_column_left}s%${lenght_title_column_right}s" "${title_column[${GRUB_BTRFS_TITLE_FORMAT[$key],,}]}" "|") # Final "|" is for visuals only done - sed -i "1imenuentry '|${header_entry}' { echo }" "$grub_directory/grub-btrfs.new" # First "|" is for visuals only + sed -i "1imenuentry '|${header_entry}' { echo }" "$grub_btrfs_directory/grub-btrfs.new" # First "|" is for visuals only } ## List of kernels, initramfs and microcode in snapshots @@ -561,8 +565,8 @@ boot_separate() IFS=$oldIFS } -rm -f "$grub_directory/grub-btrfs.new" -> "$grub_directory/grub-btrfs.new" # Create a "grub-btrfs.new" file in "grub_directory" +rm -f "$grub_btrfs_directory/grub-btrfs.new" +> "$grub_btrfs_directory/grub-btrfs.new" # Create a "grub-btrfs.new" file in "grub_btrfs_directory" # 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/" @@ -585,16 +589,16 @@ if [[ "${count_limit_snap}" = "0" || -z "${count_limit_snap}" ]]; then 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_directory/grub-btrfs.new"; then - cat "$grub_directory/grub-btrfs.new" > "$grub_directory/grub-btrfs.cfg" - rm -f "$grub_directory/grub-btrfs.new" +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 submenu '${submenuname}' ${protection_authorized_users}${unrestricted_access_submenu}{ - configfile "\${prefix}/grub-btrfs.cfg" + configfile "${grub_btrfs_search_directory}/grub-btrfs.cfg" } EOF else - print_error "Syntax errors were detected in generated ${grub_directory}/grub-btrfs.new file. Old grub-btrfs.cfg (if present) was not replaced." + print_error "Syntax errors were detected in generated ${grub_btrfs_directory}/grub-btrfs.new file. Old grub-btrfs.cfg (if present) was not replaced." fi # warn when this script is run but there is no entry in grub.cfg diff --git a/config b/config index b988f4b..cc1e582 100644 --- a/config +++ b/config @@ -1,6 +1,6 @@ #!/usr/bin/env bash -GRUB_BTRFS_VERSION=4.12-master-2022-11-26T14:08:53+00:00 +GRUB_BTRFS_VERSION=4.12-master-2022-11-26T16:38:15+00:00 # Disable grub-btrfs. # Default: "false" @@ -99,6 +99,24 @@ GRUB_BTRFS_IGNORE_PREFIX_PATH=("var/lib/docker" "@var/lib/docker" "@/var/lib/doc # Default: "/boot" #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 +# startup of the system. +# Default: "/boot/grub" +#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 +# 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 `$` +#GRUB_BTRFS_GBTRFS_SEARCH_DIRNAME="\${prefix}" + + # Name/path of grub-mkconfig command, use by "grub-btrfs.service" # Might be 'grub2-mkconfig' on some systems (Fedora ...) # Default paths are /sbin:/bin:/usr/sbin:/usr/bin, diff --git a/manpages/grub-btrfs.8.man b/manpages/grub-btrfs.8.man index af6d84d..7ba4c1e 100644 --- a/manpages/grub-btrfs.8.man +++ b/manpages/grub-btrfs.8.man @@ -48,16 +48,16 @@ Example: \fCGRUB_BTRFS_DISABLE="true"\fP 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”) -.PP --Example: \fCGRUB_BTRFS_TITLE_FORMAT=("date" "snapshot" "type" "description")\fP +.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” -.PP --Example: \fCGRUB_BTRFS_LIMIT="50"\fP +.IP \(em 4 +Example: \fCGRUB_BTRFS_LIMIT="50"\fP .SS "\fCGRUB_BTRFS_SUBVOLUME_SORT\fP" .PP @@ -69,16 +69,16 @@ See Sorting section in “-rootid” means list snapshot by new ones first. .IP \(em 4 Default: “-rootid” -.PP --Example: \fCGRUB_BTRFS_SUBVOLUME_SORT="+ogen,\-gen,path,rootid"\fP +.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” -.PP --Example: \fCGRUB_BTRFS_SHOW_SNAPSHOTS_FOUND="false"\fP +.IP \(em 4 +Example: \fCGRUB_BTRFS_SHOW_SNAPSHOTS_FOUND="false"\fP .SS "\fCGRUB_BTRFS_ROOTFLAGS\fP" .PP @@ -89,8 +89,8 @@ takes priority over `fstab` entries. NB: Do NOT include “subvol=...” or “subvolid=...” here. .IP \(em 4 Default: “” -.PP --Example: \fCGRUB_BTRFS_ROOTFLAGS="space_cache,commit=10,norecovery"\fP +.IP \(em 4 +Example: \fCGRUB_BTRFS_ROOTFLAGS="space_cache,commit=10,norecovery"\fP .SS "\fCGRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION\fP" .PP @@ -99,8 +99,8 @@ 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” -.PP --Example: \fCGRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION="true"\fP +.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" @@ -109,10 +109,10 @@ By default, “grub-btrfs” automatically detects most existing kernels, initra Customs kernel, initramfs and microcodes that are not detected can be added in these variables. .IP \(em 4 Default: (“”) -.PP --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 +.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 "SNAPSHOT FILTERING" .SS "\fCGRUB_BTRFS_IGNORE_SPECIFIC_PATH\fP" @@ -122,8 +122,8 @@ Only exact paths are ignored. e.g : if `specific path` = @, only `@` snapshot will be ignored. .IP \(em 4 Default: (“@”) -.PP --Example: \fCGRUB_BTRFS_IGNORE_SPECIFIC_PATH=("@home")\fP +.IP \(em 4 +Example: \fCGRUB_BTRFS_IGNORE_SPECIFIC_PATH=("@home")\fP .SS "\fCGRUB_BTRFS_IGNORE_PREFIX_PATH\fP" .PP @@ -132,8 +132,8 @@ 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”) -.PP --Example: \fCGRUB_BTRFS_IGNORE_PREFIX_PATH=("var/lib/docker" "@var/lib/docker" "@/var/lib/docker")\fP +.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 @@ -144,16 +144,16 @@ For Timeshift: Tag = boot, ondemand, hourly, daily, weekly, monthly. .IP \(em 4 Default: (“”) -.PP --Example: \fCGRUB_BTRFS_IGNORE_SNAPSHOT_TYPE=("ondemand")\fP +.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: (“”) -.PP --Example: \fCGRUB_BTRFS_IGNORE_SNAPSHOT_DESCRIPTION=("timeline")\fP +.IP \(em 4 +Example: \fCGRUB_BTRFS_IGNORE_SNAPSHOT_DESCRIPTION=("timeline")\fP .SS "DISTRIBUTION DEPENDENT SETTINGS" .SS "\fCGRUB_BTRFS_BOOT_DIRNAME\fP" @@ -162,8 +162,8 @@ 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” -.PP --Example: \fCGRUB_BTRFS_BOOT_DIRNAME="/"\fP +.IP \(em 4 +Example: \fCGRUB_BTRFS_BOOT_DIRNAME="/"\fP .SS "\fCGRUB_BTRFS_GRUB_DIRNAME\fP" .PP @@ -173,8 +173,37 @@ 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 --Example: \fCGRUB_BTRFS_GRUB_DIRNAME="/boot/grub2"\fP +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 +startup of the system. +.IP \(em 4 +Default: “/boot/grub” +.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” + +.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 +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: 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 @@ -184,8 +213,8 @@ Default paths are /sbin:/bin:/usr/sbin:/usr/bin, if your path is missing, report You can use the name of the command only or full the path. .IP \(em 4 Default: grub-mkconfig -.PP --Example: \fCGRUB_BTRFS_MKCONFIG=/sbin/grub2\-mkconfig\fP +.IP \(em 4 +Example: \fCGRUB_BTRFS_MKCONFIG=/sbin/grub2\-mkconfig\fP .SS "\fCGRUB_BTRFS_SCRIPT_CHECK\fP" .PP diff --git a/manpages/grub-btrfs.8.org b/manpages/grub-btrfs.8.org index 2214c19..0867bb5 100644 --- a/manpages/grub-btrfs.8.org +++ b/manpages/grub-btrfs.8.org @@ -35,12 +35,12 @@ Disable grub-btrfs if true. *** ~GRUB_BTRFS_TITLE_FORMAT~ The snapshot entries submenu in Grub are added according to this line. It is possible to change to order of the fields. - Default: ("date" "snapshot" "type" "description") --Example: ~GRUB_BTRFS_TITLE_FORMAT=("date" "snapshot" "type" "description")~ +- Example: ~GRUB_BTRFS_TITLE_FORMAT=("date" "snapshot" "type" "description")~ *** ~GRUB_BTRFS_LIMIT~ Maximum number of snapshots in the GRUB snapshots sub menu. - Default: "50" --Example: ~GRUB_BTRFS_LIMIT="50"~ +- Example: ~GRUB_BTRFS_LIMIT="50"~ *** ~GRUB_BTRFS_SUBVOLUME_SORT~ Sort the found subvolumes by "ogeneration" or "generation" or "path" or "rootid". @@ -50,12 +50,12 @@ Sort the found subvolumes by "ogeneration" or "generation" or "path" or "rootid" #+END_MAN "-rootid" means list snapshot by new ones first. - Default: "-rootid" --Example: ~GRUB_BTRFS_SUBVOLUME_SORT="+ogen,-gen,path,rootid"~ +- Example: ~GRUB_BTRFS_SUBVOLUME_SORT="+ogen,-gen,path,rootid"~ *** ~GRUB_BTRFS_SHOW_SNAPSHOTS_FOUND~ Show snapshots found during run "grub-mkconfig" - Default: "true" --Example: ~GRUB_BTRFS_SHOW_SNAPSHOTS_FOUND="false"~ +- Example: ~GRUB_BTRFS_SHOW_SNAPSHOTS_FOUND="false"~ *** ~GRUB_BTRFS_ROOTFLAGS~ Comma seperated mount options to be used when booting a snapshot. @@ -64,14 +64,14 @@ They can be defined here as well as in the "/" line inside the respective snapsh takes priority over `fstab` entries. NB: Do NOT include "subvol=..." or "subvolid=..." here. - Default: "" --Example: ~GRUB_BTRFS_ROOTFLAGS="space_cache,commit=10,norecovery"~ +- Example: ~GRUB_BTRFS_ROOTFLAGS="space_cache,commit=10,norecovery"~ *** ~GRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION~ 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. - Default: "false" --Example: ~GRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION="true"~ +- Example: ~GRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION="true"~ ** CUSTOM KERNELS @@ -79,7 +79,7 @@ Change to "true" if your boot partition is not detected as separate. 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. - Default: ("") --Example: ~GRUB_BTRFS_NKERNEL=("kernel-5.19.4-custom" "vmlinux-5.19.4-custom")~ +- Example: ~GRUB_BTRFS_NKERNEL=("kernel-5.19.4-custom" "vmlinux-5.19.4-custom")~ ~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")~ @@ -90,14 +90,14 @@ Ignore specific path during run "grub-mkconfig". Only exact paths are ignored. e.g : if `specific path` = @, only `@` snapshot will be ignored. - Default: ("@") --Example: ~GRUB_BTRFS_IGNORE_SPECIFIC_PATH=("@home")~ +- Example: ~GRUB_BTRFS_IGNORE_SPECIFIC_PATH=("@home")~ *** ~GRUB_BTRFS_IGNORE_PREFIX_PATH~ 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. - Default: ("var/lib/docker" "@var/lib/docker" "@/var/lib/docker") --Example: ~GRUB_BTRFS_IGNORE_PREFIX_PATH=("var/lib/docker" "@var/lib/docker" "@/var/lib/docker")~ +- Example: ~GRUB_BTRFS_IGNORE_PREFIX_PATH=("var/lib/docker" "@var/lib/docker" "@/var/lib/docker")~ *** ~GRUB_BTRFS_IGNORE_SNAPSHOT_TYPE~ Ignore specific type/tag of snapshot during run "grub-mkconfig". @@ -106,12 +106,12 @@ Type = single, pre, post. For Timeshift: Tag = boot, ondemand, hourly, daily, weekly, monthly. - Default: ("") --Example: ~GRUB_BTRFS_IGNORE_SNAPSHOT_TYPE=("ondemand")~ +- Example: ~GRUB_BTRFS_IGNORE_SNAPSHOT_TYPE=("ondemand")~ *** ~GRUB_BTRFS_IGNORE_SNAPSHOT_DESCRIPTION~ Ignore specific description of snapshot during run "grub-mkconfig". - Default: ("") --Example: ~GRUB_BTRFS_IGNORE_SNAPSHOT_DESCRIPTION=("timeline")~ +- Example: ~GRUB_BTRFS_IGNORE_SNAPSHOT_DESCRIPTION=("timeline")~ ** DISTRIBUTION DEPENDENT SETTINGS @@ -119,7 +119,7 @@ Ignore specific description of snapshot during run "grub-mkconfig". Location of kernels/initramfs/microcode. Used by "grub-btrfs" to detect the boot partition and the location of kernels, initramfs and microcodes. - Default: "/boot" --Example: ~GRUB_BTRFS_BOOT_DIRNAME="/"~ +- Example: ~GRUB_BTRFS_BOOT_DIRNAME="/"~ *** ~GRUB_BTRFS_GRUB_DIRNAME~ Location of the folder containing the "grub.cfg" file. @@ -127,7 +127,27 @@ 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" --Example: ~GRUB_BTRFS_GRUB_DIRNAME="/boot/grub2"~ +- Example: ~GRUB_BTRFS_GRUB_DIRNAME="/boot/grub2"~ + +*** ~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 + startup of the system. +- Default: "/boot/grub" +- Example GRUB_BTRFS_GBTRFS_DIRNAME="/boot/grub" + +*** ~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 +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}" + *** ~GRUB_BTRFS_MKCONFIG~ Name/path of the command to generate the grub menu, used by "grub-btrfs.service" @@ -135,7 +155,7 @@ 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. - Default: grub-mkconfig --Example: ~GRUB_BTRFS_MKCONFIG=/sbin/grub2-mkconfig~ +- Example: ~GRUB_BTRFS_MKCONFIG=/sbin/grub2-mkconfig~ *** ~GRUB_BTRFS_SCRIPT_CHECK~ Name of grub-script-check command, used by "grub-btrfs"