summaryrefslogblamecommitdiffstats
path: root/initramfs/initrd-stuff/init
blob: 4fcae3bd038408cdff8283346235d23f37aa8ff3 (plain) (tree)
1
2
3
4
5
6
7
8
9
         




                                                                    
 

                                                                         
 
                                                                      
 

                                                                        
 
                                                                             
                                                                        
                                                                            

                                                                    
               

                                                             

                                                                    
                                                              
                                            
                                                                     
             


                                                                      
 
 
                                          
                             
 
                   


                                       
 


                            
                                                                  

                                                                 
 
                                                                
                                 


                          
 
                                          
                                                     
                                                   
 
                                  

                                                    
 





                                                                

                                                                     



               
 

                                                                      
             
 
                                                                           
                                            
       
                                               
 

                                                                           
 

                                                                   

                              
                              
                         









                                                                            
                                    

                    
                                    
            
                               

                                                      
      

                                                        
                

                       

                                               
                

                       
                                                             
           
                

                       

                                                                     
                                                     
         
                

                       
                                                                  
           

                           

                       

                                            
                  
                                                     
            

                              
      
                                                                 
            
                 
                                                                          
                                                     
              
               
                               
      

                                                            
                                   
             

                                        

                       
                                                       

                                               
                                                                       
                                                                           




                                                                         


                                             





                                    


                                                  

          

                                              
             
                                     

                                                          
                          
                                                            
              
                              

                 


                                                                             


                                                          
                                    

                                                                           
          
                        
          
               

      


                                                                          
                                                      




                                                     

                      



                              
  
 
                                                            
                                                      
                                                                           

                                                                             
                                                                    


                                                                
                                                         
      
                       

    

                                                                         
                                                                     
                             




                                                           

                 
                                                           
                                                                        

                                 
                                         
                                          
                                                          
          

                                              
                                                                





                                          
                                                                     
                                                                  
  
                              
               
 
                                                                           
                                                                  
                                                      

                   
                               
 

                                                                   
                          
            
                                           
                           

                                       
                            




                                                                         
                                                                 

                                              
                                                              


               
                                                                         
                                                          
                                  


                              
                                               
                                                          
                                                         

                                                                 

                                                       
                                                                  
                                          
                            
                                          
                           
 
                                                                    
                            
                                      
                                                      
                             
                                   
                             




                                                                             
                                                                             
                                                                
 
                     

                                                     
                    
                                                     
                                                       
                  
          
                


                                                    

                                
                 






                                                                              
                                                      
                                                                   
                  
          
                                                     
                     
        
      
           
                                                 

                                    
                   
                               
    

                                 
                            
                 

                                                         
                                                       
                                             
              
                                  
                                        
              


                                                              
         

                                                            
            

                                  
                                     
             
                                                                 
      
                                                                            
                                 

                                                                            
                                  

                                                                            






                                                                   
  
 
                                                                     
                                                             


                                                                  
  
                              
                                                 
                                                       
                      


                                                        
                                        
                                                                    
  
 

                                                                      
                      


                                                                      
                                                        

         

                                                                         
                  
  

                                               
                                              

                                  
                 
  
 
                                                                          
                             
                                    

                                                     
                                                   
                                
                                                                      
             
                        
                                                 
                               
                                                                       
                                                                           
                               

                               
                            
                              

                                                                   
                
    
                                                            
       



                                                
                               
                                                   
                                                       
                                

                                                 
                                                      
                                                                  
      
                 
       
                                                            
                                                                   
                                 
                                 
                            


                                                         


                                                                

                                                                
      

                                               



                                          
                                                                           
                                                             
                                                               
                                                                 

                                                              
                                       
                                     
      

                                       
                                                           
                      

                                                     
                                 

                              
                                                 
                                                                          
                                           

                                                               

                                                                        


                                                                             
 
                                                                       
                                             





                                
                                                                  

                      



                                                                    
                                                                    
                   
    

                                                        

                                                                       


                                                                      
                                                                     
                     

                                                           
 
                                 
                            



                                                  
      
                          

    
                                 
  
                                                                      
                                               

                                                   


                                                           

                                               
                                                                      
                                                  
                                                        
                              
 





                                                                       
                                                                    
        

                                                  
                               

                                                                         
                        
 


 
                                            
                                                    
 
                                            


                                                                        
                             
    
 
                                            
                                                                   
                                                                             

                                                                
                                                         
                                                         
                                                     
                                                 
                                               
                                       
                                                             
                             
 

                                                               
          

                                                

                                                                       
               
                                 
                                                                        
                                                                              
                            
                                                          
                                                                             
