./init の処理 (3)devinitramfs 内の /dev や udev の準備 # Note that this only becomes /dev on the real filesystem if udev's scripts # are used; which they will be, but it's worth pointing out tmpfs_size="10M" if [ -e /etc/udev/udev.conf ]; then . /etc/udev/udev.conf fi if ! mount -t devtmpfs -o mode=0755 none /dev; then echo "W: devtmpfs not available, falling back to tmpfs for /dev" mount -t tmpfs -o size=$tmpfs_size,mode=0755 udev /dev [ -e /dev/console ] || mknod -m 0600 /dev/console c 5 1 [ -e /dev/null ] || mknod /dev/null c 1 3 fi mkdir /dev/pts mount -t devpts -o noexec,nosuid,gid=5,mode=0620 none /dev/pts || true > /dev/.initramfs-tools mkdir /dev/.initramfs 26/52
./init (5) confconfファイルの読み込み # Bring in the main config . /conf/initramfs.conf for conf in conf/conf.d/*; do [ -f ${conf} ] && . ${conf} done . /scripts/functions 28/52
./init (6) cmdlineカーネルのコマンドライン引数(/proc/cmdline) の解析 # Parse command line options for x in $(cat /proc/cmdline); do case $x in init=*) init=${x#init=} ;; root=*) ROOT=${x#root=} case $ROOT in LABEL=*) ROOT="${ROOT#LABEL=}" (省略) 31/52
33.
./init (7) noresume if [ -n "${noresume}" ]; then export noresume unset resume else resume=${RESUME:-} fi # cmdline 処理の一部: resume=*) RESUME="${x#resume=}" ;; resume_offset=*) resume_offset="${x#resume_offset=}" ;; noresume) noresume=y ;; 32/52
scripts/functions:maybe_break (1)# scripts/functions の一部: maybe_break() { if [ "${break:-}" = "$1" ]; then panic "Spawning shell within the initramfs" fi } 35/52
37.
scripts/functions:maybe_break (2)ubuntu (lucid)の initramfs-tools0.92bubuntu78(以降 ubuntu 版の話がある場合はこのバージョン)の場合、Debian と違って複数指定可能 # scripts/functions の一部: maybe_break() { if echo "${break}" | egrep -q "(,|^)$1(,|$)"; then panic "Spawning shell within the initramfs" fi } 36/52
38.
functions: panic (1)起動時にroot ファイルシステムが見つからなくて「(initramfs)」で止まることがあるのはこれ。 # scripts/functions の一部: panic() { if [ -x /sbin/usplash_write ]; then /sbin/usplash_write "QUIT" fi if command -v chvt >/dev/null 2>&1; then chvt 1 fi # Disallow console access if [ -n "${panic}" ]; then sleep ${panic} reboot fi modprobe i8042 modprobe atkbd echo "$@" REASON="$@" PS1='(initramfs) ' /bin/sh -i </dev/console >/dev/console 2>&1 } 37/52
./script/local run_scripts /scripts/local-topのようなフックを実行したり"${ROOT}" で指定されているデバイスをマウントしたりマウントできなかったときに panic "ALERT! ${ROOT} does not exist. Dropping to a shell!"で「(initramfs) 」のシェルに落ちたりする。 46/52
48.
./init (13) bottom最初の方でマウントしたsysfs と proc を本当の root ファイルシステム (real root) に移動する。 maybe_break bottom [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-bottom" run_scripts /scripts/init-bottom [ "$quiet" != "y" ] && log_end_msg # Move virtual filesystems over to the real filesystem mount -n -o move /sys ${rootmnt}/sys mount -n -o move /proc ${rootmnt}/proc 47/52
49.
./init (14) checkinit validate_init() { checktarget="${1}" # Work around absolute symlinks if [ -d "${rootmnt}" ] && [ -h "${rootmnt}${checktarget}" ]; then case $(readlink "${rootmnt}${checktarget}") in /*) checktarget="$(chroot ${rootmnt} readlink ${checktarget} )" ;; esac fi # Make sure the specified init can be executed if [ ! -x "${rootmnt}${checktarget}" ]; then return 1 fi # Upstart uses /etc/init as configuration directory :-/ if [ -d "${rootmnt}${checktarget}" ]; then return 1 fi } 48/52
50.
./init (15) checkinit # Check init bootarg if [ -n "${init}" ]; then if ! validate_init "$init"; then echo "Target filesystem doesn't have requested ${init}." init= fi fi # Common case: /sbin/init is present if [ ! -x "${rootmnt}/sbin/init" ]; then # ... if it's not available search for valid init if [ -z "${init}" ] ; then for inittest in /sbin/init /etc/init /bin/init /bin/sh; do if validate_init "${inittest}"; then init="$inittest" break fi done fi # No init on rootmount if ! validate_init "${init}" ; then panic "No init found. Try passing init= bootarg." fi fi 49/52
51.
./init (16) unsetenv # don't leak too much of env - some init(8) don't clear it # (keep init, rootmnt) unset debug unset MODPROBE_OPTIONS unset DPKG_ARCH unset ROOTFLAGS unset ROOTFSTYPE unset ROOTDELAY unset ROOT unset IP unset BOOT unset BOOTIF unset UBIMTD unset blacklist unset break unset noresume unset panic unset quiet unset readonly unset resume unset resume_offset 50/52
52.
./init (17) execinitklibc-utils パッケージ由来の run-init で realroot の /sbin/init などを実行 # Chain to real filesystem exec run-init ${rootmnt} ${init} "$@" <${rootmnt}/dev/console >${rootmnt}/dev/console panic "Could not execute run-init." 51/52
53.
real root での処理 sysvinit /etc/inittab に従って処理 upstart /etc/init/*.conf に従って処理 などPowered by Rabbit 0.6.4 52/52