#!/bin/sh # http://www.phys.ethz.ch/~franklin/Projects/dphys2/dbootstrap # - replaces /sbin/dbootstrap of install root floppy of Debian woody (3.0) # copyright ETH Zuerich Physics Deparement, use under either BSD or GPL license # author Neil Franklin, last modification 2002.12.18 # this script replaces the Debian /sbin/dbootstrap binary program # whose purpose is to install an basic Debian system # this replacement does so without asking lots of question - automatically # so that we can install 100s of machines without lots of work time usage # ------ read in setup . /etc/setup-dphys2 # ------ announce that we are running /bin/echo "============================================================" /bin/echo "*** dphys2 Debian 3.0 (woody) simple automated installer ***" /bin/echo "============================================================" /bin/echo /bin/sleep ${SLEEP} # ------ host specific stuff, changes for each host - ask user at install # ensure that rescue floppy is re-inserted into drive, for fetching kernel /bin/echo "-> eject root floppy, so that later reboot from HD does not fail <-" /bin/echo # ask user for hostname and IP address /bin/echo -n "enter hostname: " read CONF_HOSTNAME /bin/echo -n "enter IP address: " read CONF_IPADDR /bin/echo "no further questions will be asked, now auto-installing ..." # ------ from here on code to do the actual actions, follows Debians menus # --- "Configure the Keyboard" menu, replaces configure_keyboard() # set our standard keyboard /bin/echo "---------------------------------------------------" /bin/echo "*** Configure the Keyboard *** to ${CONF_KEYBD} ..." /bin/sleep ${SLEEP} /bin/echo "KEYBD='${CONF_KEYBD}'" > /tmp/keybd_settings /bin/zcat /etc/keymaps.tgz | /bin/tar -xOf - ${CONF_KEYBD}.bmap | \ /sbin/loadkmap if [ ${DEBUG} = 1 ] ; then /bin/echo "--- debug info ---" /bin/cat /tmp/keybd_settings read dummy fi # --- "Partition a Hard Disk" menu, replaces partition_disk() # use an simple boot+swap+root configuration /bin/echo "------------------------------------------------------------------" /bin/echo "*** Partition a Hard Disk *** ${CONF_DISK} into boot+swap+root ..." /bin/sleep ${SLEEP} # sfdisk is command line driven fdisk, no menu # 16M Linux for /boot, ${CONF_SWAP_SIZE} Swap for swap, rest Linux for / /sbin/sfdisk -uM ${CONF_DISK} << EOF ,16,L ,${CONF_SWAP_SIZE},S ,,L ; EOF # generate partition names PART_BOOT=${CONF_DISK}1 PART_SWAP=${CONF_DISK}2 PART_ROOT=${CONF_DISK}3 # and number for "activate" PART_BOOT_NO=1 if [ ${DEBUG} = 1 ] ; then /bin/echo "--- debug info ---" /sbin/fdisk -l ${CONF_DISK} read dummy fi # --- "Initialize and Activate a Swap Partition" menu, replaces init_swap() # straightforward usage of our swap partition /bin/echo "--------------------------------------------------------------------" /bin/echo "*** Initialize and Activate a Swap Partition *** on ${PART_SWAP} ..." /bin/sleep ${SLEEP} /sbin/mkswap ${PART_SWAP} /sbin/swapon ${PART_SWAP} if [ ${DEBUG} = 1 ] ; then /bin/echo "--- debug info ---" /usr/bin/free read dummy fi # --- "Initialize a Linux Partition" menu, twice, replaces init_linux() # first set up our root partition /bin/echo "----------------------------------------------------------------" /bin/echo "*** Initialize a Linux Partition *** of root on ${PART_ROOT} ..." /bin/sleep ${SLEEP} /sbin/mkfs.ext2 ${PART_ROOT} /bin/mount ${PART_ROOT} /target # second add our boot partition /bin/echo "*** Initialize a Linux Partition *** of boot on ${PART_BOOT} ..." /sbin/mkfs.ext2 ${PART_BOOT} /bin/mkdir /target/boot /bin/mount ${PART_BOOT} /target/boot if [ ${DEBUG} = 1 ] ; then /bin/echo "--- debug info ---" /bin/mount read dummy fi # --- "Install Kernel and Driver Modules menu", # replaces extract_kernel_and_modules() and choose_and_install() /bin/echo "--------------------------------------------------------------" /bin/echo "*** Install Kernel and Driver Modules menu *** from floppy ..." /bin/sleep ${SLEEP} # - subpart check_pending_config() # just duplicate Debian code effects, write config sofar exists to disk /bin/echo "* writing base config setting to disk ..." /bin/mkdir /target/root /bin/echo "BUILDTIME='2002.01.01-07:53+0000'" >/target/root/dbootstrap_settings /bin/cat /tmp/keybd_settings >> /target/root/dbootstrap_settings /bin/echo "LANG_INST='C'" >> /target/root/dbootstrap_settings /bin/echo "LANGUAGE_INST='en'" >> /target/root/dbootstrap_settings if [ ${DEBUG} = 1 ] ; then /bin/echo "--- debug info ---" /bin/cat /target/root/dbootstrap_settings read dummy fi # - subpart install_floppy() # install kernel, requires rescue floppy to be in drive after boot # *** do not do this here, wait until net working then install from net *** #/bin/echo "* installing kernel from rescue disk in /dev/fd0 ..." # ## Debian uses here -t auto, but -t msdos avoids warning messages #/bin/mount -r -t msdos /dev/fd0 /floppy ## allow retries if it fails (say due to an wrong disk) #while [ ! -f /floppy/type.txt ] ; do # /bin/echo dbootstrap Error: no rescue floppy in /dev/fd0, insert proper # # give User chance for corrective action, possibly using 2nd console # read dummy #done #cd /floppy #./install.sh /target #cd / #/bin/umount /floppy # #if [ ${DEBUG} = 1 ] ; then # /bin/echo "--- debug info ---" # /bin/ls -al /target /target/boot # read dummy #fi # - subpart install_floppies() # install drivers, small selection instead of 4 disks, no disk jockey /bin/echo "* installing our small selection of drivers ..." /bin/mkdir /target/tmp; chown 0.3 /target/tmp; chmod 01777 /target/tmp /bin/mkdir /target/tmp/drivers; chown 0.3 /target/tmp/drivers; # here Debian fetches the 4 drivers disks to /target/drivers.tgz # we have already included an small drivers file on this root disk # because this is incomplete we will have to add all the rest later from net /bin/cp -p ${DRIVERS_TGZ} /target/drivers.tgz cd /target/tmp/drivers /bin/zcat /target/drivers.tgz | tar -x ./install.sh /target cd / /bin/rm /target/drivers.tgz if [ ${DEBUG} = 1 ] ; then /bin/echo "--- debug info ---" /bin/ls -alR /target/lib/modules read dummy fi # - back from choose_and_install() do frob_lib_modules() # from install system to use now installed modules /bin/echo "* using installed modules while install ..." /bin/rm -rf /lib/modules.old /bin/mv /lib/modules /lib/modules.old /bin/ln -s /target/lib/modules /lib/modules # - back from frob_lib_modules() /sbin/depmod -a if [ ${DEBUG} = 1 ] ; then /bin/echo "--- debug info ---" /bin/ls -ald /lib/modules* read dummy fi # --- "Configure Device Driver Modules" menu, replaces configure_drivers() # try to activate all our possible Ethernet drivers /bin/echo "-------------------------------------------------------------------" /bin/echo "*** Configure Device Driver Modules*** for our Ethernet drivers ..." /bin/sleep ${SLEEP} /sbin/depmod -a /bin/echo /sbin/modprobe >/proc/sys/kernel/modprobe /usr/bin/test -f /target/etc/modules || cp /etc/modules /target/etc/ # here Debian uses GUI modconf to ask which drivers to install # we simply try through all our few pre-selected drivers # ***BUGFIX*** Debian only does this "cp" for s390, we need it also for x86 # perhaps this is a difference of modconf GUI vs --load-only mode /bin/cp -a /etc/modules.conf /target/etc/ for module in ${MODULESNET}; do modulebase=`/bin/echo $module | /usr/bin/cut -f 1 -d "."` /target/usr/sbin/modconf --target /target --libdir /tmp/drivers \ --load-only ${modulebase} done # then we add our driver line to /etc/modules /sbin/lsmod | /bin/grep -v ^Modules | /bin/grep -v ^unix | \ /bin/grep -v ^af_packet | /usr/bin/cut -f 1 -d " " >> /target/etc/modules /bin/echo /bin/true >/proc/sys/kernel/modprobe if [ ${DEBUG} = 1 ] ; then /bin/echo "--- debug info ---" /bin/cat /target/etc/modules /sbin/lsmod read dummy fi # --- "Configure the Network" menu, replaces configure_static_network() # set network for system given up at top of script /bin/echo "--------------------------------------------------------" /bin/echo "*** Configure the Network *** for our network config ..." /bin/sleep ${SLEEP} # - subpart write_common_network() # just duplicate Debian code effects, writing various config files /bin/echo "* writing common net config files to disk ..." /bin/mkdir /target/etc/network /bin/echo "${CONF_HOSTNAME}" > /target/etc/hostname /bin/echo "127.0.0.1 ${CONF_HOSTNAME}" > /target/etc/hosts /bin/echo "# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)" > /target/etc/network/interfaces /bin/echo "" >> /target/etc/network/interfaces /bin/echo "# The loopback interface" >> /target/etc/network/interfaces /bin/echo "auto lo" >> /target/etc/network/interfaces /bin/echo "iface lo inet loopback" >> /target/etc/network/interfaces if [ ${DEBUG} = 1 ] ; then /bin/echo "--- debug info ---" /bin/ls -al /target/etc read dummy fi # - subpart write_static_network() # just duplicate Debian code effects, writing various config files /bin/echo "* writing static net config files to disk ..." /bin/echo "127.0.0.1 localhost" > /target/etc/hosts /bin/echo "${CONF_IPADDR} ${CONF_HOSTNAME}.${CONF_DOMAIN}" >> /target/etc/hosts /bin/echo "localnet ${CONF_NETWORK}" > /target/etc/networks /bin/echo "search ${CONF_DOMAIN}" > /target/etc/resolv.conf /bin/echo "nameserver ${CONF_NAMESERVER1}" >> /target/etc/resolv.conf if [ x${CONF_NAMESERVER2} != x ] ; then /bin/echo "nameserver ${CONF_NAMESERVER2}" >> /target/etc/resolv.conf fi if [ x${CONF_NAMESERVER3} != x ] ; then /bin/echo "nameserver ${CONF_NAMESERVER3}" >> /target/etc/resolv.conf fi if [ x${CONF_NAMESERVER4} != x ] ; then /bin/echo "nameserver ${CONF_NAMESERVER4}" >> /target/etc/resolv.conf fi /bin/echo "# The first network card - this entry was created during the Debian/dphys2 installation" >> /target/etc/network/interfaces /bin/echo "# (network, broadcast and gateway are optional)" >> /target/etc/network/interfaces /bin/echo "auto eth0" >> /target/etc/network/interfaces /bin/echo "iface eth0 inet static" >> /target/etc/network/interfaces /bin/echo -e "\taddress ${CONF_IPADDR}" >> /target/etc/network/interfaces /bin/echo -e "\tnetmask ${CONF_NETMASK}" >> /target/etc/network/interfaces /bin/echo -e "\tnetwork ${CONF_NETWORK}" >> /target/etc/network/interfaces /bin/echo -e "\tbroadcast ${CONF_BROADCAST}" >> /target/etc/network/interfaces /bin/echo -e "\tgateway ${CONF_GATEWAY}" >> /target/etc/network/interfaces if [ ${DEBUG} = 1 ] ; then /bin/echo "--- debug info ---" /bin/ls -al /target/etc read dummy fi # - subpart activate_static_network() # just duplicate Debian code effects, writing various config files /bin/echo "* activating static net config ..." /bin/rm /etc/resolv.conf /bin/ln -s /target/etc/resolv.conf /etc/resolv.conf /sbin/ifconfig lo 127.0.0.1 /sbin/ifconfig eth0 down /sbin/ifconfig eth0 ${CONF_IPADDR} netmask ${CONF_NETMASK} \ broadcast ${CONF_BROADCAST} /sbin/route add default gw ${CONF_GATEWAY} metric 1 if [ ${DEBUG} = 1 ] ; then /bin/echo "--- debug info ---" /sbin/ifconfig read dummy fi # --- second "Install Kernel and Driver Modules menu", now that net is running /bin/echo "-----------------------------------------------------------" /bin/echo "*** Install Kernel and Driver Modules menu *** from net ..." /bin/sleep ${SLEEP} # - subpart install_floppy() # install kernel, requires network /bin/echo "* installing kernel from rescue floppy image from net ..." # "insert" rescue floppy image from network /usr/bin/wget -P /target http://${CONF_DEBSERVER}/${CONF_DEBDIR}/${DEBRESCUE} # Debian uses here -t auto, but -t msdos avoids warning messages /bin/mount -r -t msdos -o loop /target/rescue.bin /floppy # allow retries if it fails (say due to an wrong disk) while [ ! -f /floppy/type.txt ] ; do /bin/echo dbootstrap Error: no rescue floppy in /dev/fd0, insert proper # give User chance for corrective action, possibly using 2nd console read dummy done cd /floppy ./install.sh /target cd / /bin/umount /floppy # "eject" rescue floppy image from network rm /target/rescue.bin if [ ${DEBUG} = 1 ] ; then /bin/echo "--- debug info ---" /bin/ls -al /target /target/boot read dummy fi # - subpart install_floppies() # install drivers, full set, as now can be fetched from net /bin/echo "* installing drivers from drivers.tgz from net ..." # these directories still exit from first driver install #/bin/mkdir /target/tmp; chown 0.3 /target/tmp; chmod 01777 /target/tmp #/bin/mkdir /target/tmp/drivers; chown 0.3 /target/tmp/drivers; # here Debian fetches the 4 drivers disks to /target/drivers.tgz # we fetch the full drivers.tgz file from the net /usr/bin/wget -P /target http://${CONF_DEBSERVER}/${CONF_DEBDIR}/${DEBDRIVERS} cd /target/tmp/drivers /bin/zcat /target/drivers.tgz | tar -x ./install.sh /target cd / /bin/rm /target/drivers.tgz if [ ${DEBUG} = 1 ] ; then /bin/echo "--- debug info ---" /bin/ls -al /target/lib/modules/* read dummy fi # - back from choose_and_install() do frob_lib_modules() # symlink is already set from first driver install #/bin/rm -rf /lib/modules.old #/bin/mv /lib/modules /lib/modules.old #/bin/ln -s /target/lib/modules /lib/modules # - back from frob_lib_modules() /sbin/depmod -a if [ ${DEBUG} = 1 ] ; then /bin/echo "--- debug info ---" /bin/ls -ald /lib/modules* read dummy fi # --- "Install the Base System" menu, replaces debootstrap_extract_base() # install base.tgz, fetching it from now running network, no floppies /bin/echo "------------------------------------------------" /bin/echo "*** Install the Base System *** from network ..." /bin/sleep ${SLEEP} # thankfully Debian put all this stuff into an separate program # so we can just run it unchanged /bin/echo "* running debootstrap to install base.tzg ..." # test whether download works omitted: #/usr/bin/wget -q $SOURCE/dists/woody/Release # we get it via standard http, so no need to set up NFS to get it /usr/sbin/debootstrap --arch ${ARCH} woody /target \ http://${CONF_DEBSERVER}/${CONF_DEBDIR}/ /bin/echo "DEBIAN_MIRROR_HOSTNAME='${CONF_DEBSERVER}'" \ >> /target/root/dbootstrap_settings /bin/echo "DEBIAN_MIRROR_METHOD='http'" >> /target/root/dbootstrap_settings /bin/echo "DEBIAN_MIRROR_PATH='${CONF_DEBDIR}'" \ >> /target/root/dbootstrap_settings /bin/echo "DEBIAN_MIRROR_PORT='80'" >> /target/root/dbootstrap_settings /bin/echo "SUITE='testing'" >> /target/root/dbootstrap_settings /bin/mv /target/etc/inittab /target/etc/inittab.real /bin/cp /etc/inittab.install /target/etc/inittab if [ ${DEBUG} = 1 ] ; then /bin/echo "--- debug info ---" /bin/cat /target/root/dbootstrap_settings read dummy fi # - subpart write_fstab() # surprising that they do this so late /bin/echo "* generating fstab ..." /bin/echo "# /etc/fstab: static file system information." > /target/etc/fstab /bin/echo "#" >> /target/etc/fstab /bin/echo -e "# \t\t\t\t\t\t\t" >> /target/etc/fstab /bin/echo -e "${PART_ROOT}\t/\t\text2\tdefaults,errors=remount-ro\t0\t1" >> /target/etc/fstab /bin/echo -e "${PART_SWAP}\tnone\t\tswap\tsw\t\t\t0\t0" >> /target/etc/fstab /bin/echo -e "proc\t\t/proc\t\tproc\tdefaults\t\t\t0\t0" >> /target/etc/fstab /bin/echo -e "${PART_BOOT}\t/boot\t\text2\tdefaults\t0\t2" >> /target/etc/fstab if [ ${DEBUG} = 1 ] ; then /bin/echo "--- debug info ---" /bin/cat /target/etc/fstab read dummy fi # - subpart configure_base() # this is actually outdated code, but do it for safety /bin/echo "* tidying up unconfigured.sh ..." /bin/rm -f /target/sbin/unconfigured.sh if [ ${DEBUG} = 1 ] ; then /bin/echo "--- debug info ---" /bin/ls -al /target read dummy fi # --- "Make System Bootable" menu, replaces make_bootable() # setup LILO to boot system /bin/echo "---------------------------------------------------------------" /bin/echo "*** Make System Bootable *** with LILO, mbr, boot partition ..." /bin/sleep ${SLEEP} # we are putting LILO in the MBR (unclean), because bug using mbr and in ROOT # the boot code does not get written (or written and then overwriten?) # and this is a single-OS system anyway, and its better for security anyway # lilo.conf is 1/4 size of this script, so don't generate it, use template file # replace template %PLACEHOLDER% place holders with entire actual lines if [ x${CONF_PASSWORD_LILO} != x ] ; then /bin/sed -e "s@%PART_BOOT%@boot=${CONF_DISK}@" \ -e "s@%PART_ROOT%@root=${PART_ROOT}@" \ -e "s@%PASSWORD%@password=${CONF_PASSWORD_LILO}@" \ -e "s@%RESTRICTED%@restricted@" \ ${LILO_CONF} > /target/etc/lilo.conf else # user did not want an LILO password /bin/sed -e "s@%PART_BOOT%@boot=${CONF_DISK}@" \ -e "s@%PART_ROOT%@root=${PART_ROOT}@" \ -e "s@%PASSWORD%@# no password installed@" \ -e "s@%RESTRICTED%@# restricted if password were set@" \ ${LILO_CONF} > /target/etc/lilo.conf fi # *** WARNING *** # this file must be chmod 600 because of LILO password in it /bin/chmod 600 /target/etc/lilo.conf /usr/sbin/chroot /target /sbin/lilo # activate boot partition export LD_LIBRARY_PATH=\"/target/lib:/target/usr/lib\"; \ /target/sbin/activate ${CONF_DISK} ${PART_BOOT_NO} if [ ${DEBUG} = 1 ] ; then /bin/echo "--- debug info ---" /sbin/fdisk -l ${CONF_DISK} read dummy fi # --- fix up installed system so that 2nd boot stage has no dialogs # this is not part of the normal Debian installation program # fix up debconf database to prevent base-config dialogs /bin/echo "---------------------------------------------------------" /bin/echo "*** fixing up debconf *** for no dialogs after reboot ..." /bin/sleep ${SLEEP} # debconf-pleload is 1/2 size of this script, don't generate, use template file # replace template %PLACEHOLDER% place holders with actual content (no lines) /bin/sed -e "s@%DEBCONF_DB%@${DEBCONF_DB}@" \ -e "s@%CONF_TIMEZOME_AREA%@${CONF_TIMEZOME_AREA}@" \ -e "s@%CONF_TIMEZOME_PLACE%@${CONF_TIMEZOME_PLACE}@" \ -e "s@%CONF_PASSWORD_MD5%@${CONF_PASSWORD_MD5}@" \ -e "s@%CONF_PASSWORD_SHADOW%@${CONF_PASSWORD_SHADOW}@" \ -e "s@%CONF_PASSWORD_ROOT%@${CONF_PASSWORD_ROOT}@" \ -e "s@%CONF_PCMCIA_REMOVE%@${CONF_PCMCIA_REMOVE}@" \ -e "s@%CONF_DEBSERVER%@${CONF_DEBSERVER}@" \ -e "s@%CONF_DEBDIR%@${CONF_DEBDIR}@" \ -e "s@%CONF_PCMCIA_REMOVE%@${CONF_PCMCIA_REMOVE}@" \ -e "s@%CONF_USE_CONTRIB%@${CONF_USE_CONTRIB}@" \ -e "s@%CONF_USE_NON_FREE%@${CONF_USE_NON_FREE}@" \ -e "s@%CONF_DEBSERVER_NON_US%@${CONF_DEBSERVER_NON_US}@" \ -e "s@%CONF_DEBDIR_NON_US%@${CONF_DEBDIR_NON_US}@" \ -e "s@%CONF_DEBSUBDIR_NON_US%@${CONF_DEBSUBDIR_NON_US}@" \ -e "s@%CONF_DEBSERVER_SECURITY%@${CONF_DEBSERVER_SECURITY}@" \ -e "s@%CONF_DEBDIR_SECURITY%@${CONF_DEBDIR_SECURITY}@" \ -e "s@%CONF_DEBSUBDIR_SECURITY%@${CONF_DEBSUBDIR_SECURITY}@" \ -e "s@%CONF_DEBSERVER_LOCAL%@${CONF_DEBSERVER_LOCAL}@" \ -e "s@%CONF_DEBDIR_LOCAL%@${CONF_DEBDIR_LOCAL}@" \ -e "s@%CONF_DEBSUBDIR_LOCAL%@${CONF_DEBSUBDIR_LOCAL}@" \ ${PRELOAD_ON_FLOPPY} > /target${PRELOAD_ON_TARGET} # *** WARNING *** # this file must be chmod 700 because of root password in it /bin/chmod 700 /target${PRELOAD_ON_TARGET} /usr/sbin/chroot /target ${PRELOAD_ON_TARGET} /bin/rm /target${PRELOAD_ON_TARGET} if [ ${DEBUG} = 1 ] ; then /bin/echo "--- debug info ---" /bin/ls -al /target read dummy fi # --- "Reboot the System" menu, replaces reboot_system() # reboot into 2nd stage of install /bin/echo "----------------------------------------------" /bin/echo "*** Reboot the System *** for second stage ..." /bin/sleep ${SLEEP} /bin/sync /bin/umount /instmnt /bin/cp /var/log/messages /target/var/log/installer.log # this will work on ${DEBUG} = 1 or = 2 if [ ${DEBUG} != 0 ] ; then /bin/echo "--- debug info ---" /bin/df /usr/bin/free read dummy fi /sbin/reboot