#!/bin/sh
# Copyright (c) 2003 - 2006 - RZ Uni Freiburg
# Copyright (c) 2006, 2007 - OpenSLX GmbH
#
# This program is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your feedback to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org
#
# main script for new type of initial ramdisk for OpenSLX linux diskless
# clients version 4

#############################################################################
# functions common for all distros, messages contains all error and info
# output (for some reason the error output is not produced properly - crash)

# how do the localization here? There is not yet a country-Variable 
. /etc/messages
. /etc/functions || ( echo -e $init_mff && sleep 100 )
. /etc/distro-functions || ( echo -e $init_dff && sleep 100 )
# distro specific configuration settings (several file and directory
# variables)
. /etc/sysconfig/config || ( echo -e $init_dscf && sleep 100 )
# configuration settings for slx environment
. /etc/sysconfig/slxconfig 2>/dev/null || ( echo -e ${init_sscf} && \
  sleep 100 )
# machine-setup configuration (common settings for all clients using a
# certain InitRamFS generated by slxmkramfs/mkdxsinitrd)
[ -f /etc/machine-setup ] && . /etc/machine-setup 2>/dev/null


export PATH=/bin:/sbin:/usr/bin/:/usr/sbin
export date="${slxconf_date}"

export DEBUGLEVEL=0
export KERNEL="${slxconf_kernver}"
export NWMODULES="${slxconf_listnwmod}"
export DISTRO="${slxconf_distro}"

# do not use dnbd cache file
nodnbdcache="yes"

# device files get their own filesystem (to be move mounted later)
devdir="/dev"
mount -n -t tmpfs -o 'size=25%,mode=0755' initramfsdevs ${devdir}

# copy basic device files into dev (later udev will handle that)
cp -a /tmp/null /tmp/console /dev
mkdir -p ${devdir}/pts
mkdir -p ${devdir}/shm
mkdir -p ${devdir}/.udevdb

# mount the important standard directories
[ ! -f /proc/cpuinfo ] && mount -n -t proc proc /proc
[ ! -d /sys/class ] && mount -n -t sysfs sysfs /sys

# fixme: shut down if script fails
trap "exec (sleep 30; echo o>/proc/sysrq-trigger)" \
  SIGHUP SIGINT SIGPIPE SIGTERM SIGIO

