@@ -192,11 +192,10 @@ duplicate_snapshot() {
192192
193193 pool=" ${selected%%/* } "
194194
195- if set_rw_pool " ${pool} " ; then
196- CLEAR_SCREEN=0
197- key_wrapper " ${pool} "
198- CLEAR_SCREEN=1
199- fi
195+ set_rw_pool " ${pool} " || return 1
196+ CLEAR_SCREEN=0
197+ key_wrapper " ${pool} "
198+ CLEAR_SCREEN=1
200199
201200 zfs send " ${selected} " | mbuffer \
202201 | zfs recv -u -o canmount=noauto -o mountpoint=/ " ${target} "
@@ -224,9 +223,8 @@ clone_snapshot() {
224223 pool=" ${selected%%/* } "
225224 parent=" ${selected%%@* } "
226225
227- if set_rw_pool " ${pool} " ; then
228- key_wrapper " ${pool} "
229- fi
226+ set_rw_pool " ${pool} " || return 1
227+ key_wrapper " ${pool} "
230228
231229 while read -r PROPERTY VALUE
232230 do
@@ -272,13 +270,10 @@ set_default_kernel() {
272270 kernel=" ${2#/ boot/ } "
273271
274272 # Make sure the pool is writable
275- if set_rw_pool " ${pool} " ; then
276- CLEAR_SCREEN=1
277- key_wrapper " ${pool} "
278- CLEAR_SCREEN=0
279- else
280- return 1
281- fi
273+ set_rw_pool " ${pool} " || return 1
274+ CLEAR_SCREEN=1
275+ key_wrapper " ${pool} "
276+ CLEAR_SCREEN=0
282277
283278 # Restore nonspecific default when no kernel specified
284279 if [ -z " $kernel " ]; then
@@ -296,9 +291,8 @@ set_default_env() {
296291
297292 pool=" ${selected%%/* } "
298293
299- if set_rw_pool " ${pool} " ; then
300- key_wrapper " ${pool} "
301- fi
294+ set_rw_pool " ${pool} " || return 1
295+ key_wrapper " ${pool} "
302296
303297 # shellcheck disable=SC2034
304298 if output=" $( zpool set bootfs=" ${selected} " " ${pool} " ) " ; then
@@ -502,6 +496,21 @@ export_pool() {
502496 return ${ret}
503497}
504498
499+ # prints: nothing
500+ # returns: 0 if suspend device found, 1 otherwise
501+
502+ has_resume_device () {
503+ # These partition types come from the dracut 95resume module
504+ for stype in suspend swsuspend swsupend; do
505+ if blkid -t TYPE=" ${stype} " > /dev/null 2>&1 ; then
506+ return 0
507+ fi
508+ done
509+
510+ return 1
511+ }
512+
513+
505514# arg1: pool name
506515# prints: nothing
507516# returns: 0 on success, 1 on failure
@@ -510,17 +519,50 @@ set_rw_pool() {
510519 local pool
511520 pool=" ${1} "
512521
513- if [ " $( zpool get -H -o value readonly " ${pool} " ) " = " on" ]; then
514- import_args=" ${import_args/ readonly=on/ readonly=off} "
515- if export_pool " ${pool} " ; then
516- import_pool " ${pool} "
517- return $?
518- else
522+ # Nothing to do if the pool is not read-only
523+ [ " x$( zpool get -H -o value readonly " ${pool} " ) " = " xon" ] || return 0
524+
525+ # Try to avoid importing writable when a resume device is found
526+ if has_resume_device; then
527+ # Make sure the warning is prominent
528+ tput clear
529+ tput cnorm
530+ tput cup 0 0
531+
532+ cat << -EOF
533+ WARNING!!!
534+
535+ This system appears to have an active suspend partition.
536+
537+ The action you are requesting requires the ZFS pool
538+
539+ ${pool}
540+
541+ be imported read-write. Importing read-write and then resuming
542+ from an active suspend partition may DESTROY YOUR POOL.
543+
544+ If you are certain you want to proceed, type NORESUME. You are
545+ also STRONGLY ADVISED to boot with the "noresume" option added to
546+ your kernel command-line to prevent your system from attempting
547+ to restore this image.
548+
549+ Proceed [No] ?
550+ EOF
551+
552+ read -r decision
553+
554+ if [ " x${decision} " != " xNORESUME" ]; then
519555 return 1
520556 fi
521- else
522- return 0
523557 fi
558+
559+ import_args=" ${import_args/ readonly=on/ readonly=off} "
560+ if export_pool " ${pool} " ; then
561+ import_pool " ${pool} "
562+ return $?
563+ fi
564+
565+ return 1
524566}
525567
526568# arg1: ZFS filesystem
0 commit comments