#!/bin/sh # /usr/bin/dphys3kernel - # - build dphys3 replacement floppy image s w kernel for Debian 3.1 (sarge) # author Neil Franklin, last modification 2005.11.10 # copyright ETH Zuerich Physics Departement, # use under either BSD or GPL license ### ------ configuration for this site # first CONF_* various site or subnet dependant user config variables # then DEBUG_* various debugging settings # last SYS_* various system internal values # some of these are overridable by command line options # --- CONF_* various site or subnet dependant user config variables # base URL from which all Debian stuff can be downloaded CONF_DEBSERVER=http://ftp.debian.org/debian # where we put all the stuff needed for compiling CONF_SOURCEDIR=. # server where we upload our compiled floppy images and driver archives to CONF_INST_SERVER=not-configured-server # user as which we login to above server CONF_USER=not-configured-user # make sure multiple users (group of them) can install files on package server # if this is set, chgrp directories and files to this group and chmod g+w CONF_GROUP="" # base directory on server where we put our stuff for download # this is the base directory for adding dists/.../*.deb and pool/.../*.deb # paralleling Debians use [dist|spool]/.../*.deb on their servers # and so should appear in the http:// space of the server # the -u options upload everything relative to this CONF_INST_BASE=/not/configured/directory # this is the directory to use, within the dists/.../disks-i386 directory # vary this for multiple sets of files (say multiple kernels or configs) # naming schemes maybe by subnets, or by kernel options, or by compiling user CONF_DISKSVERSION=custom # --- DEBUG_*, various debugging settings # these can be set to "yes" by -D option, followed by name without DEBUG_ # such as like this: dphys3kernel -D PRINT_STEP -D LEAVE_TEMPFILES -g # set this to sleep after displaying each steps header, number is in seconds #DEBUG_SLEEP=2 # set this to output debug state info after each step #DEBUG_PRINT_STEP=yes # set this to wait after each debug state info #DEBUG_WAIT_STEP=yes # set this to have old initrd backupped #DEBUG_BACKUP_INITRD=yes # set this to have an copy of the generated config file in current directory #DEBUG_DUMP_CONFIG=yes # set this to prevent deleting modules for space, fails generating root image #DEBUG_LEAVE_ALL_MODULES=yes # set this to have an copy of the patched libdiscover file in current directory #DEBUG_DUMP_PCILIST=yes # set this to not delete temporary files (workdir) after -g #DEBUG_LEAVE_TEMPFILES=yes # set this to leave temporary directories undeleted after -u #DEBUG_LEAVE_TEMPDIRS=yes # --- SYS_*, various system internal values # where we want to do all the unpack/modify/pack stuff # this must be a directory that root can access (not a root-squash NFS mount) # and there should be about 70MByte free space in its filesystem SYS_WORKDIR=/var/tmp/dphys3kernel-$$-work # stuff we want to force in to the kernel # this list being added to our standard production kernel config # automagically modifying it to be usable for an install kernel # we need compiled in: # initial ram disk support is needed for booting # ram disk support is needed for initrd # floppy drive support is needed for reading from root floppy # vfat support is needed for extracting initrd from floppy # fat support is needed for vfat # loopback support is needed for mounting initrd # devfs support is needed for debian installer # we assume to already have compiled in: # whatever IDE or SCSI or USB, base and drivers, for our disks SYS_FORCE_CONFIGS="CONFIG_BLK_DEV_INITRD CONFIG_BLK_DEV_RAM CONFIG_BLK_DEV_FD \ CONFIG_VFAT_FS CONFIG_FAT_FS CONFIG_BLK_DEV_LOOP CONFIG_DEVFS_FS" # stuff we want to force in to the kernel # this list being subtracted from our standard production kernel config # automagically modifying it to be smaller for an install kernel # this is all stuff that is not used while installation # we assume to not need: # anything USB (input, keyboard or mouse) SYS_FORCE_UNCONFIGS="CONFIG_PCMCIA CONFIG_ACPI CONFIG_BLK_DEV_XD CONFIG_MD \ CONFIG_PHONE CONFIG_IEEE1394 CONFIG_I2O CONFIG_NET_RADIO CONFIG_IRDA \ CONFIG_ISDN CONFIG_INPUT CONFIG_SERIAL_EXTENDED CONFIG_SERIAL_MULTIPORT \ CONFIG_I2C CONFIG_DRM CONFIG_VIDEO_DEV CONFIG_QUOTA CONFIG_NLS CONFIG_FB \ CONFIG_SOUND CONFIG_USB CONFIG_BLUEZ" # stuff we want to remove from /lib/modules//* # this is all stuff that is not used while installation # we assume to not need: # basically all drives with exeption of network # this leaves only kernel/drivers/net (various Ethernet) and kernel/lib (crc32) SYS_RM_MODULES="build kernel/arch kernel/drivers/cdrom kernel/drivers/char \ kernel/drivers/ide kernel/drivers/scsi kernel/drivers/parport \ kernel/drivers/pnp kernel/fs kernel/net modules.*map pcmcia" # where we want to put together stuff for upload # not ./upload as this may collide with something user already has SYS_UPLOADDIR=/var/tmp/dphys3kernel-$$-upload # note: this program has only been designed for and tested with i386 # others at own risk, I expect them to fail badly SYS_ARCH=i386 ### ------ actual implementation from here on # no user settings any more below this point # --- tidy up some commands, make systematic # stuff that goes wrong, not expected by user, not in data output, use >&2 # so also with $0 in case this script was called by an other script # something within the system that user does not expect, give up CMD_FATAL="/bin/echo $0: FATAL:" # something from users input, user will correct this and continue CMD_ERROR="/bin/echo $0: ERROR:" # something we can continue with, but may be wrong, and user may not suspect it CMD_WARNING="/bin/echo $0: WARNING:" # something most likely not wrong, but tell user for the odd case it is wrong CMD_NOTE="/bin/echo $0: NOTE:" # normal stuff users expect, so to stdout as normal output, no $0, no marking CMD_INFO="/bin/echo" # stuff users asked for, so add to stdout as normal output, no $0, but mark it CMD_DEBUG="/bin/echo DEBUG:" # control output CMD_INFO_PRINT=${CMD_INFO} CMD_VERBOSE_PRINT=/bin/true # --- config file stuff # what we are, program and package name NAME=dphys3kernel PNAME=dphys3 # check user config file(s), let user override settings # same config files used in dphys3[kernel|preseed|boot|root|cd|pxe] if [ -f /etc/${PNAME} ] ; then . /etc/${PNAME} fi if [ -f ~/.${PNAME} ] ; then . ~/.${PNAME} fi if [ -f ./${PNAME} ] ; then . ./${PNAME} fi # --- parse command line # so long next parameter is a set of options (= begins with an - character) while [ x`/bin/echo $1 | /usr/bin/cut -c 1` = x- ] ; do # extract options from parameter (cut off the "-") OPTS=`/bin/echo $1 | /usr/bin/cut -c 2-` shift 1 # so long still unprocessed option characters while [ x${OPTS} != x ] ; do # first option to process OPT=`/bin/echo ${OPTS} | /usr/bin/cut -c 1` # and rest of options for later OPTS=`/bin/echo ${OPTS} | /usr/bin/cut -c 2-` case ${OPT} in d) # download: download orignal Debian files from server DO_DOWN=yes COMMAND_OPTION=yes ;; g) # generate: generate our own files DO_GEN=yes COMMAND_OPTION=yes ;; s) # sourcedir: find all files to use in this subdirectory CONF_SOURCEDIR=$1 shift 1 ;; k) # kernel: use this kernel archive KERNEL=$1 shift 1 ;; c) # config: use this config file CONFIG=$1 shift 1 ;; p) # patch: use this libdiscover patch file PATCH=$1 shift 1 ;; u) # upload: upload generated files to local install server DO_UPLOAD=yes COMMAND_OPTION=yes ;; b) # base: upload generated package files to base directory CONF_INST_BASE=$1 shift 1 ;; r) # remove: remove Debian and own files, after installing DO_REMOVE=yes COMMAND_OPTION=yes ;; q) # quiet: don't inform user what we are doing CMD_INFO_PRINT=/bin/true ;; v) # verbose: detailed inform user what we are doing CMD_VERBOSE_PRINT=${CMD_INFO} ;; D) # Debug: set an debug option to yes eval DEBUG_$1=yes shift 1 ;; h) # help: give out help how this script can be used /bin/cat << END-HELP-TEXT Usage is: $0 [options] options: -d download: download orignal Debian files from distribution server -g generate: generate our own file -s sourcedir sourcedir: use kernel/config/patch from here -k kernel kernel: use this kernel archive -c config config: use this config file -p patch patch: use this libdiscover patch file -u upload: upload generated files to local install server for usage by -f before install -b baseaddr base: upload generated files relative to this base directory -r remove: remove Debian and own files, after installing -q quiet: don't give user an running report of what we are doing -v verbose: give user detailed running report -D Debug: activate an debug option, see source for operation -h help: give out help how this script can be used If multiple of -d -g -u or -r are used, they are processed in the order they appear here in the help section, not the order they are typed on the command line. Other options modify behaviour. END-HELP-TEXT exit 0 ;; *) # not one of our recognized options ${CMD_ERROR} unknown option: ${OPT} >&2 ${CMD_INFO} >&2 # call self with -h to display help $0 -h exit 1 ;; esac done done if [ x${COMMAND_OPTION} = x ] ; then ${CMD_WARNING} no command option selected, doing nothing ... >&2 fi # --- set debugging behaviour CMD_DEBUG_SLEEP=/bin/true if [ x${DEBUG_SLEEP} != x ] ; then CMD_DEBUG_SLEEP="/bin/sleep ${DEBUG_SLEEP}" fi CMD_DEBUG_PRINT=/bin/true if [ x${DEBUG_PRINT_STEP} = xyes ] ; then CMD_DEBUG_PRINT=${CMD_DEBUG} fi CMD_DEBUG_WAIT=/bin/true if [ x${DEBUG_WAIT_STEP} = xyes ] ; then CMD_DEBUG_WAIT="read -p ---DEBUG-wait-after-step--- dummy" fi ${CMD_DEBUG_PRINT} options are: \ DO_DOWN: ${DO_DOWN}, DO_GEN: ${DO_GEN}, \ DO_UPLOAD: ${DO_UPLOAD}, DO_REMOVE: ${DO_REMOVE} ${CMD_DEBUG_WAIT} # --- test if we can work # this script is intended to be run as root, it will fail if run as user! if [ ! `/usr/bin/whoami` = root ] ; then ${CMD_ERROR} sorry, you need to run this script as root - aborting ... >&2 exit 1 fi # --- compute paths on disk image server # path for Debian directory we download from server DEBINST=dists/sarge/main/installer-${SYS_ARCH}/current # path for our directory we upload to and download from server OWNINST=dists/sarge/local/main/installer-${SYS_ARCH}/${CONF_DISKSVERSION} # actual files inside all of these BOOTIMG=images/floppy/boot.img ROOTIMG=images/floppy/root.img DRIVIMG=images/floppy/net-drivers.img # --- download Debian boot disk image to work on # determine the correct boot floppy image file # used by -d and -g and others, so once here outside of -d BOOT_URL=${CONF_DEBSERVER}/${DEBINST}/${BOOTIMG} # in current dir, not workdir, as user wants to see this BOOT=`/usr/bin/basename ${BOOT_URL}` if [ x${DO_DOWN} != x ] ; then ${CMD_INFO_PRINT} downloading Debian boot disk image ... ${CMD_DEBUG_SLEEP} # -N so only newer is got, save waisting bandwidth if already here # if user wants to force download, use an make clean before # downloaded and to-upload files should end in current directory # this is also most likely where config and kernel archive will be # everything else in work directory and then deleted at the end /usr/bin/wget -q -N ${BOOT_URL} -O ${BOOT} ${CMD_DEBUG_PRINT} `/bin/ls -al ${BOOT}` ${CMD_DEBUG_WAIT} fi # --- download Debian root disk image to work on # determine the correct root floppy image file # used by -d and -g and others, so once here outside of -d ROOT_URL=${CONF_DEBSERVER}/${DEBINST}/${ROOTIMG} ROOT=`/usr/bin/basename ${ROOT_URL}` if [ x${DO_DOWN} != x ] ; then ${CMD_INFO_PRINT} downloading Debian root disk image ... ${CMD_DEBUG_SLEEP} # -N so only newer is got, save waisting bandwidth if already here # if user wants to force download, use an make clean before /usr/bin/wget -q -N ${ROOT_URL} -O ${ROOT} ${CMD_DEBUG_PRINT} `/bin/ls -al ${ROOT}` ${CMD_DEBUG_WAIT} fi # --- download Debian drivers disk image to work on # determine the correct full drivers archive DRV_URL=${CONF_DEBSERVER}/${DEBINST}/${DRIVIMG} DRV=`/usr/bin/basename ${DRV_URL}` if [ x${DO_DOWN} != x ] ; then ${CMD_INFO_PRINT} downloading Debian drivers disk image ... ${CMD_DEBUG_SLEEP} # -N so only newer is got, save waisting bandwidth if already here # if user wants to force download, use an make clean before /usr/bin/wget -q -N ${DRV_URL} -O ${DRV} ${CMD_DEBUG_PRINT} `/bin/ls -al ${DRV}` ${CMD_DEBUG_WAIT} fi # --- find input files if [ x${DO_GEN} != x ] ; then ${CMD_VERBOSE_PRINT} looking for input files ... ${CMD_DEBUG_SLEEP} # finding stuff to use, what kernel, unless set by options if [ x${KERNEL} = x ] ; then # last file, after sorted without extension, so -*.tar.* not before .tar.* KERNEL=`/bin/ls -1U ${CONF_SOURCEDIR}/linux-*.tar.bz2 2> /dev/null | \ /usr/bin/rev | /usr/bin/cut -f 3- -d '.' | /usr/bin/rev | \ /usr/bin/sort | /usr/bin/tail -n 1`.tar.bz2 fi if [ x${KERNEL} = x ] ; then KERNEL=`/bin/ls -1U ${CONF_SOURCEDIR}/linux-*.tar.gz 2> /dev/null | \ /usr/bin/rev | /usr/bin/cut -f 3- -d '.' | /usr/bin/rev | \ /usr/bin/sort | /usr/bin/tail -n 1`.tar.gz fi if [ x${KERNEL} = x ] ; then ${CMD_ERROR} no kernel archive found in ${CONF_SOURCEDIR} >&2 exit 1 fi if [ ! -f ${KERNEL} ] ; then ${CMD_ERROR} invalid kernel file name ${KERNEL} >&2 exit 1 fi ${CMD_DEBUG_PRINT} `/bin/ls -al ${KERNEL} 2> /dev/null` ${CMD_DEBUG_WAIT} # and with what config, unless set by options if [ x${CONFIG} = x ] ; then CONFIG=`ls -1 ${CONF_SOURCEDIR}/config* 2> /dev/null | tail -n 1` fi if [ x${CONFIG} = x ] ; then ${CMD_ERROR} no kernel config found in ${CONF_SOURCEDIR} >&2 exit 1 fi if [ ! -f ${CONFIG} ] ; then ${CMD_ERROR} invalid config file name ${CONFIG} >&2 exit 1 fi ${CMD_DEBUG_PRINT} `/bin/ls -al ${CONFIG} 2> /dev/null` ${CMD_DEBUG_WAIT} # and with what facultative libdiscover DB patch file, unless options if [ x${PATCH} = x ] ; then PATCH=`ls -1 ${CONF_SOURCEDIR}/*.diff 2> /dev/null | tail -n 1` fi if [ x${PATCH} != x ] ; then if [ ! -f ${PATCH} ] ; then ${CMD_ERROR} invalid libdiscover DB patch file name ${PATCH} >&2 exit 1 fi ${CMD_DEBUG_PRINT} `/bin/ls -al ${PATCH} 2> /dev/null` ${CMD_DEBUG_WAIT} fi fi # --- space to work in if [ x${DO_GEN} != x ] ; then /bin/mkdir -p ${SYS_WORKDIR} fi # --- unpack kernel if [ x${DO_GEN} != x ] ; then ${CMD_INFO_PRINT} unpacking kernel from ${KERNEL} ... ${CMD_DEBUG_SLEEP} # remove any existing kernel, to avoid mess on overwriting # directory was linux for < 2.4, now linux- for >= 2.4 if [ -d ${SYS_WORKDIR}/linux-* ] ; then /bin/rm -rf ${SYS_WORKDIR}/linux-* fi # allow either .tar.bz or .tar.gz archives if [ x`/bin/echo ${KERNEL} | /bin/grep '\.tar\.bz2$'` != x ] ; then /bin/tar -jxpf ${KERNEL} -C ${SYS_WORKDIR} elif [ x`/bin/echo ${KERNEL} | /bin/grep '\.tar\.gz$'` != x ] ; then /bin/tar -zxpf $${KERNEL} -C ${SYS_WORKDIR} else ${CMD_FATAL} unknown '*.tar.*' file type for ${KERNEL} >&2 exit 1 fi if [ -d ${SYS_WORKDIR}/linux-* ] ; then # not LINUX=${SYS_WORKDIR}/linux-* as then cp -p ${LINUX}/.config # becomes cp -p ${SYS_WORKDIR}/linux*/.config and doesnt expand LINUX=`/bin/ls -1d ${SYS_WORKDIR}/linux-* 2> /dev/null` (cd ${SYS_WORKDIR}; /bin/ln -s ${LINUX} linux) else ${CMD_FATAL} kernel archive ${KERNEL} did not unpack >&2 exit 1 fi ${CMD_DEBUG_PRINT} `/bin/ls -ald ${LINUX}` ${CMD_DEBUG_PRINT} `/bin/ls -ald ${SYS_WORKDIR}/linux` ${CMD_DEBUG_WAIT} fi # --- insert config if [ x${DO_GEN} != x ] ; then ${CMD_VERBOSE_PRINT} inserting base config ... ${CMD_DEBUG_SLEEP} # inserting base config /bin/cp -p ${CONFIG} ${LINUX}/.config ${CMD_DEBUG_PRINT} `/bin/ls -al ${LINUX}/.config` ${CMD_DEBUG_WAIT} fi # --- fix up config if [ x${DO_GEN} != x ] ; then ${CMD_VERBOSE_PRINT} fixing missing needed stuff in config ... ${CMD_DEBUG_SLEEP} # stuff we need to force in to the kernel for FORCE_CONFIG in ${SYS_FORCE_CONFIGS} ; do if [ x`/bin/grep "${FORCE_CONFIG}=y" ${LINUX}/.config` = x ] ; then ${CMD_VERBOSE_PRINT} + adding missing ${FORCE_CONFIG}=y >&2 /bin/sed -e "s/#* *${FORCE_CONFIG}[ =].*/${FORCE_CONFIG}=y/" \ ${LINUX}/.config > ${LINUX}/.config.tmp /bin/mv ${LINUX}/.config.tmp ${LINUX}/.config fi done # stuff we want to force out of the kernel for FORCE_UNCONFIG in ${SYS_FORCE_UNCONFIGS} ; do if [ x`/bin/grep "# ${FORCE_UNCONFIG} is not set" ${LINUX}/.config | \ /usr/bin/tr -d ' '` = x ] ; then ${CMD_VERBOSE_PRINT} - removing unwanted ${FORCE_UNCONFIG}=y >&2 /bin/sed -e "s/${FORCE_UNCONFIG}=./# ${FORCE_UNCONFIG} is not set/" \ ${LINUX}/.config > ${LINUX}/.config.tmp /bin/mv ${LINUX}/.config.tmp ${LINUX}/.config fi done if [ x${DEBUG_DUMP_CONFIG} = xyes ] ; then ${CMD_INFO_PRINT} dumping generated .config and system map ... /bin/cp -p ${LINUX}/.config ${LINUX}/System.map . fi ${CMD_DEBUG_PRINT} `/bin/ls -al ${LINUX}/.config` ${CMD_DEBUG_WAIT} fi # --- make oldconfig if [ x${DO_GEN} != x ] ; then ${CMD_INFO_PRINT} making oldconfig in ${LINUX} ... ${CMD_DEBUG_SLEEP} /bin/echo /bin/echo "*** --- oldconfig... --- ***" /bin/echo (cd ${LINUX}; /usr/bin/make oldconfig) ${CMD_DEBUG_PRINT} `/bin/ls -al ${LINUX}/.config` ${CMD_DEBUG_WAIT} fi # --- build the kernel, make dep bzImage modules if [ x${DO_GEN} != x ] ; then ${CMD_INFO_PRINT} building the kernel in ${LINUX} ... ${CMD_DEBUG_SLEEP} /bin/echo /bin/echo "*** --- dep... --- ***" /bin/echo (cd ${LINUX}; /usr/bin/make dep) /bin/echo /bin/echo "*** --- bzImage... --- ***" /bin/echo # this needs to be bzImage because syslinux bootloader only knows that (cd ${LINUX}; /usr/bin/make -j 4 bzImage) /bin/echo /bin/echo "*** --- modules... --- ***" /bin/echo (cd ${LINUX}; /usr/bin/make -j 4 modules) ${CMD_DEBUG_PRINT} `/bin/ls -al ${LINUX}/vmlinux` ${CMD_DEBUG_PRINT} `/bin/ls -al ${LINUX}/System.map` ${CMD_DEBUG_PRINT} `/bin/ls -al ${LINUX}/arch/${SYS_ARCH}/boot/bzImage` ${CMD_DEBUG_WAIT} fi # --- pack stuff into boot floppy image if [ x${DO_GEN} != x ] ; then ${CMD_INFO_PRINT} packing stuff onto boot disk ... ${CMD_DEBUG_SLEEP} # - open boot floppy image and initrd # open boot floppy image BOOTFLOPPY=${SYS_WORKDIR}/boot /bin/mkdir -p ${BOOTFLOPPY} /bin/mount -o loop ${BOOT} ${BOOTFLOPPY} # open boot floppy initrd BOOTINITRD_IMG=${SYS_WORKDIR}/boot-initrd.img /bin/gunzip -c ${BOOTFLOPPY}/initrd.gz > ${BOOTINITRD_IMG} if [ x${DEBUG_BACKUP_INITRD} != x ] ; then # save the unmodified initrd for comparing stuff /bin/cp -p ${BOOTINITRD_IMG} ${BOOTINITRD_IMG}.bak fi BOOTINITRD_MOUNT=${SYS_WORKDIR}/boot-initrd.mnt /bin/mkdir -p ${BOOTINITRD_MOUNT} /bin/mount -o loop ${BOOTINITRD_IMG} ${BOOTINITRD_MOUNT} # copy boot floppy initrd content to near unlimited space, for working on it BOOTINITRD=${SYS_WORKDIR}/boot-initrd /bin/mkdir -p ${BOOTINITRD} # get rid of stderr because GNUs broken tar complains of files with time=0s # and Debian manages to package their floppy images with such nonsense /bin/tar cSlf - -C ${BOOTINITRD_MOUNT} . 2>/dev/null | \ /bin/tar xpf - -C ${BOOTINITRD} 2>/dev/null # - work on boot floppy contents # pre-delete of initrd file, so limited space is less critical # needed as kernel may be larger, and then only later smaller initrd /bin/rm ${BOOTFLOPPY}/initrd.gz # put our kernel stuff onto it # only bzImage, no System.map or .config, to save space on floppy /bin/cp -p ${LINUX}/arch/${SYS_ARCH}/boot/bzImage ${BOOTFLOPPY}/linux ${CMD_DEBUG_PRINT} `/bin/ls -al ${BOOTFLOPPY}/linux` ${CMD_DEBUG_WAIT} # delete the old unusable modules, get more space for the kernel (no modules) /bin/rm -rf ${BOOTINITRD}/lib/modules/* # prevent modprobe screaming warnings, because no or empty modules.dep file # fake modules.dep file made insmod scream, hard coded modules not found # fix up /sbin/init /bin/sed -e 's/modprobe /true /' ${BOOTINITRD}/sbin/init \ > ${BOOTINITRD}/sbin/init.temp /bin/chmod 755 ${BOOTINITRD}/sbin/init.temp /bin/mv ${BOOTINITRD}/sbin/init.temp ${BOOTINITRD}/sbin/init # fix up /usr/sbin/usb-discover /bin/sed -e 's/modprobe /true /' ${BOOTINITRD}/usr/sbin/usb-discover \ > ${BOOTINITRD}/usr/sbin/usb-discover.temp /bin/chmod 755 ${BOOTINITRD}/usr/sbin/usb-discover.temp /bin/mv ${BOOTINITRD}/usr/sbin/usb-discover.temp \ ${BOOTINITRD}/usr/sbin/usb-discover ${CMD_DEBUG_PRINT} +++ begin bootfloppy initrd modules listing +++ if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/ls -al ${BOOTINITRD}/lib/modules fi ${CMD_DEBUG_PRINT} +++ end bootfloppy initrd modules listing +++ ${CMD_DEBUG_WAIT} # - close boot floppy initrd and image # copy back to freshly dd-ed volume, max 0 sector count, smaller compressable BOOTI_BYTES=`/usr/bin/stat -c '%s' ${BOOTINITRD_IMG}` BOOTI_KBYTES=`/usr/bin/expr ${BOOTI_BYTES} / 1024` /bin/umount ${BOOTINITRD_MOUNT} /bin/dd if=/dev/zero of=${BOOTINITRD_IMG} bs=1024 count=${BOOTI_KBYTES} /sbin/mkfs.ext2 -F ${BOOTINITRD_IMG} /bin/mount -o loop ${BOOTINITRD_IMG} ${BOOTINITRD_MOUNT} /bin/tar cSlf - -C ${BOOTINITRD} . 2>/dev/null | \ /bin/tar xpf - -C ${BOOTINITRD_MOUNT} 2>/dev/null if [ $? != 0 ] ; then /bin/umount ${BOOTINITRD_MOUNT} /bin/umount ${BOOTFLOPPY} ${CMD_FATAL} not enough space for ${BOOTINITRD} on ${BOOTINITRD_IMG} >&2 exit 1 fi # before closing, to see inside initrd ${CMD_DEBUG_PRINT} +++ begin bootfloppy initrd listing +++ if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/ls -al ${BOOTFLOPPY} fi ${CMD_DEBUG_PRINT} +++ end bootfloppy initrd listing +++ ${CMD_DEBUG_WAIT} /bin/umount ${BOOTINITRD_MOUNT} /bin/gzip -9 -c ${BOOTINITRD_IMG} > ${BOOTFLOPPY}/initrd.gz if [ $? != 0 ] ; then /bin/umount ${BOOTFLOPPY} ${CMD_FATAL} not enough space for initrd.gz on ${BOOTFLOPPY} >&2 exit 1 fi # before closing, to see inside image ${CMD_DEBUG_PRINT} +++ begin bootfloppy image listing +++ if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/ls -al ${BOOTFLOPPY} fi ${CMD_DEBUG_PRINT} +++ end bootfloppy image listing +++ ${CMD_DEBUG_WAIT} /bin/umount ${BOOTFLOPPY} # writing to loop mounted image file does not seem to update its access time /bin/touch ${BOOT} ${CMD_DEBUG_PRINT} `/bin/ls -al ${BOOT}` ${CMD_DEBUG_WAIT} fi # --- pack stuff into root floppy image if [ x${DO_GEN} != x ] ; then ${CMD_INFO_PRINT} packing stuff onto root disk ... ${CMD_DEBUG_SLEEP} # - open root floppy image and initrd # open root floppy image ROOTFLOPPY=${SYS_WORKDIR}/root /bin/mkdir -p ${ROOTFLOPPY} /bin/mount -o loop ${ROOT} ${ROOTFLOPPY} # open root floppy initrd ROOTINITRD_IMG=${SYS_WORKDIR}/root-initrd.img /bin/gunzip -c ${ROOTFLOPPY}/initrd.gz > ${ROOTINITRD_IMG} if [ x${DEBUG_BACKUP_INITRD} != x ] ; then # save the unmodified initrd for comparing stuff /bin/cp -p ${ROOTINITRD_IMG} ${ROOTINITRD_IMG}.bak fi ROOTINITRD_MOUNT=${SYS_WORKDIR}/root-initrd.mnt /bin/mkdir -p ${ROOTINITRD_MOUNT} /bin/mount -o loop ${ROOTINITRD_IMG} ${ROOTINITRD_MOUNT} # copy root floppy initrd content to near unlimited space, for working on it ROOTINITRD=${SYS_WORKDIR}/root-initrd /bin/mkdir -p ${ROOTINITRD} # get rid of stderr because GNUs broken tar complains of files with time=0s # and Debian manages to package their floppy images with such nonsense /bin/tar cSlf - -C ${ROOTINITRD_MOUNT} . 2>/dev/null | \ /bin/tar xpf - -C ${ROOTINITRD} 2>/dev/null # - work on root floppy contents # delete the now old unusable modules, to get more space for the new ones /bin/rm -rf ${ROOTINITRD}/lib/modules/* # install our /lib/modules//* stuff (cd ${LINUX}; INSTALL_MOD_PATH=${ROOTINITRD} make modules_install) # delete unwanted new modules to save space if [ x${DEBUG_LEAVE_ALL_MODULES} = x ] ; then ( cd ${ROOTINITRD}/lib/modules/*; /bin/rm -rf ${SYS_RM_MODULES} ) fi ${CMD_DEBUG_PRINT} +++ begin rootfloppy initrd modules listing +++ if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/ls -al ${ROOTINITRD}/lib/modules/* fi ${CMD_DEBUG_PRINT} +++ end rootfloppy initrd modules listing +++ ${CMD_DEBUG_WAIT} # update PCI ID list in /usr/share/discover for libdiscover # patch it from an user given patch file /usr/bin/patch ${ROOTINITRD}/usr/share/discover/pci.lst ${PATCH} if [ x${DEBUG_DUMP_PCILIST} = xyes ] ; then ${CMD_INFO_PRINT} dumping generated pci.lst ... /bin/cp -p ${ROOTINITRD}/usr/share/discover/pci.lst . fi ${CMD_DEBUG_PRINT} `/bin/ls -al ${ROOTINITRD}/usr/share/discover/pci.lst` ${CMD_DEBUG_WAIT} # - close root floppy initrd and image # copy back to freshly dd-ed volume, max 0 sector count, smaller compressable ROOTI_BYTES=`/usr/bin/stat -c '%s' ${ROOTINITRD_IMG}` ROOTI_KBYTES=`/usr/bin/expr ${ROOTI_BYTES} / 1024` /bin/umount ${ROOTINITRD_MOUNT} /bin/dd if=/dev/zero of=${ROOTINITRD_IMG} bs=1024 count=${ROOTI_KBYTES} /sbin/mkfs.ext2 -F ${ROOTINITRD_IMG} /bin/mount -o loop ${ROOTINITRD_IMG} ${ROOTINITRD_MOUNT} /bin/tar cSlf - -C ${ROOTINITRD} . 2>/dev/null | \ /bin/tar xpf - -C ${ROOTINITRD_MOUNT} 2>/dev/null if [ $? != 0 ] ; then /bin/umount ${ROOTINITRD_MOUNT} /bin/umount ${ROOTFLOPPY} ${CMD_FATAL} not enough space for ${ROOTINITRD} on ${ROOTINITRD_IMG} >&2 exit 1 fi # before closing, to see inside initrd ${CMD_DEBUG_PRINT} +++ begin rootfloppy initrd listing +++ if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/ls -al ${ROOTINITRD} fi ${CMD_DEBUG_PRINT} +++ end rootfloppy initrd listing +++ ${CMD_DEBUG_WAIT} /bin/umount ${ROOTINITRD_MOUNT} /bin/gzip -9 -c ${ROOTINITRD_IMG} > ${ROOTFLOPPY}/initrd.gz if [ $? != 0 ] ; then /bin/umount ${ROOTFLOPPY} ${CMD_FATAL} not enough space for initrd.gz on ${ROOTFLOPPY} >&2 exit 1 fi # before closing, to see inside image ${CMD_DEBUG_PRINT} +++ begin rootfloppy image listing +++ if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/ls -al ${ROOTFLOPPY} fi ${CMD_DEBUG_PRINT} +++ end rootfloppy image listing +++ ${CMD_DEBUG_WAIT} /bin/umount ${ROOTFLOPPY} # writing to loop mounted image file does not seem to update its access time /bin/touch ${ROOT} ${CMD_DEBUG_PRINT} `/bin/ls -al ${ROOT}` ${CMD_DEBUG_WAIT} fi # --- tidy up after working if [ x${DO_GEN} != x ] ; then ${CMD_INFO_PRINT} tidying up from working ... ${CMD_DEBUG_SLEEP} ${CMD_DEBUG_PRINT} ${SYS_WORKDIR} ${CMD_DEBUG_PRINT} +++ begin workdirectory listing +++ if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/ls -al ${SYS_WORKDIR} fi ${CMD_DEBUG_PRINT} +++ end workdirectory listing +++ ${CMD_DEBUG_WAIT} # remove temporary directory and its contents, to save space # must be after debug printout if [ x${DEBUG_LEAVE_TEMPFILES} != xyes ] ; then # but offer to leave this to investigate bugs /bin/rm -rf ${SYS_WORKDIR} fi fi # --- upload generated floppy images if [ x${DO_UPLOAD} != x ] ; then ${CMD_INFO_PRINT} uploading images to ${CONF_INST_SERVER} ... ${CMD_DEBUG_SLEEP} # put together stuff to upload, needs an temp dir BOOT_DIR=${SYS_UPLOADDIR}/`/usr/bin/dirname ${OWNINST}/${BOOTIMG}` ROOT_DIR=${SYS_UPLOADDIR}/`/usr/bin/dirname ${OWNINST}/${ROOTIMG}` /bin/mkdir -p ${BOOT_DIR} ${ROOT_DIR} if [ x${CONF_GROUP} != x ] ; then /bin/chgrp -R ${CONF_GROUP} ${SYS_UPLOADDIR} /bin/chmod -R 2775 ${SYS_UPLOADDIR} fi if [ -f ${BOOT} ] ; then /bin/cp -p ${BOOT} ${BOOT_DIR} if [ x${CONF_GROUP} != x ] ; then /bin/chgrp ${CONF_GROUP} ${BOOT_DIR}/* /bin/chmod 664 ${BOOT_DIR}/* fi fi if [ -f ${ROOT} ] ; then /bin/cp -p ${ROOT} ${ROOT_DIR} if [ x${CONF_GROUP} != x ] ; then /bin/chgrp ${CONF_GROUP} ${ROOT_DIR}/* /bin/chmod 664 ${ROOT_DIR}/* fi fi # include directory tree, duplicating tree to server, in case server has none # may be none if new package is in an previously unused section # this is a bit site dependant, you need ssh on your local package server # 2> needed to get rid of error message, because scp can not change dir modes # this loses us the progress bar, because scp tests also 2> for tty or not # if user has given us somewhere to upload to, else dphys2root gets screwed if [ x${CONF_INST_SERVER} != x ] ; then /usr/bin/scp -pr ${SYS_UPLOADDIR}/* \ ${CONF_USER}@${CONF_INST_SERVER}:${CONF_INST_BASE} 2> /dev/null else ${CMD_FATAL} no server to upload boot floppy image to >&2 exit 1 fi ${CMD_DEBUG_PRINT} `/bin/ls -al ${SYS_UPLOADDIR}/${OWNINST}/${BOOTIMG}` ${CMD_DEBUG_PRINT} `/bin/ls -al ${SYS_UPLOADDIR}/${OWNINST}/${ROOTIMG}` ${CMD_DEBUG_WAIT} # remove temporary directory and its contents, to save space # must be after debug printout if [ x${DEBUG_LEAVE_TEMPDIRS} != xyes ] ; then # but offer to leave this to investigate bugs /bin/rm -rf ${SYS_UPLOADDIR} fi fi # --- remove disk images if [ x${DO_REMOVE} != x ] ; then ${CMD_INFO_PRINT} removing boot disk images and drivers tar archives ... ${CMD_DEBUG_PRINT} `/bin/ls -al ${BOOT} 2> /dev/null` ${CMD_DEBUG_PRINT} `/bin/ls -al ${ROOT} 2> /dev/null` ${CMD_DEBUG_PRINT} `/bin/ls -al ${DRV} 2> /dev/null` ${CMD_DEBUG_WAIT} /bin/rm -f ${BOOT} ${ROOT} ${DRV} fi exit 0