home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / initramfs-tools / init < prev    next >
Encoding:
Text File  |  2012-09-21  |  6.6 KB  |  330 lines

  1. #!/bin/sh
  2.  
  3. echo "Loading, please wait..."
  4.  
  5. [ -d /dev ] || mkdir -m 0755 /dev
  6. [ -d /root ] || mkdir -m 0700 /root
  7. [ -d /sys ] || mkdir /sys
  8. [ -d /proc ] || mkdir /proc
  9. [ -d /tmp ] || mkdir /tmp
  10. mkdir -p /var/lock
  11. mount -t sysfs -o nodev,noexec,nosuid sysfs /sys
  12. mount -t proc -o nodev,noexec,nosuid proc /proc
  13.  
  14. # Note that this only becomes /dev on the real filesystem if udev's scripts
  15. # are used; which they will be, but it's worth pointing out
  16. tmpfs_size="10M"
  17. if [ -e /etc/udev/udev.conf ]; then
  18.     . /etc/udev/udev.conf
  19. fi
  20. if ! mount -t devtmpfs -o size=$tmpfs_size,mode=0755 udev /dev; then
  21.     echo "W: devtmpfs not available, falling back to tmpfs for /dev"
  22.     mount -t tmpfs -o size=$tmpfs_size,mode=0755 udev /dev
  23.     [ -e /dev/console ] || mknod -m 0600 /dev/console c 5 1
  24.     [ -e /dev/null ] || mknod /dev/null c 1 3
  25. fi
  26. mkdir /dev/pts
  27. mount -t devpts -o noexec,nosuid,gid=5,mode=0620 devpts /dev/pts || true
  28. mount -t tmpfs -o "nosuid,size=20%,mode=0755" tmpfs /run
  29. mkdir -m 0755 /run/initramfs
  30.  
  31. # Export the dpkg architecture
  32. export DPKG_ARCH=
  33. . /conf/arch.conf
  34.  
  35. # Set modprobe env
  36. export MODPROBE_OPTIONS="-qb"
  37.  
  38. # Export relevant variables
  39. export ROOT=
  40. export ROOTDELAY=
  41. export ROOTFLAGS=
  42. export ROOTFSTYPE=
  43. export IP=
  44. export BOOT=
  45. export BOOTIF=
  46. export UBIMTD=
  47. export break=
  48. export init=/sbin/init
  49. export quiet=n
  50. export readonly=y
  51. export rootmnt=/root
  52. export debug=
  53. export panic=
  54. export blacklist=
  55. export resume=
  56. export resume_offset=
  57.  
  58. # Bring in the main config
  59. . /conf/initramfs.conf
  60. for conf in conf/conf.d/*; do
  61.     [ -f ${conf} ] && . ${conf}
  62. done
  63. . /scripts/functions
  64.  
  65. # Parse command line options
  66. for x in $(cat /proc/cmdline); do
  67.     case $x in
  68.     init=*)
  69.         init=${x#init=}
  70.         ;;
  71.     root=*)
  72.         ROOT=${x#root=}
  73.         case $ROOT in
  74.         LABEL=*)
  75.             ROOT="${ROOT#LABEL=}"
  76.  
  77.             # support any / in LABEL= path (escape to \x2f)
  78.             case "${ROOT}" in
  79.             */*)
  80.             if command -v sed >/dev/null 2>&1; then
  81.                 ROOT="$(echo ${ROOT} | sed 's,/,\\x2f,g')"
  82.             else
  83.                 if [ "${ROOT}" != "${ROOT#/}" ]; then
  84.                     ROOT="\x2f${ROOT#/}"
  85.                 fi
  86.                 if [ "${ROOT}" != "${ROOT%/}" ]; then
  87.                     ROOT="${ROOT%/}\x2f"
  88.                 fi
  89.                 IFS='/'
  90.                 newroot=
  91.                 for s in $ROOT; do
  92.                     newroot="${newroot:+${newroot}\\x2f}${s}"
  93.                 done
  94.                 unset IFS
  95.                 ROOT="${newroot}"
  96.             fi
  97.             esac
  98.             ROOT="/dev/disk/by-label/${ROOT}"
  99.             ;;
  100.         UUID=*)
  101.             ROOT="/dev/disk/by-uuid/${ROOT#UUID=}"
  102.             ;;
  103.         /dev/nfs)
  104.             [ -z "${BOOT}" ] && BOOT=nfs
  105.             ;;
  106.         esac
  107.         ;;
  108.     rootflags=*)
  109.         ROOTFLAGS="-o ${x#rootflags=}"
  110.         ;;
  111.     rootfstype=*)
  112.         ROOTFSTYPE="${x#rootfstype=}"
  113.         ;;
  114.     rootdelay=*)
  115.         ROOTDELAY="${x#rootdelay=}"
  116.         case ${ROOTDELAY} in
  117.         *[![:digit:].]*)
  118.             ROOTDELAY=
  119.             ;;
  120.         esac
  121.         ;;
  122.     nfsroot=*)
  123.         NFSROOT="${x#nfsroot=}"
  124.         ;;
  125.     ip=*)
  126.         IP="${x#ip=}"
  127.         ;;
  128.     boot=*)
  129.         BOOT=${x#boot=}
  130.         ;;
  131.     ubi.mtd=*)
  132.         UBIMTD=${x#ubi.mtd=}
  133.         ;;
  134.     resume=*)
  135.         RESUME="${x#resume=}"
  136.         ;;
  137.     resume_offset=*)
  138.         resume_offset="${x#resume_offset=}"
  139.         ;;
  140.     noresume)
  141.         noresume=y
  142.         ;;
  143.     panic=*)
  144.         panic="${x#panic=}"
  145.         case ${panic} in
  146.         *[![:digit:].]*)
  147.             panic=
  148.             ;;
  149.         esac
  150.         ;;
  151.     quiet)
  152.         quiet=y
  153.         ;;
  154.     ro)
  155.         readonly=y
  156.         ;;
  157.     rw)
  158.         readonly=n
  159.         ;;
  160.     debug)
  161.         debug=y
  162.         quiet=n
  163.         exec >/run/initramfs/initramfs.debug 2>&1
  164.         set -x
  165.         ;;
  166.     debug=*)
  167.         debug=y
  168.         quiet=n
  169.         set -x
  170.         ;;
  171.     break=*)
  172.         break=${x#break=}
  173.         ;;
  174.     break)
  175.         break=premount
  176.         ;;
  177.     blacklist=*)
  178.         blacklist=${x#blacklist=}
  179.         ;;
  180.     netconsole=*)
  181.         netconsole=${x#netconsole=}
  182.         ;;
  183.     BOOTIF=*)
  184.         BOOTIF=${x#BOOTIF=}
  185.         ;;
  186.     esac
  187. done
  188.  
  189. # Default to BOOT=local if no boot script defined.
  190. if [ -z "${BOOT}" ]; then
  191.     BOOT=local
  192. fi
  193.  
  194. if [ -n "${noresume}" ]; then
  195.     export noresume
  196.     unset resume
  197. else
  198.     resume=${RESUME:-}
  199. fi
  200.  
  201. maybe_break top
  202.  
  203. # Don't do log messages here to avoid confusing graphical boots
  204. run_scripts /scripts/init-top
  205.  
  206. maybe_break modules
  207. [ "$quiet" != "y" ] && log_begin_msg "Loading essential drivers"
  208. load_modules
  209. [ "$quiet" != "y" ] && log_end_msg
  210.  
  211. [ -n "${netconsole}" ] && modprobe netconsole netconsole="${netconsole}"
  212.  
  213. maybe_break premount
  214. [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-premount"
  215. run_scripts /scripts/init-premount
  216. [ "$quiet" != "y" ] && log_end_msg
  217.  
  218. maybe_break mount
  219. log_begin_msg "Mounting root file system"
  220. . /scripts/${BOOT}
  221. parse_numeric ${ROOT}
  222. maybe_break mountroot
  223. mountroot
  224. log_end_msg
  225.  
  226. maybe_break bottom
  227. [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-bottom"
  228. run_scripts /scripts/init-bottom
  229. [ "$quiet" != "y" ] && log_end_msg
  230.  
  231. # Preserve information on old systems without /run on the rootfs
  232. if [ -d ${rootmnt}/run ]; then
  233.     mount -n -o move /run ${rootmnt}/run
  234. else
  235.     # The initramfs udev database must be migrated:
  236.     if [ -d /run/udev ] && [ ! -d /dev/.udev ]; then
  237.         mv /run/udev /dev/.udev
  238.     fi
  239.     # The initramfs debug info must be migrated:
  240.     if [ -d /run/initramfs ] && [ ! -d /dev/.initramfs ]; then
  241.         mv /run/initramfs /dev/.initramfs
  242.     fi
  243.     umount /run
  244. fi
  245.  
  246. validate_init() {
  247.     checktarget="${1}"
  248.  
  249.     # Work around absolute symlinks
  250.     if [ -d "${rootmnt}" ] && [ -h "${rootmnt}${checktarget}" ]; then
  251.         case $(readlink "${rootmnt}${checktarget}") in /*)
  252.             checktarget="$(chroot ${rootmnt} readlink ${checktarget})"
  253.             ;;
  254.         esac
  255.     fi
  256.  
  257.     # Make sure the specified init can be executed
  258.     if [ ! -x "${rootmnt}${checktarget}" ]; then
  259.         return 1
  260.     fi
  261.  
  262.     # Upstart uses /etc/init as configuration directory :-/
  263.     if [ -d "${rootmnt}${checktarget}" ]; then
  264.         return 1
  265.     fi
  266. }
  267.  
  268. # Check init bootarg
  269. if [ -n "${init}" ]; then
  270.     if ! validate_init "$init"; then
  271.         echo "Target filesystem doesn't have requested ${init}."
  272.         init=
  273.     fi
  274. fi
  275.  
  276. # Common case: /sbin/init is present
  277. if [ ! -x "${rootmnt}/sbin/init" ]; then
  278.     # ... if it's not available search for valid init
  279.     if [ -z "${init}" ] ; then
  280.         for inittest in /sbin/init /etc/init /bin/init /bin/sh; do
  281.             if validate_init "${inittest}"; then
  282.                 init="$inittest"
  283.                 break
  284.             fi
  285.         done
  286.     fi
  287.  
  288.     # No init on rootmount
  289.     if ! validate_init "${init}" ; then
  290.         panic "No init found. Try passing init= bootarg."
  291.     fi
  292. fi
  293.  
  294. maybe_break init
  295.  
  296. # don't leak too much of env - some init(8) don't clear it
  297. # (keep init, rootmnt)
  298. unset debug
  299. unset MODPROBE_OPTIONS
  300. unset DPKG_ARCH
  301. unset ROOTFLAGS
  302. unset ROOTFSTYPE
  303. unset ROOTDELAY
  304. unset ROOT
  305. unset IP
  306. unset BOOT
  307. unset BOOTIF
  308. unset UBIMTD
  309. unset blacklist
  310. unset break
  311. unset noresume
  312. unset panic
  313. unset quiet
  314. unset readonly
  315. unset resume
  316. unset resume_offset
  317.  
  318. # Move virtual filesystems over to the real filesystem
  319. mount -n -o move /sys ${rootmnt}/sys
  320. mount -n -o move /proc ${rootmnt}/proc
  321.  
  322. # Chain to real filesystem
  323. if command -v switch_root >/dev/null 2>&1; then
  324.     exec switch_root ${rootmnt} ${init} "$@" <${rootmnt}/dev/console >${rootmnt}/dev/console
  325. elif command -v run-init >/dev/null 2>&1; then
  326.     exec run-init ${rootmnt} ${init} "$@" <${rootmnt}/dev/console >${rootmnt}/dev/console
  327. fi
  328. echo "Something went badly wrong in the initramfs."
  329. panic "Please file a bug on initramfs-tools."
  330.