# if no kernel version is set, try to get it directly from /proc
if [ -z $KERNEL ] ; then
  KERNEL=$(cat /proc/version)
  KERNEL=${KERNEL#*version }
  KERNEL=${KERNEL% (*) (*}
fi
# set defaults for some important variables, might be overwritten via
# kernel commandline
tmpfssize="50%"
cowsize="50%"
rwdir=/dev/shm
nfsro="nfs"

# load usb modules for keyboard (reenable usb keyboards, otherwise the
# admin has to wait until second run of hwsetup late in stage3)
hwautocfg pre

# run pre init script and user defined preinit.local, copied by mkdxsinitrd
# from /var/lib/openslx/config/... in stage2
preinit
[ -x /bin/preinit.local ] && /bin/preinit.local

# start device auto discovery service - busybox or distro specific function
runudev

# switch off the several configuration methods, will be switched on
# according to kernel commandline settings
echo "noldap" > /tmp/ldap-done
echo "nodhcp" > /tmp/dhcp-done
echo "nofile" > /tmp/file-done
# read kernel commandline
read KCMDLINE < /proc/cmdline
export KCMDLINE
for opts in ${KCMDLINE} ; do
  case ${opts} in
    # localization
    country=*)
      COUNTRY=${opts#country=}
      echo -e "\n# localization information gotten via kernel command line \
in $0\ncountry=\"${COUNTRY}\"" >> /etc/machine-setup
    ;;
    # single token for debugging ...
    debug)
      DEBUGLEVEL=1;;
    # ... or a specified debug level
    debug=*)
      DEBUGLEVEL=${opts#debug=}
      [ $DEBUGLEVEL -eq 8 -o $DEBUGLEVEL -eq 20 ] && \
        echo "** SLX init started near $(sysup)"
    ;;
    # if configuration should be gathered by dhcp client
    dhcp)
      dhcp="yes"
      rm /tmp/dhcp-done
    ;;
    # if ldap configuration should be triggered
    ldap)
      ldap="yes"
      rm /tmp/ldap-done
    ;;
    # ldap configuration with host and port to contact (base)
    ldap=*)
      ldap="yes"
      rm /tmp/ldap-done
    ;;
    # if (external, via tftp) configuration file retrieval should be
    # triggered, if no source is given try dhcp server and predefined
    # standard path (.../tftpboot/client-config/ ...)
    file)
      file="yes"
      rm /tmp/file-done
    ;;
    # file source with tftp server and file location on the server
    file=*)
      file="yes"
      filesrc=${opts#file=}
      rm /tmp/file-done
    ;;
    # if ld.so.cache should not be generated
    noldsc)
      noldsc=yes;;
    # additional source to unify root filesystem with
    union=*)
      unionfs=1
      uniondirs=${opts#union=}
    ;;
    # if unionfs should be used over the complete root filesystem
    unionfs)
      unionfs=1;;
    # if cowloop should be used, only ontop of network block device and in
    # combination with classical fs, like ext2 useful
    cowloop=*)
      cowloop=1
      #cowsize=${opts#cowloop=}
    ;;
    # rootfs will void the variables (d)nbdroot, nfsroot ...
    # fixme: allow multiple rootfs sources to be unioned!?
    # if strinstr " " "$rootfs" ...
    rootfs=*)
      rootfs=${opts#rootfs=}
      srvproto=$(uri_token $rootfs prot)
      case $srvproto in
        nfs)
          # nfsroot consists now of two different parts
          root_path=/$(uri_token $rootfs path)
          nfsserver=$(uri_token $rootfs server)
          echo -e "\n# nfs root information gotten via kernel command \
line in $0\n#nfsroot=\"${nfsserver}:${root_path}\"\n" >> /etc/machine-setup
        ;;
        *nbd)
          nbdmod=$srvproto
          # get settings for nbd-client, filesystem equals to path in URI
          # notation
          nbdhost=$(uri_token $rootfs server)
          nbdport=$(uri_token $rootfs port)
          nbdrfst=$(uri_token $rootfs path)
        ;;
        aoe)
          echo "Not implemented yet"
        ;;
        iscsi)
          echo "Not implemented yet"
          #iscsiserver=$(uri_token $rootfs server)
          #iscsiport=$(uri_token $rootfs port)
          #iscsitarget=$(uri_token $rootfs path)
        ;;
      esac
    ;;
    # size of cache dnbd should use within ram
    dcsize=*)
      dnbdcachesize=${opts#dcsize=};;
    # ip configuration client-ip:server-ip:gateway:netmask
    ip=*)
      ipinfo=${opts#ip=};;
    # deprecated: nfs server and path (will be removed soon)
    nfsroot=*)
      nfsroot=${opts#nfsroot=}
      #root_path=
      #nfsserver=
      echo -e "\n# nfs root information gotten via kernel command line in \n\
$0\n# deprecated: please use rootfs=nfs://...\nnfsroot=\"${nfsroot}\"\n" \
>> /etc/machine-setup
    ;;
    # size of tempfs if not max. 50% of RAM should be used
    tmpfssize=*)
      tmpfssize=${opts#tmpfssize=};;
    # vendor code identifier for dhcp requests, that way odlx clients could
	# be distinguished from other (dhcp) clients
    vci=*)
      vci=${opts#vci=};;
    xenbr)
      xenbr=1;;
  esac
done
# at this point a timer should be started to ensure an automated reboot
# or halt of the machine if SLX init does not succeed (e.g. missing kernel
# module for the network adaptor)
if [ ${DEBUGLEVEL} -lt 3 -o ${DEBUGLEVEL} = 8 ] ; then
  [ -x /bin/busybox ] && shtype=a
  cat<<EOF > /bin/watchdog
