summaryrefslogtreecommitdiffstats
path: root/builder/modules.d/kexec-reboot/scripts/kexec-reboot.sh
blob: 68fa73b9e149dfe991d0b4ba813eb885ff0eb55d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash

kexec_load() {
	. /lib/dracut-lib.sh

	local SLXSRV="$(getarg slxsrv)"
	local SLXBASE="$(getarg slxbase)"
	local DIR="$(mktemp -d)"

	if [ -z "$SLXSRV" -o -z "$SLXBASE" -o -z "$DIR" ]; then
		echo "Failed to construct download URL..."
		return 1
	fi
	for FILE in kernel initramfs-stage31; do
		if ! slx-tools download_retry "http://${SLXSRV}/${SLXBASE}/${FILE}" > "${DIR}/${FILE}" ; then
			echo "Failed to download ${FILE}."
			return 1
		fi
	done

	if ! kexec --load "${DIR}/kernel" \
		--initrd "${DIR}/initramfs-stage31" \
		--reuse-cmdline "${1:+--append "$@"}"; then
		echo "Failed to load kernel/initrd from ${DIR}"
		return 1
	fi
	return 0
}

if ! hash kexec; then
	echo "kexec binary not found, aborting..."
	exit 1
fi
if kexec_load $@; then
	kexec -e
else
	echo "Failed to execute kexec --load"
	exit 1
fi