| 1 |
#!/bin/bash |
| 2 |
type lib_initialize >/dev/null 2>&1 || . /lib/kiwi-lib.sh |
| 3 |
type report_and_quit >/dev/null 2>&1 || . /lib/kiwi-dump-image.sh |
| 4 |
type get_selected_disk >/dev/null 2>&1 || . /lib/kiwi-dump-image.sh |
| 5 |
type run_dialog >/dev/null 2>&1 || . /lib/kiwi-dialog-lib.sh |
| 6 |
|
| 7 |
#====================================== |
| 8 |
# Functions |
| 9 |
#-------------------------------------- |
| 10 |
function boot_installed_system { |
| 11 |
declare kiwi_oemreboot=${kiwi_oemreboot} |
| 12 |
declare kiwi_oemrebootinteractive=${kiwi_oemrebootinteractive} |
| 13 |
declare kiwi_oemshutdown=${kiwi_oemshutdown} |
| 14 |
declare kiwi_oemshutdowninteractive=${kiwi_oemshutdowninteractive} |
| 15 |
local ask_reboot_text="Reboot System ?" |
| 16 |
local ask_shutdown_text="Shutdown System ?" |
| 17 |
local boot_options |
| 18 |
kiwi_oemreboot=$(bool "${kiwi_oemreboot}") |
| 19 |
kiwi_oemrebootinteractive=$(bool "${kiwi_oemrebootinteractive}") |
| 20 |
kiwi_oemshutdown=$(bool "${kiwi_oemshutdown}") |
| 21 |
kiwi_oemshutdowninteractive=$(bool "${kiwi_oemshutdowninteractive}") |
| 22 |
|
| 23 |
if [ "${kiwi_oemrebootinteractive}" = "true" ];then |
| 24 |
ask_and_reboot "${ask_reboot_text}" |
| 25 |
fi |
| 26 |
if [ "${kiwi_oemreboot}" = "true" ];then |
| 27 |
reboot -f |
| 28 |
fi |
| 29 |
if [ "${kiwi_oemshutdowninteractive}" = "true" ];then |
| 30 |
ask_and_shutdown "${ask_shutdown_text}" |
| 31 |
fi |
| 32 |
if [ "${kiwi_oemshutdown}" = "true" ];then |
| 33 |
systemctl poweroff |
| 34 |
fi |
| 35 |
|
| 36 |
# if rd.kiwi.install.pass.bootparam is given, pass on most |
| 37 |
# boot options to the kexec kernel |
| 38 |
if getargbool 0 rd.kiwi.install.pass.bootparam; then |
| 39 |
local cmdline |
| 40 |
local option |
| 41 |
read -r cmdline < /proc/cmdline |
| 42 |
for option in ${cmdline}; do |
| 43 |
case ${option} in |
| 44 |
rd.kiwi.*) ;; # skip all rd.kiwi options, they might do harm |
| 45 |
*) boot_options="${boot_options}${option} ";; |
| 46 |
esac |
| 47 |
done |
| 48 |
fi |
| 49 |
boot_options="${boot_options}$(cat /config.bootoptions)" |
| 50 |
if getargbool 0 rd.kiwi.debug; then |
| 51 |
boot_options="${boot_options} rd.kiwi.debug" |
| 52 |
fi |
| 53 |
kexec_options="" |
| 54 |
if kexec --help | grep -q kexec-syscall-auto;then |
| 55 |
# try file based syscall first and fall back to kexec_load |
| 56 |
# syscall if not present. On systems using kexec that does |
| 57 |
# provide --kexec-syscall-auto the assumption is made that |
| 58 |
# neither kexec nor the kernel supports file based syscall |
| 59 |
# and thus no syscall selection is made |
| 60 |
kexec_options="${kexec_options} --kexec-syscall-auto" |
| 61 |
fi |
| 62 |
# shellcheck disable=SC2116,SC2086 |
| 63 |
kexec_options=$(echo ${kexec_options}) # strip spaces |
| 64 |
kexec "${kexec_options}" \ |
| 65 |
--load /run/install/boot/*/loader/linux \ |
| 66 |
--initrd /run/install/initrd.system_image \ |
| 67 |
--command-line "${boot_options}" |
| 68 |
if ! kexec -e; then |
| 69 |
report_and_quit "Failed to kexec boot system" |
| 70 |
fi |
| 71 |
} |
| 72 |
|
| 73 |
#====================================== |
| 74 |
# Reboot into system |
| 75 |
#-------------------------------------- |
| 76 |
lib_initialize |
| 77 |
|
| 78 |
if getargbool 0 rd.kiwi.ramdisk; then |
| 79 |
# For ramdisk deployment a kexec boot is not possible as it |
| 80 |
# will wipe the contents of the ramdisk. Therefore we prepare |
| 81 |
# the switch_root from this deployment initrd. See |
| 82 |
# kiwi-mount-ramdisk.sh mount hook for further details. |
| 83 |
image_target=$(get_selected_disk) |
| 84 |
kpartx -s -a "${image_target}" |
| 85 |
else |
| 86 |
# Standard deployment will use kexec to activate and boot the |
| 87 |
# deployed system |
| 88 |
boot_installed_system |
| 89 |
fi |