LPICデバイスや起動まわりについて
かなり長い。
/proc/
以下の主なファイル
Linuxカーネルが認識しているデバイスに関する情報は、/proc
以下のファイルで確認できる。
ファイル名 | 説明 |
---|---|
/proc/bus/usb/* |
USBデバイス情報 |
/proc/cpuinfo/ |
CPU情報 |
/proc/interrupts/ |
IRQ情報 |
proc/pci |
PCIデバイス情報 |
/proc/scsi/scsi |
SCSIデバイス情報 |
デバイス周り
デバイスファイルの一覧。 ここにファイルがないとデバイスは使えない。
$ ls /dev/
MAKEDEV core fb input loop5 mcelog port ram12 ram6 rtc0 snapshot tty0 tty16 tty23 tty30 tty38 tty45 tty52 tty6 ttyS0 vcs1 vcsa2
VolGroup cpu fb0 kmsg loop6 mem ppp ram13 ram7 scd0 snd tty1 tty17 tty24 tty31 tty39 tty46 tty53 tty60 ttyS1 vcs2 vcsa3
block cpu_dma_latency fd log loop7 net ptmx ram14 ram8 sda sr0 tty10 tty18 tty25 tty32 tty4 tty47 tty54 tty61 ttyS2 vcs3 vcsa4
bsg crash full loop0 lp0 network_latency pts ram15 ram9 sda1 stderr tty11 tty19 tty26 tty33 tty40 tty48 tty55 tty62 ttyS3 vcs4 vcsa5
bus disk fuse loop1 lp1 network_throughput ram0 ram2 random sda2 stdin tty12 tty2 tty27 tty34 tty41 tty49 tty56 tty63 urandom vcs5 vcsa6
cdrom dm-0 hpet loop2 lp2 null ram1 ram3 raw sg0 stdout tty13 tty20 tty28 tty35 tty42 tty5 tty57 tty7 usbmon0 vcs6 vga_arbiter
char dm-1 hugepages loop3 lp3 nvram ram10 ram4 root sg1 systty tty14 tty21 tty29 tty36 tty43 tty50 tty58 tty8 usbmon1 vcsa zero
console dvd hvc0 loop4 mapper oldmem ram11 ram5 rtc shm tty tty15 tty22 tty3 tty37 tty44 tty51 tty59 tty9 vcs vcsa1
lsusb
コマンドでusbデバイスの情報が確認できる。
lspci
で pciデバイスの情報を確認できる。
-v
で詳しい情報を。-vv
で更に詳しい情報を得ることができる。
lsmod
でロードされているカーネルモジュールを確認できる。
これは/proc/modules
の情報を出力している。
# lsmod
Module Size Used by
ipt_REJECT 2351 2
nf_conntrack_ipv4 9506 4
nf_defrag_ipv4 1483 1 nf_conntrack_ipv4
iptable_filter 2793 1
ip_tables 17831 1 iptable_filter
ip6t_REJECT 4628 2
nf_conntrack_ipv6 8748 2
nf_defrag_ipv6 11182 1 nf_conntrack_ipv6
xt_state 1492 6
nf_conntrack 79357 3 nf_conntrack_ipv4,nf_conntrack_ipv6,xt_state
ip6table_filter 2889 1
ip6_tables 19458 1 ip6table_filter
ipv6 321454 15 ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6
ppdev 8537 0
parport_pc 22690 0
parport 36209 2 ppdev,parport_pc
i2c_piix4 12608 0
i2c_core 31084 1 i2c_piix4
snd_intel8x0 30556 0
snd_ac97_codec 124967 1 snd_intel8x0
ac97_bus 1452 1 snd_ac97_codec
snd_seq 55759 0
snd_seq_device 6500 1 snd_seq
snd_pcm 86635 2 snd_intel8x0,snd_ac97_codec
snd_timer 22411 2 snd_seq,snd_pcm
snd 69907 6 snd_intel8x0,snd_ac97_codec,snd_seq,snd_seq_device,snd_pcm,snd_timer
soundcore 7958 1 snd
snd_page_alloc 8470 2 snd_intel8x0,snd_pcm
e1000 170678 0
sg 29350 0
ext4 363408 2
mbcache 8193 1 ext4
jbd2 90230 1 ext4
sd_mod 38976 3
crc_t10dif 1541 1 sd_mod
sr_mod 15177 0
cdrom 39085 1 sr_mod
ahci 41127 2
pata_acpi 3701 0
ata_generic 3837 0
ata_piix 24121 0
dm_mirror 14133 0
dm_region_hash 12085 1 dm_mirror
dm_log 9930 2 dm_mirror,dm_region_hash
dm_mod 82839 8 dm_mirror,dm_log
modprobe
でモジュールのロード
modprobe - システム管理コマンドの説明 - Linux コマンド集 一覧表
# modprobe e1000
# lsmod
Module Size Used by
ipt_REJECT 2351 2
nf_conntrack_ipv4 9506 4
nf_defrag_ipv4 1483 1 nf_conntrack_ipv4
iptable_filter 2793 1
(省略)
e1000 170678 0
(省略)
システム起動の流れ
BIOS -> ブートローダー -> カーネル -> init
- BIOSはハードウェアのチェックや初期化を行い、ブートディスクからブートローダーを起動する
- ブートローダはハードディスクからメモリにカーネルを読み込む
- カーネルはメモリの初期化やクロックの設定を行いinitを起動する
dmesg
dmesg
コマンドで起動時のメッセージが確認できる。
$ dmesg |more
Initializing cgroup subsys cpuset
Initializing cgroup subsys cpu
Linux version 2.6.32-358.2.1.el6.x86_64 (mockbuild@c6b8.bsys.dev.centos.org) (gcc version 4.4.7
20120313 (Red Hat 4.4.7-3) (GCC) ) #1 SMP Wed Mar 13 00:26:49 UTC 2013
Command line: ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_
LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=jp106
rd_LVM_LV=VolGroup/lv_root rd_NO_DM rhgb quiet
KERNEL supported cpus:
Intel GenuineIntel
AMD AuthenticAMD
Centaur CentaurHauls
BIOS-provided physical RAM map:
BIOS-e820: 0000000000000000 - 000000000009fc00 (usable)
(以下省略)
/var/log/messages, /var/log/boot.log
/var/log/messages
や/var/log/boot.log
にも起動時のメッセージがある。
# cat /var/log/messages | more
May 22 16:16:01 localhost rsyslogd: [origin software="rsyslogd" swVersion="5.8.10" x-pid="986"
x-info="http://www.rsyslog.com"] rsyslogd was HUPed
May 23 03:42:56 localhost dhclient[915]: DHCPREQUEST on eth0 to 10.0.2.2 port 67 (xid=0x3db999f
a)
May 23 03:42:56 localhost dhclient[915]: DHCPACK from 10.0.2.2 (xid=0x3db999fa)
May 23 03:42:58 localhost dhclient[915]: bound to 10.0.2.15 -- renewal in 41498 seconds.
May 23 11:24:50 localhost yum[4366]: Installed: compat-readline5-5.2-17.1.el6.x86_64
May 23 11:24:52 localhost yum[4366]: Installed: ruby-libs-1.8.7.352-10.el6_4.x86_64
May 23 11:24:52 localhost yum[4366]: Installed: ruby-1.8.7.352-10.el6_4.x86_64
May 23 13:42:05 localhost kernel: tmux invoked oom-killer: gfp_mask=0x201da, order=0, oom_adj=0
, oom_score_adj=0
May 23 13:42:05 localhost kernel: tmux cpuset=/ mems_allowed=0
May 23 13:42:05 localhost kernel: Pid: 2180, comm: tmux Not tainted 2.6.32-358.2.1.el6.x86_64 #
1
May 23 13:42:05 localhost kernel: Call Trace:
May 23 13:42:05 localhost kernel: [<ffffffff810cb5f1>] ? cpuset_print_task_mems_allowed+0x91/0xb0
(以下省略)
# more /var/log/boot.log
Welcome to CentOS
Starting udev: [ OK ]
Setting hostname localhost.localdomain: [ OK ]
Setting up Logical Volume Management: 2 logical volume(s) in volume group "VolGroup" now acti
ve
[ OK ]
Checking filesystems
/dev/mapper/VolGroup-lv_root: clean, 86443/429088 files, 741154/1714176 blocks
/dev/sda1: recovering journal
/dev/sda1: clean, 44/128016 files, 69961/512000 blocks
[ OK ]
Remounting root filesystem in read-write mode: [ OK ]
Mounting local filesystems: [ OK ]
Enabling /etc/fstab swaps: [ OK ]
Entering non-interactive startup
Starting monitoring for VG VolGroup: 2 logical volume(s) in volume group "VolGroup" monitored
[ OK ]
ip6tables: Applying firewall rules: [ OK ]
iptables: Applying firewall rules: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0:
Determining IP information for eth0... done.
[ OK ]
Starting auditd: [ OK ]
Starting system logger: [ OK ]
Mounting other filesystems: [ OK ]
Retrigger failed udev events [ OK ]
Starting sshd: [ OK ]
Starting postfix: [ OK ]
Starting perl: [ OK ]
Starting crond: [ OK ]
May 24 13:02:31 localhost NET[29747]: /sbin/dhclient-script : updated /etc/resolv.conf
initの振る舞い
/etc/inittab
を読み込む/etc/rc.sysinit
を実行する/etc/rc
を実行する/etc/rc
が/etc/rc<ランレベル>.d/
以下のスクリプトを実行する
これはSysVinitと呼ばれる仕組みで、逐次処理なので起動時間が遅いとうデメリットがある。
これに対してUpstartやSystemdといった並列で起動処理を行う仕組みを採用するディストリもある。
ランレベル
ランレベルとは動作のモード。
Redhat系列
ランレベル | モード |
---|---|
0 | 停止 |
1 | シングルユーザーモード |
2 | マルチユーザーモード (テキストログイン、NFS^1サーバ停止) |
3 | マルチユーザーモード(テキストログイン) |
4 | 未使用 |
5 | マルチユーザーモード (グラフィカルログイン) |
6 | 再起動 |
S または s | シングルユーザーモード |
ランレベル | モード |
---|---|
0 | 停止 |
1 | シングルユーザーモード |
2 | マルチユーザーモード |
3 | マルチユーザーモード |
4 | マルチユーザーモード |
5 | マルチユーザーモード |
6 | 再起動 |
S または s | シングルユーザーモード |
ランレベルの確認・変更
runlevel
コマンドで現在のランレベルを確認できる
# runlevel
N 3
右の数字が現在のランレベル。左が一個前のランレベル(Nの場合は何もない。)
init
やtelinit
コマンドでランレベルの変更が可能。
# init 1
(以降フルパスでないとコマンドが実行できなかった)
# /usr/bin/passwd
(シングルユーザーモードにするとパスワードなしでrootログイン
できるのでうっかりpassを忘れた時に便利)
# init 3
(ログインプロンプトが表示される)
# runlevel
S 3
起動スクリプト
/etc/rc<ランレベル>.d/
以下にスクリプトファイルが格納されていて、
Kから始まるものが停止用Sから始まるのが起動用スクリプトとなっている。
数字は起動する順序。
# ls /etc/rc3.d/
K10saslauthd K89rdisc S10network S25netfs S85perl-fastcgi
K15nginx S02lvm2-monitor S11auditd S26udev-post S90crond
K50netconsole S08ip6tables S12rsyslog S55sshd S99local
K87restorecond S08iptables S25blk-availability S80postfix
それぞれ/etc/init.d/
以下のスクリプトへのシンボリックリンクとなっている。
# ls -l /etc/rc3.d/
total 0
lrwxrwxrwx. 1 root root 19 Apr 4 17:00 K10saslauthd -> ../init.d/saslauthd
lrwxrwxrwx. 1 root root 15 Apr 7 15:09 K15nginx -> ../init.d/nginx
lrwxrwxrwx. 1 root root 20 Apr 4 17:00 K50netconsole -> ../init.d/netconsole
lrwxrwxrwx. 1 root root 21 Apr 4 17:00 K87restorecond -> ../init.d/restorecond
lrwxrwxrwx. 1 root root 15 Apr 4 17:00 K89rdisc -> ../init.d/rdisc
lrwxrwxrwx. 1 root root 22 Apr 4 17:02 S02lvm2-monitor -> ../init.d/lvm2-monitor
lrwxrwxrwx. 1 root root 19 Apr 4 17:00 S08ip6tables -> ../init.d/ip6tables
lrwxrwxrwx. 1 root root 18 Apr 4 17:00 S08iptables -> ../init.d/iptables
lrwxrwxrwx. 1 root root 17 Apr 4 17:21 S10network -> ../init.d/network
lrwxrwxrwx. 1 root root 16 Apr 4 17:02 S11auditd -> ../init.d/auditd
lrwxrwxrwx. 1 root root 17 Apr 4 17:00 S12rsyslog -> ../init.d/rsyslog
lrwxrwxrwx. 1 root root 26 Apr 4 17:02 S25blk-availability -> ../init.d/blk-availability
lrwxrwxrwx. 1 root root 15 Apr 4 17:21 S25netfs -> ../init.d/netfs
lrwxrwxrwx. 1 root root 19 Apr 4 17:00 S26udev-post -> ../init.d/udev-post
lrwxrwxrwx. 1 root root 14 Apr 4 17:02 S55sshd -> ../init.d/sshd
lrwxrwxrwx. 1 root root 17 Apr 4 17:00 S80postfix -> ../init.d/postfix
lrwxrwxrwx. 1 root root 22 Apr 7 14:35 S85perl-fastcgi -> ../init.d/perl-fastcgi
lrwxrwxrwx. 1 root root 15 Apr 4 17:00 S90crond -> ../init.d/crond
lrwxrwxrwx. 1 root root 11 Apr 4 17:21 S99local -> ../rc.local
起動停止はかなりよく知られている
# /etc/init.d/nginx start
Starting nginx: [ OK ]
# /etc/init.d/nginx stop
Stopping nginx: [ OK ]
デフォルトランレベル
/etc/inittab
を編集することで起動時のランレベルを指定できる。
# cat /etc/inittab
(一部省略)
# Default runlevel. The runlevels used 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:
指定方法は上記例を見て分かる通り
id:<ランレベル>:initdefault
で指定できる。
システムのシャットダウンと再起動
当たり前だけどshutdown
コマンドを使う。
5分で停止 (-hはhaltのh)
shutdown -h +5 "Shutdown in 5 minutes"
すると下のようなメッセージが表示される
Broadcast message from kisho@localhost.localdomain
(/dev/pts/2) at 8:04 ...
The system is going down for halt in 3 minutes!
Shutdown in 5 minutes
以下の例では実際にはシャットダウンせず警告メッセージのみ表示
shutdown -k now "May be I will shutdown this machine"
22:00に再起動
shutdown -r 22:00
現在実行中のシャットダウン処理をキャンセル
shutdown -c
fsck(ファイル・システムの検査と修復。file system checkの略?)を次回起動時に実行
shutdown -Fh
fsckを次回起動時にスキップ
shutdown -fr