squid: update to 6.13
[openadk.git] / package / kexec-tools / files / kreboot
blob1a32e18cf412ce84f27496cf55c021f109dbc797
1 #!/bin/sh
3 ARCH=$(uname -m)
4 KERNEL="/mnt/boot/kernel"
5 KEXEC_ARGS="-l"
6 if [ $ARCH = "arm" ]; then
7 KEXEC_ARGS="$KEXEC_ARGS --atags"
8 fi
9 PART_A=2
10 PART_B=3
11 me=$0
13 usage() {
14 cat >&2 <<EOF
15 Syntax: $me [-k kernel]
17 -k give the path to the kernel eg. /boot/vmlinuz-4.7.4
18 (default: $KERNEL)
19 EOF
20 exit $1
23 while getopts "k:" ch; do
24 case $ch {
25 (k)
26 # if default does not fit, give the actual keren via -k otion eg "-k /boot/vmlinuz-4.7.4
27 KERNEL="$OPTARG"
30 (*)
31 usage 1
34 done
35 shift $((OPTIND - 1))
38 load_kernel(){
39 # get the Bootargs and replace the current Partition with
40 # the one in $1 e.g. replace /dev/mmcblk0p2 with /dev/mmcblk0p3
41 BOOT_ARGS="$(cat /proc/cmdline | sed s#$CURRENT_PART#$1#g)"
42 # echo "kexec $KEXEC_ARG --append=\"$BOOT_ARGS\" $KERNEL"
43 # set -x
44 # Load the new kernel, unmount the partition and exec the new kernel
45 kexec $KEXEC_ARGS --append=\""$BOOT_ARGS"\" $KERNEL
46 umount /mnt
47 kexec -e
50 # just to be sure
51 umount /mnt 2> /dev/null
53 # get the partiton of the current kernel
54 PART="/dev/$(readlink /dev/root)"
55 # extract the partition number
56 C_M_PART_NUM=$(readlink /dev/root | grep -o -e '[[:digit:]]*$')
58 # cut off the Partition Number
59 C_M_PART=$(readlink /dev/root | sed "s/$C_M_PART_NUM\$//")
61 CURRENT_PART="/dev/${C_M_PART}${C_M_PART_NUM}"
63 case $C_M_PART_NUM in
64 "$PART_A")
65 DEVICE="/dev/${C_M_PART}${PART_B}"
66 mount -r $DEVICE /mnt
67 load_kernel $DEVICE
69 "$PART_B")
70 DEVICE="/dev/${C_M_PART}${PART_A}"
71 mount -r $DEVICE /mnt
72 load_kernel $DEVICE
75 echo "FAILURE"
77 esac