#!/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 Departement, # use under either BSD or GPL license # author Neil Franklin, last modification 2004.02.13 # this script is intended to be run as root, it will fail if run as user! # ------ read in setup # this is shared by Makefile, makerescue, makeroot, dbootstrap . ./setup-dphys2 # ------ from here on code to do the actual actions # --- test if we can work if [ ! `/usr/bin/whoami` = root ] ; then /bin/echo "sorry, you need to run this script as root - aborting ..." exit 1 fi # --- place to work on root /bin/mkdir -p ${SYS_ROOTWORK} # --- fetch root disk image to work on /bin/echo "-----------------------------------" /bin/echo "*** downloading root disk image ***" if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # fetch correct root floppy image file from the net if [ x${CONF_KERNEL_24} = xyes ] ; then ROOT="http://${CONF_DEBSERVER}/${CONF_DEBDIR}/${SYS_DEBROOT_BF24}" else ROOT="http://${CONF_DEBSERVER}/${CONF_DEBDIR}/${SYS_DEBROOT}" fi # -N so only newer is fetched, save waisting bandwidth if already here # if user wants to force download, use an make clean before /usr/bin/wget -N -P ${SYS_ROOTWORK} ${ROOT} # --- fetch drivers archive to work on /bin/echo "---------------------------------------" /bin/echo "*** downloading drivers tar archive ***" if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # fetch the correct full drivers archive from the net if [ x${CONF_KERNEL_OWN} != x ] ; then DRV="http://${CONF_OWNSERVER_KERNEL}/${CONF_OWNDIR_KERNEL}/${SYS_OWNDRIVERS}" elif [ x${CONF_KERNEL_24} = xyes ] ; then DRV="http://${CONF_DEBSERVER}/${CONF_DEBDIR}/${SYS_DEBDRIVERS_BF24}" else DRV="http://${CONF_DEBSERVER}/${CONF_DEBDIR}/${SYS_DEBDRIVERS}" fi # -N to only newer is fetched, save waisting bandwidth if already here # if user wants to force download, use an make clean before /usr/bin/wget -N -P ${SYS_ROOTWORK} ${DRV} # --- unpack it into an temporary filesystem /bin/echo "-------------------------------------------------------" /bin/echo "*** unpacking Debian stuff *** into ${SYS_ROOTWORK} ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # place to work on root file system /bin/rm -rf ${SYS_ROOTWORK}/root-dphys /bin/mkdir ${SYS_ROOTWORK}/root-dphys # correct Debians broken naming, this file is compressed, should be .gz # also we need the .gz-less name for the uncompressed file /bin/mv ${SYS_ROOTWORK}/`/usr/bin/basename ${ROOT}` \ ${SYS_ROOTWORK}/`/usr/bin/basename ${ROOT}`.gz # uncompress the root image so that it becomes (loopback) mountable /bin/gunzip -c ${SYS_ROOTWORK}/`/usr/bin/basename ${ROOT}`.gz \ > ${SYS_ROOTWORK}/`/usr/bin/basename ${ROOT}` # unpack root file system from floppy image ROOTFLOPPY=${SYS_ROOTWORK}/floppy /bin/mkdir -p ${ROOTFLOPPY} /bin/mount -o loop ${SYS_ROOTWORK}/`/usr/bin/basename ${ROOT}` ${ROOTFLOPPY} /bin/tar cf - -C ${ROOTFLOPPY} . | /bin/tar xpf - -C ${SYS_ROOTWORK}/root-dphys /bin/umount ${ROOTFLOPPY} /bin/rm -rf ${ROOTFLOPPY} # get rid of space waste of uncompressed root image /bin/rm ${SYS_ROOTWORK}/`/usr/bin/basename ${ROOT}` # un-correct our correction of Debians broken naming, so that back to "normal" # else wget -N will fail to work, if user runs this program a second time /bin/mv ${SYS_ROOTWORK}/`/usr/bin/basename ${ROOT}`.gz \ ${SYS_ROOTWORK}/`/usr/bin/basename ${ROOT}` # unpack drivers from large drivers archive file /bin/rm -rf ${SYS_ROOTWORK}/drivers /bin/mkdir ${SYS_ROOTWORK}/drivers /bin/tar zxf ${SYS_ROOTWORK}/`/usr/bin/basename ${DRV}` \ -C ${SYS_ROOTWORK}/drivers # unpack modules from modules.tgz in drivers /bin/rm -rf ${SYS_ROOTWORK}/modules /bin/mkdir ${SYS_ROOTWORK}/modules /bin/tar zxf ${SYS_ROOTWORK}/drivers/modules.tgz -C ${SYS_ROOTWORK}/modules # unpack modconf from modconf.tgz in drivers /bin/rm -rf ${SYS_ROOTWORK}/modconf-dphys /bin/mkdir ${SYS_ROOTWORK}/modconf-dphys /bin/tar zxf ${SYS_ROOTWORK}/drivers/modconf.tgz -C \ ${SYS_ROOTWORK}/modconf-dphys if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/echo "--- debug info ---" /bin/ls -al ${SYS_ROOTWORK} 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 /bin/mv ${SYS_ROOTWORK}/root-dphys/etc/messages.en ${SYS_ROOTWORK} /bin/rm ${SYS_ROOTWORK}/root-dphys/etc/messages.* /bin/mv ${SYS_ROOTWORK}/messages.en ${SYS_ROOTWORK}/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 /bin/rm -rf ${SYS_ROOTWORK}/drivers-dphys /bin/mkdir ${SYS_ROOTWORK}/drivers-dphys for file in install.sh modcont type.txt; do /bin/cp -p ${SYS_ROOTWORK}/drivers/$file ${SYS_ROOTWORK}/drivers-dphys done # and modules.tgz: only copy the few drivers we need or want /bin/rm -rf ${SYS_ROOTWORK}/modules-dphys /bin/mkdir ${SYS_ROOTWORK}/modules-dphys # determine modules directory name/number KERNELVERS=`/usr/bin/basename ${SYS_ROOTWORK}/modules/lib/modules/*` # standard Debian 2.2(.20) kernel needs these (Debian what were you thinking?) # 2.4 kernels do not have these any more, so they are not needed/possible if [ `echo ${KERNELVERS} | cut -f 2 -d "."` = 2 ] ; then MODULEDIRMISC=lib/modules/${KERNELVERS}/misc # test if at least one module is wanted if [ x`/bin/echo ${SYS_MODULESMISC} | /usr/bin/cut -f 1 -d " "` != x ] ; then /bin/mkdir -p ${SYS_ROOTWORK}/modules-dphys/${MODULEDIRMISC} for module in ${SYS_MODULESMISC}; do /bin/cp -a ${SYS_ROOTWORK}/modules/${MODULEDIRMISC}/$module \ ${SYS_ROOTWORK}/modules-dphys/${MODULEDIRMISC} done fi fi # our network hardware needs these # non-modular kernels (users may want to make such) may not want any # so test if at least one module is wanted if [ x`/bin/echo ${CONF_MODULESNET} | /usr/bin/cut -f 1 -d " "` != x ] ; then # determine where to place modules, as minor versions 2 and 4 are different if [ `echo ${KERNELVERS} | cut -f 2 -d "."` = 2 ] ; then # 2.2 flat structure MODULEDIRNET=lib/modules/${KERNELVERS}/net else # 2.4 tree structure MODULEDIRNET=lib/modules/${KERNELVERS}/kernel/drivers/net fi /bin/mkdir -p ${SYS_ROOTWORK}/modules-dphys/${MODULEDIRNET} for module in ${CONF_MODULESNET}; do /bin/cp -a ${SYS_ROOTWORK}/modules/${MODULEDIRNET}/${module} \ ${SYS_ROOTWORK}/modules-dphys/${MODULEDIRNET} done fi # - and prune some unused stuff from modconf.tgz /bin/echo "* prune some unused stuff from modconf.tgz ..." /bin/mv ${SYS_ROOTWORK}/modconf-dphys/usr/share/modconf/eval_C ${SYS_ROOTWORK} /bin/mv ${SYS_ROOTWORK}/modconf-dphys/usr/share/modconf/eval_C.utf-8 \ ${SYS_ROOTWORK} /bin/rm ${SYS_ROOTWORK}/modconf-dphys/usr/share/modconf/eval_* /bin/mv ${SYS_ROOTWORK}/eval_C ${SYS_ROOTWORK}/modconf-dphys/usr/share/modconf /bin/mv ${SYS_ROOTWORK}/eval_C.utf-8 \ ${SYS_ROOTWORK}/modconf-dphys/usr/share/modconf if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/echo "--- debug info ---" /bin/ls -al ${SYS_ROOTWORK} 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 stuff /bin/echo "* packing in drivers subset ..." # pack new modules into modules.tgz in drivers-dphys /bin/tar zcf ${SYS_ROOTWORK}/drivers-dphys/modules.tgz \ -C ${SYS_ROOTWORK}/modules-dphys . # pack new modconf into modconf.tgz in drivers-dphys /bin/tar zcf ${SYS_ROOTWORK}/drivers-dphys/modconf.tgz \ -C ${SYS_ROOTWORK}/modconf-dphys . # pack drivers archive subset file into root-dphys # this avoids need for separate drivers floppys /bin/tar zcf ${SYS_ROOTWORK}/root-dphys/${SYS_DRIVERSTGZ_ON_FLOPPY} \ -C ${SYS_ROOTWORK}/drivers-dphys . # - replace Debians dbootstrap with our automatic script and our/its setup /bin/echo "* packing in our replacement dbootstrap ..." /bin/cp -p dbootstrap ${SYS_ROOTWORK}/root-dphys/sbin /bin/chown root.root ${SYS_ROOTWORK}/root-dphys/sbin/dbootstrap /bin/chmod 755 ${SYS_ROOTWORK}/root-dphys/sbin/dbootstrap /bin/cp -p setup-dphys2 ${SYS_ROOTWORK}/root-dphys/etc /bin/chown root.root ${SYS_ROOTWORK}/root-dphys/etc/setup-dphys2 # *** WARNING *** # this file must be chmod 600 because of LILO and root passwords in it! /bin/chmod 600 ${SYS_ROOTWORK}/root-dphys/etc/setup-dphys2 # - and give our script the /sbin/sfdisk it needs /bin/echo "* packing in sfdisk, used by replacement dbootstrap ..." /bin/cp -p sfdisk ${SYS_ROOTWORK}/root-dphys/sbin /bin/chown root.root ${SYS_ROOTWORK}/root-dphys/sbin/sfdisk /bin/chmod 755 ${SYS_ROOTWORK}/root-dphys/sbin/sfdisk # - and give dbootstrap the lilo.conf template it needs /bin/echo "* packing in lilo.conf used by replacement dbootstrap ..." /bin/cp -p lilo.conf ${SYS_ROOTWORK}/root-dphys/${SYS_LILOCONF_ON_FLOPPY} /bin/chown root.root ${SYS_ROOTWORK}/root-dphys/${SYS_LILOCONF_ON_FLOPPY} /bin/chmod 644 ${SYS_ROOTWORK}/root-dphys/${SYS_LILOCONF_ON_FLOPPY} if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/echo "--- debug info ---" /bin/ls -al ${SYS_ROOTWORK}/root-dphys read dummy fi # --- fudge up debconf, so that we don't get base-config dialogs /bin/echo "-------------------------------------------------------------------" /bin/echo "*** Include debconf script, 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 /bin/cp -p debconf-preload ${SYS_ROOTWORK}/root-dphys/${SYS_PRELOAD_ON_FLOPPY} /bin/chown root.root ${SYS_ROOTWORK}/root-dphys/${SYS_PRELOAD_ON_FLOPPY} /bin/chmod 755 ${SYS_ROOTWORK}/root-dphys/${SYS_PRELOAD_ON_FLOPPY} if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/echo "--- debug info ---" /bin/ls -al ${SYS_ROOTWORK}/root-dphys read dummy fi # --- package to use swapfile, so that we can avoid fixed size swap partition if [ x${CONF_SWAP_FILE} != x ] ; then /bin/echo "---------------------------------------------------------------" /bin/echo "*** Include dphys2-swapfile package, to manage swapfile *** ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # for this we add an package that will be installed by dbootstrap # after all the first stage install, but before reboot, chrooted to /target # and then installed by an base-config script before starting large work /bin/cp -p dphys2-swapfile_*.deb \ ${SYS_ROOTWORK}/root-dphys/${SYS_SWAPDEB_ON_FLOPPY} if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/echo "--- debug info ---" /bin/ls -al ${SYS_ROOTWORK}/root-dphys read dummy fi 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 "*** Include user script, user specific further automation *** ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi if [ ! -f ${CONF_ENDFIRSTRUN_SCRIPT} ] ; then /bin/echo "error: CONF_ENDFIRSTRUN_SCRIPT feature enabled in setup," \ "but file ${CONF_ENDFIRSTRUN_SCRIPT} is missing" 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 /bin/cp -p ${CONF_ENDFIRSTRUN_SCRIPT} \ ${SYS_ROOTWORK}/root-dphys/${SYS_ENDFIRSTRUN_ON_FLOPPY} /bin/chown root.root ${SYS_ROOTWORK}/root-dphys/${SYS_ENDFIRSTRUN_ON_FLOPPY} /bin/chmod 755 ${SYS_ROOTWORK}/root-dphys/${SYS_ENDFIRSTRUN_ON_FLOPPY} if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/echo "--- debug info ---" /bin/ls -al ${SYS_ROOTWORK}/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 /bin/dd if=/dev/zero of=${SYS_ROOTWORK}/root-dphys.bin bs=1024 count=8192 # we need slightly over 3000 inodes, this gives us 8192*1024/2048=4096 inodes /sbin/mke2fs -i 2048 -F ${SYS_ROOTWORK}/root-dphys.bin # pack root file system onto floppy image ROOTFLOPPY=${SYS_ROOTWORK}/floppy /bin/mkdir -p ${ROOTFLOPPY} /bin/mount -o loop ${SYS_ROOTWORK}/root-dphys.bin ${ROOTFLOPPY} /bin/tar cf - -C ${SYS_ROOTWORK}/root-dphys . | \ /bin/tar xpf - -C ${ROOTFLOPPY} /bin/umount ${ROOTFLOPPY} /bin/rm -rf ${ROOTFLOPPY} # compress own root image so that it becomes kernel boot ramdisk mountable # compressed so that it fits on floppy # maximising space that will fit is more important than runtime, so -9 if [ -f ${SYS_ROOTWORK}/root-dphys.bin.gz ] ; then /bin/rm ${SYS_ROOTWORK}/root-dphys.bin.gz fi /bin/gzip -9 ${SYS_ROOTWORK}/root-dphys.bin if [ `/usr/bin/basename ${SYS_OWNROOT}` != root-dphys.bin.gz ] ; then mv ${SYS_ROOTWORK}/root-dphys.bin.gz \ ${SYS_ROOTWORK}/`/usr/bin/basename ${SYS_OWNROOT}` fi if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/echo "--- debug info ---" /bin/ls -al ${SYS_ROOTWORK}/`/usr/bin/basename ${SYS_OWNROOT}` read dummy fi # --- tidy up after working /bin/echo "-----------------------------------" /bin/echo "*** tidying up from working *** ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # remove all root owned directories, so user can clean up without being root if [ x${DEBUG_LEAVE_UNPACKED} != xyes ] ; then # but offer to leave them to investigate bugs /bin/rm -rf ${SYS_ROOTWORK}/modules-dphys /bin/rm -rf ${SYS_ROOTWORK}/drivers-dphys /bin/rm -rf ${SYS_ROOTWORK}/modconf-dphys /bin/rm -rf ${SYS_ROOTWORK}/modules /bin/rm -rf ${SYS_ROOTWORK}/drivers /bin/rm -rf ${SYS_ROOTWORK}/root-dphys fi if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/echo "--- debug info ---" /bin/ls -al ${SYS_ROOTWORK} read dummy fi