#!/bin/bash # # Install the standalone boot files into the USB stick # ---------------------------------------------------- # # Usage # ---------- # Standalone.Install.2005.0912.sh # # -dev hda use CompactFlash on /dev/hda # -dev sda use USB-Stick on /dev/sda # # -syslinux use syslinux # -lilo use lilo # -grub use grub # # -vfat use vfat for /dev/sda1 ( aka /boot ) # # -X11 isntall x11 files # -KDE install kde files # # # --------------------------------------------------------------------- # CAUTION: When moving the usb-stick or CompactFlash between machines # --------------------------------------------------------------------- # - fix /boot/grub/devices.map for grub # - fix /boot/map for lilo # # # Original File # ------------- # http://Linux-Boot.net/Bootable.2005/Standalone.Install.sh.txt # # # BootLoader-Howto # ---------------- # http://linux-boot.net/Loaders # # # 30-Aug-05 amo Date-of-Birth # 06-Sep-05 amo Change to TGZ with datecode ( 0829 or 0831 ) # 11-Sep-05 amo Working kanji-KDE + fvwm menu # 11-Sep-05 amo Release 2005.0911 # 12-Sep-05 amo Use global VER variable, redefine usage of TGZ # 13-Sep-05 amo Option to install Lilo or Syslinux # 15-Sep-05 amo Allow Grub and usb-modules should be built into the kernel # 17-Sep-05 amo Test lilo vs grub # 18-Sep-05 amo Added argv command line parsing # 19-Sep-05 amo Fix file hierarchy for syslinux on usb-stick # 24-Sep-05 amo Removed LOADER check, sometimes we only update initrd and roots, not lilo/grub # 25-Sep-05 amo Added -vfat for /boot even for lilo # 28-Sep-05 amo Release 2005.0928, check for KDE-$VER and X11-$VER # # # fdisk -l /dev/sda # ------------------ # # # # note that different usb sticks will have different C/H/S info # # # # we want approximately the same sized block sizes per partition # # # # # Disk /dev/sda: 1048 MB, 1048576000 bytes # 255 heads, 63 sectors/track, 127 cylinders # Units = cylinders of 16065 * 512 = 8225280 bytes # # Device Boot Start End Blocks Id System # /dev/sda1 * 1 5 40131 83 Linux # /dev/sda2 6 13 64260 83 Linux # /dev/sda3 14 17 32130 83 Linux # /dev/sda4 18 127 883575 5 Extended # /dev/sda5 18 67 401593+ 83 Linux # /dev/sda6 68 71 32098+ 82 Linux swap # /dev/sda7 72 127 449788+ 83 Linux # # SRC="157.22.35.142" #RC="Linux-Boot.net" # # USB="/opt/Bootable.2005" # #GZ="2005.0829" #GZ="2005.0831" #GZ="2005.0911" #ER="2005.0912" VER="2005.0928" # ERR="" # # if [ ! -d "$USB/TGZ" ]; then echo "#" echo "# ERROR: Aborting: Missing $USB/TGZ" echo "#" # exit 1 # fi # TGZ="$USB/TGZ" # # X11="" KDE="" # # TAR="/bin/tar" # # USB-stick or CompactFlash # ------------------------- USBCF="" # # # Which BootLoader to use # ----------------------- # LOADER="" # # # Default to vfat to allow for "pull the power anytime" VFAT="" # # # # # --------------------------- # echo the command and run it, abort on errors # --------------------------- # function docmd() { cmd="$1" # echo "$cmd" eval "$cmd" stat=$? # if [ "$stat" != 0 ]; then echo "#" echo "# ERROR: Aborting.. " echo "#" # exit 1 # fi # } # docmd # # # See if the REQUIRED variable is defined # ---------------------------------------- # function CheckVar() { nam="$1" var="$2" # if [ -z "$var" ]; then echo "#" echo "# ABORTING: $nam NOT defined" echo "#" # exit 1 # fi # } # CheckVar # # # Abort if the file doesn't exist # ------------------------------- # function CheckFile() { # file="$1" # if [ ! -f "$file" ]; then # if [ -z "$ERR" ]; then echo "#" ; fi # echo "# ERROR: Could NOT find $file" echo "#" # ERR="$part" # exit 1 # fi # } # CheckFile # # # Format /boot # -------------- # - # - we want vfat --> more likely to be able to pull the power at anytime # - function Format_Boot() { # echo "LOADER=$LOADER..VFAT=$VFAT.." # if [ "$LOADER" = "SysLinux" ]; then # # clear the MBR dd if=/dev/zero of=/dev/sda bs=446 count=1 conv=sync # echo "#" echo "# Boot with SysLinux, Creating vfat-16 instead" echo "#" # # use -F 16 ( msdos ) for syslinux, but syslinux doesn't boot so use # syslinux does not like -F 32 ( vfat ) # docmd "mkfs.msdos -n USB-Stick -F 16 /dev/$part" docmd "" # # dd if=/dev/$part/dos.bss of=/boot/syslinux/dos.bss conv=sync # # use syslinux mbr # ---------------- # docmd "dd if=/boot/syslinux/mbr.bin of=/dev/sda bs=446 count=1 conv=sync " # # # docmd "syslinux -s /dev/$part" # docmd "#" # elif [ "$VFAT" = "vfat" ]; then # # use vfat for sda1 ( with long filenames ) # docmd "mkfs.msdos -n USB-Stick -F 32 /dev/$part" # # elif [ "$LOADER" = "Lilo" -o "$LOADER" = "Grub" ]; then # echo "#" echo "# You really should use be using -vfat " echo "#" # # use ext3 docmd "mke2fs -j -q -m 0 /dev/$part" # docmd "mke2fs -q -m 0 /dev/$part" # else # # probably just reinstalling initrd.gz and vmlinuz # echo "#" echo "# WARNING: Skipping reformatting /dev/$part.." echo "#" # fi # } # Format_Boot # # # Extract vmlinuz initrd.gz into /boot # ------------------------------------ # NOTE: vfat does NOT support symlinks # function Create_Boot() { # if [ "$LOADER" = "SysLinux" ]; then # # fat-16(msdos) and fat-32(vfat) does not like symlinks # docmd "cd /mnt/$part ; $TAR zxfp $TGZ/$tgz boot/vmlinuz-2.4.31ow.p4 boot/initrd-$VER.gz boot/message.* " # # # syslinux looks for linux # syslinux is fat-16 ( 8.3 filename format ) # # # seems to work at /vmlinuz but fails as /boot/vmlinuz # ------------------------- # cd /mnt/$part # mv boot/vmlinuz-2.4.31ow.p4 vmlinuz mv boot/initrd-$VER.gz initrd.gz mv boot/message.* . # rmdir boot # # works as /syslinux.cfg but fails as /syslinux/syslinux.cfg # ---------------------- docmd "cp -dr /boot/syslinux/* /mnt/$part " docmd "#" # docmd "dd if=/boot/syslinux/mbr.bin of=/dev/$USBCF bs=446 count=1 conv=sync " docmd "syslinux /dev/$part " docmd "#" # elif [ "$LOADER" = "Grub" ]; then # docmd "cd /mnt/$part ; $TAR zxfp $TGZ/$tgz boot/vmlinuz-2.4.31ow.p4 boot/initrd-$VER.gz boot/message.* " # if [ "$VFAT" = "vfat" ]; then # no symlinks mkdir /mnt/$part/boot/grub docmd "cp -dpar /boot/grub/* /mnt/$part/boot/grub" # # else # docmd "cp -dpar /boot/grub* /mnt/$part/boot " fi # # Install GRUB # ------------ docmd "grub-install /dev/sda" # elif [ "$LOADER" = "Lilo" ]; then # docmd "cd /mnt/$part ; $TAR zxfp $TGZ/$tgz boot/vmlinuz-2.4.31ow.p4 boot/initrd-$VER.gz boot/message.* " # rm /mnt/$part/boot/map* /boot/map.sda docmd "lilo -v -C /etc/lilo.sda.2.4.31.conf" cp /boot/map.sda /mnt/$part/boot # else # echo "#" # if [ ! -d "/mnt/$part/boot" ]; then echo "# ERROR: Fatal: Missing directory on BootMedia:/mnt/$part/boot" echo "# /boot/initrd.gz /boot/vmlinuz ... " echo "#" # exit 1 # else echo "# WARNING: Skipping updating MBR with lilo/grub/syslinux " echo "#" fi # fi # sync # } # Create_Boot # # # Install the *.tgz file into the partition # ------------------------------------------- # function install_tgz() { part="$1" # tgz="$2" # # # -------------------------------- # Download the tar files if needed # -------------------------------- # if [ ! -f "$TGZ/$tgz" ]; then # if [ "$SRC" = "157.22.35.142" ]; then # CheckFile $TGZ/$tgz # cp -dpar $TGZ/$tgz $USB # else xx wget http://157.22.35.142/Bootable.2005/$tgz . fi # fi # # Sanity Checking # --------------- CheckFile "$TGZ/$tgz" # umount /dev/$part # # # --------------------- # Format the partitions # --------------------- # if [ "$part" = "sda1" ]; then # # format for vfat or ext3 or ?? for /boot/vmlinuz /boot/initrd.gz # Format_Boot # elif [ "$part" = "sda6" ]; then # # user defined stuff docmd "echo 'y' | mkfs.jfs -q /dev/$part" # else # sda2, sda3, sda5 docmd "echo 'y' | mkfs.xfs -f -q /dev/$part" # # no xfs on rh, reiser needs too much space, use ext3 for now # docmd "mke2fs -j -q -m 0 /dev/$part" # fi # echo "" docmd " mount /dev/$part /mnt/$part " df | egrep "^Filesystem|/mnt ; mount |grep /mnt" # docmd "cd /mnt/$part " # # # -------------------------------- # Install data into the partitions # -------------------------------- # if [ "$part" = "sda1" ]; then # # install /boot/vmlinuz /boot/initrd.gz # Create_Boot # else # docmd "cd /mnt/$part ; $TAR zxfp $TGZ/$tgz " # fi echo "" # } # install_tgz # # # Command line options # ===================== # # for argv in $1 $2 $3 $4 $5 $6 $7 $8 $9 do case $argv in # -dev) # # Where are the devices # --------------------- # where is the CF ( /dev/hda or /dev/hdc or .. ) # where is the USB-stick ( /dev/sda or /dev/sdb or .. ) # shift USBCF=$1 # if [ "$USBCF" = "hda" ]; then USBMOUNTS=" mnt/hda1 mnt/hda2 mnt/hda3 mnt/hda5 mnt/hda6 mnt/hda7 " USBLinks=" cd mnt ; ln -s ./hda1 CF ; ln -s ./hda6 Customizations ; ln -s ./hda6 UserDefined " fi if [ "$USBCF" = "sda" ]; then USBMOUNTS=" mnt/sda1 mnt/sda2 mnt/sda3 mnt/sda5 mnt/sda6 mnt/sda7 " USBLinks=" cd mnt ; ln -s ./sda1 USB ; ln -s ./sda6 Customizations ; ln -s ./sda6 UserDefined " fi ;; # -vfat) VFAT="vfat" ;; # -Grub) LOADER="Grub" ;; # -Lilo) LOADER="Lilo" ;; # -SysLinux) LOADER="SysLinux" VFAT="vfat" ;; # -IsoLinux) LOADER="IsoLinux" ;; # -X11) X11="x11" ;; # -KDE) KDE="kde" ;; # esac # done # echo "" # # # Check that the variables are defined, abort otherwise # ------------------------------------ # - sometimes we update initrd/rootfs only # CheckVar LOADER "$LOADER" # CheckVar USBCF "$USBCF" # # # # See if we can see the USB-Stick, load the USB modules # ------------------------------- if [ "$USBCF" = "sda" ]; then # /etc/rc.d/rc.usb-stick start # fi # umount /dev/${USBCF}1 docmd " mount /dev/${USBCF}1 /mnt/USB" # docmd "cd $USB" # docmd "ls -la /mnt/${USBCF}1 /mnt/${USBCF}2 /mnt/${USBCF}3 /mnt/${USBCF}5 /mnt/${USBCF}6 > /dev/null " # # partition=`fdisk -l /dev/$USBCF | grep ${USBCF}1 ` FSType=`fdisk -l /dev/$USBCF | grep ${USBCF}1 | awk '{ print $6 }' ` # if [ "$FSType" = "Linux" -a "$VFAT" = "vfat" ]; then # echo "#" echo "# ABORTING: for vfat filesystem, /dev/${USBCF}1 partitionID should be vfat(c) , not be Linux(83) " echo "# $partition " echo "#" # exit 1 # fi # # # /dev/sda1 is formatted for /boot # ---------------------- install_tgz ${USBCF}1 boot-$VER.tgz # # # /dev/sda2 is formatted for initrd+rootfs # ---------------------- install_tgz ${USBCF}2 RootFS-$VER.tgz # # # /dev/sda3 is formatted for /dev/loop1 ( X11 ) # ---------------------- # loopfile created by InitRD-RootFS -X11 # if [ ! -z "$X11" ]; then # if [ -f "$TGZ/X11-$VER.tgz" -a ! -z "$X11" ]; then install_tgz ${USBCF}3 X11-$VER.tgz else echo "#" echo "# WARNING: Missing file=$TGZ/X11-$VER.tgz" echo "#" fi # fi # # # /dev/sda5 is formatted for /dev/loop2 ( KDE ) # ---------------------- # loopfile created by InitRD-RootFS -X11 # if [ ! -z "$KDE" ]; then # if [ -f "$TGZ/KDE-$VER.tgz" ]; then install_tgz ${USBCF}5 KDE-$VER.tgz else echo "#" echo "# WARNING: Missing file=$TGZ/KDE-$VER.tgz" echo "#" fi # fi # # # /dev/sda6 has User-Defined Changes # ---------------------------------- if [ -f "$TGZ/Customize.tgz" ]; then install_tgz ${USBCF}6 Customize.tgz fi # # # Apply Maxnet Customizations ( ip# and hostname ) # --------------------------- cd /mnt/${USBCF}6 # $TAR zxpvf $USB/TGZ/${USBCF}6.maxnet.tgz # sync df | egrep "^Filesystem|/mnt" # echo "#" docmd "# ls -laR /mnt/${USBCF}1 /mnt/${USBCF}2 /mnt/${USBCF}3 /mnt/${USBCF}5 /mnt/${USBCF}6" echo "#" # # if [ -z "$ERR" ]; then exit 0 else exit 1 fi # # # End of file