#!/bin/sh # This file is run by calling /sbin/init.alboot via its /sbin/altboot symlink. # It is used to configure the boot-partition for the next reboot while the system # is running. # Try to determine the original root device file via /proc/cmdline for par in `cat /proc/cmdline` do if ( echo "$par" | grep -q "^root=" ) then ROOT_DEVICE="`echo "$par" | sed -n "s/.*\=\(.*\)/\1/p"`" #test -e "$ROOT_DEVICE" && ROOT_DEVICE="" fi if ( echo "$par" | grep -q "^rootfstype=" ) then ROOT_FSTYPE="`echo "$par" | sed -n "s/.*\=\(.*\)/\1/p"`" fi done #debug_echo "ROOT_DEVICE [$ROOT_DEVICE] FSTYPE [$ROOT_FSTYPE]" if test -n "$ROOT_DEVICE" -a -n "$ROOT_FSTYPE" then if test "`df | grep " /$" | awk '{print $1}'`" != "$ROOT_DEVICE" then # We are pivoted into a different rootfs # Now try to determine where the real rootfs is mounted (if it is mounted at all) # There might be more than one entry for ROOT_DEVICE (think udev and friends) root_mountpoint="`df | grep "$ROOT_DEVICE " | awk '{print $6}'`" if test -z "$root_mountpoint" then # debug_echo "altboot(): Trying to mount [$ROOT_DEVICE]..." mkdir -p /media/ROM mount -t $ROOT_FSTYPE $ROOT_DEVICE /media/ROM ALTBOOT_LAST_FILE="/media/ROM$ALTBOOT_LAST_FILE" else mount -o remount,rw "$root_mountpoint" ALTBOOT_LAST_FILE="$root_mountpoint$ALTBOOT_LAST_FILE" fi else x=y # debug_echo "altboot.sbin(): Running from the original rootfs!" fi else echo -e "\nWARNING: ROOT_DEVICE is not defined in /etc/altboot-2.*.conf\nand could not be determined by looking at your kernel CMDLINE." echo -e "If you are pivoted into a different rootfs than the original rootfs\nof your device, the \"altboot\" command will *not* work correctly." echo -en "\nPress [ENTER] to continue, or Ctrl-C to abort. " read junk fi # debug_echo "altboot(): ALTBOOT_LAST_FILE [$ALTBOOT_LAST_FILE]" ! test -e "$ALTBOOT_LAST_FILE" && mdie "Failed to determine rootfs mountpoint...." # last_selection is the previously selected menu item by the user last_selection_num="`cat "$ALTBOOT_LAST_FILE" | awk '{print $1}'`" >/dev/null 2>&1 last_selection_data="`cat "$ALTBOOT_LAST_FILE" | sed -n "s/[0-9]\{1,\}\ \(.*\)$/\1/p"`" test -z "$last_selection_num" && last_selection_num="1" show_menu /etc/altboot-menu wait_for_input >"$OUT_TTY" launch_selection /etc/altboot-menu >"$OUT_TTY" exit 0