See also Multistrap
Customising Rootfs
For the embedded context an optional rootfs-config script can be run after the rootfs has been generated, because often /etc/fstab, /etc/inittab, /etc/hosts, /etc/securetty, /etc/modules (for example) need to be modified before the rootfs will boot enough to be configured.
Here is an example script (as used on balloon3):
set -e -x # Emdebian grip compatibility version # variant tcl-sl40 #pass path to the root. Don't let it run without one as it will break your system if [ "" = "$1" ] ; then echo "You need to specify a path to the target rootfs" else if [ -e "$1" ] ; then ROOTFS="$1" else echo "Root dir $ROOTFS not found" fi fi if [ "/" = "ROOTFS" ] ; then echo "Refusing to change your build system's files" ; fi #Do things that need to be done at 1st stage so that rootfs will boot. #Set securetty #Add modules - e.g. to support USB serial/ethernet console # specify config to use if [ "" = "$2" ] ; then CONFIG="files" fi if [ -d "$2" ] ; then CONFIG="$2" else echo "Config dir $CONFIG not found" fi #read in settings for $CONSOLE if [ -e config ] ; then . config fi #add serial ports to securetty - now idempotent DONECONSOLE=`grep $CONSOLE $ROOTFS/etc/securetty || true` if [ -z "$DONECONSOLE" ]; then echo "$CONSOLE" >> $ROOTFS/etc/securetty fi DONETELNET=`grep pts/0 $ROOTFS/etc/securetty || true` if [ -z "$DONETELNET" ]; then echo "pts/0" >> $ROOTFS/etc/securetty fi #put our standard fstab and network and modules files in if [ ! -d $ROOTFS/etc/network ]; then mkdir -p $ROOTFS/etc/network; fi if [ ! -d $ROOTFS/etc/init.d ]; then mkdir -p $ROOTFS/etc/init.d; fi if [ ! -d $ROOTFS/etc/dhcp3 ]; then mkdir -p $ROOTFS/etc/dhcp3; fi if [ ! -d $ROOTFS/etc/apt/apt.conf.d/ ]; then mkdir -p $ROOTFS/etc/apt/apt.conf.d/ fi cp -v $CONFIG/fstab $ROOTFS/etc/fstab cp -v $CONFIG/interfaces $ROOTFS/etc/network/interfaces cp -v $CONFIG/modules $ROOTFS/etc/modules cp -v $CONFIG/dhclient.conf $ROOTFS/etc/dhcp3/ cp -v $CONFIG/urandom $ROOTFS/etc/init.d/ cp -v $CONFIG/inittab $ROOTFS/etc/ cp -v $CONFIG/10disablerecommends $ROOTFS/etc/apt/apt.conf.d/ # make sure sudo uses group sudo by default rm -f $ROOTFS/etc/sudoers cp -v $CONFIG/sudoers $ROOTFS/etc/ chmod 400 $ROOTFS/etc/sudoers # creating devices (cd $ROOTFS/dev; /dev/MAKEDEV -v fb ) (cd $ROOTFS/dev; /dev/MAKEDEV -v ttyS0 ttyS1 ttyS2 ) (cd $ROOTFS/dev; /dev/MAKEDEV -v sd ) (cd $ROOTFS/dev; /dev/MAKEDEV -v mtd ) (cd $ROOTFS/dev; mknod rtc c 253 0 ) #mutter - it makes mtd butnot mtdblock - patch MAKEDEV? (cd $ROOT/FSdev; /dev//MAKEDEV -v mtdblock{0..7}) (cd $ROOTFS/dev; mkdir -p mtdblock; for DEVICE in 0 1 2 3 4 5 6 7; do mknod mtdblock/$DEVICE b 31 $DEVICE; done) # making devices so far missing between old and new multistrap versions preventing # chroot from running into newly untarred rootfs (cd $ROOTFS/dev; /dev/MAKEDEV -v std ) (cd $ROOTFS/dev; /dev/MAKEDEV -v fd ) (cd $ROOTFS/dev; /dev/MAKEDEV -v ptmx ) # tidy up after old multistrap code if [ -f $ROOTFS/etc/apt/sources.list.d/sources.list ]; then rm -v $ROOTFS/etc/apt/sources.list.d/sources.list fi #set hostname echo sl40 > $ROOTFS/etc/hostname #be nice to put these in the right places in files (perl -pi?) echo "127.0.0.1 localhost.localdomain localhost" > ${ROOTFS}/etc/hosts echo "127.0.1.1 sl40 sl40" >> ${ROOTFS}/etc/hosts