#!/bin/${shtype}sh
echo \$$ > /tmp/watchdogpid
[ ! -f /proc/version ] && mount -n -t proc proc /proc
. /etc/functions
sleep 120 2> /dev/null
echo "o" > /proc/sysrq-trigger
EOF
  chmod u+x /bin/watchdog
  watchdog &
fi

# check if at least one type of IP configuration is availabe
if [ -z "$dhcp" -a -z "$ldap" -a -z "$ipinfo" ] ; then
  echo -e "# You did not specify any advanced configuration mode for your \
clients. You\n# might want to add the token 'dhcp' for DHCP configuration, \
'file(=source)'\n# for config file get via TFTP or 'ldap(=source)' for LDAP \
configuration to\n# your kernel command line." >> /etc/machine-setup
  if strinfile "clientip" /etc/machine-setup ; then
    # IP configuration seems to be present in machine-setup file
    . /etc/machine-setup
    ipinfo="ip=$clientip:$serverip:$gateway:$subnet_mask"
  else
    error "$init_errip"
  fi
fi
# for ldap configuration at least basic IP setup is needed to contact the
# server
[ -z "$dhcp" -a -n "$ldap" -a -z "$ipinfo" ] && error "$init_errldap"
# set debug level and logfile
if [ $DEBUGLEVEL -eq 20 ] ; then
  echo "** Setting debuglevel to ${DEBUGLEVEL} at $(sysup)"
else
  echo "Setting debuglevel to ${DEBUGLEVEL}"
fi
export MODPRV=" "
export LOGFILE
if [ "${DEBUGLEVEL}" -gt 0 -a "${DEBUGLEVEL}" != 8 ] ; then
  # if LOGFILE should be used within initial ramdisk add '/mnt' in front
  # of the variable
  LOGFILE="/var/log/dxs-boot.log"
  echo "1 4 1 7" >/proc/sys/kernel/printk
  [ "${DEBUGLEVEL}" -ge 2 ] && MODPRV="-v"
  [ "${DEBUGLEVEL}" -gt 3 -a "${DEBUGLEVEL}" -le 10 ] && {
    set -x
    # and the kernel too
    echo "7 7 7 7" >/proc/sys/kernel/printk; }
  [ "${DEBUGLEVEL}" -gt 10 -a "${DEBUGLEVEL}" -le 20 ] && set +x
else
  # switch off most of kernel debug output
  echo "0 0 0 0" >/proc/sys/kernel/printk
  # modprobe should stay quiet
  MODPRV="-q"
  LOGFILE="/dev/null"
  # redirect console (after /dev/null is available, and /dev mounted)
  [ "${DEBUGLEVEL}" != 8 ] && exec < /dev/console > /dev/null 2>&1
fi
# load network adaptor modules
hwautocfg nwmod

# set up loopback networking (ipsetup - function defined in /etc/functions)
[ $DEBUGLEVEL -eq 20 ] && echo "** starting ip config at $(sysup)"
ipsetup 127.0.0.1 255.0.0.0 0.0.0.0 127.255.255.255 lo

# Xen bridge config
[ -n "$xenbr" ] && xenbr_config

