summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWaldemar Brodkorb <wbx@openadk.org>2010-06-28 13:23:59 +0200
committerWaldemar Brodkorb <wbx@openadk.org>2010-06-28 13:23:59 +0200
commit35c8150f713288319398ef855bbee58a49c855dd (patch)
tree2f21ecef9a9ab2efe0f56c56875c202e91860343
parent6274e55f29fa492a2a34c437354c8fcc22e8a3d4 (diff)
boot into rescue mode, when button is pressed once
-rw-r--r--package/adkinstall/src/adkinstall50
-rw-r--r--package/alix-switch/files/alix-switch8
-rw-r--r--package/alix-switch/files/alix-switch.postinst2
-rw-r--r--package/alix-switch/src/alix-switchd.c11
4 files changed, 54 insertions, 17 deletions
diff --git a/package/adkinstall/src/adkinstall b/package/adkinstall/src/adkinstall
index 9faab9391..62ab3225a 100644
--- a/package/adkinstall/src/adkinstall
+++ b/package/adkinstall/src/adkinstall
@@ -49,10 +49,11 @@ start=0
rootp=1
cfgfsp=2
if [ $rescue -eq 1 ];then
- rootp=2
- cfgfsp=3
+ rootp=3
+ cfgfsp=4
start=2
- parted -s /dev/sda unit cyl mkpartfs primary ext2 0 $start
+ parted -s /dev/sda unit cyl mkpartfs primary ext2 0 1
+ parted -s /dev/sda unit cyl mkpartfs primary ext2 1 2
check_exit
fi
parted -s /dev/sda unit cyl mkpartfs primary ext2 $start $rootsize
@@ -72,33 +73,64 @@ tar -C /mnt -xzpf $1
check_exit
chmod 1777 /mnt/tmp
chmod 4755 /mnt/bin/busybox
+if [ $rescue -eq 1 ];then
+ mkdir /mnt/boot/grub
+fi
speed=$(awk -F \, '/console=ttyS0/ { print $2 }' /proc/cmdline|sed -e "s/ .*$//")
if [ $rescue -eq 1 ];then
umount /mnt
- mount /dev/sda1 /mnt
+ mount /dev/sda2 /mnt
cp $2 /mnt/rescue
fi
printf "Installing bootloader ...\n"
mkdir -p /mnt/boot/grub
if [ $rescue -eq 1 ];then
+mount /dev/sda1 /mnt/boot/grub
cat << EOF > /mnt/boot/grub/grub.cfg
-set default=0
set timeout=1
serial --unit=0 --speed=$speed
terminal_output serial
terminal_input serial
+if [ -s \$prefix/grubenv ]; then
+ load_env
+fi
+
+set default="\${saved_entry}"
+
+if [ \${prev_saved_entry} ]; then
+ set saved_entry=\${prev_saved_entry}
+ save_env saved_entry
+ set prev_saved_entry=
+ save_env prev_saved_entry
+ set boot_once=true
+fi
+
+function savedefault {
+ if [ -z \${boot_once} ]; then
+ saved_entry=\${chosen}
+ save_env saved_entry
+ fi
+}
+
+function recordfail {
+ set recordfail=1
+ if [ -n \${have_grubenv} ]; then if [ -z \${boot_once} ]; then save_env recordfail; fi; fi
+}
+
menuentry "GNU/Linux (OpenADK)" {
+ recordfail
insmod ext2
- set root=(hd0,2)
+ set root=(hd0,3)
linux /boot/vmlinuz-adk root=/dev/sda$rootp ro init=/init panic=10
}
menuentry "GNU/Linux (OpenADK) Rescue Mode" {
+ recordfail
insmod ext2
- set root=(hd0,1)
+ set root=(hd0,2)
linux /rescue ro init=/init panic=10
}
EOF
@@ -119,6 +151,10 @@ EOF
fi
grub-install --root-directory=/mnt /dev/sda
check_exit
+if [ $rescue -eq 1 ];then
+ grub-set-default --root-directory=/mnt 0
+ umount /mnt/boot/grub
+fi
umount /mnt
printf "Successfully installed. You can reboot now.\n"
exit 0
diff --git a/package/alix-switch/files/alix-switch b/package/alix-switch/files/alix-switch
index ad439a221..b61a6a48f 100644
--- a/package/alix-switch/files/alix-switch
+++ b/package/alix-switch/files/alix-switch
@@ -1,9 +1,13 @@
#!/bin/sh
# launched by alix-switchd in case of button event
-
+# f.e. boot rescue system once
case "$1" in
on)
echo "alix-switch: on"
+ mount /dev/sda1 /boot/grub
+ grub-reboot 1
+ umount /boot/grub
+ reboot
;;
off)
echo "alix-switch: off"
@@ -12,4 +16,4 @@ case "$1" in
echo "Usage: $0 {on|off}"
;;
esac
-exit 0
+exit $?
diff --git a/package/alix-switch/files/alix-switch.postinst b/package/alix-switch/files/alix-switch.postinst
index 6e0e60f12..28146bf44 100644
--- a/package/alix-switch/files/alix-switch.postinst
+++ b/package/alix-switch/files/alix-switch.postinst
@@ -1,3 +1,3 @@
#!/bin/sh
. $IPKG_INSTROOT/etc/functions.sh
-add_rcconf alix_switchd alix_switchd NO
+add_rcconf alix_switch alix_switch YES
diff --git a/package/alix-switch/src/alix-switchd.c b/package/alix-switch/src/alix-switchd.c
index d98748fa1..78b52f19c 100644
--- a/package/alix-switch/src/alix-switchd.c
+++ b/package/alix-switch/src/alix-switchd.c
@@ -44,18 +44,15 @@ static sighandler_t handle_signal (int sig_nr, sighandler_t signalhandler) {
static void start_daemon (void) {
int i;
- pid_t pid;
-
- if (setsid() > 0)
- exit(EXIT_FAILURE);
+ pid_t pid, sid;
handle_signal(SIGHUP, SIG_IGN);
-
if ((pid = fork ()) != 0)
exit(EXIT_FAILURE);
-
- chdir("/");
umask(0);
+ if ((sid = setsid()) < 0)
+ exit(EXIT_FAILURE);
+ chdir("/");
for (i = sysconf(_SC_OPEN_MAX); i > 0; i--)
close(i);
}