summaryrefslogtreecommitdiff
path: root/sys/src/9/boot
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2018-09-16 22:35:16 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2018-09-16 22:35:16 +0200
commit2985d53b7a06d8a1712493aa899d6ffcfacd9e3b (patch)
treebe0bd7c85483f49c2e1ca4d1a4761ebe42ef110f /sys/src/9/boot
parent9d60ece81651aedea9136615f40cbee27e1eda97 (diff)
bootrc: add experimental reboot method to load another kernel
syntax: reboot!bootfile[!method...] this echos bootfile to /dev/reboot, causing bootfile kernel to be started. when method is given, we first connect to the filesystem and set bootargs so that bootfile can be loaded from the target network or local fileserver. note, when no bootfile is given, this causes the kernel to reboot to bios.
Diffstat (limited to 'sys/src/9/boot')
-rw-r--r--sys/src/9/boot/bootfs.proto1
-rwxr-xr-xsys/src/9/boot/reboot.rc56
2 files changed, 57 insertions, 0 deletions
diff --git a/sys/src/9/boot/bootfs.proto b/sys/src/9/boot/bootfs.proto
index a59ad6db5..1bffa0c47 100644
--- a/sys/src/9/boot/bootfs.proto
+++ b/sys/src/9/boot/bootfs.proto
@@ -48,6 +48,7 @@ $objtype
rc
lib
rcmain
+ reboot.rc 555 sys sys ../boot/reboot.rc
local.rc 555 sys sys ../boot/local.rc
net.rc 555 sys sys ../boot/net.rc
bin
diff --git a/sys/src/9/boot/reboot.rc b/sys/src/9/boot/reboot.rc
new file mode 100755
index 000000000..536ac2009
--- /dev/null
+++ b/sys/src/9/boot/reboot.rc
@@ -0,0 +1,56 @@
+#!/bin/rc
+
+fn configreboot {
+ if(~ $"* *!*){
+ *=`{echo $* | sed 's,!, ,'}
+ shift
+ *=`{echo $* | sed 's,!, ,'}
+ x=m$1
+ x=$$x
+ shift
+
+ # config method
+ $x(1) $*
+ }
+}
+
+fn connectreboot {
+ if(~ $"* *!*){
+ *=`{echo $* | sed 's,!, ,'}
+ bootfile=$1
+ shift
+ bootargs=$*
+ *=`{echo $* | sed 's,!, ,'}
+ x=m$1
+ x=$$x
+ shift
+
+ # connect method
+ $x(2) $*
+
+ rfork ne
+
+ # set new kernel parameters
+ echo -n $bootargs > '#ec/bootargs'
+
+ # remove part of our temporary root
+ /mnt/broot/$cputype/bin/unmount /$cputype/bin /bin
+ /mnt/broot/$cputype/bin/unmount /rc/bin /bin
+ /mnt/broot/$cputype/bin/unmount /
+
+ # create the name space, mount the root fs
+ /mnt/broot/$cputype/bin/bind / /
+ /mnt/broot/$cputype/bin/mount -ac '#s/boot' /
+ }
+ if not {
+ bootfile=$1
+ }
+
+ # load the new kernel
+ /mnt/broot/$cputype/bin/echo reboot $bootfile > /dev/reboot
+ exit 'reboot failed'
+}
+
+mreboot=(configreboot connectreboot)
+
+mt=(mreboot $mt)