# analyze ip information from the kernel command line and put parts
# of it into several variables
if [ -n "$ipinfo" ] ; then
  getip () {
    local val="$ipinfo:"; i=$(expr $1 - 1);
    while [ $i -gt 0 ] ; do
      val=${val#*:} ; i=$(expr $i - 1);
    done;
  echo $val|sed "s/:.*//"; }
  clientip=$(getip 1)
  serverip=$(getip 2)
  gateway=$(getip 3)
  subnet_mask=$(getip 4)
  echo -e "# ip configuration written by $0 script\nclientip=$clientip\n\
subnet_mask=$subnet_mask\ngateway=$gateway\nserverip=$serverip" \
    >>/etc/machine-setup
  # set static ip address via function ipsetup
  ipsetup $clientip $subnet_mask $gateway 255.255.255.255 eth0
else
  noipyet="yes"
fi
# get configuration data via dhcp (with vendor code identifier if present
# in ${vci} from kernel command line or machine-setup) ...
[ -n "$dhcp" ] && rundhcp ${vci} &
if [ -n "$noipyet" ] ; then
  waitfor /tmp/dhcp-done 20000
  . /etc/machine-setup
  [ -f /tmp/confviadhcp ] && . /tmp/confviadhcp
  [ -z "$clientip" -o -z "$subnet_mask" -o -z "$gateway" \
    -o -z "$broadcast_address" ] && error "$init_errdhcp"
  ipsetup $clientip $subnet_mask $gateway $broadcast_address eth0
fi
# check if serverip is set as variable @@@serverip@@@
sed "s,@@@serverip@@@,$serverip," -i /etc/machine-setup
[ $DEBUGLEVEL -eq 20 ] && echo "** finished ip config at $(sysup)"
# ... or ldap if available (in background)
[ -n "$ldap" ] && ldapconf &
# ... or via tftp file get (in background)
[ -n "$file" ] && fileget &

# if root filesystem should be imported via (d) network block device
if [ -n "${nbdmod}" ] ; then
  # load block device driver if needed
  modprobe ${MODPRV} ${nbdmod} || error "$init_errnbd"
  [ -x /bin/mdev ] && mdev -s
  [ -z "$nbdrfst" ] && nbdrfst=ext2
  nbdhost=$(checkip $nbdhost)
  if [ $DEBUGLEVEL -eq 20 ] ; then
    echo "** starting setup of ${nbdmod} at $(sysup)"
  else
    echo "Diskless client using ${nbdmod} on $nbdhost:$nbdport with $nbdrfst"
  fi
  # fixme: check for fs in /proc/filesystems before trying to load the module
  modprobe ${MODPRV} ${nbdrfst} || error "$init_errnbd" nonfatal

  case "${nbdmod}" in
    # network block device present in standard kernel
    nbd)
      RDEV=/dev/nbd0
      waitfor "${RDEV}" 20000 || error "$init_nbddev"
      while ! nbd-client $nbdhost $nbdport ${RDEV} ; do
        usleep 100
      done
      usleep 100
      # switch off unneeded block read ahead
      echo "0" > /sys/block/nbd0/queue/read_ahead_kb
      ;;
    # dnbd by Thorsten Zitterell
    dnbd)
      # quickhack
      if [ -z $nodnbdcache ] ; then  # variable not really used yet
        mkdir /dnbd
        mount -n -o 'size=10%' -t tmpfs tmpfs /dnbd
        ( cat /dev/zero > /dnbd/cache 2>/dev/null || echo "ok" >/tmp/cache ) &
        clientopt="-c /dnbd/cache"
        waitfor /tmp/cache 10000
      fi
      waitfor /dev/dnbd0 10000 || error "$init_nbddev"
      while ! dnbd-client -b $nbdhost -d /dev/dnbd0 $clientopt ; do
        usleep 100
      done
      echo "0" > /sys/block/dnbd0/queue/read_ahead_kb
      RDEV=/dev/dnbd0
      ;;
  esac
  RWRO="ro"
  if [ -n "${cowloop}" -a -x /bin/cowdev ] ; then
    modprobe ${MODPRV} cowloop || {
      error "$init_loadcow" nonfatal
      cowloop=""; }
    [ -x /bin/mdev ] && mdev -s
  fi
  if [ -n "${cowloop}" ] ; then
    if [ -n "${unionfs}" ] ; then
      error "$init_cownonbd"
      unionfs="";
    fi
    echo "Using Copy-on-Write block device for rw access"
    mount -n -t tmpfs -o size=${cowsize} ramfs ${rwdir}
    mkdir /dev/cow && cp -a /tmp/ctl /dev/cow
    usleep 200
    ln -s /dev/cowloop0 /dev/cow/0
    cowdev -a /dev/nbd0 ${rwdir}/nbd.cow
    usleep 200
    RWRO="rw"
    RDEV=/dev/cow/0
    # run ldconfig if not switched off via kernel command line
    ldcfg
  else
    # use normal UnionFS behaviour because rootfs is not NFS
    nfsro=""
  fi
  # finally mount the block device
  for i in 1 50 100 200 400 1000 ; do
    usleep $i
    mount -n -t $nbdrfst -o $RWRO $RDEV /mnt 2>/dev/null && break
  done
  [ $DEBUGLEVEL -eq 20 ] && echo "** finished nw blockdev stuff at $(sysup)"
