summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWaldemar Brodkorb <wbx@openadk.org>2010-06-28 11:44:49 +0200
committerWaldemar Brodkorb <wbx@openadk.org>2010-06-28 11:44:49 +0200
commit6274e55f29fa492a2a34c437354c8fcc22e8a3d4 (patch)
tree0da0ff39de84aab60cf050b19c8cab4561a09664
parenta3d8e37ab74b7ad1092d15e1a9225b1e18584e26 (diff)
implement rescue mode installation via -r
if you have an alix board and like to have a fallback safemode system, you can use adkinstall with -r and install a kernel with initramfs as a read-only never changing rescue image. Grub will then installed on the same rescue partition on the compact flash card, to avoid a broken system after grub upgrade. System should always come up with the rescue system without any dependency to the live system.
-rw-r--r--package/adkinstall/Makefile9
-rw-r--r--package/adkinstall/src/adkinstall112
2 files changed, 93 insertions, 28 deletions
diff --git a/package/adkinstall/Makefile b/package/adkinstall/Makefile
index e758b1f2f..5210e9d49 100644
--- a/package/adkinstall/Makefile
+++ b/package/adkinstall/Makefile
@@ -5,7 +5,7 @@ include ${TOPDIR}/rules.mk
PKG_NAME:= adkinstall
PKG_VERSION:= 1.0
-PKG_RELEASE:= 4
+PKG_RELEASE:= 5
PKG_DESCR:= installer for cf, mmc, sd or mtd devices
PKG_SECTION:= base
PKG_DEPENDS:= parted sfdisk e2fsprogs
@@ -31,13 +31,10 @@ do-install:
ifeq ($(ADK_LINUX_MIPS_RB532),y)
${INSTALL_BIN} ./src/adkinstall.rb532 \
$(IDIR_ADKINSTALL)/sbin/adkinstall
-else ifeq ($(ADK_LINUX_ARM_FOXBOARD),y)
+else ifeq ($(ADK_LINUX_ARM_FOXG20),y)
${INSTALL_BIN} ./src/adkinstall.foxg20 \
$(IDIR_ADKINSTALL)/sbin/adkinstall
-else ifeq ($(ADK_LINUX_MIPS_RB433),y)
- ${INSTALL_BIN} ./src/adkinstall.rb4xx \
- $(IDIR_ADKINSTALL)/sbin/adkinstall
-else ifeq ($(ADK_LINUX_MIPS_RB411),y)
+else ifeq ($(ADK_LINUX_MIPS_RB4XX),y)
${INSTALL_BIN} ./src/adkinstall.rb4xx \
$(IDIR_ADKINSTALL)/sbin/adkinstall
else
diff --git a/package/adkinstall/src/adkinstall b/package/adkinstall/src/adkinstall
index 2ea991928..9faab9391 100644
--- a/package/adkinstall/src/adkinstall
+++ b/package/adkinstall/src/adkinstall
@@ -1,38 +1,88 @@
#!/bin/sh
# installs a rootfs tar archive from OpenADK onto a Compact Flash disk
+check_exit() {
+ if [ $? -ne 0 ];then
+ echo "Installation failed."
+ exit 1
+ fi
+}
+
+rescue=0
+while getopts "r" option
+do
+ case $option in
+ r)
+ rescue=1
+ ;;
+ *)
+ printf "Option not recognized\n"
+ exit 1
+ ;;
+ esac
+done
+shift $(($OPTIND - 1))
+
if [ -z $1 ];then
printf "Please give your root tar archive as parameter\n"
exit 1
fi
-# create empty partition table
+
+if [ $rescue -eq 1 ];then
+ if [ -z $2 ];then
+ printf "Please give your rescue kernel image as second parameter\n"
+ exit 2
+ fi
+ if [ ! -f $2 ];then
+ printf "$2 is not a file, Exiting.\n"
+ exit 1
+ fi
+fi
+
+printf "Creating partitions ...\n"
parted -s /dev/sda mklabel msdos
+check_exit
sleep 2
maxsize=$(env LC_ALL=C parted /dev/sda -s unit cyl print |awk '/^Disk/ { print $3 }'|sed -e 's/cyl//')
rootsize=$(($maxsize-2))
-parted -s /dev/sda unit cyl mkpartfs primary ext2 0 $rootsize
-parted -s /dev/sda unit cyl mkpart primary fat32 $rootsize $maxsize
-parted -s /dev/sda set 1 boot on
-sfdisk --change-id /dev/sda 2 88 >/dev/null 2>&1
-if [ $? -eq 0 ];then
- printf "Successfully created partition ${rootpart}\n"
-else
- printf "Partition creation failed, Exiting.\n"
- exit 1
+start=0
+rootp=1
+cfgfsp=2
+if [ $rescue -eq 1 ];then
+ rootp=2
+ cfgfsp=3
+ start=2
+ parted -s /dev/sda unit cyl mkpartfs primary ext2 0 $start
+ check_exit
fi
-mount -t ext2 /dev/sda1 /mnt
-printf "Extracting install archive\n"
+parted -s /dev/sda unit cyl mkpartfs primary ext2 $start $rootsize
+check_exit
+parted -s /dev/sda unit cyl mkpart primary fat32 $rootsize $maxsize
+check_exit
+parted -s /dev/sda set $rootp boot on
+check_exit
+sfdisk --change-id /dev/sda $cfgfsp 88 >/dev/null 2>&1
+check_exit
+# settle down
+sleep 2
+mount -t ext2 /dev/sda$rootp /mnt
+check_exit
+printf "Extracting install archive ...\n"
tar -C /mnt -xzpf $1
+check_exit
chmod 1777 /mnt/tmp
chmod 4755 /mnt/bin/busybox
speed=$(awk -F \, '/console=ttyS0/ { print $2 }' /proc/cmdline|sed -e "s/ .*$//")
-printf "Install bootloader\n"
+if [ $rescue -eq 1 ];then
+ umount /mnt
+ mount /dev/sda1 /mnt
+ cp $2 /mnt/rescue
+fi
+printf "Installing bootloader ...\n"
mkdir -p /mnt/boot/grub
-mount -o bind /dev /mnt/dev
-chroot /mnt mount -t proc /proc /proc
-chroot /mnt mount -t sysfs /sys /sys
+if [ $rescue -eq 1 ];then
cat << EOF > /mnt/boot/grub/grub.cfg
set default=0
set timeout=1
@@ -42,15 +92,33 @@ terminal_input serial
menuentry "GNU/Linux (OpenADK)" {
insmod ext2
+ set root=(hd0,2)
+ linux /boot/vmlinuz-adk root=/dev/sda$rootp ro init=/init panic=10
+}
+
+menuentry "GNU/Linux (OpenADK) Rescue Mode" {
+ insmod ext2
set root=(hd0,1)
- linux /boot/vmlinuz-adk root=/dev/sda1 ro init=/init panic=10
+ linux /rescue ro init=/init panic=10
}
EOF
-chroot /mnt grub-install /dev/sda >/dev/null 2>&1
-umount /mnt/proc
-umount /mnt/sys
-umount /mnt/dev
+else
+cat << EOF > /mnt/boot/grub/grub.cfg
+set default=0
+set timeout=1
+serial --unit=0 --speed=$speed
+terminal_output serial
+terminal_input serial
+menuentry "GNU/Linux (OpenADK)" {
+ insmod ext2
+ set root=(hd0,1)
+ linux /boot/vmlinuz-adk root=/dev/sda$rootp ro init=/init panic=10
+}
+EOF
+fi
+grub-install --root-directory=/mnt /dev/sda
+check_exit
umount /mnt
-printf "Successfully installed.\n"
+printf "Successfully installed. You can reboot now.\n"
exit 0