システム起動プロセス
ブートからカーネルの起動まで
BIOS: Basic Input/Output System
- メモリのチェック
- H/W設定の読み込み
- 起動デバイスのチェック
-
ブートローダを実行
- 起動デバイスのマスターブートレコード内に格納されている
UEFI: Unified Extensible Firmware Interface
- BIOSの後継
BIOS | UEFI | |
---|---|---|
起動ドライブの容量制限 | 一部OSでは2GB | なし |
GUIベースのセットアップ画面 | 利用不可 | 利用可能な製品もある |
パーティション管理 | MBR | GPT |
MBR/GPT: Master Boot Record / GUID Partition Table
-
MBR: Master Boot Record
- 起動デバイスの最初のセクタ
- 512バイト
-
内訳
-
446
- ブートローダ部分
-
64
- パーティション16 x 4
-
2
- マジックナンバー
- 正しいブートセクタであることの確認用
-
-
GPT: GUID Partition Table
-
UEFIシステムパーティション(ESP)に格納される
-
EFIシステムパーティション
- ESPを格納するパーティション
- FAT(or VFAT)でフォーマットされる
/boot/efi/
ディレクトリにマウントされる
-
-
ブートローダ
-
GRUB: Grand Unified Bootloader
- GRUB Legacy
- GRUB2
-
2段構成
- 1段目: MBRに格納
-
2段目: MBRに格納しきれなかった分
- 指定されたパーティションからカーネルをロードし、制御を移す
カーネル
-
やること
- H/Wの認識
- メモリの初期化
- システムクロックの設定
- IRQの設定
- ルートパーティションのマウント
-
/sbin/init
の実行- PID 1
dmesg
コマンドでカーネル起動中のメッセージを確認できる
[ 0.000000] microcode: microcode updated early to revision 0x24, date = 2018-04-02
[ 0.000000] Linux version 4.15.0-47-generic (buildd@lgw01-amd64-001) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #50-Ubuntu SMP Wed Mar 13 10:44:52 UTC 2019 (Ubuntu 4.15.0-47.50-generic 4.15.18)
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-4.15.0-47-generic root=UUID=bbddb2bb-7fde-4777-88b4-d762aadc173d ro quiet splash vt.handoff=1
[ 0.000000] KERNEL supported cpus:
[ 0.000000] Intel GenuineIntel
[ 0.000000] AMD AuthenticAMD
[ 0.000000] Centaur CentaurHauls
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[ 0.000000] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
[ 0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'standard' format.
[ 0.000000] e820: BIOS-provided physical RAM map:
[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x0000000000057fff] usable
[ 0.000000] BIOS-e820: [mem 0x0000000000058000-0x0000000000058fff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000000059000-0x000000000009bfff] usable
[ 0.000000] BIOS-e820: [mem 0x000000000009c000-0x000000000009cfff] reserved
[ 0.000000] BIOS-e820: [mem 0x000000000009d000-0x000000000009dfff] usable
[ 0.000000] BIOS-e820: [mem 0x000000000009e000-0x00000000000bffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000d0298fff] usable
[ 0.000000] BIOS-e820: [mem 0x00000000d0299000-0x00000000d049afff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000d049b000-0x00000000da941fff] usable
[ 0.000000] BIOS-e820: [mem 0x00000000da942000-0x00000000dcd3efff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000dcd3f000-0x00000000dce7efff] ACPI NVS
[ 0.000000] BIOS-e820: [mem 0x00000000dce7f000-0x00000000dcefefff] ACPI data
[ 0.000000] BIOS-e820: [mem 0x00000000dceff000-0x00000000dcefffff] usable
[ 0.000000] BIOS-e820: [mem 0x00000000dcf00000-0x00000000df9fffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000f80f8000-0x00000000f80f8fff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000fe101000-0x00000000fe112fff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000fed1c000-0x00000000fed1ffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000100000000-0x000000021f5fffff] usable
[ 0.000000] NX (Execute Disable) protection: active
[ 0.000000] e820: update [mem 0xd171b018-0xd172b057] usable ==> usable
[ 0.000000] e820: update [mem 0xd171b018-0xd172b057] usable ==> usable
[ 0.000000] e820: update [mem 0xd170a018-0xd171a657] usable ==> usable
[ 0.000000] e820: update [mem 0xd170a018-0xd171a657] usable ==> usable
[ 0.000000] extended physical RAM map:
...
SysVinitの概要
-
UNIX系OS全般で広く使われてきたやつ
- UNIXのSystemV(システム5)で採用されていた起動の仕組みに基づいている
- 今はSystemdに取って代わられた
-
/etc/inittab
ファイル- centos7ではsystemdになったので、ない
- centos6ではあるはずだが、centos6コンテナにはなかった
- centos5コンテナにはあった(抜粋)
- 流れ
- まず
/etc/inittab
ファイルが読み込まれる
#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
#
# Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
# Modified for RHS Linux by Marc Ewing and Donnie Barnes
#
# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:3:initdefault:
# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit
l0:0:wait:/etc/rc.d/rc 0
...
-
/etc/rc.sysinit
スクリプトが実行される- centos5コンテナでは
/etc/rc.d/rc.sysinit
へのシンボリックリンクだった - クッソ長い
- centos5コンテナでは
-
/etc/rc
スクリプトが実行される- centos5コンテナでは
/etc/rc.d/rc
へのシンボリックリンクだった
- centos5コンテナでは
...
# Now run the START scripts.
for i in /etc/rc$runlevel.d/S* ; do
check_runlevel "$i" || continue
...
/etc/rc<ランレベル>.d/
ディレクトリ下のスクリプトが実行される- 以上
/etc/inittab
の書式
# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1
<ID(4文字以下)>:<実行するランレベル>:<アクション指示子>:<処理>
- 最終的に
mingetty
やagetty
等のプロセスを端末に関連付け、
(ttyプロセスが)/bin/login
プロセスを起動して各端末でログインできるようにする
...
# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6
# Run xdm in runlevel 5
x:5:respawn:/etc/X11/prefdm -nodaemon
agetty
のマニュアル
AGETTY(8) System Administration AGETTY(8)
NAME
agetty - alternative Linux getty
SYNOPSIS
agetty [options] port [baud_rate...] [term]
DESCRIPTION
agetty opens a tty port, prompts for a login name and
invokes the /bin/login command. It is normally invoked by
init(8).
...
- アクション指示子
-
boot
- システム起動時に実行
- プロセス終了待たない
-
bootwait
- システム起動時に実行
- プロセス終了待つ
-
ctrlaltdel
-
SIGINTがinitに送られたら実行
- Ctrl + Alt + Del 押下等
-
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now
-
initdefault
- デフォルトのランレベルを設定する
id:3:initdefault:
-
respawn
- 指定したプロセスが終了すれば再起動する
-
sysinit
- システム起動時に、
boot
やbootwait
よりも先に実行される
- システム起動時に、
# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit
-
once
- 指定したランレベルになったときに一度だけ実行される
- プロセスが終了待たない
-
wait
- 指定したランレベルになったときに一度だけ実行される
- プロセスが終了待つ
...
l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6
...
起動スクリプトとランレベル
- ランレベルごとに起動サービスは異なる
-
/etc/rc{0,1,2,3,4,5,6}.d/
ディレクトリ- ランレベル別起動スクリプト置き場
ls -l /etc/rc3.d/
lrwxrwxrwx 1 root root 20 Mar 31 2016 K50netconsole -> ../init.d/netconsole
lrwxrwxrwx 1 root root 17 Mar 31 2016 K74rsyslog -> ../init.d/rsyslog
lrwxrwxrwx 1 root root 20 Mar 31 2016 K87multipathd -> ../init.d/multipathd
lrwxrwxrwx 1 root root 18 Mar 31 2016 K89netplugd -> ../init.d/netplugd
lrwxrwxrwx 1 root root 15 Mar 31 2016 K89rdisc -> ../init.d/rdisc
lrwxrwxrwx 1 root root 16 Mar 31 2016 S07iscsid -> ../init.d/iscsid
lrwxrwxrwx 1 root root 18 Mar 31 2016 S08mcstrans -> ../init.d/mcstrans
lrwxrwxrwx 1 root root 17 Mar 31 2016 S10network -> ../init.d/network
lrwxrwxrwx 1 root root 15 Mar 31 2016 S13iscsi -> ../init.d/iscsi
lrwxrwxrwx 1 root root 15 Mar 31 2016 S25netfs -> ../init.d/netfs
lrwxrwxrwx 1 root root 22 Mar 31 2016 S26lvm2-monitor -> ../init.d/lvm2-monitor
lrwxrwxrwx 1 root root 20 Mar 31 2016 S56rawdevices -> ../init.d/rawdevices
lrwxrwxrwx 1 root root 11 Mar 31 2016 S99local -> ../rc.local
-
[SK]\d+.+
な感じな名前- いずれも
/etc/init.d/
以下のスクリプトへのシンボリックリンク -
[SK]
- S: このランレベルで起動するサービス
- K: このランレベルで終了するサービス
-
\d+
- 数値の小さい順に起動/終了される
-
.+
- シンボリックリンク先の名前
- いずれも
./rsyslog --help
Usage: ./rsyslog {start|stop|restart|condrestart|try-restart|reload|force-reload|status}
- サービス起動スクリプトの主なコマンド
サブコマンド | 説明 |
---|---|
start | サービスを開始 |
stop | サービスを終了 |
restart | サービスを再起動する |
condrestart | サービスが起動している場合のみ再起動 |
status | 状態を表示する |
コラム
-
service
コマンド使え-
/etc/init.d/
のスクリプトを使って制御する代わり- CentOSでは挙動が異なることがあるらしい
-
systemd採用システムでも使える
- でも
systemctl
使え
- でも
-
- LSB: Linux Standard Base
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic