システム初期化処理

システム初期化処理は /etc/rc.d/rc.S で行います。/etc/rc.d/rc.S は Bourne シェルスクリプトです。

/etc/rc.d/rc.S
PATH=/sbin:/usr/sbin:/bin:/usr/bin

コマンドを検索するパスを設定します。

/etc/rc.d/rc.S
# Start devfsd if necessary
if [ -r /dev/.devfsd ]; then
  if [ -x /sbin/devfsd ]; then
    echo "Starting devfs daemon:  /sbin/devfsd /dev"
    /sbin/devfsd /dev
  fi
fi

/dev/.devfsd が読み取り可能であり、/sbin/devfsd が実行可能であれば /sbin/devfsd /dev を実行します。

/etc/rc.d/rc.S
# enable swapping
/sbin/swapon -a

スワッピングを有効にします。

/etc/rc.d/rc.S
# Test to see if the root partition is read-only, like it ought to be.
READWRITE=no
if echo -n >> "Testing filesystem status"; then
  rm -f "Testing filesystem status"
  READWRITE=yes
fi

ルートパーティションの状態を調べます。読み取り専用の場合は READWRITE を no と設定します。読み書きが可能な場合は READWRITE を yes と設定します。

/etc/rc.d/rc.S
# See if a forced filesystem check was requested at shutdown:
if [ -r /etc/forcefsck ]; then
  FORCEFSCK="-f"
fi

/etc/forcefsck が読み込み可能であれば、FORCEFSCK を -f と設定します。

/etc/rc.d/rc.S
# Check the root filesystem:
if [ ! $READWRITE = yes ]; then
  if [ ! -r /etc/fastboot ]; then
    echo "Checking root filesystem:"
    /sbin/fsck $FORCEFSCK -C -a /
  fi
  # If there was a failure, drop into single-user mode.
  if [ $? -gt 1 ] ; then
    echo
    echo
    echo "***********************************************************"
    echo "*** An error occurred during the root filesystem check. ***"
    echo "*** You will now be given a chance to log into the      ***"
    echo "*** system in single-user mode to fix the problem.      ***"
    echo "***                                                     ***"
    echo "*** If you are using the ext2 filesystem, running       ***"
    echo "*** 'e2fsck -v -y <partition>' might help.              ***"
    echo "***********************************************************"
    echo
    echo "Once you exit the single-user shell, the system will reboot."
    echo
    PS1="(Repair filesystem) ¥#"; export PS1
    sulogin
    echo "Unmounting file systems."
    umount -a -r
    mount -n -o remount,ro /
    echo "Rebooting system."
    sleep 2
    reboot -f
  fi
  # Remount the root filesystem in read-write mode
  echo "Remounting root device with read-write enabled."
  /sbin/mount -w -v -n -o remount /
  if [ $? -gt 0 ] ; then
    echo
    echo "Attempt to remount root device as read-write failed!  This is going to"
    echo "cause serious problems."
    echo 
    echo "If you're using the UMSDOS filesystem, you **MUST** mount the root partition"
    echo "read-write!  You can make sure the root filesystem is getting mounted "
    echo "read-write with the 'rw' flag to Loadlin:"
    echo
    echo "loadlin vmlinuz root=/dev/hda1 rw   (replace /dev/hda1 with your root device)"
    echo
    echo "Normal bootdisks can be made to mount a system read-write with the rdev command:"
    echo
    echo "rdev -R /dev/fd0 0"
    echo
    echo "You can also get into your system by using a boot disk with a command like this"
    echo "on the LILO prompt line:  (change the root partition name as needed)"
    echo 
    echo "LILO: mount root=/dev/hda1 rw"
    echo
    echo "Please press ENTER to continue, then reboot and use one of the above methods to"
    echo -n "get into your machine and start looking for the problem. " 
    read junk; 
  fi
else
  echo "Testing filesystem status: read-write filesystem"
  if cat /etc/fstab | grep ' / ' | grep umsdos 1> /dev/null 2> /dev/null ; then
    ROOTTYPE="umsdos"
  fi
  if [ ! "$ROOTTYPE" = "umsdos" ]; then # no warn for UMSDOS
    echo
    echo "*** ERROR: Root partition has already been mounted read-write. Cannot check!"
    echo
    echo "For filesystem checking to work properly, your system must initially mount"
    echo "the root partition as read only. Please modify your kernel with 'rdev' so that"
    echo "it does this. If you're booting with LILO, add a line:"
    echo
    echo "   read-only"
    echo
    echo "to the Linux section in your /etc/lilo.conf and type 'lilo' to reinstall it."
    echo
    echo "If you boot from a kernel on a floppy disk, put it in the drive and type:"
    echo "   rdev -R /dev/fd0 1"
    echo
    echo "If you boot from a bootdisk, or with Loadlin, you can add the 'ro' flag."
    echo
    echo "This will fix the problem *AND* eliminate this annoying message. :^)"
    echo
    echo -n "Press ENTER to continue. "
    read junk;
  fi
fi # Done checking root filesystem

ルートファイルシステムが読み取り専用であり、/etc/fastboot が存在しなければ /sbin/fsck $FORCEFSCK -C -a / を実行しファイルシステムのチェックを行います。エラーが起きた場合はシングルユーザモードでログインします。シングルユーザモードからログアウトした後は、再起動します。エラーが起きなかった場合は、ルートファイルシステムを読み書き可能なモードで再マウントします。エラーが起きた場合は対処法を示し実行を続けます。

ルートファイルシステムが読み書き可能であれば、/etc/fstab を検査します。その結果、ルートファイルシステムが UMSDOS と分かれば ROOTTYPE を umsdos と設定します。UMSDOS ではない場合は、エラーメッセージと対処法を表示します。

/etc/rc.d/rc.S
# Any /etc/mtab that exists here is old, so we delete it to start over:
/bin/rm -f /etc/mtab*
# Remounting the / partition will initialize the new /etc/mtab:
/sbin/mount -w -o remount /

すでに古くなった /etc/mtab* を消去し、/sbin/mount -w -o remount / を実行して読み書き可能なモードで再マウントします。これにより、/etc/mtab が初期化されます。

/etc/rc.d/rc.S
# Initialize the Logical Volume Manager.
# This won't start unless /etc/lvmtab is found, which is created by /sbin/vgscan.
# Therefore, to use LVM you must run /sbin/vgscan yourself the first time.
if [ -r /etc/lvmtab ]; then
  # Mount /proc early (it's needed for vgscan):
  /sbin/mount -a -t proc
  # Scan for new volume groups:
  /sbin/vgscan
  if [ $? = 0 ]; then
    # Make volume groups available to the kernel:
    /sbin/vgchange -ay
  fi
fi

/etc/lvmtab が読み取り可能であれば、/sbin/mount -a -t proc を実行して /proc をマウントします。そして、/sbin/vgscan を実行しエラーが発生しなければ、/sbin/vgchange -ay を実行します。

/etc/rc.d/rc.S
# Check all the non-root filesystems:
if [ ! -r /etc/fastboot ]; then
  echo "Checking non-root filesystems:"
  /sbin/fsck $FORCEFSCK -C -R -A -a
fi

/etc/fastboot が読み込み可能でない場合、/sbin/fsck $FORCEFSCK -C -R -A -a を実行して、ルートファイルシステム以外をチェックします。

/etc/rc.d/rc.S
# mount non-root file systems in fstab (but not NFS or SMB 
# because TCP/IP is not yet configured):
/sbin/mount -a -v -t nonfs,nosmbfs

/sbin/mount -a -v -t nonfs,nosmbfs を実行して、ルートファイルシステム以外をマウントします。但し、まだ TCP/IP の設定がされていないので、NFS と SMB ファイルシステムはマウントしません。

/etc/rc.d/rc.S
# Clean up some temporary files:
( cd /var/log/setup/tmp && rm -rf * )
/bin/rm -f /var/run/utmp /var/run/*pid /etc/nologin /var/run/lpd* ¥
  /var/run/ppp* /etc/dhcpc/dhcpcd-eth0.pid /etc/forcefsck /etc/fastboot

いくつかのテンポラリファイルを削除します。

/etc/rc.d/rc.S
# Create a fresh utmp file:
cat /dev/null > /var/run/utmp

新しい utmp ファイルを作成します。

/etc/rc.d/rc.S
if [ "$ROOTTYPE" = "umsdos" ]; then # we need to update any files added in DOS:
  echo "Synchronizing UMSDOS directory structure:"
  echo "  umssync -r99 -v- /"
  umssync -r99 -v- /
fi

ルートファイルシステムが UMSDOS であれば、umssync -r99 -v- / を実行します。

/etc/rc.d/rc.S
# Setup the /etc/motd to reflect the current kernel level:
# THIS WIPES ANY CHANGES YOU MAKE TO /ETC/MOTD WITH EACH BOOT.
# COMMENT THIS OUT IF YOU WANT TO MAKE A CUSTOM VERSION.
echo "`/bin/uname -sr`." > /etc/motd

/etc/motd を作成します。/etc/motd の内容はカーネルのバージョンを含んだものとなります。

/etc/rc.d/rc.S
# Configure ISA Plug-and-Play devices:
if [ -r /etc/isapnp.conf ]; then
  if [ -x /sbin/isapnp ]; then
    /sbin/isapnp /etc/isapnp.conf
  fi
fi

/etc/isapnp.conf が読み取り可能であり、/sbin/isapnp が実行可能であれば、/sbin/isapnp /etc/isapnp.conf を実行します。

/etc/rc.d/rc.S
# Set the system time from the hardware clock using hwclock --hctosys.
# Detect SGI Visual Workstation, since hwclock will make those freeze up:
if fgrep -l Cobalt-APIC /proc/interrupts 1> /dev/null 2> /dev/null ; then
  echo "SGI Visual Workstation detected.  Not running hwclock."
elif [ -x /sbin/hwclock ]; then
  if grep "^UTC" /etc/hardwareclock 1> /dev/null 2> /dev/null ; then
    echo "Setting system time from the hardware clock (UTC)."
    /sbin/hwclock --utc --hctosys
  else
    echo "Setting system time from the hardware clock (localtime)."
    /sbin/hwclock --localtime --hctosys
  fi
fi

システムタイムを設定します。但し、SGI Visual Workstation であることを検出した場合は、何もしません。/sbin/hwclock が実行可能であれば、/etc/hardwareclock を検査します。UTC と記載されている場合は、/sbin/hwclock --utc --hctosys を実行します。UTC と記載されていなければ、/sbin/hwclock --localtime --hctosys を実行します。

/etc/rc.d/rc.S
# This loads any kernel modules that are needed.  These might be required to
# use your CD-ROM drive, bus mouse, ethernet card, or other optional hardware.
if [ -x /etc/rc.d/rc.modules ]; then
  . /etc/rc.d/rc.modules
fi

/etc/rc.d/rc.modules が実行可能であれば、/etc/rc.d/rc.modules を実行します。これは、Bourne シェルスクリプトです。いくつかのモジュールを読み込みます。

/etc/rc.d/rc.S
# Carry an entropy pool between reboots to improve randomness.
# Load and then save 512 bytes, which is the size of the entropy pool.
if [ -f /etc/random-seed ]; then
  echo "Using /etc/random-seed to initialize /dev/urandom."
  cat /etc/random-seed >/dev/urandom
fi
dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2> /dev/null

/etc/random-seed が普通のファイルであれば、cat /etc/random-seed >/dev/urandom を実行します。そして、いずれの場合でも dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2> /dev/null を実行します。これらは、より良い乱数を発生させるための準備です。

参考文献


前へ 起動プロセス入門 次へ