3.1 システム起動プロセス つづき
3.1.5 systemdの概要
ps p 1
PID TTY STAT TIME COMMAND
1 ? Ss 0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize
こいつ
systemdと名のつくデーモンプロセスは複数ある
ps aux | grep systemd
root 1 0.2 0.6 127992 6620 ? Ss 13:38 0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root 304 0.0 0.2 37228 2352 ? Ss 13:38 0:00 /usr/lib/systemd/systemd-journald
root 326 0.0 0.4 48020 4968 ? Ss 13:38 0:00 /usr/lib/systemd/systemd-udevd
dbus 445 0.0 0.2 66472 2580 ? Ssl 13:38 0:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
root 1070 0.0 0.1 26384 1752 ? Ss 13:38 0:00 /usr/lib/systemd/systemd-logind
-
systemd
- メイン
-
systemd-journald
- ログ管理
-
systemd-logind
- ユーザログイン処理
-
systemd-udevd
- デバイス動的検知
Unit
種類
- service
-
device
- udevのデバイス認識により自動作成
-
mount
- /etc/fstabより自動作成
-
swap
- /etc/fstabより自動作成
-
target
- 複数のunitをまとめる
- 【所感】composite pattern的な
拡張子で区別できる
targetに含まれるunitは*.wants/
ディレクトリ内のsymlinkで表現
基本のものは/lib/
ls -l /lib/systemd/system/multi-user.target.wants/
total 0
lrwxrwxrwx. 1 root root 15 Nov 10 18:10 dbus.service -> ../dbus.service
lrwxrwxrwx. 1 root root 15 Nov 10 18:10 getty.target -> ../getty.target
lrwxrwxrwx. 1 root root 29 Nov 10 18:06 plymouth-quit-wait.service -> ../plymouth-quit-wait.service
lrwxrwxrwx. 1 root root 24 Nov 10 18:06 plymouth-quit.service -> ../plymouth-quit.service
lrwxrwxrwx. 1 root root 33 Nov 10 18:10 systemd-ask-password-wall.path -> ../systemd-ask-password-wall.path
lrwxrwxrwx. 1 root root 25 Nov 10 18:10 systemd-logind.service -> ../systemd-logind.service
lrwxrwxrwx. 1 root root 39 Nov 10 18:10 systemd-update-utmp-runlevel.service -> ../systemd-update-utmp-runlevel.service
lrwxrwxrwx. 1 root root 32 Nov 10 18:10 systemd-user-sessions.service -> ../systemd-user-sessions.service
systemctl enable
等でカスタムするのは/etc/
のもの
ls /etc/systemd/system/multi-user.target.wants/
NetworkManager.service google-guest-agent.service rhel-configure.service
acpid.service google-osconfig-agent.service rsyslog.service
atd.service google-shutdown-scripts.service sshd.service
auditd.service google-startup-scripts.service sysstat.service
chronyd.service ntpd.service tuned.service
crond.service postfix.service yum-cron.service
firewalld.service remote-fs.target
SysVinitとの違い
-
各種サービスの依存関係や順序関係を処理できる
- cf. SysVnitでは起動タイミングを指定できるだけ(sysinitとか)
3.1.6 systemdの起動手順
ls -l /etc/systemd/system/
total 4
drwxr-xr-x. 2 root root 66 Nov 10 18:09 basic.target.wants
lrwxrwxrwx. 1 root root 41 Nov 10 18:06 dbus-org.fedoraproject.FirewallD1.service -> /usr/lib/systemd/system/firewalld.service
lrwxrwxrwx. 1 root root 57 Nov 10 18:06 dbus-org.freedesktop.nm-dispatcher.service -> /usr/lib/systemd/system/NetworkManager-dispatcher.service
lrwxrwxrwx. 1 root root 37 Nov 10 18:08 default.target -> /lib/systemd/system/multi-user.target
drwxr-xr-x. 2 root root 87 Nov 10 18:06 default.target.wants
drwxr-xr-x. 2 root root 38 Nov 10 18:07 dev-virtio\x2dports-org.qemu.guest_agent.0.device.wants
drwxr-xr-x. 2 root root 32 Nov 10 18:06 getty.target.wants
drwxr-xr-x. 2 root root 35 Nov 10 18:06 local-fs.target.wants
drwxr-xr-x. 2 root root 4096 Dec 9 15:35 multi-user.target.wants
drwxr-xr-x. 2 root root 48 Nov 10 18:06 network-online.target.wants
drwxr-xr-x. 2 root root 40 Nov 10 18:09 sshd.service.wants
drwxr-xr-x. 2 root root 171 Nov 10 18:06 sysinit.target.wants
drwxr-xr-x. 2 root root 44 Nov 10 18:06 system-update.target.wants
drwxr-xr-x. 2 root root 40 Nov 10 18:09 timers.target.wants
システムが起動するとdefault.target
が起動
default.target
は /lib/systemd/system/multi-user.target
へのsymlink
cat /lib/systemd/system/multi-user.target
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=Multi-User System
Documentation=man:systemd.special(7)
Requires=basic.target
Conflicts=rescue.service rescue.target
After=basic.target rescue.service rescue.target
AllowIsolate=yes
ランレベルとの対応
ls -l /lib/systemd/system/runlevel*.target
lrwxrwxrwx. 1 root root 15 Nov 10 18:10 /lib/systemd/system/runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root 13 Nov 10 18:10 /lib/systemd/system/runlevel1.target -> rescue.target
lrwxrwxrwx. 1 root root 17 Nov 10 18:10 /lib/systemd/system/runlevel2.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Nov 10 18:10 /lib/systemd/system/runlevel3.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Nov 10 18:10 /lib/systemd/system/runlevel4.target -> multi-user.target
lrwxrwxrwx. 1 root root 16 Nov 10 18:10 /lib/systemd/system/runlevel5.target -> graphical.target
lrwxrwxrwx. 1 root root 13 Nov 10 18:10 /lib/systemd/system/runlevel6.target -> reboot.target
グラフィカルログインのやつも見てみる
cat /lib/systemd/system/graphical.target
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=Graphical Interface
Documentation=man:systemd.special(7)
Requires=multi-user.target
Wants=display-manager.service
Conflicts=rescue.service rescue.target
After=multi-user.target rescue.service rescue.target display-manager.service
AllowIsolate=yes
必要なもの全てが直接記述されているわけではない
抜粋
After=multi-user.target ...
- graphcal.targetはmulti-user.target以降に起動しますよ、の意
-
graphcal.targetが実行されるとき、結局
multi-user.target
(ランレベル3相当)も実行済- 記述の共通化
3.1.7 systemctlコマンドによるサービスの管理
例: postfix
cat /lib/systemd/system/postfix.service
[Unit]
Description=Postfix Mail Transport Agent
After=syslog.target network.target
Conflicts=sendmail.service exim.service
[Service]
Type=forking
PIDFile=/var/spool/postfix/pid/master.pid
EnvironmentFile=-/etc/sysconfig/network
ExecStartPre=-/usr/libexec/postfix/aliasesdb
ExecStartPre=-/usr/libexec/postfix/chroot-update
ExecStart=/usr/sbin/postfix start
ExecReload=/usr/sbin/postfix reload
ExecStop=/usr/sbin/postfix stop
[Install]
例えば systemctl reload postfix
すると
ExecReload=/usr/sbin/postfix reload
が実行される。
例えばsysstat.serviceにはExecReloadの記述がない
cat /lib/systemd/system/sysstat.service
# /usr/lib/systemd/system/sysstat.service
# (C) 2012 Peter Schiffer (pschiffe <at> redhat.com)
#
# sysstat-10.1.5 systemd unit file:
# Insert a dummy record in current daily data file.
# This indicates that the counters have restarted from 0.
[Unit]
Description=Resets System Activity Logs
[Service]
Type=oneshot
RemainAfterExit=yes
User=root
ExecStart=/usr/lib64/sa/sa1 --boot
[Install]
WantedBy=multi-user.target
のでreloadしようとすると「ないよ」ってなる
sudo systemctl reload sysstat
Failed to reload sysstat.service: Job type reload is not applicable for unit sysstat.service.
See system logs and 'systemctl status sysstat.service' for details.
3.1.8 Unit設定ファイル
cat /lib/systemd/system/rsyslog.service
[Unit]
Description=System Logging Service
;Requires=syslog.socket
Wants=network.target network-online.target
After=network.target network-online.target
Documentation=man:rsyslogd(8)
Documentation=http://www.rsyslog.com/doc/
[Service]
Type=notify
EnvironmentFile=-/etc/sysconfig/rsyslog
ExecStart=/usr/sbin/rsyslogd -n $SYSLOGD_OPTIONS
Restart=on-failure
UMask=0066
StandardOutput=null
Restart=on-failure
[Install]
WantedBy=multi-user.target
;Alias=syslog.service
抜粋
WantedBy=multi-user.target
unitをenableすると、WantedByで指定のtargetの*.wants/
ディレクトリに追加される
今回のrsyslogは最初からenableされてるので…
systemctl is-enabled rsyslog.service
enabled
multi-user.target.wants/
に元々ある
ls -l /etc/systemd/system/multi-user.target.wants/ | grep rsyslog
lrwxrwxrwx. 1 root root 39 Dec 11 14:43 rsyslog.service -> /usr/lib/systemd/system/rsyslog.service
システム起動時のサービス自動起動を無効化する
sudo systemctl disable rsyslog.service
Removed symlink /etc/systemd/system/multi-user.target.wants/rsyslog.service.
/etc/の.wants/ディレクトリからsymlinkが消える
ls -l /etc/systemd/system/multi-user.target.wants/ | grep rsyslog
(空)
再度システム起動時のサービス自動起動を有効化する
sudo systemctl enable rsyslog.service
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyslog.service to /usr/lib/systemd/system/rsyslog.service.
symlink復活
ls -l /etc/systemd/system/multi-user.target.wants/ | grep rsyslog
lrwxrwxrwx. 1 root root 39 Dec 11 14:43 rsyslog.service -> /usr/lib/systemd/system/rsyslog.service
3.1.9 systemdのログ
systemd-journald
が収集したログをjournalctl
で見る
-f
follow(たぶん) 末尾を追う-u
unit指定
$ journalctl -u postfix -f
別の端末で
# systemctl reload postfix
すると、元の端末のログ末尾にreloadのログが追記される
Dec 11 14:59:16 lpic2-study-1 systemd[1]: Reloading Postfix Mail Transport Agent.
Dec 11 14:59:16 lpic2-study-1 postfix/master[1059]: reload -- version 2.10.1, configuratiDec 11 14:59:16 lpic2-study-1 systemd[1]: Reloaded Postfix Mail Transport Agent.
-p
: priority。指定のログレベル以上のものだけ表示
journalctl -p err --no-pager
-- Logs begin at Fri 2020-12-11 13:38:16 UTC, end at Fri 2020-12-11 15:01:01 UTC. --
Dec 11 13:38:19 lpic2-study-1 kernel: piix4_smbus 0000:00:01.3: SMBus base address uninitialized - upgrade BIOS or use force_addr=0xaddr
Dec 11 13:38:21 lpic2-study-1 oslogin_cache_refresh[459]: Failure getting users, quitting
Dec 11 13:38:21 lpic2-study-1 oslogin_cache_refresh[459]: Produced empty passwd cache file, removing /etc/oslogin_passwd.cache.bak.
Dec 11 13:38:21 lpic2-study-1 oslogin_cache_refresh[459]: Failure getting groups, quitting
Dec 11 13:38:21 lpic2-study-1 oslogin_cache_refresh[459]: Produced empty group cache file, removing /etc/oslogin_group.cache.bak.
Dec 11 14:19:54 lpic2-study-1 polkit-agent-helper-1[1653]: pam_unix(polkit-1:auth): conversation failed
Dec 11 14:19:54 lpic2-study-1 polkit-agent-helper-1[1653]: pam_unix(polkit-1:auth): auth could not identify password for [root]
ログ永続化
ログの実体
ls /var/run/log/journal/
cd7c85585b483d2656ce72740e5b59f7
/var/run/
にあるとマシン再起動でログは失われる
永続化するには /etc/systemd/journald.conf
(かjournald.conf.d/*.conf
)で設定する
cat /etc/systemd/journald.conf
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See journald.conf(5) for details.
[Journal]
#Storage=auto
#Compress=yes
#Seal=yes
#SplitMode=uid
#SyncIntervalSec=5m
#RateLimitInterval=30s
#RateLimitBurst=1000
#SystemMaxUse=
#SystemKeepFree=
#SystemMaxFileSize=
#RuntimeMaxUse=
#RuntimeKeepFree=
#RuntimeMaxFileSize=
#MaxRetentionSec=
#MaxFileSec=1month
#ForwardToSyslog=yes
#ForwardToKMsg=no
#ForwardToConsole=no
#ForwardToWall=yes
#TTYPath=/dev/console
#MaxLevelStore=debug
#MaxLevelSyslog=debug
#MaxLevelKMsg=notice
#MaxLevelConsole=info
#MaxLevelWall=emerg
#LineMax=48K
これ
#Storage=auto
Storageにはvolatile
,persistent
,auto
,none
を設定できる
volatile
: オンメモリのみauto
:/var/run/log/journal/
persistence
:/var/log/journal/
none
: none
3.2 ブートローダ
3.2.1 GRUB
GRUB: GRand Unified Bootloader
- 0.97まで: GRUB Legacy
- 1.9x以上: GRUB2
ステージ
BIOS搭載機ではMBRのうち446Bしかブートローダに使えないので、ブートローダ全体は載りきらない
-
ステージ1
- MBR内に配置
- ステージ1.5,ステージ2を起動
-
ステージ1.5
- ステージ2を見つける
-
ステージ2
/boot/grub/
以下にあるブートローダ本体
デバイスマッピング
/boot/grub/device.map
(hd0) /dev/sda1
...
GRUB Legacyでは/dev/sda1
がhd(0,0)
、/dev/sda2/
がhd(0,1)
のようにマッピングされる
番号が0から始まる
3.2.2 GRUB 2
設定ファイル
sudo ls -l /etc/grub.d/
total 72
-rwxr-xr-x. 1 root root 8702 Jul 28 20:21 00_header
-rwxr-xr-x. 1 root root 1043 Mar 21 2019 00_tuned
-rwxr-xr-x. 1 root root 232 Jul 28 20:21 01_users
-rwxr-xr-x. 1 root root 10781 Jul 28 20:21 10_linux
-rwxr-xr-x. 1 root root 10275 Jul 28 20:21 20_linux_xen
-rwxr-xr-x. 1 root root 2559 Jul 28 20:21 20_ppc_terminfo
-rwxr-xr-x. 1 root root 11169 Jul 28 20:21 30_os-prober
-rwxr-xr-x. 1 root root 214 Jul 28 20:21 40_custom
-rwxr-xr-x. 1 root root 216 Jul 28 20:21 41_custom
-rw-r--r--. 1 root root 483 Jul 28 20:21 README
sudo cat /etc/grub.d/01_users
#!/bin/sh -e
cat << EOF
if [ -f \${prefix}/user.cfg ]; then
source \${prefix}/user.cfg
if [ -n "\${GRUB2_PASSWORD}" ]; then
set superusers="root"
export superusers
password_pbkdf2 root \${GRUB2_PASSWORD}
fi
fi
EOF
grub2-mkconfig
コマンドはこれらのテンプレートをもとにgrub.cfg
ファイルを指定の場所に書き出す
sudo grub2-mkconfig -o ~/grub2/grub.cfg
cat ~/grub2/grub.cfg
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#
### BEGIN /etc/grub.d/00_header ###
set pager=1
if [ -s $prefix/grubenv ]; then
load_env
fi
if [ "${next_entry}" ] ; then
set default="${next_entry}"
set next_entry=
save_env next_entry
set boot_once=true
else
set default="${saved_entry}"
fi
if [ x"${feature_menuentry_id}" = xy ]; then
menuentry_id_option="--id"
else
menuentry_id_option=""
fi
export menuentry_id_option
if [ "${prev_saved_entry}" ]; then
set saved_entry="${prev_saved_entry}"
save_env saved_entry
set prev_saved_entry=
save_env prev_saved_entry
set boot_once=true
fi
function savedefault {
if [ -z "${boot_once}" ]; then
saved_entry="${chosen}"
save_env saved_entry
fi
}
function load_video {
if [ x$feature_all_video_module = xy ]; then
insmod all_video
else
insmod efi_gop
insmod efi_uga
insmod ieee1275_fb
insmod vbe
insmod vga
insmod video_bochs
insmod video_cirrus
fi
}
serial --speed=38400
terminal_input serial console
terminal_output serial console
if [ x$feature_timeout_style = xy ] ; then
set timeout_style=menu
set timeout=0
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
set timeout=0
fi
### END /etc/grub.d/00_header ###
### BEGIN /etc/grub.d/00_tuned ###
set tuned_params=""
set tuned_initrd=""
### END /etc/grub.d/00_tuned ###
### BEGIN /etc/grub.d/01_users ###
if [ -f ${prefix}/user.cfg ]; then
source ${prefix}/user.cfg
if [ -n "${GRUB2_PASSWORD}" ]; then
set superusers="root"
export superusers
password_pbkdf2 root ${GRUB2_PASSWORD}
fi
fi
### END /etc/grub.d/01_users ###
### BEGIN /etc/grub.d/10_linux ###
menuentry 'CentOS Linux (3.10.0-1127.19.1.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1127.19.1.el7.x86_64-advanced-24481a5c-eda4-4815-b7e5-9d86ef6e4320' {
load_video
set gfxpayload=keep
insmod gzio
insmod part_gpt
insmod xfs
set root='hd0,gpt2'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2 24481a5c-eda4-4815-b7e5-9d86ef6e4320
else
search --no-floppy --fs-uuid --set=root 24481a5c-eda4-4815-b7e5-9d86ef6e4320
fi
linuxefi /boot/vmlinuz-3.10.0-1127.19.1.el7.x86_64 root=UUID=24481a5c-eda4-4815-b7e5-9d86ef6e4320 ro crashkernel=auto console=ttyS0,38400n8 elevator=noop
initrdefi /boot/initramfs-3.10.0-1127.19.1.el7.x86_64.img
}
menuentry 'CentOS Linux (3.10.0-1127.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1127.el7.x86_64-advanced-24481a5c-eda4-4815-b7e5-9d86ef6e4320' {
load_video
set gfxpayload=keep
insmod gzio
insmod part_gpt
insmod xfs
set root='hd0,gpt2'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2 24481a5c-eda4-4815-b7e5-9d86ef6e4320
else
search --no-floppy --fs-uuid --set=root 24481a5c-eda4-4815-b7e5-9d86ef6e4320
fi
linuxefi /boot/vmlinuz-3.10.0-1127.el7.x86_64 root=UUID=24481a5c-eda4-4815-b7e5-9d86ef6e4320 ro crashkernel=auto console=ttyS0,38400n8 elevator=noop
initrdefi /boot/initramfs-3.10.0-1127.el7.x86_64.img
}
menuentry 'CentOS Linux (0-rescue-cd7c85585b483d2656ce72740e5b59f7) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-cd7c85585b483d2656ce72740e5b59f7-advanced-24481a5c-eda4-4815-b7e5-9d86ef6e4320' {
load_video
insmod gzio
insmod part_gpt
insmod xfs
set root='hd0,gpt2'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2 24481a5c-eda4-4815-b7e5-9d86ef6e4320
else
search --no-floppy --fs-uuid --set=root 24481a5c-eda4-4815-b7e5-9d86ef6e4320
fi
linuxefi /boot/vmlinuz-0-rescue-cd7c85585b483d2656ce72740e5b59f7 root=UUID=24481a5c-eda4-4815-b7e5-9d86ef6e4320 ro crashkernel=auto console=ttyS0,38400n8 elevator=noop
initrdefi /boot/initramfs-0-rescue-cd7c85585b483d2656ce72740e5b59f7.img
}
if [ "x$default" = 'CentOS Linux (3.10.0-1127.19.1.el7.x86_64) 7 (Core)' ]; then default='Advanced options for CentOS Linux>CentOS Linux (3.10.0-1127.19.1.el7.x86_64) 7 (Core)'; fi;
### END /etc/grub.d/10_linux ###
### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###
### BEGIN /etc/grub.d/20_ppc_terminfo ###
### END /etc/grub.d/20_ppc_terminfo ###
### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###
### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###
### BEGIN /etc/grub.d/41_custom ###
if [ -f ${config_directory}/custom.cfg ]; then
source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f $prefix/custom.cfg ]; then
source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###
流し込むべきパラメータは /etc/default/grub
で設定する
cat /etc/default/grub
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL="serial console"
GRUB_SERIAL_COMMAND="serial --speed=38400"
GRUB_CMDLINE_LINUX="crashkernel=auto console=ttyS0,38400n8 elevator=noop"
GRUB_DISABLE_RECOVERY="true"
grub.cfg
の置き場は
- BIOS:
/boot/grub/grub/
- UEFI:
/boot/efi/EFI/${id}/
勉強環境のGCEインスタンスでは後者だった
sudo ls /boot/efi/EFI/centos/
BOOT.CSV MokManager.efi grub.cfg grubx64.efi shim.efi shimx64.efi
BOOTX64.CSV fonts grubenv mmx64.efi shimx64-centos.efi
idはlsb_release -i
の出力を小文字にしたやつ(多分)
lsb_release -i
Distributor ID: CentOS
デバイスマッピング
参考: https://manual.geeko.jp/ja/grub2.html
デバイスのUUIDやファイルシステムのラベルを利用するようになった
grub.cfgより抜粋。カーネルパラメータ
root=UUID=24481a5c-eda4-4815-b7e5-9d86ef6e4320
cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Nov 10 18:06:00 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=24481a5c-eda4-4815-b7e5-9d86ef6e4320 / xfs defaults 0 0
UUID=6879-2FAF /boot/efi vfat defaults,uid=0,gid=0,umask=0077,shortname=winnt 0 0
Legacyのようなラベリングを行うことも可能。その場合は /boot/grub2/device.map
を作成する
パーティション番号が1から始まる事に注意する
grub.cfgより抜粋
set root='hd0,gpt2'
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
|-sda1 8:1 0 200M 0 part /boot/efi
`-sda2 8:2 0 19.8G 0 part /
hd0 = sda, gpt2 = 2番目のGPTパーティションの意。多分
3.2.3 起動オプションの設定
カーネルパラメータ
cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-3.10.0-1127.19.1.el7.x86_64 root=UUID=24481a5c-eda4-4815-b7e5-9d86ef6e4320 ro crashkernel=auto console=ttyS0,38400n8 elevator=noop
カーネルが処理できないパラメータはinitプログラム(systemd)に渡される
- single, emergency等
3.2.4 システムの回復
レスキューモードの話
ルートファイルシステムが/mnt/sysimage
等にマウントされる
- 一部コマンドが動かなくなる(rpmが
--root
オプション必須になったり) chroot
でルートディレクトリ指定してコマンド実行したりシェルにログインしたりできる
3.3 その他のブートローダ
3.3.1 SYSLINUX
USBブート、CDブート等
-
SYSLINUX
- FATファイルシステム(USB等)から起動
-
ISOLINUX
- ISO9660ファイルシステム、要するにCD-ROMから起動
-
EXTLINUX
- ext2/ext3/ext4から
-
PXELINUX
- PXEを使ってネットワークブート
3.3.2 PXEブート
-
PXE: Preboot eXcution Environment
- ネットワークブートの規格
- DHCPを使ってネットワーク情報を取得
- TFTPを使ってブートイメージのホスティング/読み込み
sudo yum install -y dhcp tftp-server
/etc/dhcp/dhcpd.conf
でブートイメージ名の設定等を行う- OSイメージもホストする場合はHTTPなりNFSなりさらに必要