elif [ -n ${iscsiserver} ] ; then
  [ $DEBUGLEVEL -eq 20 ] && echo "** started setting up iSCSI initiator at \
$(sysup)" 
  #if [ -n ${iscsitarget} ] ; then
  #  echo "InitiatorName=${iscsitarget}"|sed "s,@@@serverip@@@,$serverip," \
  #    >/etc/initiatorname.iscsi
  #else
  # discovery
  #fi
  #echo -e "node.startup = automatic">/etc/iscsid.conf
  #iscsid -c /etc/iscsid.conf
  # the cowloop part has to be moved (option for iscsi devices too)
  # and should be generalized for nbd, dnbd, iscsi
fi

# if no type of root filesystem is passed via kernel command line try
# information gathered from dhcp process (only valid for nfs)
if [ -z "${nbdmod}" -a -z "${nbdhost}" -a -z "${nfsroot}" ] ; then
  # information has to be read from dhcp and ldap configuration
  cfgcomplete
fi
# call function for nfs mounts
if [ -z "${nbdmod}" -a -z "${nbdserver}" ] ; then
  [ $DEBUGLEVEL -eq 20 ] && echo "** started nfs mount"
  . /etc/machine-setup
  # check if nfsserver is set as variable @@@serverip@@@
  nfsserver=$(checkip $nfsserver)
  nfsroot=${nfsserver}:${root_path}
  nfsmnt ${nfsroot} || error "$init_nfs"
  [ $DEBUGLEVEL -eq 20 ] && echo "** finished nfs mount at $(sysup)"
fi

# get the complete collection of kernel modules available
mount -n --bind /mnt/lib/modules/${KERNEL} /lib/modules/${KERNEL} || \
  error "$init_moddir"
# start hardware configuration as background process if not a special 
# debuglevel (21) is used for the option of manual hwautocfg start
if [ ${DEBUGLEVEL} = 21 ] ; then
  echo "You can run 'hwautocfg main &' manually now ..."
  /bin/sh
else
  [ $DEBUGLEVEL -eq 20 ] && echo "** started hwautocfg in background at \
$(sysup)"
  hwautocfg main &
fi

# try to use unionfs for rw access if available
if [ -n "${unionfs}" -o -n "${union}" ] ; then
  modprobe ${MODPRV} unionfs || {
    error "$init_loadufs" nonfatal
    unionfs=""; }
fi

