فهرست منبع

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.
Waldemar Brodkorb 14 سال پیش
والد
کامیت
6274e55f29
2فایلهای تغییر یافته به همراه93 افزوده شده و 28 حذف شده
  1. 3 6
      package/adkinstall/Makefile
  2. 90 22
      package/adkinstall/src/adkinstall

+ 3 - 6
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

+ 90 - 22
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
@@ -41,16 +91,34 @@ terminal_output serial
 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