#!/bin/sh # /usr/bin/dphys3kernel - # - build dphys3 replacement floppy image s w kernel for Debian 3.1 (sarge) # author Neil Franklin, last modification 2006.11.17 # 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=. # upload server for compiled floppy images, where our image files go # the -u option uploads everything relative to this # /dir 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 our own install server # we upload via ssh/scp, as this is most likely available on boot servers # so this line needs to be in user@server:/directory format for scp CONF_UPLOAD_SERVER=not-configured-user@server:/dir # 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_UPLOAD_GROUP="" # 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=dphys3-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 #DEBUG_SLEEP=yes # 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, to make it smaller to fit floppy # this list gets subtracted from our standard production kernel config # automagically modifying it to be smaller for an install kernel SYS_FORCE_UNCONFIGS="CONFIG_MICROCODE CONFIG_X86_MSR CONFIG_X86_CPUID \ CONFIG_EDD CONFIG_MTRR CONFIG_HOTPLUG CONFIG_PCMCIA CONFIG_SYSVIPC \ CONFIG_BSD_PROCESS_ACCT CONFIG_ACPI CONFIG_PARPORT CONFIG_PNP \ CONFIG_ISAPNP CONFIG_BLK_DEV_XD CONFIG_BLK_STATS CONFIG_MD \ CONFIG_BLK_DEV_LVM CONFIG_NETLINK_DEV CONFIG_IP_MULTICAST CONFIG_PHONE \ CONFIG_BLK_DEV_IDECD CONFIG_BLK_DEV_IDEFLOPPY CONFIG_BLK_DEV_IDESCSI \ CONFIG_CHR_DEV_ST CONFIG_BLK_DEV_SR CONFIG_CHR_DEV_SG \ CONFIG_SCSI_MULTI_LUN CONFIG_SCSI_LOGGING CONFIG_IEEE1394 CONFIG_I2O \ CONFIG_DUMMY CONFIG_TUN CONFIG_NET_RADIO CONFIG_WAN CONFIG_IRDA \ CONFIG_ISDN CONFIG_INPUT CONFIG_INPUT_MOUSEDEV CONFIG_INPUT_JOYDEV \ CONFIG_INPUT_EVDEV CONFIG_SERIAL CONFIG_PRINTER CONFIG_I2C CONFIG_MOUSE \ CONFIG_PSMOUSE CONFIG_AGP CONFIG_DRM CONFIG_VIDEO_DEV CONFIG_QUOTA \ CONFIG_AUTOFS_FS CONFIG_AUTOFS4_FS CONFIG_REISERFS_FS CONFIG_SUPERMOUNT \ CONFIG_MSDOS_FS CONFIG_UMSDOS CONFIG_CRAMFS CONFIG_RAMFS \ CONFIG_ISO9660_FS CONFIG_JFS_FS CONFIG_MINIX_FS CONFIG_NTFS_FS \ CONFIG_UDF_FS CONFIG_UFS_FS CONFIG_XFS_FS CONFIG_NFS_FS CONFIG_NFS_V3 \ CONFIG_NFSD CONFIG_NFSD_V3 CONFIG_SUNRPC CONFIG_LOCKD CONFIG_LOCKD_V4 \ CONFIG_SMB_FS CONFIG_ZISOFS_FS CONFIG_FB CONFIG_SOUND CONFIG_USB \ CONFIG_BLUEZ CONFIG_ZLIB_INFLATE CONFIG_ZLIB_DEFLATE" # stuff we want to force in to the kernel, else the installer fails # this list gets added to our standard production kernel config # automagically modifying it to be usable for an install kernel # needed kernel features are: # CONFIG_BLK_DEV_INITRD (initial ram disk) is needed for boot floppy # CONFIG_BLK_DEV_RAM (ram disk) is needed for initrd # CONFIG_TMPFS (temporary filesystem) is needed for / of root floppy # CONFIG_BLK_DEV_FD (floppy drive) is needed for reading root floppy # CONFIG_VFAT_FS (VFAT filesystem) is needed for extracting root initrd # CONFIG_FAT_FS (FAT filesystem) is needed for vfat # CONFIG_BLK_DEV_LOOP (loopback mount) is needed for mounting root initrd # CONFIG_DEVFS_FS (device filesystem) is needed for installer mounts # CONFIG_PACKET (packet protocol) is needed for dhcp direct ip access # CONFIG_NET (network support) is needed for packet protocol # CONFIG_FILTER (socket filter) is needed for dhcp, reason unknown # we assume that the production kernel config already has compiled in: # whatever IDE or SCSI (base and drivers!) that the systems hard disks need SYS_FORCE_CONFIGS="CONFIG_BLK_DEV_INITRD CONFIG_BLK_DEV_RAM CONFIG_TMPFS \ CONFIG_BLK_DEV_FD CONFIG_VFAT_FS CONFIG_FAT_FS CONFIG_BLK_DEV_LOOP \ CONFIG_DEVFS_FS CONFIG_NET CONFIG_PACKET CONFIG_FILTER" # 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 set -e # --- get ready to work # sanitise this place, else some commands may fail # must be before any commands are executed, incl config/input processing PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH # --- tidy up some commands, make systematic, common infrastructure # 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="echo $0: FATAL:" # something from users input, user will correct this and continue CMD_ERROR="echo $0: ERROR:" # something we can continue with, but may be wrong, and user may not suspect it CMD_WARNING="echo $0: WARNING:" # something most likely not wrong, but tell user for the odd case it is wrong CMD_NOTE="echo $0: NOTE:" # normal stuff users expect, so to stdout as normal output, no $0, no marking CMD_INFO="echo" # stuff users asked for, so add to stdout as normal output, no $0, but mark it CMD_DEBUG="echo DEBUG:" # other stuff we may want to use CMD_SLEEP="sleep 2" CMD_WAIT="read -p ---DEBUG-wait-after-step--- dummy" # DEBUG_* or option controllable stuff CMD_INFO_PRINT="${CMD_INFO}" CMD_VERBOSE_PRINT=true CMD_DEBUG_SLEEP=true CMD_DEBUG_PRINT=true CMD_DEBUG_WAIT=true # set debug option controllable stuff here if [ "${DEBUG_SLEEP}" = yes ] ; then CMD_DEBUG_SLEEP="${CMD_SLEEP}" fi if [ "${DEBUG_PRINT_STEP}" = yes ] ; then CMD_DEBUG_PRINT="${CMD_DEBUG}" fi if [ "${DEBUG_WAIT_STEP}" = yes ] ; then CMD_DEBUG_WAIT="${CMD_WAIT}" fi # --- 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 [ "`echo "$1" | cut -c 1`" = - ] ; do # extract options from parameter (cut off the "-") OPTS="`echo "$1" | cut -c 2-`" shift 1 # so long still unprocessed option characters while [ "${OPTS}" != "" ] ; do # first option to process OPT="`echo "${OPTS}" | cut -c 1`" # and rest of options for later OPTS="`echo "${OPTS}" | 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 ;; 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=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 if [ "DEBUG_$1" = DEBUG_SLEEP ] ; then CMD_DEBUG_SLEEP="${CMD_SLEEP}" fi if [ "DEBUG_$1" = DEBUG_PRINT_STEP ] ; then CMD_DEBUG_PRINT="${CMD_DEBUG}" fi if [ "DEBUG_$1" = DEBUG_WAIT_STEP ] ; then CMD_DEBUG_WAIT="${CMD_WAIT}" fi shift 1 ;; h) # help: give out help how this script can be used cat << END-HELP-TEXT Usage is: $0 command [option]... [command [option]... ]... command/function/action letters: one or multiple of the following commands must be used, default nothing done if multiple of these are used, they are processed in the row they appear here, not the row they are typed on the command line -d download: download orignal Debian files from distribution server -g generate: generate our own file -u upload: upload generated files to local install server for usage by -f before install -r remove: remove Debian and own files, after installing options: [only for -g generate] -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 [for all commands] -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 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 [ "${COMMAND_OPTION}" = "" ] ; then ${CMD_ERROR} "no command option selected, will not do anything" >&2 ${CMD_INFO} >&2 # call self with -h to display help "$0" -h >&2 exit 1 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 [ ! "`whoami`" = root ] ; then ${CMD_ERROR} "sorry, you need to run this 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 # variable 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 file BOOT="`basename "${BOOT_URL}"`" if [ "${DO_DOWN}" != "" ] ; then ${CMD_INFO_PRINT} "downloading Debian boot disk image ..." ${CMD_DEBUG_SLEEP} # check if we can download if ! which wget > /dev/null ; then ${CMD_FATAL} "failed to find wget, can not download, aborting ..." >&2 ${CMD_LOG_FATAL} "failed to find wget, can not download, aborting ..." exit 1 fi # -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 wget -q -N "${BOOT_URL}" -O "${BOOT}" ${CMD_DEBUG_PRINT} "`ls -al "${BOOT}"`" ${CMD_DEBUG_WAIT} fi # --- download Debian root disk image to work on # determine the correct root floppy image file ROOT_URL="${CONF_DEBSERVER}/${DEBINST}/${ROOTIMG}" ROOT="`basename "${ROOT_URL}"`" if [ "${DO_DOWN}" != "" ] ; 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 wget -q -N "${ROOT_URL}" -O "${ROOT}" ${CMD_DEBUG_PRINT} "`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="`basename "${DRV_URL}"`" if [ "${DO_DOWN}" != "" ] ; 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 wget -q -N "${DRV_URL}" -O "${DRV}" ${CMD_DEBUG_PRINT} "`ls -al "${DRV}"`" ${CMD_DEBUG_WAIT} fi # --- find input files if [ "${DO_GEN}" != "" ] ; then ${CMD_VERBOSE_PRINT} "looking for input files ..." ${CMD_DEBUG_SLEEP} # finding stuff to use, what kernel, unless set by options if [ "${KERNEL}" = "" ] ; then # last numbered (and hopefully newest) kernel # complicated ls stuff is used because we need each file on separate line # ls -U is used as only sorted later, after extensions are removed # so that "-" for -*.tar.* does not end up before "." for .tar.* # then after sorting re-add extension for full file name KERNEL="`ls -1U "${CONF_SOURCEDIR}"/linux-*.tar.bz2 2> /dev/null | \ rev | cut -f 3- -d '.' | rev | sort | tail -n 1`.tar.bz2" fi if [ "${KERNEL}" = ".tar.bz2" ] ; then # only an empty ending, no .tar.bz2 archive, retry for .tar.gz archive KERNEL="`ls -1U "${CONF_SOURCEDIR}"/linux-*.tar.gz 2> /dev/null | \ rev | cut -f 3- -d '.' | rev | sort | tail -n 1`.tar.gz" fi if [ "${KERNEL}" = ".tar.gz" ] ; then ${CMD_ERROR} "no kernel archive in ${CONF_SOURCEDIR}, aborting ..." >&2 exit 1 fi if [ ! -f "${KERNEL}" ] ; then ${CMD_ERROR} "invalid kernel archive ${KERNEL}, aborting ..." >&2 exit 1 fi ${CMD_VERBOSE_PRINT} "using kernel: `basename "${KERNEL}"`" # and with what config, unless set by options if [ "${CONFIG}" = "" ] ; then CONFIG="`ls -1 "${CONF_SOURCEDIR}"/config* 2> /dev/null | tail -n 1`" fi if [ "${CONFIG}" = "" ] ; then CONFIG="`ls -1 "${CONF_SOURCEDIR}"/.config* 2> /dev/null | tail -n 1`" fi if [ "${CONFIG}" = "" ] ; then ${CMD_ERROR} "no kernel config in ${CONF_SOURCEDIR}, aborting ..." >&2 exit 1 fi if [ ! -f "${CONFIG}" ] ; then ${CMD_ERROR} "invalid kernel config ${CONFIG}, aborting ..." >&2 exit 1 fi ${CMD_VERBOSE_PRINT} "using config: `basename "${CONFIG}"`" # and with what facultative libdiscover DB patch file, unless options if [ "${PATCH}" = "" ] ; then PATCH="`ls -1 "${CONF_SOURCEDIR}"/*.diff 2> /dev/null | tail -n 1`" fi if [ "${PATCH}" != "" ] ; then # no patch at all is allowed, unlike kernel and config if [ ! -f "${PATCH}" ] ; then ${CMD_ERROR} "invalid libdiscover DB patch ${PATCH}, aborting ..." >&2 exit 1 fi fi ${CMD_DEBUG_PRINT} "`ls -al "${KERNEL}" 2> /dev/null`" ${CMD_DEBUG_PRINT} "`ls -al "${CONFIG}" 2> /dev/null`" if [ "${PATCH}" != "" ] ; then ${CMD_DEBUG_PRINT} "`ls -al "${PATCH}" 2> /dev/null`" fi ${CMD_DEBUG_WAIT} fi # --- space to work in if [ "${DO_GEN}" != "" ] ; then mkdir -p "${SYS_WORKDIR}" fi # --- unpack kernel if [ "${DO_GEN}" != "" ] ; 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 rm -rf "${SYS_WORKDIR}"/linux-* fi # allow either .tar.bz or .tar.gz archives if echo "${KERNEL}" | grep -q '\.tar\.bz2$' ; then tar -jxpf "${KERNEL}" -C "${SYS_WORKDIR}" elif echo "${KERNEL}" | grep -q '\.tar\.gz$' ; then 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 doesn't expand LINUX="`ls -1d "${SYS_WORKDIR}"/linux-* 2> /dev/null`" (cd "${SYS_WORKDIR}"; ln -s "${LINUX}" linux) else ${CMD_FATAL} "kernel archive ${KERNEL} did not unpack" >&2 exit 1 fi ${CMD_DEBUG_PRINT} "`ls -ald "${LINUX}"`" ${CMD_DEBUG_PRINT} "`ls -ald "${SYS_WORKDIR}/linux"`" ${CMD_DEBUG_WAIT} fi # --- insert config if [ "${DO_GEN}" != "" ] ; then ${CMD_VERBOSE_PRINT} "inserting base config ..." ${CMD_DEBUG_SLEEP} # inserting base config cp -p "${CONFIG}" "${LINUX}/.config" ${CMD_DEBUG_PRINT} "`ls -al "${LINUX}/.config"`" ${CMD_DEBUG_WAIT} fi # --- fix up config if [ "${DO_GEN}" != "" ] ; then ${CMD_VERBOSE_PRINT} "fixing up config for install kernels ..." ${CMD_DEBUG_SLEEP} # stuff we want to force out of the kernel, to make it smaller to fit floppy for FORCE_UNCONFIG in \ `echo "${SYS_FORCE_UNCONFIGS}" | tr -c -d 'A-Z0-9_ '` ; do if ! grep -q "# ${FORCE_UNCONFIG} is not set" ${LINUX}/.config ; then ${CMD_VERBOSE_PRINT} "- removing unwanted ${FORCE_UNCONFIG}" >&2 sed -e "s/${FORCE_UNCONFIG}=./# ${FORCE_UNCONFIG} is not set/" \ "${LINUX}/.config" > "${LINUX}/.config.tmp" mv "${LINUX}/.config.tmp" "${LINUX}/.config" fi done # stuff we need to force in to the kernel, else the installer fails for FORCE_CONFIG in \ `echo "${SYS_FORCE_CONFIGS}" | tr -c -d 'A-Z0-9_ '` ; do if ! grep -q "${FORCE_CONFIG}=y" "${LINUX}/.config" ; then ${CMD_VERBOSE_PRINT} "+ adding missing ${FORCE_CONFIG}=y" >&2 # match either ${FORCE_CONFIG} is not set or ${FORCE_CONFIG}=m sed -e "s/#* *${FORCE_CONFIG}[ =].*/${FORCE_CONFIG}=y/" \ "${LINUX}/.config" > "${LINUX}/.config.tmp" mv "${LINUX}/.config.tmp" "${LINUX}/.config" fi done if [ "${DEBUG_DUMP_CONFIG}" = yes ] ; then ${CMD_INFO_PRINT} "dumping generated .config ..." cp -p "${LINUX}/.config" . fi ${CMD_DEBUG_PRINT} "`ls -al "${LINUX}/.config"`" ${CMD_DEBUG_WAIT} fi # --- make oldconfig if [ "${DO_GEN}" != "" ] ; then ${CMD_INFO_PRINT} "making oldconfig in ${LINUX} ..." ${CMD_DEBUG_SLEEP} echo echo "*** --- oldconfig... --- ***" echo (cd "${LINUX}"; make oldconfig) ${CMD_DEBUG_PRINT} "`ls -al "${LINUX}/.config"`" ${CMD_DEBUG_WAIT} fi # --- build the kernel, make dep bzImage modules if [ "${DO_GEN}" != "" ] ; then ${CMD_INFO_PRINT} "building the kernel in ${LINUX} ..." ${CMD_DEBUG_SLEEP} echo echo "*** --- dep... --- ***" echo (cd "${LINUX}"; make dep) echo echo "*** --- bzImage... --- ***" echo # this needs to be bzImage because syslinux bootloader only knows that (cd "${LINUX}"; make -j 4 bzImage) echo echo "*** --- modules... --- ***" echo (cd "${LINUX}"; make -j 4 modules) ${CMD_DEBUG_PRINT} "`ls -al "${LINUX}/vmlinux"`" ${CMD_DEBUG_PRINT} "`ls -al "${LINUX}/System.map"`" ${CMD_DEBUG_PRINT} "`ls -al "${LINUX}/arch/${SYS_ARCH}/boot/bzImage"`" ${CMD_DEBUG_WAIT} fi # --- pack stuff into boot floppy image if [ "${DO_GEN}" != "" ] ; 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" mkdir -p "${BOOTFLOPPY}" mount -o loop "${BOOT}" "${BOOTFLOPPY}" # open boot floppy initrd BOOTINITRD_IMG="${SYS_WORKDIR}/boot-initrd.img" gunzip -c "${BOOTFLOPPY}/initrd.gz" > "${BOOTINITRD_IMG}" if [ "${DEBUG_BACKUP_INITRD}" != "" ] ; then # save the unmodified initrd for comparing stuff cp -p "${BOOTINITRD_IMG}" "${BOOTINITRD_IMG}.bak" fi BOOTINITRD_MOUNT="${SYS_WORKDIR}/boot-initrd.mnt" mkdir -p "${BOOTINITRD_MOUNT}" 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" 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 tar cSlf - -C "${BOOTINITRD_MOUNT}" . 2>/dev/null | \ 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 smaller initrd only later rm "${BOOTFLOPPY}/initrd.gz" # delete the old unusable modules, get more space for the kernel # no modules here any more, all that are needed here are compiled in rm -rf "${BOOTINITRD}"/lib/modules/* # put our kernel stuff onto it # only bzImage, no System.map or .config, to save space on floppy cp -p "${LINUX}/arch/${SYS_ARCH}/boot/bzImage" "${BOOTFLOPPY}/linux" ${CMD_DEBUG_PRINT} "`ls -al "${BOOTFLOPPY}/linux"`" ${CMD_DEBUG_WAIT} # 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 the init script INIT="${BOOTINITRD}/sbin/init" sed -e 's/modprobe /true /' "${INIT}" > "${INIT}.temp" mv "${INIT}.temp" "${INIT}" chmod 755 "${INIT}" # fix up the usb-discover script USBDISC="${BOOTINITRD}/usr/sbin/usb-discover" sed -e 's/modprobe /true /' "${USBDISC}" > "${USBDISC}.temp" mv "${USBDISC}.temp" "${USBDISC}" chmod 755 "${USBDISC}" ${CMD_DEBUG_PRINT} "+++ begin bootfloppy initrd modules listing +++" if [ "${DEBUG_PRINT_STEP}" = yes ] ; then ls -al "${BOOTINITRD}/lib/modules" fi ${CMD_DEBUG_PRINT} "+++ end bootfloppy initrd modules listing +++" ${CMD_DEBUG_WAIT} # - close boot floppy initrd # copy back to freshly dd-ed volume, max 0 sector count, smaller compressable BOOTI_BYTES="`stat -c '%s' "${BOOTINITRD_IMG}"`" BOOTI_KBYTES="`expr "${BOOTI_BYTES}" / 1024`" umount "${BOOTINITRD_MOUNT}" dd if=/dev/zero of="${BOOTINITRD_IMG}" bs=1024 count="${BOOTI_KBYTES}" mkfs.ext2 -F "${BOOTINITRD_IMG}" mount -o loop "${BOOTINITRD_IMG}" "${BOOTINITRD_MOUNT}" set +e tar cSlf - -C "${BOOTINITRD}" . 2> /dev/null | \ tar xpf - -C "${BOOTINITRD_MOUNT}" 2> /dev/null RETVAL="$?" set -e if [ "${RETVAL}" != 0 ] ; then umount "${BOOTINITRD_MOUNT}" 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 [ "${DEBUG_PRINT_STEP}" = yes ] ; then ls -al "${BOOTFLOPPY}" fi ${CMD_DEBUG_PRINT} "+++ end bootfloppy initrd listing +++" ${CMD_DEBUG_PRINT} "`du -sk "${BOOTINITRD_IMG}"`" ${CMD_DEBUG_WAIT} umount "${BOOTINITRD_MOUNT}" # - close boot floppy image BOOTINITRD_GZ="${SYS_WORKDIR}/boot-initrd.gz" gzip -9 -c "${BOOTINITRD_IMG}" > "${BOOTINITRD_GZ}" ${CMD_DEBUG_PRINT} "`ls -al "${BOOTINITRD_GZ}"`" ${CMD_DEBUG_WAIT} set +e cp -p "${BOOTINITRD_GZ}" "${BOOTFLOPPY}/initrd.gz" 2> /dev/null RETVAL="$?" set -e if [ "${RETVAL}" != 0 ] ; then umount "${BOOTFLOPPY}" ${CMD_FATAL} "not enough space for ${BOOTINITRD_GZ} on ${BOOTFLOPPY}" >&2 exit 1 fi # before closing, to see inside image ${CMD_DEBUG_PRINT} "+++ begin bootfloppy image listing +++" if [ "${DEBUG_PRINT_STEP}" = yes ] ; then ls -al "${BOOTFLOPPY}" fi ${CMD_DEBUG_PRINT} "+++ end bootfloppy image listing +++" ${CMD_DEBUG_WAIT} umount "${BOOTFLOPPY}" # writing to loop mounted image file does not seem to update its access time touch "${BOOT}" ${CMD_DEBUG_PRINT} "`ls -al "${BOOT}"`" ${CMD_DEBUG_WAIT} fi # --- pack stuff into root floppy image if [ "${DO_GEN}" != "" ] ; 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" mkdir -p "${ROOTFLOPPY}" mount -o loop "${ROOT}" "${ROOTFLOPPY}" # open root floppy initrd ROOTINITRD_IMG="${SYS_WORKDIR}/root-initrd.img" gunzip -c "${ROOTFLOPPY}/initrd.gz" > "${ROOTINITRD_IMG}" if [ "${DEBUG_BACKUP_INITRD}" != "" ] ; then # save the unmodified initrd for comparing stuff cp -p "${ROOTINITRD_IMG}" "${ROOTINITRD_IMG}.bak" fi ROOTINITRD_MOUNT="${SYS_WORKDIR}/root-initrd.mnt" mkdir -p "${ROOTINITRD_MOUNT}" 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" 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 tar cSlf - -C "${ROOTINITRD_MOUNT}" . 2>/dev/null | \ 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 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 [ "${DEBUG_LEAVE_ALL_MODULES}" = "" ] ; then ( cd "${ROOTINITRD}"/lib/modules/*; rm -rf "${SYS_RM_MODULES}" ) fi ${CMD_DEBUG_PRINT} "+++ begin rootfloppy initrd modules listing +++" if [ "${DEBUG_PRINT_STEP}" = yes ] ; then 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, if one was given if [ "${PATCH}" != "" ] ; then patch "${ROOTINITRD}/usr/share/discover/pci.lst" "${PATCH}" fi if [ "${DEBUG_DUMP_PCILIST}" = yes ] ; then ${CMD_INFO_PRINT} "dumping generated pci.lst ..." cp -p "${ROOTINITRD}/usr/share/discover/pci.lst" . fi ${CMD_DEBUG_PRINT} "`ls -al "${ROOTINITRD}/usr/share/discover/pci.lst"`" ${CMD_DEBUG_WAIT} # - close root floppy initrd # copy back to freshly dd-ed volume, max 0 sector count, smaller compressable ROOTI_BYTES="`stat -c '%s' "${ROOTINITRD_IMG}"`" ROOTI_KBYTES="`expr "${ROOTI_BYTES}" / 1024`" umount "${ROOTINITRD_MOUNT}" dd if=/dev/zero of="${ROOTINITRD_IMG}" bs=1024 count="${ROOTI_KBYTES}" mkfs.ext2 -F "${ROOTINITRD_IMG}" mount -o loop "${ROOTINITRD_IMG}" "${ROOTINITRD_MOUNT}" set +e tar cSlf - -C "${ROOTINITRD}" . 2> /dev/null | \ tar xpf - -C "${ROOTINITRD_MOUNT}" 2> /dev/null RETVAL="$?" set -e if [ "${RETVAL}" != 0 ] ; then umount "${ROOTINITRD_MOUNT}" 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 [ "${DEBUG_PRINT_STEP}" = yes ] ; then ls -al "${ROOTINITRD}" fi ${CMD_DEBUG_PRINT} "+++ end rootfloppy initrd listing +++" ${CMD_DEBUG_PRINT} "`du -sk "${ROOTINITRD_IMG}"`" ${CMD_DEBUG_WAIT} umount "${ROOTINITRD_MOUNT}" # - close root floppy image ROOTINITRD_GZ="${SYS_WORKDIR}/root-initrd.gz" gzip -9 -c "${ROOTINITRD_IMG}" > "${ROOTINITRD_GZ}" ${CMD_DEBUG_PRINT} "`ls -al "${ROOTINITRD_GZ}"`" ${CMD_DEBUG_WAIT} set +e cp -p "${ROOTINITRD_GZ}" "${ROOTFLOPPY}/initrd.gz" 2> /dev/null RETVAL="$?" set -e if [ "${RETVAL}" != 0 ] ; then umount "${ROOTFLOPPY}" ${CMD_FATAL} "not enough space for ${ROOTINITRD_GZ} on ${ROOTFLOPPY}" >&2 exit 1 fi # before closing, to see inside image ${CMD_DEBUG_PRINT} "+++ begin rootfloppy image listing +++" if [ "${DEBUG_PRINT_STEP}" = yes ] ; then ls -al "${ROOTFLOPPY}" fi ${CMD_DEBUG_PRINT} "+++ end rootfloppy image listing +++" ${CMD_DEBUG_WAIT} umount "${ROOTFLOPPY}" # writing to loop mounted image file does not seem to update its access time touch "${ROOT}" ${CMD_DEBUG_PRINT} "`ls -al "${ROOT}"`" ${CMD_DEBUG_WAIT} fi # --- tidy up after working if [ "${DO_GEN}" != "" ] ; then ${CMD_INFO_PRINT} "tidying up from working ..." ${CMD_DEBUG_SLEEP} ${CMD_DEBUG_PRINT} "SYS_WORKDIR = ${SYS_WORKDIR}" ${CMD_DEBUG_PRINT} "+++ begin workdirectory listing +++" if [ "${DEBUG_PRINT_STEP}" = yes ] ; then 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 [ "${DEBUG_LEAVE_TEMPFILES}" != yes ] ; then # but offer to leave this to investigate bugs rm -rf "${SYS_WORKDIR}" fi fi # --- upload generated floppy images if [ "${DO_UPLOAD}" != "" ] ; then ${CMD_INFO_PRINT} "uploading images to ${CONF_UPLOAD_SERVER} ..." ${CMD_DEBUG_SLEEP} # put together stuff to upload, needs an temp dir BOOT_DIR="${SYS_UPLOADDIR}/`dirname "${OWNINST}/${BOOTIMG}"`" ROOT_DIR="${SYS_UPLOADDIR}/`dirname "${OWNINST}/${ROOTIMG}"`" mkdir -p "${BOOT_DIR}" "${ROOT_DIR}" if [ "${CONF_UPLOAD_GROUP}" != "" ] ; then chgrp -R "${CONF_UPLOAD_GROUP}" "${SYS_UPLOADDIR}" chmod -R 2775 "${SYS_UPLOADDIR}" fi if [ -f "${BOOT}" ] ; then cp -p "${BOOT}" "${BOOT_DIR}" if [ "${CONF_UPLOAD_GROUP}" != "" ] ; then chgrp "${CONF_UPLOAD_GROUP}" "${BOOT_DIR}"/* chmod 664 "${BOOT_DIR}"/* fi fi if [ -f "${ROOT}" ] ; then cp -p "${ROOT}" "${ROOT_DIR}" if [ "${CONF_UPLOAD_GROUP}" != "" ] ; then chgrp "${CONF_UPLOAD_GROUP}" "${ROOT_DIR}"/* 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 [ "${CONF_UPLOAD_SERVER}" != "" ] ; then scp -pr "${SYS_UPLOADDIR}"/* "${CONF_UPLOAD_SERVER}" 2> /dev/null else ${CMD_FATAL} "no server to upload boot floppy image to" >&2 exit 1 fi ${CMD_DEBUG_PRINT} "`ls -al "${SYS_UPLOADDIR}/${OWNINST}/${BOOTIMG}"`" ${CMD_DEBUG_PRINT} "`ls -al "${SYS_UPLOADDIR}/${OWNINST}/${ROOTIMG}"`" ${CMD_DEBUG_WAIT} # remove temporary directory and its contents, to save space # must be after debug printout if [ "${DEBUG_LEAVE_TEMPDIRS}" != yes ] ; then # but offer to leave this to investigate bugs rm -rf "${SYS_UPLOADDIR}" fi fi # --- remove disk images if [ "${DO_REMOVE}" != "" ] ; then ${CMD_INFO_PRINT} "removing boot disk images and drivers tar archives ..." ${CMD_DEBUG_PRINT} "`ls -al "${BOOT}" 2> /dev/null`" ${CMD_DEBUG_PRINT} "`ls -al "${ROOT}" 2> /dev/null`" ${CMD_DEBUG_PRINT} "`ls -al "${DRV}" 2> /dev/null`" ${CMD_DEBUG_WAIT} rm -f "${BOOT}" "${ROOT}" "${DRV}" fi exit 0