|
@@ -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
|