daily pastebin goal
26%
SHARE
TWEET

Untitled

a guest Dec 7th, 2018 58 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #!/bin/sh
  2. # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
  3. # ex: ts=8 sw=4 sts=4 et filetype=sh
  4. #
  5. # Licensed under the GPLv2
  6. #
  7. # Copyright 2008-2010, Red Hat, Inc.
  8. # Harald Hoyer <harald@redhat.com>
  9. # Jeremy Katz <katzj@redhat.com>
  10.  
  11. export -p > /tmp/export.orig
  12.  
  13. NEWROOT="/sysroot"
  14. [ -d $NEWROOT ] || mkdir -p -m 0755 $NEWROOT
  15.  
  16. OLDPATH=$PATH
  17. PATH=/usr/sbin:/usr/bin:/sbin:/bin
  18. export PATH
  19.  
  20. RD_DEBUG=""
  21. . /lib/dracut-lib.sh
  22. trap "emergency_shell Signal caught!" 0
  23.  
  24. [ -c /dev/null ] || mknod -m 0666 /dev/null c 1 3
  25.  
  26. # mount some important things
  27. [ ! -d /proc/self ] && \
  28.     mount -t proc -o nosuid,noexec,nodev proc /proc >/dev/null 2>&1
  29.  
  30. [ ! -d /sys/kernel ] && \
  31.     mount -t sysfs -o nosuid,noexec,nodev sysfs /sys >/dev/null 2>&1
  32.  
  33. if [ -x /lib/systemd/systemd-timestamp ]; then
  34.     RD_TIMESTAMP=$(/lib/systemd/systemd-timestamp)
  35. else
  36.     read RD_TIMESTAMP _tmp < /proc/uptime
  37.     unset _tmp
  38. fi
  39.  
  40. setdebug
  41.  
  42. if [ "$RD_DEBUG" = "yes" ]; then
  43.     getarg quiet && DRACUT_QUIET="yes"
  44.     a=$(getarg loglevel=)
  45.     [ -n "$a" ] && [ $a -ge 8 ] && unset DRACUT_QUIET
  46. fi
  47.  
  48. if ! ismounted /dev; then
  49.     mount -t devtmpfs -o mode=0755,nosuid,strictatime devtmpfs /dev >/dev/null
  50. fi
  51.  
  52. # prepare the /dev directory
  53. [ ! -h /dev/fd ] && ln -s /proc/self/fd /dev/fd >/dev/null 2>&1
  54. [ ! -h /dev/stdin ] && ln -s /proc/self/fd/0 /dev/stdin >/dev/null 2>&1
  55. [ ! -h /dev/stdout ] && ln -s /proc/self/fd/1 /dev/stdout >/dev/null 2>&1
  56. [ ! -h /dev/stderr ] && ln -s /proc/self/fd/2 /dev/stderr >/dev/null 2>&1
  57.  
  58. if ! ismounted /dev/pts; then
  59.     mkdir -m 0755 /dev/pts
  60.     mount -t devpts -o gid=5,mode=620,noexec,nosuid devpts /dev/pts >/dev/null
  61. fi
  62.  
  63. if ! ismounted /dev/shm; then
  64.     mkdir -m 0755 /dev/shm
  65.     mount -t tmpfs -o mode=1777,nosuid,nodev,strictatime tmpfs /dev/shm >/dev/null
  66. fi
  67.  
  68. if ! ismounted /run; then
  69.     mkdir -m 0755 /newrun
  70.     mount -t tmpfs -o mode=0755,nosuid,nodev,strictatime tmpfs /newrun >/dev/null
  71.     cp -a /run/* /newrun >/dev/null 2>&1
  72.     mount --move /newrun /run
  73.     rm -fr /newrun
  74. fi
  75.  
  76. [ -d /run/initramfs ] || mkdir -p -m 0755 /run/initramfs
  77.  
  78. UDEVVERSION=$(udevadm --version)
  79. if [ $UDEVVERSION -gt 166 ]; then
  80.     # newer versions of udev use /run/udev/rules.d
  81.     export UDEVRULESD=/run/udev/rules.d
  82.     [ -d /run/udev ] || mkdir -p -m 0755 /run/udev
  83.     [ -d $UDEVRULESD ] || mkdir -p -m 0755 $UDEVRULESD
  84. else
  85.     mkdir -m 0755 /dev/.udev /dev/.udev/rules.d
  86.     export UDEVRULESD=/dev/.udev/rules.d
  87. fi
  88.  
  89. if [ "$RD_DEBUG" = "yes" ]; then
  90.     mkfifo /run/initramfs/loginit.pipe
  91.     loginit $DRACUT_QUIET </run/initramfs/loginit.pipe >/dev/console 2>&1 &
  92.     exec >/run/initramfs/loginit.pipe 2>&1
  93. else
  94.     exec 0<>/dev/console 1<>/dev/console 2<>/dev/console
  95. fi
  96.  
  97. source_conf /etc/conf.d
  98.  
  99. # run scriptlets to parse the command line
  100. getarg 'rd.break=cmdline' 'rdbreak=cmdline' && emergency_shell -n cmdline "Break before cmdline"
  101. source_hook cmdline
  102.  
  103. [ -z "$root" ] && die "No or empty root= argument"
  104. [ -z "$rootok" ] && die "Don't know how to handle 'root=$root'"
  105.  
  106. export root rflags fstype netroot NEWROOT
  107.  
  108. # pre-udev scripts run before udev starts, and are run only once.
  109. getarg 'rd.break=pre-udev' 'rdbreak=pre-udev' && emergency_shell -n pre-udev "Break before pre-udev"
  110. source_hook pre-udev
  111.  
  112. # start up udev and trigger cold plugs
  113. udevd --daemon --resolve-names=never
  114.  
  115. UDEV_LOG_PRIO_ARG=--log-priority
  116. UDEV_QUEUE_EMPTY="udevadm settle --timeout=0"
  117.  
  118. if [ $UDEVVERSION -lt 140 ]; then
  119.     UDEV_LOG_PRIO_ARG=--log_priority
  120.     UDEV_QUEUE_EMPTY="udevadm settle --timeout=1"
  121. fi
  122.  
  123. getargbool 0 rd.udev.info -y rdudevinfo && udevadm control "$UDEV_LOG_PRIO_ARG=info"
  124. getargbool 0 rd.udev.debug -y rdudevdebug && udevadm control "$UDEV_LOG_PRIO_ARG=debug"
  125. udevproperty "hookdir=$hookdir"
  126.  
  127. getarg 'rd.break=pre-trigger' 'rdbreak=pre-trigger' && emergency_shell -n pre-trigger "Break before pre-trigger"
  128. source_hook pre-trigger
  129.  
  130. udevadm control --reload >/dev/null 2>&1 || :
  131. # then the rest
  132. udevadm trigger --type=subsystems --action=add >/dev/null 2>&1
  133. udevadm trigger --type=devices --action=add >/dev/null 2>&1
  134.  
  135. getarg 'rd.break=initqueue' 'rdbreak=initqueue' && emergency_shell -n initqueue "Break before initqueue"
  136.  
  137. RDRETRY=$(getarg rd.retry 'rd_retry=')
  138. RDRETRY=${RDRETRY:-20}
  139. RDRETRY=$(($RDRETRY*2))
  140. export RDRETRY
  141. main_loop=0
  142. export main_loop
  143. while :; do
  144.  
  145.     check_finished && break
  146.  
  147.     udevsettle
  148.  
  149.     check_finished && break
  150.  
  151.     if [ -f $hookdir/initqueue/work ]; then
  152.         rm $hookdir/initqueue/work
  153.     fi
  154.  
  155.     for job in $hookdir/initqueue/*.sh; do
  156.         [ -e "$job" ] || break
  157.         job=$job . $job
  158.         check_finished && break 2
  159.     done
  160.  
  161.     $UDEV_QUEUE_EMPTY >/dev/null 2>&1 || continue
  162.  
  163.     for job in $hookdir/initqueue/settled/*.sh; do
  164.         [ -e "$job" ] || break
  165.         job=$job . $job
  166.         check_finished && break 2
  167.     done
  168.  
  169.     $UDEV_QUEUE_EMPTY >/dev/null 2>&1 || continue
  170.  
  171.     # no more udev jobs and queues empty.
  172.     sleep 0.5
  173.  
  174.  
  175.     if [ $main_loop -gt $(($RDRETRY/2)) ]; then
  176.         for job in $hookdir/initqueue/timeout/*.sh; do
  177.             [ -e "$job" ] || break
  178.             job=$job . $job
  179.             main_loop=0
  180.         done
  181.     fi
  182.  
  183.     main_loop=$(($main_loop+1))
  184.     [ $main_loop -gt $RDRETRY ] \
  185.         && { flock -s 9 ; emergency_shell "Unable to process initqueue"; } 9>/.console_lock
  186. done
  187. unset job
  188. unset queuetriggered
  189. unset main_loop
  190. unset RDRETRY
  191.  
  192. # pre-mount happens before we try to mount the root filesystem,
  193. # and happens once.
  194. getarg 'rd.break=pre-mount' 'rdbreak=pre-mount' && emergency_shell -n pre-mount "Break pre-mount"
  195. source_hook pre-mount
  196.  
  197.  
  198. getarg 'rd.break=mount' 'rdbreak=mount' && emergency_shell -n mount "Break mount"
  199. # mount scripts actually try to mount the root filesystem, and may
  200. # be sourced any number of times. As soon as one suceeds, no more are sourced.
  201. i=0
  202. while :; do
  203.     if ismounted "$NEWROOT"; then
  204.         usable_root "$NEWROOT" && break;
  205.         umount "$NEWROOT"
  206.     fi
  207.     for f in $hookdir/mount/*.sh; do
  208.         [ -f "$f" ] && . "$f"
  209.         if ismounted "$NEWROOT"; then
  210.             usable_root "$NEWROOT" && break;
  211.             warn "$NEWROOT has no proper rootfs layout, ignoring and removing offending mount hook"
  212.             umount "$NEWROOT"
  213.             rm -f "$f"
  214.         fi
  215.     done
  216.  
  217.     i=$(($i+1))
  218.     [ $i -gt 20 ] \
  219.         && { flock -s 9 ; emergency_shell "Can't mount root filesystem"; } 9>/.console_lock
  220. done
  221.  
  222. {
  223.     echo -n "Mounted root filesystem "
  224.     while read dev mp rest; do [ "$mp" = "$NEWROOT" ] && echo $dev; done < /proc/mounts
  225. } | vinfo
  226.  
  227. # pre pivot scripts are sourced just before we doing cleanup and switch over
  228. # to the new root.
  229. getarg 'rd.break=pre-pivot' 'rdbreak=pre-pivot' && emergency_shell -n pre-pivot "Break pre-pivot"
  230. source_hook pre-pivot
  231.  
  232. # pre pivot cleanup scripts are sourced just before we switch over to the new root.
  233. getarg 'rd.break=pre-pivot-cleanup' 'rdbreak=pre-pivot-cleanup' && emergency_shell -n pre-pivot-cleanup "Break pre-pivot-cleanup"
  234. source_hook pre-pivot-cleanup
  235.  
  236. # By the time we get here, the root filesystem should be mounted.
  237. # Try to find init.
  238. for i in "$(getarg real_init=)" "$(getarg init=)" $(getargs rd.distroinit=) /sbin/init; do
  239.     [ -n "$i" ] || continue
  240.  
  241.     __p=$(readlink -f "${NEWROOT}/${i}")
  242.     if [ -x "$__p" ]; then
  243.         INIT="$i"
  244.         break
  245.     fi
  246. done
  247.  
  248. [ "$INIT" ] || {
  249.     echo "Cannot find init!"
  250.     echo "Please check to make sure you passed a valid root filesystem!"
  251.     emergency_shell
  252. }
  253.  
  254.  
  255. if [ $UDEVVERSION -lt 168 ]; then
  256.     # stop udev queue before killing it
  257.     udevadm control --stop-exec-queue
  258.  
  259.     HARD=""
  260.     while pidof udevd >/dev/null 2>&1; do
  261.         for pid in $(pidof udevd); do
  262.             kill $HARD $pid >/dev/null 2>&1
  263.         done
  264.         HARD="-9"
  265.     done
  266. else
  267.     udevadm control --exit
  268.     udevadm info --cleanup-db
  269. fi
  270.  
  271. # Retain the values of these variables but ensure that they are unexported
  272. # This is a POSIX-compliant equivalent of bash's "export -n"
  273. for var in root rflags fstype netroot NEWROOT; do
  274.     eval tmp=\$$var
  275.     unset $var
  276.     [ -n "$tmp" ] && eval $var=\"$tmp\"
  277. done
  278.  
  279. export RD_TIMESTAMP
  280. set +x # Turn off debugging for this section
  281. # Clean up the environment
  282. for i in $(export -p); do
  283.     i=${i#declare -x}
  284.     i=${i#export}
  285.     strstr "$i" "=" || continue
  286.     i=${i%%=*}
  287.     [ -z "$i" ] && continue
  288.     case $i in
  289.         root|PATH|HOME|TERM|PS4|RD_*)
  290.             :;;
  291.         *)
  292.             unset "$i";;
  293.     esac
  294. done
  295. . /tmp/export.orig 2>/dev/null || :
  296. rm -f /tmp/export.orig
  297.  
  298. initargs=""
  299. read CLINE </proc/cmdline
  300. if getarg init= >/dev/null ; then
  301.     set +x # Turn off debugging for this section
  302.     ignoreargs="console BOOT_IMAGE"
  303.     # only pass arguments after init= to the init
  304.     CLINE=${CLINE#*init=}
  305.     set -- $CLINE
  306.     shift # clear out the rest of the "init=" arg
  307.     for x in "$@"; do
  308.         for s in $ignoreargs; do
  309.             [ "${x%%=*}" = $s ] && continue 2
  310.         done
  311.         initargs="$initargs $x"
  312.     done
  313.     unset CLINE
  314. else
  315.     set +x # Turn off debugging for this section
  316.     set -- $CLINE
  317.     for x in "$@"; do
  318.         case "$x" in
  319.             [0-9]|s|S|single|emergency|auto ) \
  320.                 initargs="$initargs $x"
  321.                 ;;
  322.         esac
  323.     done
  324. fi
  325. [ "$RD_DEBUG" = "yes" ] && set -x
  326.  
  327. if ! [ -d "$NEWROOT"/run ]; then
  328.     NEWRUN=/dev/.initramfs
  329.     mkdir -m 0755 "$NEWRUN"
  330.     mount --rbind /run/initramfs "$NEWRUN"
  331. fi
  332.  
  333. wait_for_loginit
  334.  
  335. # remove helper symlink
  336. [ -h /dev/root ] && rm -f /dev/root
  337.  
  338. getarg rd.break rdbreak && emergency_shell -n switch_root "Break before switch_root"
  339. info "Switching root"
  340.  
  341. source_hook cleanup
  342.  
  343. unset PS4
  344.  
  345. CAPSH=$(command -v capsh)
  346. SWITCH_ROOT=$(command -v switch_root)
  347. PATH=$OLDPATH
  348. export PATH
  349.  
  350. if [ -f /etc/capsdrop ]; then
  351.     . /etc/capsdrop
  352.     info "Calling $INIT with capabilities $CAPS_INIT_DROP dropped."
  353.     unset RD_DEBUG
  354.     exec $CAPSH --drop="$CAPS_INIT_DROP" -- \
  355.         -c "exec switch_root \"$NEWROOT\" \"$INIT\" $initargs" || \
  356.     {
  357.     warn "Command:"
  358.     warn capsh --drop=$CAPS_INIT_DROP -- -c exec switch_root "$NEWROOT" "$INIT" $initargs
  359.     warn "failed."
  360.     emergency_shell
  361.     }
  362. else
  363.     unset RD_DEBUG
  364.     exec $SWITCH_ROOT "$NEWROOT" "$INIT" $initargs || {
  365.     warn "Something went very badly wrong in the initramfs.  Please "
  366.     warn "file a bug against dracut."
  367.     emergency_shell
  368.     }
  369. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top