Advertisement
arter97

Untitled

Jul 26th, 2018
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.82 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Default PATH differs between shells, and is not automatically exported
  4. # by klibc dash.  Make it consistent.
  5. export PATH=/sbin:/usr/sbin:/bin:/usr/bin
  6.  
  7. [ -d /dev ] || mkdir -m 0755 /dev
  8. [ -d /root ] || mkdir -m 0700 /root
  9. [ -d /sys ] || mkdir /sys
  10. [ -d /proc ] || mkdir /proc
  11. [ -d /tmp ] || mkdir /tmp
  12. mkdir -p /var/lock
  13. mount -t sysfs -o nodev,noexec,nosuid sysfs /sys
  14. mount -t proc -o nodev,noexec,nosuid proc /proc
  15.  
  16. case " $(cat /proc/cmdline) " in
  17. *\ quiet\ *)
  18.     quiet=y
  19.     ;;
  20. *)
  21.     quiet=n
  22.     echo "Loading, please wait..."
  23.     ;;
  24. esac
  25. export quiet
  26.  
  27. # Note that this only becomes /dev on the real filesystem if udev's scripts
  28. # are used; which they will be, but it's worth pointing out
  29. mount -t devtmpfs -o nosuid,mode=0755 udev /dev
  30. mkdir /dev/pts
  31. mount -t devpts -o noexec,nosuid,gid=5,mode=0620 devpts /dev/pts || true
  32. mount -t tmpfs -o "noexec,nosuid,size=10%,mode=0755" tmpfs /run
  33. mkdir -m 0755 /run/initramfs
  34.  
  35. # Export the dpkg architecture
  36. export DPKG_ARCH=
  37. . /conf/arch.conf
  38.  
  39. # Set modprobe env
  40. export MODPROBE_OPTIONS="-qb"
  41.  
  42. # Export relevant variables
  43. export ROOT=
  44. export ROOTDELAY=
  45. export ROOTFLAGS=
  46. export ROOTFSTYPE=
  47. export IP=
  48. export IP6=
  49. export BOOT=
  50. export BOOTIF=
  51. export UBIMTD=
  52. export break=
  53. export init=/sbin/init
  54. export readonly=y
  55. export rootmnt=/root
  56. export debug=
  57. export panic=
  58. export blacklist=
  59. export resume=
  60. export resume_offset=
  61. export drop_caps=
  62. export fastboot=n
  63. export forcefsck=n
  64. export fsckfix=
  65. export recovery=
  66.  
  67.  
  68. # mdadm needs hostname to be set. This has to be done before the udev rules are called!
  69. if [ -f "/etc/hostname" ]; then
  70.         /bin/hostname -F /etc/hostname >/dev/null 2>&1
  71. fi
  72.  
  73. # Bring in the main config
  74. . /conf/initramfs.conf
  75. for conf in conf/conf.d/*; do
  76.     [ -f ${conf} ] && . ${conf}
  77. done
  78. . /scripts/functions
  79.  
  80. # Parse command line options
  81. for x in $(cat /proc/cmdline); do
  82.     case $x in
  83.     init=*)
  84.         init=${x#init=}
  85.         ;;
  86.     root=*)
  87.         ROOT=${x#root=}
  88.         if [ -z "${BOOT}" ] && [ "$ROOT" = "/dev/nfs" ]; then
  89.             BOOT=nfs
  90.         fi
  91.                 ;;
  92.     rootflags=*)
  93.         ROOTFLAGS="-o ${x#rootflags=}"
  94.         ;;
  95.     rootfstype=*)
  96.         ROOTFSTYPE="${x#rootfstype=}"
  97.         ;;
  98.     rootdelay=*)
  99.         ROOTDELAY="${x#rootdelay=}"
  100.         case ${ROOTDELAY} in
  101.         *[![:digit:].]*)
  102.             ROOTDELAY=
  103.             ;;
  104.         esac
  105.         ;;
  106.     resumedelay=*)
  107.         RESUMEDELAY="${x#resumedelay=}"
  108.         ;;
  109.     loop=*)
  110.         LOOP="${x#loop=}"
  111.         ;;
  112.     loopflags=*)
  113.         LOOPFLAGS="-o ${x#loopflags=}"
  114.         ;;
  115.     loopfstype=*)
  116.         LOOPFSTYPE="${x#loopfstype=}"
  117.         ;;
  118.     cryptopts=*)
  119.         cryptopts="${x#cryptopts=}"
  120.         ;;
  121.     nfsroot=*)
  122.         NFSROOT="${x#nfsroot=}"
  123.         ;;
  124.     netboot=*)
  125.         NETBOOT="${x#netboot=}"
  126.         ;;
  127.     ip=*)
  128.         IP="${x#ip=}"
  129.         ;;
  130.     ip6=*)
  131.         IP6="${x#ip6=}"
  132.         ;;
  133.     boot=*)
  134.         BOOT=${x#boot=}
  135.         ;;
  136.     ubi.mtd=*)
  137.         UBIMTD=${x#ubi.mtd=}
  138.         ;;
  139.     resume=*)
  140.         RESUME="${x#resume=}"
  141.         case $RESUME in
  142.             UUID=*)
  143.             RESUME="/dev/disk/by-uuid/${RESUME#UUID=}"
  144.         esac
  145.         ;;
  146.     resume_offset=*)
  147.         resume_offset="${x#resume_offset=}"
  148.         ;;
  149.     noresume)
  150.         noresume=y
  151.         ;;
  152.     drop_capabilities=*)
  153.         drop_caps="-d ${x#drop_capabilities=}"
  154.         ;;
  155.     panic=*)
  156.         panic="${x#panic=}"
  157.         case ${panic} in
  158.         *[![:digit:].]*)
  159.             panic=
  160.             ;;
  161.         esac
  162.         ;;
  163.     ro)
  164.         readonly=y
  165.         ;;
  166.     rw)
  167.         readonly=n
  168.         ;;
  169.     debug)
  170.         debug=y
  171.         quiet=n
  172.         if [ -n "${netconsole}" ]; then
  173.             exec >/dev/kmsg 2>&1
  174.         else
  175.             exec >/run/initramfs/initramfs.debug 2>&1
  176.         fi
  177.         set -x
  178.         ;;
  179.     debug=*)
  180.         debug=y
  181.         quiet=n
  182.         set -x
  183.         ;;
  184.     break=*)
  185.         break=${x#break=}
  186.         ;;
  187.     break)
  188.         break=premount
  189.         ;;
  190.     blacklist=*)
  191.         blacklist=${x#blacklist=}
  192.         ;;
  193.     netconsole=*)
  194.         netconsole=${x#netconsole=}
  195.         [ "x$debug" = "xy" ] && exec >/dev/kmsg 2>&1
  196.         ;;
  197.     BOOTIF=*)
  198.         BOOTIF=${x#BOOTIF=}
  199.         ;;
  200.     hwaddr=*)
  201.         BOOTIF=${x#hwaddr=}
  202.         ;;
  203.     fastboot|fsck.mode=skip)
  204.         fastboot=y
  205.         ;;
  206.     forcefsck|fsck.mode=force)
  207.         forcefsck=y
  208.         ;;
  209.     fsckfix|fsck.repair=yes)
  210.         fsckfix=y
  211.         ;;
  212.     fsck.repair=no)
  213.         fsckfix=n
  214.         ;;
  215.     recovery)
  216.         recovery=y
  217.         ;;
  218.     esac
  219. done
  220.  
  221. # Default to BOOT=local if no boot script defined.
  222. if [ -z "${BOOT}" ]; then
  223.     BOOT=local
  224. fi
  225.  
  226. if [ -n "${noresume}" ] || [ "$RESUME" = none ]; then
  227.     export noresume=y
  228.     unset resume
  229. else
  230.     resume=${RESUME:-}
  231. fi
  232.  
  233. maybe_break top
  234.  
  235. # export BOOT variable value for compcache,
  236. # so we know if we run from casper
  237. export BOOT
  238.  
  239. # Don't do log messages here to avoid confusing graphical boots
  240. run_scripts /scripts/init-top
  241.  
  242. maybe_break modules
  243. [ "$quiet" != "y" ] && log_begin_msg "Loading essential drivers"
  244. [ -n "${netconsole}" ] && modprobe netconsole netconsole="${netconsole}"
  245. load_modules
  246. [ "$quiet" != "y" ] && log_end_msg
  247.  
  248. maybe_break premount
  249. [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-premount"
  250. run_scripts /scripts/init-premount
  251. [ "$quiet" != "y" ] && log_end_msg
  252.  
  253. maybe_break mount
  254. log_begin_msg "Mounting root file system"
  255. # Always load local and nfs (since these might be needed for /etc or
  256. # /usr, irrespective of the boot script used to mount the rootfs).
  257. . /scripts/local
  258. . /scripts/nfs
  259. . /scripts/${BOOT}
  260. parse_numeric ${ROOT}
  261. maybe_break mountroot
  262. mount_top
  263. mount_premount
  264. mountroot
  265. log_end_msg
  266.  
  267. if read_fstab_entry /usr; then
  268.     log_begin_msg "Mounting /usr file system"
  269.     mountfs /usr
  270.     log_end_msg
  271. fi
  272.  
  273. # Mount cleanup
  274. mount_bottom
  275. nfs_bottom
  276. local_bottom
  277.  
  278. maybe_break bottom
  279. [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-bottom"
  280. # We expect udev's init-bottom script to move /dev to ${rootmnt}/dev
  281. run_scripts /scripts/init-bottom
  282. [ "$quiet" != "y" ] && log_end_msg
  283.  
  284. # Move /run to the root
  285. mount -n -o move /run ${rootmnt}/run
  286.  
  287. validate_init() {
  288.     run-init -n "${rootmnt}" "${1}"
  289. }
  290.  
  291. # Check init is really there
  292. if ! validate_init "$init"; then
  293.     echo "Target filesystem doesn't have requested ${init}."
  294.     init=
  295.     for inittest in /sbin/init /etc/init /bin/init /bin/sh; do
  296.         if validate_init "${inittest}"; then
  297.             init="$inittest"
  298.             break
  299.         fi
  300.     done
  301. fi
  302.  
  303. # No init on rootmount
  304. if ! validate_init "${init}" ; then
  305.     panic "No init found. Try passing init= bootarg."
  306. fi
  307.  
  308. maybe_break init
  309.  
  310. # don't leak too much of env - some init(8) don't clear it
  311. # (keep init, rootmnt, drop_caps)
  312. unset debug
  313. unset MODPROBE_OPTIONS
  314. unset DPKG_ARCH
  315. unset ROOTFLAGS
  316. unset ROOTFSTYPE
  317. unset ROOTDELAY
  318. unset ROOT
  319. unset IP
  320. unset IP6
  321. unset BOOT
  322. unset BOOTIF
  323. unset UBIMTD
  324. unset blacklist
  325. unset break
  326. unset noresume
  327. unset panic
  328. unset quiet
  329. unset readonly
  330. unset resume
  331. unset resume_offset
  332. unset fastboot
  333. unset forcefsck
  334. unset fsckfix
  335.  
  336. # Move virtual filesystems over to the real filesystem
  337. mount -n -o move /sys ${rootmnt}/sys
  338. mount -n -o move /proc ${rootmnt}/proc
  339.  
  340. # Chain to real filesystem
  341. exec run-init ${drop_caps} ${rootmnt} ${init} "$@" ${recovery:+--startup-event=recovery} <${rootmnt}/dev/console >${rootmnt}/dev/console 2>&1
  342. echo "Something went badly wrong in the initramfs."
  343. panic "Please file a bug on initramfs-tools."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement