#!/bin/sh # http://www.phys.ethz.ch/~franklin/Projects/dphys2/makeroot # - build our replacement root floppy image for Debian woody (3.0) # copyright ETH Zuerich Physics Deparement, use under either BSD or GPL license # author Neil Franklin, last modification 2003.07.31 # this script is intended to be run as root, it will fail if run as user! # ------ read in setup . ./setup-dphys2 # ------ from here on code to do the actual actions # --- test if we can work if [ ! ${USER} = root ] ; then echo "sorry, you need to run this script as root - aborting ..." exit 1 fi # --- get ready for work if [ ! -d ${CONF_WORKDIR} ] ; then mkdir -p ${CONF_WORKDIR} fi # --- fetch stuff to work on /bin/echo "--------------------------------------------------------------------------" /bin/echo "*** downloading root disk image and drivers *** from ${CONF_DEBSERVER} ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # un-correct our correction of Debians broken naming, so that wget -N works if [ -f ${CONF_WORKDIR}/root.bin.gz ] ; then mv ${CONF_WORKDIR}/root.bin.gz ${CONF_WORKDIR}/root.bin fi # -N to only newer is fetched, save waisting bandwidth if already here # if user wants to force download, use an make clean before if [ x${CONF_KERNEL_24} = xyes ] ; then # change path to files for 2.4 kernel SYS_DEBROOT=${SYS_DEBROOT_24} SYS_DEBDRIVERS=${SYS_DEBDRIVERS_24} fi wget -N -P ${CONF_WORKDIR} \ http://${CONF_DEBSERVER}/${CONF_DEBDIR}/${SYS_DEBROOT} wget -N -P ${CONF_WORKDIR} \ http://${CONF_DEBSERVER}/${CONF_DEBDIR}/${SYS_DEBDRIVERS} # (re-)correct Debians broken naming, this file is compressed, should be .gz mv ${CONF_WORKDIR}/root.bin ${CONF_WORKDIR}/root.bin.gz if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/echo "--- debug info ---" /bin/ls -al ${CONF_WORKDIR} read dummy fi # --- unpack it into an temporary filesystem /bin/echo "-------------------------------------------------------" /bin/echo "*** unpacking Debian stuff *** into ${CONF_WORKDIR} ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # uncompress root image so that it becomes mountable gunzip -c ${CONF_WORKDIR}/root.bin.gz > ${CONF_WORKDIR}/root.bin # unpack root file system from floppy image mkdir -p ${CONF_WORKDIR}/root-mnt rm -rf ${CONF_WORKDIR}/root-dphys mkdir ${CONF_WORKDIR}/root-dphys mount -o loop ${CONF_WORKDIR}/root.bin ${CONF_WORKDIR}/root-mnt tar cf - -C ${CONF_WORKDIR}/root-mnt . \ | tar xpf - -C ${CONF_WORKDIR}/root-dphys umount ${CONF_WORKDIR}/root-mnt # unpack drivers.tgz from large file rm -rf ${CONF_WORKDIR}/drivers mkdir ${CONF_WORKDIR}/drivers tar zxvf ${CONF_WORKDIR}/drivers.tgz -C ${CONF_WORKDIR}/drivers # unpack modules.tgz from drivers.tgz rm -rf ${CONF_WORKDIR}/modules mkdir ${CONF_WORKDIR}/modules tar zxf ${CONF_WORKDIR}/drivers/modules.tgz -C ${CONF_WORKDIR}/modules # unpack modconf.tgz from drivers.tgz rm -rf ${CONF_WORKDIR}/modconf-dphys mkdir ${CONF_WORKDIR}/modconf-dphys tar zxf ${CONF_WORKDIR}/drivers/modconf.tgz -C ${CONF_WORKDIR}/modconf-dphys if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/echo "--- debug info ---" /bin/ls -al ${CONF_WORKDIR} read dummy fi # --- extract the stuff we still want /bin/echo "---------------------------------------" /bin/echo "*** Extract stuff we still want *** ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # - we need to fit onto one floppy, including our drivers /bin/echo "* deleting some unused stuff, for space ..." # root file system: delete some unused stuff mv ${CONF_WORKDIR}/root-dphys/etc/messages.en ${CONF_WORKDIR} rm ${CONF_WORKDIR}/root-dphys/etc/messages.* mv ${CONF_WORKDIR}/messages.en ${CONF_WORKDIR}/root-dphys/etc # - copy only the few drivers we need, to avoid needing driver disks /bin/echo "* copying only the few drivers we need/want ..." # and drivers disk: only copy the auxillary files rm -rf ${CONF_WORKDIR}/drivers-dphys mkdir ${CONF_WORKDIR}/drivers-dphys for file in install.sh modcont type.txt; do cp -p ${CONF_WORKDIR}/drivers/$file ${CONF_WORKDIR}/drivers-dphys done # and from modules.tgz: the few drivers we need or want rm -rf ${CONF_WORKDIR}/modules-dphys mkdir ${CONF_WORKDIR}/modules-dphys # standard install /etc/modules needs these if [ x${CONF_KERNEL_24} != xyes ] ; then # this is not used any more with 2.4 kernel (bf2.4) mkdir -p ${CONF_WORKDIR}/modules-dphys/${SYS_MODULEDIRMISC} for module in ${SYS_MODULESMISC}; do cp -p ${CONF_WORKDIR}/modules/${SYS_MODULEDIRMISC}/$module \ ${CONF_WORKDIR}/modules-dphys/${SYS_MODULEDIRMISC} done fi # our network hardware wants these if [ x${CONF_KERNEL_24} = xyes ] ; then # change path to files for 2.4 kernel SYS_MODULEDIRNET=${SYS_MODULEDIRNET_24} fi mkdir -p ${CONF_WORKDIR}/modules-dphys/${SYS_MODULEDIRNET} for module in ${CONF_MODULESNET}; do cp -p ${CONF_WORKDIR}/modules/${SYS_MODULEDIRNET}/${module} \ ${CONF_WORKDIR}/modules-dphys/${SYS_MODULEDIRNET} done # - and prune some unused stuff from modconf.tgz /bin/echo "* prune some unused stuff from modconf.tgz ..." mv ${CONF_WORKDIR}/modconf-dphys/usr/share/modconf/eval_C ${CONF_WORKDIR} mv ${CONF_WORKDIR}/modconf-dphys/usr/share/modconf/eval_C.utf-8 ${CONF_WORKDIR} rm ${CONF_WORKDIR}/modconf-dphys/usr/share/modconf/eval_* mv ${CONF_WORKDIR}/eval_C ${CONF_WORKDIR}/modconf-dphys/usr/share/modconf mv ${CONF_WORKDIR}/eval_C.utf-8 ${CONF_WORKDIR}/modconf-dphys/usr/share/modconf if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/echo "--- debug info ---" /bin/ls -al ${CONF_WORKDIR} read dummy fi # --- add various new stuff, to create the modified root disk /bin/echo "-------------------------------------------------------------" /bin/echo "*** Packing various new stuff onto modified root disk *** ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # - pack up the new reduced drivers.tgz stuff /bin/echo "* packing in drivers.tgz subset ..." # pack new modules.tgz into drivers.tgz tar zcvf ${CONF_WORKDIR}/drivers-dphys/modules.tgz \ -C ${CONF_WORKDIR}/modules-dphys . # pack new modconf.tgz into drivers.tgz tar zcf ${CONF_WORKDIR}/drivers-dphys/modconf.tgz \ -C ${CONF_WORKDIR}/modconf-dphys . # pack new drivers.tgz into root-dphys, avoid separate drivers floppys tar zcvf ${CONF_WORKDIR}/root-dphys/${SYS_DRIVERS_TGZ} \ -C ${CONF_WORKDIR}/drivers-dphys . # - replace Debians dbootstrap with our automatic script and our/its setup /bin/echo "* packing in our replacement dbootstrap ..." cp -p dbootstrap ${CONF_WORKDIR}/root-dphys/sbin chown root.root ${CONF_WORKDIR}/root-dphys/sbin/dbootstrap chmod 755 ${CONF_WORKDIR}/root-dphys/sbin/dbootstrap cp -p setup-dphys2 ${CONF_WORKDIR}/root-dphys/etc chown root.root ${CONF_WORKDIR}/root-dphys/etc/setup-dphys2 # *** WARNING *** # this file must be chmod 600 because of LILO and root passwords in it! chmod 600 ${CONF_WORKDIR}/root-dphys/etc/setup-dphys2 # - and give our script the /sbin/sfdisk it needs /bin/echo "* packing in sfdisk, used by replacement dbootstrap ..." cp -p sfdisk ${CONF_WORKDIR}/root-dphys/sbin chown root.root ${CONF_WORKDIR}/root-dphys/sbin/sfdisk chmod 755 ${CONF_WORKDIR}/root-dphys/sbin/sfdisk # - and give dbootstrap the lilo.conf template it needs /bin/echo "* packing in lilo.conf used by replacement dbootstrap ..." cp -p lilo.conf ${CONF_WORKDIR}/root-dphys/${SYS_LILO_CONF} chown root.root ${CONF_WORKDIR}/root-dphys/${SYS_LILO_CONF} chmod 644 ${CONF_WORKDIR}/root-dphys/${SYS_LILO_CONF} if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/echo "--- debug info ---" /bin/ls -al ${CONF_WORKDIR}/root-dphys read dummy fi # --- fudge up debconf, so that we don't get base-config dialogs /bin/echo "-------------------------------------------------------------" /bin/echo "*** Fudge up debconf, so 2nd install stage no dialogs *** ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # for this we add an script that will be run by dbootstrap # after all the first stage install, but before reboot, chrooted to /target cp -p debconf-preload ${CONF_WORKDIR}/root-dphys/${SYS_PRELOAD_ON_FLOPPY} chown root.root ${CONF_WORKDIR}/root-dphys/${SYS_PRELOAD_ON_FLOPPY} chmod 755 ${CONF_WORKDIR}/root-dphys/${SYS_PRELOAD_ON_FLOPPY} if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/echo "--- debug info ---" /bin/ls -al ${CONF_WORKDIR}/root-dphys read dummy fi # --- run user script (or binary) at end of first install stage, further autom if [ x${CONF_ENDFIRSTRUN_SCRIPT} != x ] ; then # give user chance to do further site specific automation /bin/echo "---------------------------------------------------" /bin/echo "*** Run user script, for further automation *** ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # for this we add an script that will be run by dbootstrap # after all the first stage install, but before reboot, chrooted to /target if [ ! -f ${CONF_ENDFIRSTRUN_SCRIPT} ] ; then echo "error: CONF_ENDFIRSTRUN_SCRIPT feature enabled in setup," \ "but file ${CONF_ENDFIRSTRUN_SCRIPT} is missing" fi cp -p ${CONF_ENDFIRSTRUN_SCRIPT} \ ${CONF_WORKDIR}/root-dphys/${SYS_ENDFIRSTRUN_ON_FLOPPY} chown root.root ${CONF_WORKDIR}/root-dphys/${SYS_ENDFIRSTRUN_ON_FLOPPY} chmod 755 ${CONF_WORKDIR}/root-dphys/${SYS_ENDFIRSTRUN_ON_FLOPPY} if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/echo "--- debug info ---" /bin/ls -al ${CONF_WORKDIR}/root-dphys read dummy fi fi # --- create the root disk image /bin/echo "----------------------------------" /bin/echo "*** creating new root disk *** ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # get our pseudo disk ready for making floppy image, 8MByte will fit compressed dd if=/dev/zero of=${CONF_WORKDIR}/root-dphys.bin bs=1024 count=8192 # we need slightly over 3000 inodes, this makes 8192*1024/2048=4096 inodes mke2fs -i 2048 -F ${CONF_WORKDIR}/root-dphys.bin # pack root file system onto floppy image mkdir -p ${CONF_WORKDIR}/root-mnt mount -o loop ${CONF_WORKDIR}/root-dphys.bin ${CONF_WORKDIR}/root-mnt tar cf - -C ${CONF_WORKDIR}/root-dphys . | \ tar xpf - -C ${CONF_WORKDIR}/root-mnt umount ${CONF_WORKDIR}/root-mnt # compress root image so that it fits on floppy gzip -9 -c ${CONF_WORKDIR}/root-dphys.bin > ${CONF_WORKDIR}/root-dphys.bin.gz if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/echo "--- debug info ---" /bin/ls -al ${CONF_WORKDIR} read dummy fi