# setup of client root filesystem dependent on the availability of UnionFS
if [ -n "${unionfs}" ] ; then
  echo "Using UnionFS for rw access"
  mkdir -p ${rwdir}/union ${rwdir}/uniontmp /rorootfs
  mount -n -t tmpfs none ${rwdir}/uniontmp
  # hack for handling unionfs with patched run-init
  mount -n --move /mnt /rorootfs
  mount -n -t unionfs -o dirs=${rwdir}/uniontmp:/rorootfs=${nfsro}ro \
    none /mnt
  mkdir -p /mnt/uniontmp
  mount -n --move ${rwdir}/uniontmp /mnt/uniontmp
  chmod 0755 /mnt/uniontmp /mnt
  # if additional sources should be used for a combined root filesystem
  # probably more sources should be merged into union (${union} is defined)
  # allow more than one union??
  if [ -n "${union}" ] ; then
    # for dir in "${union}"; do
    # testmkd /unionadd/$dir
    # mount $dir unionadd/$dir
    # unionctl mnt --add --after /mnt --mode ro /unionadd/$dir
    # most probably it is a good idea to run ldconfig, so enable it
    unset noldsc
  fi
  # run ldconfig if not switched off via kernel command line
  ldcfg
  # runlevel directories should contain no links
  for i in ${D_RCDIRS} ${D_INITBOOTD} ; do
    rm -f /mnt/etc/$i/* 2>/dev/null
  done
elif [ -z "${cowloop}" ] ; then
  echo "Using bind mounts to ramdisk for rw access"
  mount -n -t tmpfs -o size=${tmpfssize} ramfs ${rwdir}
  for path in ${D_BINDMPTS} ; do
    mkdir -p ${rwdir}/${path} >/dev/null 2>&1
    mount -n --bind ${rwdir}/${path} /mnt/${path}
    [ ${DEBUGLEVEL} -gt 1 -a ${DEBUGLEVEL} != 8 ] && \
      echo "Created ${rwdir}/${path} and mounted it to /mnt/$path"
  done
  # see above ...
  ldcfg
  # save the RO directories mentioned in the distro-specific
  # config to a temporary directory. They will lateron be restored 
  for path in ${D_RODIRSINRW}; do
    if [ -d /mnt/${path} ] ; then
      list=${path}" "${list}
      # exclude them from etc copy process too
      echo ${path}|sed -e "s,/root/,," >>/tmp/etc.exclude
      mkdir -p /root/${path} >/dev/null 2>&1
      mount -n --bind /mnt/${path} /root/${path} >/dev/null 2>&1
    fi
  done
  for path in /etc/${D_SYSCONFDIR} ${D_DIRINBINDMNT} ${list}; do
    mkdir -p ${rwdir}/${path}
  done
  testmkd ${rwdir}/var/tmp
  chmod a+rwxt ${rwdir}/var/tmp >/dev/null 2>&1
  # exclude all sysv runlevel link stuff
  for i in ${D_RCDIRS} ${D_INITBOOTD} ; do
    echo "*$i/*" >>/tmp/etc.exclude
  done
  # add list of files to be excluded and common excludes to the filter list
  echo -e "${D_ETCEXCL}\n@@@COMETCEXCL@@@" >>/tmp/etc.exclude
  # if ld.so.cache is to be generated then do not copy the file
  [ -z "${noldsc}" ] && echo -e "ld.so.cache*" >>/tmp/etc.exclude
  # for tar exclude lists might be used, more difficult for cp
  cd /mnt
  tar -X /tmp/etc.exclude -cp etc/* | \
    tar -xp -C ${rwdir} 2>/dev/null ;
  cd /
  mount -n --bind ${rwdir}/etc /mnt/etc
  mount -n --bind ${rwdir}/var /mnt/var
  # get the "covered" mounts back into filesystem structure
  for i in ${list}; do
    mount -n --move /root/$i /mnt/$i #>>$LOGFILE 2>&1
  done
  #rm -rf /root/* >/dev/null 2>&1
  # run some specific stuff !?
fi
# script for stuff to execute during early bootup
d_mkrlscript init boot.ld "Running configuration postponed from InitRamFS"
echo "fs complete at $(sysup)" >/tmp/fscmpl

# write debug file information after filesystem setup completed
echo -e "# /etc${D_SYSCONFDIR}/logfile - file created by $0 (initramfs \
from $date)\n#\n# logfile \
for linux diskless client specific debugging output\nLOGFILE=\"$LOGFILE\"\n#\
\n# debug level\nDEBUGLEVEL=\"$DEBUGLEVEL\"" \
  > /mnt/etc/${D_SYSCONFDIR}/logfile || error "$init_errlog"

# run distribution independent and dependent configuration of files and
# services (offer debug shell in runlevel 22)
if [ ${DEBUGLEVEL} = 22 ] ; then
  /bin/sh
else
  servconfig &
fi
  
for path in @@@COMDIRINDXS@@@ ${D_DIRINDXS} ${D_DIRINBINDMNT} ; do
  testmkd /mnt/${path}
done
# Needed writable subdirs nested in readonly subdirs of writable one
for path in ${D_RWDIRSINRO}; do
  mount -n -t tmpfs none /mnt/${path}
done
for i in /var/run/utmp /var/log/wtmp /var/log/lastlog /etc/mtab ; do
  echo -n > /mnt/$i
done
chown 65534:0 /mnt/var/lib/nobody
# /proc/bus/usb might be deprecated in newer kernels ...
echo -e "# /etc/fstab - file generated by $0 (initramfs from $date)\n#\
\tDirk von \
Suchodoletz, dirk@goe.net\n\nrootfs\t\t/\t\trootfs\t\tro\t\t 0 0\n\
proc\t\t/proc\t\tproc\t\tdefaults\t 0 0\ninitramdevs\t/dev\t\ttmpfs\
\t\trw\t\t 0 0\ndevpts\t\t/dev/pts\tdevpts\t\tmode=0620,gid=5\t 0 0\n\
usbfs\t\t/proc/bus/usb\tusbfs\t\tnoauto\t\t 0 0" >/mnt/etc/fstab || \
  error "$init_fstab"
echo -e "rootfs / rootfs rw 0 0\ninitramdevs /dev tmpfs rw\
 0 0" > /mnt/etc/mtab

# copy library cache if generated
if [ -z "${noldsc}" ] ; then
  if waitfor /tmp/ldcfg 50000 ; then
    test -s /mnt/tmp/ld.so.cache && {
      cp /mnt/tmp/ld.so.cache /mnt/etc/ld.so.cache
      rm /mnt/tmp/ld.so.cache; }
  else
    error "$init_errldcfg"
  fi
else
  error "$init_infldcfg" nonfatal
fi
# wait a while for hardware setup to complete and copy stuff to stage4
waitfor /tmp/hwcfg 30000 || error "$init_errhw"
[ -f /tmp/scanner-udev ] && cat /tmp/scanner-udev \
  >> /mnt/etc/udev/rules.d/04-scanner.rules
# wait for completion of Xorg configuration and finalize it
waitfor /tmp/xready 20000 || error "$init_errxorg" nonfatal
cp /etc/xorg.conf /mnt/${D_XF86CONFFILE}
# wait a while for services setup to complete
waitfor /tmp/svcfg 20000 || error "$init_errsw"
# IP configuration is complete and should not be updated automatically
killall -9 dhcpcd dhclient pump udhcpc 2>/dev/null
# copy machine configuration file into stage4 filesystem
cp /etc/machine-setup /mnt/etc


# If locations are given that should be unioned with the fs root, do it
if [ -n "$uniondirs" ]; then
  include_in_fsroot_union $uniondirs
fi

# post init for some distro specific (fixme!! more elegant solution)
postinit
[ -s /initramfs/postinit.local ] && \
  cp /initramfs/postinit.local /bin/postinit.local
[ -x /bin/postinit.local ] && {
  [ $DEBUGLEVEL -gt 0 ] && \
    echo "Running postinit.local - if boot stops here, check the script!"
  /bin/postinit.local; }




# start a debug shell in higher debug levels
[ $DEBUGLEVEL -gt 2 -a $DEBUGLEVEL != 8 ] && /bin/sh

# unmount the bind mounted modules directory
export ticks
for ticks in 0 200 300 500 800 1000 1200 2000 5000 ; do
  usleep $ticks && umount -n /lib/modules/${KERNEL} 2>/dev/null && break
  error "$init_wait" nonfatal
done

[ $ticks -gt 1000 ] && error "$init_errumnt"
# check for inittab file (might fail for new style init -> upstart)
test -f /mnt/etc/inittab || test -d /mnt/etc/event.d || error "$init_erritab"
# close runlevel script for stuff to execute during early bootup
d_mkrlscript close boot.ld ""
# put /tmp into stage4 mtab and add stuff to stage4 fstab
sed -n "s,/mnt,,;/\/tmp /p" /proc/mounts >> /mnt/etc/mtab
[ -f /tmp/fstab ] && cat /tmp/fstab >> /mnt/etc/fstab
# preparations to leave initramfs - umounting ...
umount -n /sys || error "$init_errsys" nonfatal
umount -n /proc/bus/usb >/dev/null 2>&1
chmod 1777 /mnt/dev/shm /mnt/tmp /mnt/tmp/scratch 2>/dev/null
mount -n --move /dev /mnt/dev

# stop udevd (non-busybox udevs) and kill hwautocfg, servconfig
killall -9 udevd hwautocfg servconfig 2>/mnt/dev/null
# runtimer
[ $DEBUGLEVEL -eq 8 -o $DEBUGLEVEL -eq 20 ] && \
  echo "** SLX init ended near $(sysup)"
# kill the watchdog (autopoweroff, if stage3 init never finishes)
[ -f /tmp/watchdogpid ] && kill $(cat /tmp/watchdogpid) 2>/mnt/dev/null
umount -n /proc
# unset old environment variables
unset debug date initrd ip dnbdroot nbdroot nfsroot rootfs ticks vci vga
unset BOOT_IMAGE KCMDLINE KERNEL MODPRV NWMODULES OLDPWD UDEVD_EVENT_TIMEOUT \
  UDEVD_EXPECTED_SEQNUM PATH
# new style of pivoting (switch_root or run-init in klibc)
exec /bin/switch_root -c dev/console /mnt /sbin/init || error "$init_runinit"