#!/bin/sh myname=`basename $0` cwd=`pwd` make_initrd_from_template() { uname_r=$1 target=$2 modules_dir=$3 template=$4 shift 4 mod_names="$*" # set up work space dir=`mktemp -d "/tmp/$myname""_XXXXXX"` mkdir $dir/source # unpack template and copy it cat $template | (cd $dir/source; gunzip | cpio -i) cp -rp $dir/source $dir/target rm -rf $dir/target/lib/modules/* # copy all modules both in template and kernel ( cd $dir/source find . -name '*.ko' ) | while read tmpl_relpath; do mod_name=`basename $tmpl_relpath` source_mod=`cd $modules_dir; find . -name $mod_name` if [ ! "$source_mod" ]; then echo "warning: module $mod_name not found in $modules_dir" >&2 # exit 1 else mod_relpath=`dirname $source_mod` target_path=$dir/target/lib/modules/$uname_r/$mod_relpath echo "copying $mod_name from $mod_relpath to $target_path" mkdir -p $target_path cp -p $modules_dir/$source_mod $target_path fi done # copy all explicitly specified modules for mod_name in $mod_names; do echo "processing explicitly requested module $mod_name" mod_source_path=`find $modules_dir -name $mod_name.ko` if [ -z "$mod_source_path" ]; then echo "warning: explicitly specified module $mod_name not found in $uname_r" >&2 continue fi mod_relpath=`echo $mod_source_path | sed "s%$modules_dir%%g; s/$mod_name.ko$//"` target_path=$dir/target/lib/modules/$uname_r/$mod_relpath echo "copying $mod_name from $mod_relpath to $target_path" mkdir -p $target_path cp -p $mod_source_path $target_path done # linuxrc if [ "$linux_rc" ]; then echo "copying $linux_rc to linuxrc" cp $linux_rc $dir/target/init fi # depmod /sbin/depmod -a -b $dir/target -v $uname_r > /dev/null # pack stuff up (cd $dir/target; find . | cpio -co) | gzip -9 > $target rm -rf $dir } unquote() { cat | sed 's/^[ ]*|//' } config_section() { output_file= add_boot_dir= add_modules_basedir= root_dev= initrd_template= sed -n "/\[$2\]/,/\[/ p" $1 | sed '/]/ d; s/#.*//; /./ !d; s/ *= */=/; s/=\(.*\)/="\1"/' } boot_sections() { sed '/\[boot\..*\]/ !d; s/\[boot\.//; s/\].*//' $1 } name_filter() { echo $1 | \ tr [A-Z] [a-z] | \ sed 's/\.tar\.gz/.tgz/; s/-/_/g; s/\([^.]*\)\.\([^.]*\)$$/\1@\2/; s/\./_/g; s/@/./' } #make_initrd $template $modules_dir set -- `getopt 'i:f:o:d:' $*` while [ "$1" != -- ]; do case $1 in -f) opt_config_file="$2" shift ;; -o) opt_output_file="$2" shift ;; -d) opt_build_dir="$2" boot_dir="$2" shift ;; -i) linux_rc="$2" shift ;; *) usage ;; esac shift done shift if [ ! "$opt_build_dir" ]; then boot_dir=`mktemp -d "/tmp/$myname""_XXXXXX"` fi eval `config_section $opt_config_file global` echo DEFAULT menu.c32 > $boot_dir/isolinux.cfg echo PROMPT 0 >> $boot_dir/isolinux.cfg for sec in `boot_sections $opt_config_file`; do echo "+ processing section boot.$sec" config_section $opt_config_file boot.$sec eval `config_section $opt_config_file boot.$sec` if [ "$add_boot_dir" ]; then echo "+ adding boot directory $add_boot_dir" for f in $add_boot_dir/*; do b=`basename $f` n=`name_filter $b` echo "+ copying $f -> $n" cp -p $f $boot_dir/$n done kernels=`file $add_boot_dir/* | grep -ie 'linux.*kernel' | sed 's/:.*//'` for kernel in $kernels; do kernel_version=`basename $kernel | sed 's/vmlinuz-//'` kernel_version_iso=`name_filter $kernel_version | cut -b1-21` echo "+ processing kernel $kernel (version $kernel_version)" # create initrd if [ "$initrd_template" ]; then echo "+ creating initial ram disk from template $initrd_template" make_initrd_from_template \ $kernel_version \ $boot_dir/initrd_$kernel_version_iso \ $add_modules_basedir/$kernel_version \ $initrd_template \ $included_modules fi # create isolinux.cfg cat << EOT | unquote >> $boot_dir/isolinux.cfg | |LABEL $kernel_version |KERNEL vmlinuz_$kernel_version_iso |APPEND initrd=initrd_$kernel_version_iso root=$root_dev EOT done fi done cp $* $boot_dir mkisofs -l --iso-level 2 -o $opt_output_file \ -b isolinux.bin -c boot.cat \ -no-emul-boot -boot-load-size 4 -boot-info-table \ $boot_dir if [ ! "$opt_build_dir" ]; then rm -rf $boot_dir fi