@@ -1041,10 +1041,13 @@ find_be_kernels() {
1041
1041
done
1042
1042
done
1043
1043
done
1044
-
1045
1044
done
1046
1045
1046
+ # No further need for the mount
1047
+ umount " ${mnt} "
1048
+
1047
1049
defaults=" $( select_kernel " ${fs} " ) "
1050
+
1048
1051
# shellcheck disable=SC2034
1049
1052
IFS=' ' read -r def_fs def_kernel def_initramfs <<< " ${defaults}"
1050
1053
@@ -1053,19 +1056,16 @@ find_be_kernels() {
1053
1056
# If no default kernel is found, there are no kernels; leave the BE
1054
1057
# directory in the same state it would be in had no /boot existed
1055
1058
if [ -z " ${def_kernel} " ]; then
1056
- umount " ${mnt} "
1057
1059
zdebug " no default kernel found for ${fs} "
1058
1060
rm -f " ${kernel_records} " " ${def_kernel_file} "
1059
1061
return 1
1060
1062
fi
1061
- zdebug " default kernel set to ${def_kernel} "
1062
1063
1064
+ zdebug " default kernel set to ${def_kernel} "
1063
1065
echo " ${def_kernel##*/ } " > " ${def_kernel_file} "
1064
1066
1065
- # Pre-load cmdline arguments, possibly from files on the mount
1066
- preload_be_cmdline " ${fs} " " ${mnt} "
1067
-
1068
- umount " ${mnt} "
1067
+ # Pre-load cmdline arguments, possibly from files in the environment
1068
+ preload_be_cmdline " ${fs} "
1069
1069
return 0
1070
1070
}
1071
1071
@@ -1242,50 +1242,93 @@ read_kcl_prop() {
1242
1242
}
1243
1243
1244
1244
# arg1: ZFS filesystem
1245
- # arg2: path for a mounted filesystem
1246
1245
# prints: nothing
1247
1246
# returns: 0 on success
1248
1247
1249
1248
preload_be_cmdline () {
1250
- local zfsbe_mnt zfsbe_fs zfsbe_args args_file
1251
-
1252
- zfsbe_fs=" ${1} "
1253
- if [ -z " ${zfsbe_fs} " ]; then
1254
- zerror " zfsbe_fs is undefined"
1255
- return 1
1256
- fi
1257
- zdebug " zfsbe_fs set to ${zfsbe_fs} "
1249
+ local fs mnt args args_file deprecated need_rw zsout
1258
1250
1259
- zfsbe_mnt =" ${2 } "
1260
- if [ -z " ${zfsbe_mnt } " ]; then
1261
- zerror " zfsbe_mnt is undefined"
1251
+ fs =" ${1 } "
1252
+ if [ -z " ${fs } " ]; then
1253
+ zerror " fs is undefined"
1262
1254
return 1
1263
1255
fi
1264
- zdebug " zfsbe_mnt set to ${zfsbe_mnt } "
1256
+ zdebug " fs set to ${fs } "
1265
1257
1266
- args_file=" ${BASE} /${zfsbe_fs } /cmdline"
1258
+ args_file=" ${BASE} /${fs } /cmdline"
1267
1259
1268
- if zfsbe_args =" $( read_kcl_prop " ${zfsbe_fs } " ) " && [ -n " ${zfsbe_args } " ]; then
1260
+ if args =" $( read_kcl_prop " ${fs } " ) " && [ -n " ${args } " ]; then
1269
1261
zdebug " using org.zfsbootmenu:commandline"
1270
- echo " ${zfsbe_args } " > " ${args_file} "
1271
- return
1262
+ echo " ${args } " > " ${args_file} "
1263
+ return 0
1272
1264
fi
1273
1265
1274
- if [ -n " ${zfsbe_mnt} " ] && [ -r " ${zfsbe_mnt} /etc/default/zfsbootmenu " ] ; then
1275
- zdebug " using ${zfsbe_mnt} /etc/default/zfsbootmenu "
1276
- head -1 " ${zfsbe_mnt} /etc/default/zfsbootmenu " | tr -d ' \n ' > " ${args_file }"
1277
- return
1266
+ # Mount R/O to check for config files
1267
+ if ! mnt= " $( mount_zfs " ${fs} " ) " ; then
1268
+ zerror " unable to mount ${fs }"
1269
+ return 1
1278
1270
fi
1279
1271
1280
- if [ -n " ${zfsbe_mnt} " ] && [ -r " ${zfsbe_mnt} /etc/default/grub" ]; then
1281
- zdebug " using ${zfsbe_mnt} /etc/default/grub"
1272
+ if [ -r " ${mnt} /etc/default/zfsbootmenu" ]; then
1273
+ zdebug " using ${mnt} /etc/default/zfsbootmenu"
1274
+ head -1 " ${mnt} /etc/default/zfsbootmenu" | tr -d ' \n' > " ${args_file} "
1275
+ deprecated=" /etc/default/zfsbootmenu"
1276
+ elif [ -r " ${mnt} /etc/default/grub" ]; then
1277
+ zdebug " using ${mnt} /etc/default/grub"
1282
1278
echo " $(
1283
1279
# shellcheck disable=SC1090,SC1091
1284
- . " ${zfsbe_mnt } /etc/default/grub" ;
1280
+ . " ${mnt } /etc/default/grub" ;
1285
1281
echo " ${GRUB_CMDLINE_LINUX_DEFAULT} "
1286
1282
) " > " ${args_file} "
1287
- return
1283
+ deprecated= " /etc/default/grub "
1288
1284
fi
1285
+
1286
+ # Always unmount, pool must be writable to perform migration
1287
+ umount " ${mnt} " || return 1
1288
+
1289
+ if [ " ${deprecated} " = " /etc/default/zfsbootmenu" ]; then
1290
+ # Need an R/W mount to remove deprecated config
1291
+ need_rw=" yes"
1292
+ elif [ -z " ${deprecated} " ] || [ -n " ${zbm_ignore_kcl_deprecation} " ]; then
1293
+ # Nothing is deprecated, so there is nothing to do
1294
+ return 0
1295
+ fi
1296
+
1297
+ # It is not an error if user declines automatic migration
1298
+ if ! color=green delay=60 prompt=" Will attempt migration in %0.2d seconds" \
1299
+ timed_prompt " Using KCL from ${deprecated} on ${fs} " \
1300
+ " This behavior is DEPRECATED and will be removed soon" " " \
1301
+ " KCL should be migrated to an org.zfsbootmenu:commandline property" " " \
1302
+ " [RETURN] to migrate" " [ESCAPE] to ignore " ; then
1303
+ # Suppress repeated messages
1304
+ export zbm_ignore_kcl_deprecation=1
1305
+ echo ' export zbm_ignore_kcl_deprecation="1"' >> /etc/zfsbootmenu.conf
1306
+ return 0
1307
+ fi
1308
+
1309
+ zdebug " migrating ${deprecated} to org.zfsbootmenu:commandline"
1310
+
1311
+ # Pool must be writable to set property and remove config
1312
+ set_rw_pool " ${fs%%/* } " || return 1
1313
+ CLEAR_SCREEN=1 load_key " ${fs} "
1314
+
1315
+ if ! mnt=" $( allow_rw=" ${need_rw} " mount_zfs " ${fs} " ) " ; then
1316
+ zerror " unable to mount ${fs} "
1317
+ return 1
1318
+ fi
1319
+
1320
+ read -r args < " ${args_file} "
1321
+
1322
+ if ! zsout=" $( zfs set org.zfsbootmenu:commandline=" ${args} " " ${fs} " 2>&1 ) " ; then
1323
+ zerror " Unable to migrate ${deprecated} to org.zfsbootmenu:commandline: ${zsout} "
1324
+ elif [ " ${deprecated} " = " /etc/default/zfsbootmenu" ] ; then
1325
+ zdebug " removing ${deprecated} from ${fs} "
1326
+ rm " ${mnt}${deprecated} " > /dev/null 2>&1
1327
+ else
1328
+ zdebug " not removing ${deprecated} from ${fs} "
1329
+ fi
1330
+
1331
+ umount " ${mnt} "
1289
1332
}
1290
1333
1291
1334
# arg1: key(and associated value) to suppress from KCL
@@ -1560,7 +1603,7 @@ timed_prompt() {
1560
1603
1561
1604
[ $# -gt 0 ] || return
1562
1605
[ -n " ${delay} " ] || delay=" 30"
1563
- [ -n " ${prompt} " ] || prompt=" Press [RETURN] or wait %0.2d seconds to continue"
1606
+ [ -n " ${prompt} " ] || prompt=" Press [RETURN] or wait %0.${ # delay} d seconds to continue"
1564
1607
1565
1608
[ " ${delay} " -eq 0 ] && return
1566
1609
0 commit comments