Help us understand the problem. What is going on with this article?

Amazon Linux Booting process

More than 1 year has passed since last update.

概要

Amazon Linuxを利用して、sudo /etc/init.d/xxxを利用することが多くて、そちらどう動いてるかを調べた

booting process

こちらを参考にして、
systemdが使っていないので、少し変更した

  1. The computer’s BIOS performs POST.
  2. BIOS reads the MBR for the bootloader.
  3. GRUB 2 bootloader loads the vmlinuz kernel image.
  4. GRUB 2 extracts the contents of the initramfs image.
  5. The kernel loads driver modules from initramfs. Kernel starts the system’s first process, systemd.
  6. Reads configuration files from the /etc/ directory
    • Execute /etc/rc{runlevel}.rd
    • Execute /etc/rc.local

rc3.rd

runlevel3でログインする場合は多くて、rc3.rd下のファイル一覧確認すると

$ ls -la /etc/rc3.d/
一部省略
lrwxrwxrwx  1 root root   17  5月  9 01:32 S10network -> ../init.d/network
lrwxrwxrwx  1 root root   15  3月 19  2015 S90crond -> ../init.d/crond
一部省略

/etc/init.d/下のスクリプトからリンクをつけて、実行されるのは/etc/init.d/下のスクリプトファイル

init.d script

/etc/init.d/crondを例で見ると、shellスクリプトを実行するだけ

case "$1" in
    start)
        hogehoge
    stop)
        hogehoge
    restart)
        hogehoge
    reload)
        etc...
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
        exit 2
esac
exit $?

実行順番

  1. Kから始まるscriptを先に実行、番号が小さい方から実行
    • Kはkill、停止の意味
  2. Sから始まるscriptを先に実行、番号が小さい方から実行
    • Sはstart、開始の意味

chkconfig

chkconfigで起動してるサービスが多くて

# chkconfig: 2345 90 60

runlevel 2345で起動する、起動する時の順番は90、停止時には60という意味

こちらは詳しい

nginxなどどう起動してるか分かる

/etc/init.d/nginx中身を見ると、config file、pidfileの場所が分かるので、その辺不明な時には起動スクリプト確認するのが一番早い

sysconfig="hogehoge"
lockfile="hogehoge"
pidfile="hogehoge"

NGINX_CONF_FILE="hogehoge"

grub

/boot/grub/grub.confで設定

default=0 # titleの0番実行
fallback=1
timeout=1
hiddenmenu

title Amazon Linux 2015.03 (3.14.35-28.38.amzn1.x86_64)
root (hd0,0)
# kernelのパス
kernel /boot/vmlinuz-3.14.35-28.38.amzn1.x86_64 root=LABEL=/ console=ttyS0
# initrdのパス
initrd /boot/initramfs-3.14.35-28.38.amzn1.x86_64.img
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away