1#!/bin/bash 2 3KERNEL= 4RAMDISK= 5CMDLINE= 6GENEXT2FS= 7GRUBCONF= 8TMPDIR= 9OUTPUT= 10 11while [ $# -gt 0 ]; do 12 case $1 in 13 --kernel) 14 KERNEL=$2 15 shift 16 ;; 17 18 --ramdisk) 19 RAMDISK=$2 20 shift 21 ;; 22 23 --cmdline) 24 CMDLINE=$2 25 shift 26 ;; 27 28 --genext2fs) 29 GENEXT2FS=$2 30 shift 31 ;; 32 33 --tmpdir) 34 TMPDIR=$2 35 shift 36 ;; 37 --grubconf) 38 GRUBCONF=$2 39 shift 40 ;; 41 --output) 42 OUTPUT=$2 43 shift 44 ;; 45 46 --help) 47 echo "Usage: $0 OPTIONS" 48 echo "Create an ext2 image that contains everything necessary" 49 echo -e "to be the boot file system.\n" 50 echo "The following options exist:" 51 echo " --genext2fs <genext2fs> The location of genext2fs binary" 52 echo " --kernel <kernel> The kernel to boot" 53 echo " --ramdisk <ramdisk> The ramdisk to be used" 54 echo " --cmdline <cmdline> The command line to use" 55 echo " --grubconf <confile> The path to grub conf file" 56 echo " --tmpdir <tmpdir> The temporary dir where files"\ 57 "can be copied" 58 echo " --output <output> The filename of the output image" 59 echo 60 exit 0 61 ;; 62 63 *) 64 echo "Unknown option $1." 65 exit 1 66 ;; 67 esac 68 shift 69done 70 71if [ -z "$KERNEL" -o -z "$RAMDISK" -o -z "$GENEXT2FS" -o -z "$TMPDIR" -o \ 72 -z "$OUTPUT" ]; then 73 echo "Missing required arguments." 74 exit 1 75fi 76 77if ! [ -x "$GENEXT2FS" -a -f "$RAMDISK" -a -f "$KERNEL" ]; then 78 echo "Must provide path to a valid genext2fs binary." 79 exit 1 80fi 81 82rm -rf $TMPDIR 83mkdir -p $TMPDIR 84 85echo -n "$CMDLINE" > $TMPDIR/cmdline 86cp -f $KERNEL $TMPDIR/kernel 87cp -f $RAMDISK $TMPDIR/ramdisk 88 89if [ -f "$GRUBCONF" ]; then 90 mkdir -p $TMPDIR/boot/grub 91 cp -f $GRUBCONF $TMPDIR/boot/grub/menu.lst 92fi 93 94num_blocks=`du -sk $TMPDIR | tail -n1 | awk '{print $1;}'` 95 96# add 1% 97extra=`expr $num_blocks / 100` 98reserve=10 99[ $extra -lt $reserve ] && extra=$reserve 100 101num_blocks=`expr $num_blocks + $extra` 102num_inodes=`find $TMPDIR | wc -l` 103 104$GENEXT2FS -d $TMPDIR -b $num_blocks -N $num_inodes -m 0 $OUTPUT 105 106exit 0 107