Skip to content

Commit cfec416

Browse files
committed
Support automatic "noresume" when importing pools R/W
Rather than just warn the user about the need to set the "noresume" kernel argument when booting after an active suspend partition is detected and a pool is imported R/W, ZFSBootMenu now supports rewriting the kernel command line to remove any "resume=" arguments and append a "noresume". This uses awk to cleanly (and, it seems, correctly) handle the possibility of double-quoted strings in the argument list, which the kernel docs say are permitted. (The docs do not mention single-quoted strings, so we don't support them.) The prior behavior has been preserved by allowing the user to type DANGEROUS instead of the redefined NORESUME response to the resume guard prompt, just in case there is some unexpected edge case that thwarts automatic redirection and the user wants to assume responsibility for pool corruption. Closes #78.
1 parent 91296d1 commit cfec416

File tree

2 files changed

+57
-5
lines changed

2 files changed

+57
-5
lines changed

90zfsbootmenu/module-setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ install() {
7979
"tr"
8080
"tac"
8181
"blkid"
82+
"awk"
8283
)
8384

8485
for _exec in "${essential_execs[@]}"; do

90zfsbootmenu/zfsbootmenu-lib.sh

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,43 @@ kexec_kernel() {
188188
cli_args="$( find_kernel_args "${fs}" "${mnt}" )"
189189
root_prefix="$( find_root_prefix "${fs}" "${mnt}" )"
190190

191+
if [ -e "${BASE}/noresume" ]; then
192+
# Must replace resume= arguments and append a noresume
193+
cli_args="$( awk <<<"${cli_args}" '
194+
BEGIN {
195+
quot = 0;
196+
supp = 0;
197+
ORS = " ";
198+
}
199+
200+
{
201+
for (i=1; i <= NF; i++) {
202+
if ( quot == 0 ) {
203+
# If unquoted, determine if output should be suppressed
204+
if ( $(i) ~ /^resume=/ ) {
205+
# Argument starts with "resume=", suppress
206+
supp = 1;
207+
} else {
208+
# Nothing else is suppressed
209+
supp = 0;
210+
}
211+
}
212+
213+
# If output is not suppressed, print the field
214+
if ( supp == 0 && length($(i)) > 0 ) {
215+
print $(i);
216+
}
217+
218+
# If an odd number of quotes are in this field, toggle quoting
219+
if ( gsub(/"/, "\"", $(i)) % 2 == 1 ) {
220+
quot = (quot + 1) % 2;
221+
}
222+
}
223+
printf "noresume";
224+
}
225+
' )"
226+
fi
227+
191228
# restore kernel log level just before we kexec
192229
# shellcheck disable=SC2154
193230
echo "${printk}" > /proc/sys/kernel/printk
@@ -689,17 +726,31 @@ resume_prompt() {
689726
be imported read-write. Importing read-write and then resuming
690727
from an active suspend partition may DESTROY YOUR POOL.
691728
692-
If you are certain you want to proceed, type NORESUME. You are
693-
also STRONGLY ADVISED to boot with the "noresume" option added to
694-
your kernel command-line to prevent your system from attempting
695-
to restore this image.
729+
If you choose to proceed, ZFSBootMenu can attempt to remove any
730+
"resume=" arguments from your kernel command line and append a
731+
"noresume" argument to prevent your system from attempting to
732+
restore from the active suspend partition.
733+
734+
Type NORESUME to proceed with the import, allowing ZFSBootMenu
735+
to add a "noresume" argument to your kernel command line.
736+
737+
Type DANGEROUS to proceed with the import without allowing
738+
ZFSBootMenu to modify your kernel command line. Make sure to
739+
add the "noresume" argument yourself if necesary.
740+
741+
Type any other text, or just press enter, to abort.
696742
697743
Proceed [No] ?
698744
EOF
699745

700746
read -r decision
701747

702-
if [ "x${decision}" != "xNORESUME" ]; then
748+
if [ "x${decision}" = "xDANGEROUS" ]; then
749+
return 0
750+
elif [ "x${decision}" = "xNORESUME" ]; then
751+
: > "${BASE}/noresume"
752+
return 0
753+
else
703754
return 1
704755
fi
705756
fi

0 commit comments

Comments
 (0)