From: Heiko Z. <smi...@us...> - 2004-05-18 01:06:53
|
Update of /cvsroot/devil-linux/build/scripts/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18592/scripts/scripts Modified Files: install-on-usb Log Message: major feature enhancements and code cleanups for install-on-usb script increased version number Index: install-on-usb =================================================================== RCS file: /cvsroot/devil-linux/build/scripts/scripts/install-on-usb,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- install-on-usb 16 Nov 2003 16:29:38 -0000 1.12 +++ install-on-usb 18 May 2004 01:06:43 -0000 1.13 @@ -10,18 +10,41 @@ # # -BOOTLOADER="syslinux" -#BOOTLOADER="grub" -#BOOTLOADER="lilo" +TMPDIR="./tmp-install2usb" +#### Pick your favorite disk part tool: FDISK="fdisk" #FDISK="cfdisk" +copy_iso_file () +{ + # $1 = source device or file + # $2 = target file path + + isosize_bin="$TMPDIR/iso-mnt/usr/bin/isosize" + if [ -b "$1" ]; then + #which isosize || { echo "Utility isosize not found - can not copy from a CD."; return 1; } + echo "copying image of CD in $1 to device mounted on $2" + iso_info=`$isosize_bin -x $1` + nsectors=`echo $iso_info | cut -d' ' -f3 | cut -d',' -f1` + bs=`echo $iso_info | cut -d' ' -f6` + nice dd bs=$bs count=$nsectors if=$1 of=$2 || return 1 + return 0 + elif [ -f "$1" ]; then + echo "copying source file $1 to device mounted on $2" + nice cp -p $1 $2 || return 1 + return 0 + else + echo "$1 is not a valid source for the ISO" + return 1 + fi +} + ask_yes_no () { ANS="" - read -p " (y/n) " -t 60 -n 1 -rs ANS - echo + read -p " (y/n) " -n 1 -rs ANS + echo $ANS [ ${ANS:-n} = "y" -o ${ANS:-n} = "Y" ] && return 0 return 1 } @@ -41,7 +64,8 @@ install_lilo () { - cat > ./tmp/mnt2/boot/lilo.conf <<-EOF + echo "Configuring LILO boot sector and menu" + cat > $TMPDIR/disk-mnt/boot/lilo.conf <<-EOF read-only compact lba32 @@ -56,68 +80,77 @@ image = /boot/vmlinuz label = Devil-Linux - append = "init=/linuxrc ramdisk_blocksize=4096" + append = "init=/linuxrc $RAMDISK" root = /dev/ram0 initrd = /boot/initrd.gz EOF - cp /boot/boot.b tmp/mnt2/boot/ || return 1 - cp /boot/mbr.b tmp/mnt2/boot/ || return 1 - lilo -r ./tmp/mnt2 -C /boot/lilo.conf -M $1 || return 1 - lilo -r ./tmp/mnt2 -C /boot/lilo.conf -b $1 || return 1 + cp /boot/boot.b tmp/disk-mnt/boot/ || return 1 + cp /boot/mbr.b tmp/disk-mnt/boot/ || return 1 + lilo -r $TMPDIR/disk-mnt -C /boot/lilo.conf -M $1 || return 1 + lilo -r $TMPDIR/disk-mnt -C /boot/lilo.conf -b $1 || return 1 } install_grub () { - grub_shell=./tmp/mnt2/sbin/grub + echo "Configuring Grub boot sector and menu..." + grub_shell=$TMPDIR/iso-mnt/sbin/grub device_map=grub-tmp-map force_lba="" + + if [ ! -f "$grub_shell" ]; then + echo "Grub not found in ISO image - was it included in the DL build?" + umount $TMPDIR/iso-mnt #|| exit 1 + umount $TMPDIR/disk-mnt #|| exit 1 + exit 1 + fi + rm -f $device_map - cat > ./tmp/mnt2/boot/grub/grub.conf <<-EOF + cat > $TMPDIR/disk-mnt/boot/grub/grub.conf <<-EOF timeout=10 splashimage=(hd0,$2)/boot/grub/devil-linux.xpm.gz title Devil-Linux - Standard VGA root (hd0,$2) - kernel /boot/vmlinuz ro root=/dev/ram0 init=/linuxrc ramdisk_blocksize=4096 + kernel /boot/vmlinuz ro root=/dev/ram0 init=/linuxrc $RAMDISK initrd /boot/initrd.gz title Devil-Linux - VESA Frame Buffer 640x480 root (hd0,$2) - kernel /boot/vmlinuz ro root=/dev/ram0 init=/linuxrc ramdisk_blocksize=4096 vga=769 + kernel /boot/vmlinuz ro root=/dev/ram0 init=/linuxrc $RAMDISK vga=769 initrd /boot/initrd.gz title Devil-Linux - VESA Frame Buffer 800x600 root (hd0,$2) - kernel /boot/vmlinuz ro root=/dev/ram0 init=/linuxrc ramdisk_blocksize=4096 vga=771 + kernel /boot/vmlinuz ro root=/dev/ram0 init=/linuxrc $RAMDISK vga=771 initrd /boot/initrd.gz title Devil-Linux - VESA Frame Buffer 1024x768 root (hd0,$2) - kernel /boot/vmlinuz ro root=/dev/ram0 init=/linuxrc ramdisk_blocksize=4096 vga=773 + kernel /boot/vmlinuz ro root=/dev/ram0 init=/linuxrc $RAMDISK vga=773 initrd /boot/initrd.gz title Devil-Linux - Other root (hd0,$2) - kernel /boot/vmlinuz ro root=/dev/ram0 init=/linuxrc ramdisk_blocksize=4096 vga=ask + kernel /boot/vmlinuz ro root=/dev/ram0 init=/linuxrc $RAMDISK vga=ask initrd /boot/initrd.gz EOF - if [ -f ./tmp/mnt2/boot/memtest ]; then - cat >> ./tmp/mnt2/boot/grub/grub.conf <<-EOF + if [ -f "$TMPDIR/disk-mnt/boot/memtest" ]; then + cat >> $TMPDIR/disk-mnt/boot/grub/grub.conf <<-EOF title Memtest86 root (hd0,$2) kernel /boot/memtest EOF fi - pushd ./tmp/mnt2/boot/grub > /dev/null + pushd $TMPDIR/disk-mnt/boot/grub > /dev/null rm -f menu.lst ln -s grub.conf menu.lst popd > /dev/null - $grub_shell --batch --device-map=$device_map <<-EOF + $grub_shell --batch --device-map=$device_map <<-EOF > /dev/null quit EOF install_drive=$(grep "$1\$" $device_map|cut -f1) root_drive="${install_drive%%)},0)" - $grub_shell --batch --device-map=$device_map <<-EOF + $grub_shell --batch --device-map=$device_map <<-EOF > /dev/null root $root_drive setup $force_lba $install_drive quit @@ -125,97 +158,235 @@ rm -f $device_map } -function install +install_dl () { - test -d ./tmp && rm -rf ./tmp - mkdir -p ./tmp/mnt{1,2} || return 1 + if [ -d "$TMPDIR" ]; then + # unclean exit before + umount $TMPDIR/iso-mnt &> /dev/null + umount $TMPDIR/disk-mnt &> /dev/null + rm -rf $TMPDIR &> /dev/null + fi + + mkdir -p $TMPDIR/iso-mnt || return 1 + mkdir -p $TMPDIR/disk-mnt || return 1 # echo "Available USB storage devices: " # for device in $(allAttachedScsiUsb) # do # echo -n "$(scsiDevFromScsiUsb $device) " # done + echo - read -p "Enter PARTITION name on USB device (i.e. /dev/sda1) -> " PARTITION - read -p "Enter DEVICE name of USB device (i.e. /dev/sda) -> " DEVICE + read -p "Enter DL ISO source (disk file (default: bootcd.iso) or CD device) -> " DLISO + if [ -z "$DLISO" ]; then + DLISO="bootcd.iso" + fi - for device in "$PARTITION" "$DEVICE" - do - if [ -L $device ]; then - echo "If you are using devfs, you must supply the full device, not the link." - exit - fi - if [ ! -b $device ]; then - echo "Cannot find: $device" - exit - fi - done + if [ -L "$DLISO" ]; then + DLISO=$(readlink -fns $DLISO) + echo " Expanding link to: $DLISO" + fi + if [ ! -e "$DLISO" ]; then + echo " Cannot find file or device: $DLISO" + return 1 + fi - GRUBPART=$(expr $(basename ${PARTITION} | sed -e 's/^part//' -e 's/^[hs]d[a-z]//') - 1) + if [ -b "$DLISO" ]; then + mount -t iso9660 -o ro $DLISO $TMPDIR/iso-mnt || return 1 + else + mount -o loop,ro -t iso9660 $DLISO $TMPDIR/iso-mnt || return 1 + fi + if [ -f "$TMPDIR/iso-mnt/DEVIL-LINUX" ]; then + dl_version=`cat $TMPDIR/iso-mnt/DEVIL-LINUX` + echo " Devil Linux $dl_version found in ISO" + else + echo + echo "$DLISO does not seem to contain Devil-Linux!" + return 1 + fi echo - #echo "Please make sure the partition type is 'Linux' (83) " - echo "Please make sure the partition type is 'FAT16' (06) " - echo + read -p "Enter DEVICE name of disk device (i.e. /dev/sda) -> " DEVICE $FDISK -l $DEVICE - echo;echo -n "Do you want to partition the media ? " + echo + echo "If you wish to store the ISO and configuration on the same media, two partitions are recommended." + echo -n "Do you want to partition the media first? " ask_yes_no && $FDISK $DEVICE + + echo + read -p "Enter PARTITION name of disk device to put ISO file (i.e. /dev/sda1) -> " PARTITION - echo;echo " Partition: $PARTITION" - echo " Device: $DEVICE" + if [ -L "$PARTITION" ]; then + PARTITION=$(readlink -fns $PARTITION) + echo " Expanding link to full partition name for devfs : $PARTITION" + fi + if [ ! -b "$PARTITION" ]; then + echo " Cannot find device: $PARTITION" + return 1 + fi - echo;echo -n "All data on device will be lost, continue ? " - ask_yes_no || return 0 + if [ -L "$DEVICE" ]; then + DEVICE=$(readlink -fns $DEVICE) + echo " Expanding link to full device name for devfs : $DEVICE" + fi + if [ ! -b "$DEVICE" ]; then + echo " Cannot find device: $DEVICE" + return 1 + fi + + echo + ETC_FILE="" + read -p "Enter configuration file to preload to disk (if any) -> " ETC_FILE + if [ -n "$ETC_FILE" ]; then + if [ ! -f "$ETC_FILE" ]; then + echo " No such file: \"$ETC_FILE\"" + return 1 + else + read -p "Enter seperate partition for configuration (recommended) or enter if same -> " ETC_PART + if [ -z "$ETC_PART" ]; then + ETC_PART=$PARTITION + elif [ ! -b "$ETC_PART" ]; then + echo " Can not find partition \"$ETC_PART\"" + return 1 + else + echo;echo -n "All data on device $ETC_PART will be lost, continue ? " + ask_yes_no || return 1 + + echo;echo -n "Last chance, do you really want to continue ? " + ask_yes_no || return 1 + + mkfs.ext2 $ETC_PART > /dev/null || return 1 + fi + fi + fi + + echo + echo "This will install DL on \"$DEVICE\" using the \"$BOOTLOADER\" bootloader. " + + if [ "$BOOTLOADER" = "syslinux" ]; then + echo "Please make sure the partition type is 'FAT16' (06) " + echo + else + echo "Please make sure the partition type is 'Linux' (83) " + echo + fi + + echo;echo -n "All data on device $PARTITION will be lost, continue ? " + ask_yes_no || return 1 echo;echo -n "Last chance, do you really want to continue ? " - ask_yes_no || return 0 + ask_yes_no || return 1 if [ "$BOOTLOADER" = "syslinux" ]; then - mkfs.msdos $PARTITION || return 1 - mount -o loop -t iso9660 bootcd.iso ./tmp/mnt1 || return 1 + mkfs.msdos $PARTITION > /dev/null || return 1 - echo installing MBR - SIZE=$(du -b ./tmp/mnt1/boot/syslinux/mbr.bin | cut -f 1 ) - dd if=./tmp/mnt1/boot/syslinux/mbr.bin of=$DEVICE count=$SIZE || return 1 + echo "Installing syslinux MBR" + SIZE=$(du -b $TMPDIR/iso-mnt/boot/syslinux/mbr.bin | cut -f 1 ) + dd if=$TMPDIR/iso-mnt/boot/syslinux/mbr.bin of=$DEVICE count=$SIZE || return 1 echo installing SysLinux boot sector - ./tmp/mnt1/boot/syslinux/syslinux-nomtools $PARTITION || return 1 + $TMPDIR/iso-mnt/boot/syslinux/syslinux-nomtools $PARTITION || return 1 - mount -t vfat $PARTITION ./tmp/mnt2 || return 1 + mount -t vfat $PARTITION $TMPDIR/disk-mnt || return 1 - echo copying files - cp ./tmp/mnt1/boot/* ./tmp/mnt2/ &> /dev/null - cp ./tmp/mnt1/{DEVIL-LINUX,LICENSE} ./tmp/mnt2/ &> /dev/null - cat ./tmp/mnt1/isolinux.cfg | sed -e s%"/boot/"%""% > ./tmp/mnt2/syslinux.cfg || return 1 - cat ./tmp/mnt1/boot/message | sed -e s%"/boot/"%""% > ./tmp/mnt2/message || return 1 - cp bootcd.iso ./tmp/mnt2/ || return 1 - fi + echo "copying files" + cp -p $TMPDIR/iso-mnt/boot/* $TMPDIR/disk-mnt/ > /dev/null + cp -p $TMPDIR/iso-mnt/{DEVIL-LINUX,LICENSE} $TMPDIR/disk-mnt/ > /dev/null + cat $TMPDIR/iso-mnt/isolinux.cfg | sed -e s%"/boot/"%""% > $TMPDIR/disk-mnt/syslinux.cfg || return 1 + cat $TMPDIR/iso-mnt/boot/message | sed -e s%"/boot/"%""% > $TMPDIR/disk-mnt/message || return 1 + copy_iso_file $DLISO $TMPDIR/disk-mnt/bootcd.iso || return 1 - if [ "$BOOTLOADER" = "grub" ] || [ "$BOOTLOADER" = "lilo" ]; then - mkfs.ext2 $PARTITION || return 1 + elif [ "$BOOTLOADER" = "grub" ] || [ "$BOOTLOADER" = "lilo" ]; then + + mkfs.ext2 $PARTITION > /dev/null || return 1 tune2fs -c 0 $PARTITION - mount -o loop -t iso9660 bootcd.iso ./tmp/mnt1 || return 1 - mount -t auto $PARTITION ./tmp/mnt2 || return 1 + mount -t auto $PARTITION $TMPDIR/disk-mnt || return 1 - echo copying files... - nice -n19 cp -dpR ./tmp/mnt1/* ./tmp/mnt2/ || return 1 - nice -n19 cp -dpR etc.tar.bz2 ./tmp/mnt2/ || return 1 + echo "copying files" + cp -a $TMPDIR/iso-mnt/boot/ $TMPDIR/disk-mnt/ > /dev/null + cp -p $TMPDIR/iso-mnt/{DEVIL-LINUX,LICENSE} $TMPDIR/disk-mnt/ > /dev/null + copy_iso_file $DLISO $TMPDIR/disk-mnt/bootcd.iso || return 1 + GRUBPART=$(expr $(basename ${PARTITION} | sed -e 's/^part//' -e 's/^[hs]d[a-z]//') - 1) [ "$BOOTLOADER" = "grub" ] && install_grub $DEVICE $GRUBPART - [ "$BOOTLOADER" = "lilo" ] && install_lilo $DEVICE + [ "$BOOTLOADER" = "lilo" ] && install_lilo $DEVICE + + else + echo "Unknown Bootloader: $BOOTLOADER" + return 1 + fi + + if [ -n "$ETC_FILE" ]; then + mkdir -p $TMPDIR/etc-mnt + mount -t auto $ETC_PART $TMPDIR/etc-mnt + echo + echo "Copying $ETC_FILE to $TMPDIR/etc-mnt/etc.tar.bz2" + cp -p $ETC_FILE $TMPDIR/etc-mnt/etc.tar.bz2 > /dev/null || return 1 + sync + umount $TMPDIR/etc-mnt > /dev/null fi + + return 0; } -install +########################################################################## + +echo +echo "This will install the Devil Linux ISO image to a disk device (USB/SCSI/IDE)" +echo "and make it bootable, assuming that your PC can boot this device." + +### Get some user info for the install +echo +echo "Select which bootloader you want to use:" +echo " 1) SysLinux (default)" +echo " 2) Grub" +echo " 3) Lilo" +ANS="" +read -p "Choice: " -n 1 -rs ANS +ANS=${ANS:-1} +echo $ANS + +### set the default +BOOTLOADER="syslinux" +#BOOTLOADER="grub" +#BOOTLOADER="lilo" + +[ ${ANS:-n} = "1" ] && BOOTLOADER="syslinux" +[ ${ANS:-n} = "2" ] && BOOTLOADER="grub" +[ ${ANS:-n} = "3" ] && BOOTLOADER="lilo" + +#### Choose the format used during build for initrd.gz: +echo +echo "Select correct initrd.gz format used (DL default is CramFS):" +echo " 1) CramFS (default)" +echo " 2) Ext2" +ANS="" +read -p "Choice: " -n 1 -rs ANS +ANS=${ANS:-1} +echo $ANS + +# For initrd.gz as CRAMFS +RAMDISK="ramdisk_blocksize=4096" +# For initrd.gz as EXT2 +#RAMDISK="ramdisk_blocksize=1024" + +[ ${ANS:-n} = "1" ] && RAMDISK="ramdisk_blocksize=4096"; +[ ${ANS:-n} = "2" ] && RAMDISK="ramdisk_blocksize=1024"; + +# Do install +install_dl || echo "Install failed!" echo "syncing and unmounting (this could take a while)" sync -umount ./tmp/mnt1 || exit 1 -umount ./tmp/mnt2 || exit 1 +umount $TMPDIR/iso-mnt &> /dev/null +umount $TMPDIR/disk-mnt &> /dev/null +umount $TMPDIR/etc-mnt &> /dev/null -rm -rf ./tmp || exit 1 +rm -rf $TMPDIR &> /dev/null + +exit |