home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / initramfs-tools / init < prev    next >
Encoding:
Text File  |  2006-08-23  |  2.7 KB  |  150 lines

  1. #!/bin/sh
  2.  
  3. mkdir /sys
  4. mkdir /proc
  5. mkdir /tmp
  6. mkdir -p /var/lock
  7. mount -t sysfs none /sys -onodev,noexec,nosuid
  8. mount -t proc none /proc -onodev,noexec,nosuid
  9.  
  10. # Note that this only becomes /dev on the real filesystem if udev's scripts
  11. # are used; which they will be, but it's worth pointing out
  12. tmpfs_size="10M"
  13. mount -t tmpfs -o size=$tmpfs_size,mode=0755 udev /dev
  14. > /dev/.initramfs-tools
  15. mkdir /dev/.initramfs
  16. mknod /dev/console c 5 1 
  17. mknod /dev/null c 1 3
  18.  
  19. # Export the dpkg architecture
  20. export DPKG_ARCH=
  21. . /conf/arch.conf
  22.  
  23. # Export it for root hardcoding
  24. export ROOT=
  25.  
  26. # Bring in the main config
  27. . /conf/initramfs.conf
  28. for i in conf/conf.d/*; do
  29.     [ -f ${i} ] && . ${i}
  30. done
  31. . /scripts/functions
  32.  
  33. # Parse command line options
  34. export break=
  35. export init=/sbin/init
  36. export quiet=n
  37. export readonly=y
  38. export rootmnt=/root
  39. export debug=
  40. export cryptopts=${CRYPTOPTS}
  41.  
  42. for x in $(cat /proc/cmdline); do
  43.     case $x in
  44.     init=*)
  45.         init=${x#init=}
  46.         ;;
  47.     root=*)
  48.         ROOT=${x#root=}
  49.         case $ROOT in
  50.         LABEL=*)
  51.             ROOT="/dev/disk/by-label/${ROOT#LABEL=}"
  52.             ;;
  53.         UUID=*)
  54.             ROOT="/dev/disk/by-uuid/${ROOT#UUID=}"
  55.             ;;
  56.         esac
  57.         ;;
  58.     rootflags=*)
  59.         ROOTFLAGS="-o ${x#rootflags=}"
  60.         ;;
  61.     cryptopts=*)
  62.         cryptopts="${x#cryptopts=}"
  63.         ;;
  64.     nfsroot=*)
  65.         NFSROOT="${x#nfsroot=}"
  66.         ;;
  67.     nfsopts=*)
  68.         NFSOPTS="-o ${x#nfsopts=}"
  69.         ;;
  70.     boot=*)
  71.         BOOT=${x#boot=}
  72.         ;;
  73.     resume=*)
  74.         RESUME=${x#resume=}
  75.         ;;
  76.     noresume)
  77.         NORESUME=y
  78.         ;;
  79.     quiet)
  80.         quiet=y
  81.         ;;
  82.     ro)
  83.         readonly=y
  84.         ;;
  85.     rw)
  86.         readonly=n
  87.         ;;
  88.     debug)
  89.         debug=y
  90.         exec >/tmp/initramfs.debug 2>&1
  91.         set -x
  92.         ;;
  93.     break=*)
  94.         break=${x#break=}
  95.         ;;
  96.     break)
  97.         break=premount
  98.         ;;
  99.     esac
  100. done
  101.  
  102. if [ -z ${NORESUME} ]; then
  103.     export resume=${RESUME}
  104. fi
  105.  
  106. depmod -a
  107. maybe_break top
  108.  
  109. # Don't do log messages here to avoid confusing usplash
  110. run_scripts /scripts/init-top
  111.  
  112. maybe_break modules
  113. log_begin_msg "Loading essential drivers..."
  114. load_modules
  115. log_end_msg
  116.  
  117. maybe_break premount
  118. [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-premount"
  119. run_scripts /scripts/init-premount
  120. [ "$quiet" != "y" ] && log_end_msg
  121.  
  122. maybe_break mount
  123. log_begin_msg "Mounting root file system..."
  124. . /scripts/${BOOT}
  125. parse_numeric ${ROOT}
  126. mountroot
  127. log_end_msg
  128.  
  129. maybe_break bottom
  130. [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-bottom"
  131. run_scripts /scripts/init-bottom
  132. [ "$quiet" != "y" ] && log_end_msg
  133.  
  134. # Move virtual filesystems over to the real filesystem
  135. mount -n -o move /sys ${rootmnt}/sys
  136. mount -n -o move /proc ${rootmnt}/proc
  137.  
  138. while [ ! -x ${rootmnt}${init} ]; do
  139.     panic "Target filesystem doesn't have ${init}"
  140. done
  141.  
  142. # Confuses /etc/init.d/rc
  143. if [ -n ${debug} ]; then
  144.     unset debug
  145. fi
  146.  
  147. # Chain to real filesystem
  148. maybe_break init
  149. exec run-init ${rootmnt} ${init} "$@" <${rootmnt}/dev/console >${rootmnt}/dev/console
  150.