ハードウェアの基本知識と設定
基本的なシステムハードウェア
-
CPU
-
Linuxは非常に多くのアーキテクチャに対応
- x86
- IA-32
- x86_64
- ARM
- etc.
-
-
メモリ
- Linuxの動作には256MG~1GBくらい
-
ハードディスク
- Linuxインストールには必要
- Linux動作には必須ではない
- SSDもこのカテゴリ
-
入力装置
- サーバでは接続されないことも
-
拡張カード
-
マザーボードの拡張スロットに装着し、さまざまな機能を提供
- ネットワークカード(NIC: Network Interface Card)
- サウンドカード
- モデムカード
- ビデオカード
- SCSIカード(Small Computer System Interface)
- RAIDカード(Redundant Array of Inexpensive Disks)
-
コールドプラグ
- システムの電源を切って付け外しする必要あり
-
-
USB機器
-
さまざまな周辺機器を接続
- キーボード
- マウス
- ハードディスク
- フラッシュメモリ
- DVDドライブ
-
ホットプラグ
- システムの電源をオンにしたまま付け外しできる
-
BIOS/UEFI
-
BIOS: Basic Input Output System (入出力基本システム)
-
分類
-
システムBIOS
- マザーボード上
-
拡張BIOS
- 拡張カード上
-
- マザーボードや拡張カード上のフラッシュROMに書き込まれている
- 最も基本的な制御プログラム
-
OSやアプリケーションはBIOSのインターフェース経由で簡単にH/Wにアクセスできる
- BIOSがあまりに古いと、大容量のハードディスクを正常に認識できなかったりする
-
役割
- OSを起動するためのプログラムをディスクから読み込んで実行
- デバイスの動作を設定
- 基本的な入出力
-
-
UEFI: Unified Extensible Firmware Interface
-
BIOSの後継規格
- 起動ドライブの容量制限(2TB)の撤廃
- GUIベースのセットアップ画面
-
-
広義のBIOS
- BIOS + UEFI
-
BIOS/UEFIセットアップ画面
- PC電源投入時にDelete、F1、F2等を入力して呼び出せるやつ
-
よくある設定項目
- 日付や時刻(ハードウェアクロック)
- ディスクドライブや各種デバイスのパラメータ
-
キーボードの使用/不使用
- H/Wによっては接続されていないとエラーになる
- サーバ等、キーボードが不要なときはBIOSで無効化しておく
- 電源管理
-
起動ドライブの順序
- 特に重要
- デバイスへのIRQ: Interrupt Request(割り込み要求)の割り当て
- 各種デバイスの使用/不使用
デバイス情報の確認
-
デバイスファイル
- H/Wアクセスはファイルに抽象化されている
/dev
ディレクトリ以下- udevという仕組みにより自動的に生成される
docker container run -it --rm centos:centos7 bash
[root@dee995e55b9f /]# cd dev/
[root@dee995e55b9f dev]# ls
console core fd full mqueue null ptmx pts random shm stderr stdin stdout tty urandom zero
-
/proc
- カーネルが認識しているデバイスに関する情報が格納されている場所
- 仮想的なファイルシステム(procfs)
[root@dee995e55b9f proc]# cd proc/
[root@dee995e55b9f proc]# ls
1 cmdline diskstats fs kcore kpageflags mounts sched_debug sys uptime
17 config.gz dma interrupts key-users loadavg mpt self sysrq-trigger version
acpi consoles driver iomem keys locks mtrr slabinfo sysvipc vmallocinfo
buddyinfo cpuinfo execdomains ioports kmsg meminfo net softirqs thread-self vmstat
bus crypto fb irq kpagecgroup misc pagetypeinfo stat timer_list zoneinfo
cgroups devices filesystems kallsyms kpagecount modules partitions swaps tty
-
/proc/cpuinfo
- CPU情報
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i5-8500 CPU @ 3.00GHz
stepping : 10
microcode : 0xffffffff
cpu MHz : 2995.226
cache size : 9216 KB
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
apicid : 1
initial apicid : 1
fpu : yes
fpu_exception : yes
cpuid level : 21
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ibrs ibpb stibp kaiser fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf
bogomips : 5990.45
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
-
/proc/interrupts
-
IRQ情報
- NMI: マスク不可割り込みとか聞いたことあるぞ
- IRQ番号は0-15ということになっている
- 数値が小さいほうが優先度高い
- BIOSでHT: Hyper Threadingを有効にしていると16以上も割り振られるらしい
- PCIとかは16以上
-
CPU0 CPU1 CPU2 CPU3
0: 11 0 0 0 IO-APIC 2-edge timer
1: 5444 11 0 0 IO-APIC 1-edge i8042
8: 0 0 1 0 IO-APIC 8-edge rtc0
9: 2260 834 0 0 IO-APIC 9-fasteoi acpi
12: 492905 0 0 0 IO-APIC 12-edge i8042
23: 30 0 45 0 IO-APIC 23-fasteoi ehci_hcd:usb1
40: 0 27 0 336 PCI-MSI 327680-edge xhci_hcd
41: 13 0 0 25 PCI-MSI 1048576-edge rtsx_pci
42: 0 66 0 0 PCI-MSI 49152-edge snd_hda_intel:card0
43: 32671 14267 0 0 PCI-MSI 512000-edge ahci[0000:00:1f.2]
44: 183 0 83428 0 PCI-MSI 32768-edge i915
45: 0 0 16 0 PCI-MSI 360448-edge mei_me
46: 630 57741 0 0 PCI-MSI 1572864-edge iwlwifi
47: 0 113 0 0 PCI-MSI 442368-edge snd_hda_intel:card1
48: 0 0 7 925 PCI-MSI 409600-edge enp0s25
NMI: 0 13 14 13 Non-maskable interrupts
LOC: 210953 173477 262211 178113 Local timer interrupts
SPU: 0 0 0 0 Spurious interrupts
PMI: 0 13 14 13 Performance monitoring interrupts
IWI: 60 22 21130 71 IRQ work interrupts
RTR: 0 0 0 0 APIC ICR read retries
RES: 46555 39478 41004 43535 Rescheduling interrupts
CAL: 74112 69873 71103 68808 Function call interrupts
TLB: 70472 67898 68574 65976 TLB shootdowns
TRM: 0 0 0 0 Thermal event interrupts
THR: 0 0 0 0 Threshold APIC interrupts
DFR: 0 0 0 0 Deferred Error APIC interrupts
MCE: 0 0 0 0 Machine check exceptions
MCP: 10 11 11 11 Machine check polls
HYP: 0 0 0 0 Hypervisor callback interrupts
ERR: 0
MIS: 0
PIN: 0 0 0 0 Posted-interrupt notification event
NPI: 0 0 0 0 Nested posted-interrupt event
PIW: 0 0 0 0 Posted-interrupt wakeup event
-
/proc/ioports
- I/Oアドレス情報
- sudoじゃないと全部0になっちゃう
0000-0000 : PCI Bus 0000:00
0000-0000 : dma1
0000-0000 : pic1
0000-0000 : timer0
0000-0000 : timer1
0000-0000 : keyboard
0000-0000 : PNP0800:00
0000-0000 : PNP0C09:00
0000-0000 : EC data
0000-0000 : keyboard
0000-0000 : PNP0C09:00
0000-0000 : EC cmd
0000-0000 : rtc0
0000-0000 : dma page reg
0000-0000 : pic2
0000-0000 : dma2
0000-0000 : fpu
0000-0000 : PNP0C04:00
0000-0000 : pnp 00:01
0000-0000 : pnp 00:01
0000-0000 : pnp 00:01
0000-0000 : pnp 00:01
0000-0000 : pnp 00:01
0000-0000 : pnp 00:01
0000-0000 : pnp 00:01
0000-0000 : pnp 00:01
0000-0000 : PCI conf1
0000-0000 : PCI Bus 0000:00
0000-0000 : pnp 00:01
0000-0000 : pnp 00:01
0000-0000 : pnp 00:01
0000-0000 : pnp 00:01
0000-0000 : ACPI PM1a_EVT_BLK
0000-0000 : ACPI PM1a_CNT_BLK
0000-0000 : ACPI PM_TMR
0000-0000 : ACPI CPU throttle
0000-0000 : iTCO_wdt.0.auto
0000-0000 : ACPI PM2_CNT_BLK
0000-0000 : iTCO_wdt.0.auto
0000-0000 : ACPI GPE0_BLK
0000-0000 : 0000:00:02.0
0000-0000 : 0000:00:1f.2
0000-0000 : ahci
0000-0000 : 0000:00:19.0
0000-0000 : 0000:00:1f.2
0000-0000 : ahci
0000-0000 : 0000:00:1f.2
0000-0000 : ahci
0000-0000 : 0000:00:1f.2
0000-0000 : ahci
0000-0000 : 0000:00:1f.2
0000-0000 : ahci
0000-0000 : 0000:00:1f.3
- sudo
0000-0cf7 : PCI Bus 0000:00
0000-001f : dma1
0020-0021 : pic1
0040-0043 : timer0
0050-0053 : timer1
0060-0060 : keyboard
0061-0061 : PNP0800:00
0062-0062 : PNP0C09:00
0062-0062 : EC data
0064-0064 : keyboard
0066-0066 : PNP0C09:00
0066-0066 : EC cmd
0070-0071 : rtc0
0080-008f : dma page reg
00a0-00a1 : pic2
00c0-00df : dma2
00f0-00ff : fpu
00f0-00f0 : PNP0C04:00
0800-087f : pnp 00:01
0880-08ff : pnp 00:01
0900-097f : pnp 00:01
0980-09ff : pnp 00:01
0a00-0a7f : pnp 00:01
0a80-0aff : pnp 00:01
0b00-0b7f : pnp 00:01
0b80-0bff : pnp 00:01
0cf8-0cff : PCI conf1
0d00-ffff : PCI Bus 0000:00
15e0-15ef : pnp 00:01
1600-167f : pnp 00:01
1640-165f : pnp 00:01
1800-189f : pnp 00:01
1800-1803 : ACPI PM1a_EVT_BLK
1804-1805 : ACPI PM1a_CNT_BLK
1808-180b : ACPI PM_TMR
1810-1815 : ACPI CPU throttle
1830-1833 : iTCO_wdt.0.auto
1850-1850 : ACPI PM2_CNT_BLK
1860-187f : iTCO_wdt.0.auto
1880-189f : ACPI GPE0_BLK
3000-303f : 0000:00:02.0
3060-307f : 0000:00:1f.2
3060-307f : ahci
3080-309f : 0000:00:19.0
30a0-30a7 : 0000:00:1f.2
30a0-30a7 : ahci
30a8-30af : 0000:00:1f.2
30a8-30af : ahci
30b0-30b3 : 0000:00:1f.2
30b0-30b3 : ahci
30b4-30b7 : 0000:00:1f.2
30b4-30b7 : ahci
efa0-efbf : 0000:00:1f.3
-
/proc/meminfo
- メモリ情報
MemTotal: 2027864 kB
MemFree: 121180 kB
MemAvailable: 438512 kB
Buffers: 55792 kB
Cached: 363092 kB
SwapCached: 4064 kB
Active: 720592 kB
Inactive: 721688 kB
Active(anon): 479844 kB
Inactive(anon): 545392 kB
Active(file): 240748 kB
Inactive(file): 176296 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 1048572 kB
SwapFree: 897576 kB
Dirty: 44 kB
Writeback: 0 kB
AnonPages: 1021164 kB
Mapped: 163916 kB
Shmem: 1840 kB
Slab: 136700 kB
SReclaimable: 64040 kB
SUnreclaim: 72660 kB
KernelStack: 17632 kB
PageTables: 7896 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 2062504 kB
Committed_AS: 3427348 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
AnonHugePages: 28672 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 46508 kB
DirectMap2M: 2050048 kB
DirectMap1G: 0 kB
-
/proc/bus/usb/*
- USBデバイス情報
- 見当たらず
-
/proc/bus/pci/*
-
PCIデバイス情報
-
PCI: Peripheral Component Interconnect
- 拡張カードを増設するためのバス標準
- SATAチップ
- サウンド
- etc.
-
-
-
デバイス情報確認用コマンド
-
lspci
- PCIデバイスの情報出力
-
-v
,-vv
で詳細出力--verbose
とかはない
-
lspci
00:00.0 Host bridge: Intel Corporation Haswell-ULT DRAM Controller (rev 0b)
00:02.0 VGA compatible controller: Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 0b)
00:03.0 Audio device: Intel Corporation Haswell-ULT HD Audio Controller (rev 0b)
00:14.0 USB controller: Intel Corporation 8 Series USB xHCI HC (rev 04)
00:16.0 Communication controller: Intel Corporation 8 Series HECI #0 (rev 04)
00:19.0 Ethernet controller: Intel Corporation Ethernet Connection I218-V (rev 04)
00:1b.0 Audio device: Intel Corporation 8 Series HD Audio Controller (rev 04)
00:1c.0 PCI bridge: Intel Corporation 8 Series PCI Express Root Port 6 (rev e4)
00:1c.1 PCI bridge: Intel Corporation 8 Series PCI Express Root Port 3 (rev e4)
00:1d.0 USB controller: Intel Corporation 8 Series USB EHCI #1 (rev 04)
00:1f.0 ISA bridge: Intel Corporation 8 Series LPC Controller (rev 04)
00:1f.2 SATA controller: Intel Corporation 8 Series SATA Controller 1 [AHCI mode] (rev 04)
00:1f.3 SMBus: Intel Corporation 8 Series SMBus Controller (rev 04)
02:00.0 Unassigned class [ff00]: Realtek Semiconductor Co., Ltd. RTS5227 PCI Express Card Reader (rev 01)
03:00.0 Network controller: Intel Corporation Wireless 7260 (rev 83)
-
verbose
lspci -v
-
rootじゃないと一部見られなかったりする
00:00.0 Host bridge: Intel Corporation Haswell-ULT DRAM Controller (rev 0b) Subsystem: Lenovo ThinkPad X240 Flags: bus master, fast devsel, latency 0 Capabilities: [e0] Vendor Specific Information: Len=0c <?> Kernel driver in use: hsw_uncore ...
lspci -vv
00:00.0 Host bridge: Intel Corporation Haswell-ULT DRAM Controller (rev 0b)
Subsystem: Lenovo ThinkPad X240
Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
Status: Cap+ 66MHz- UDF- FastB2B+ ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort+ >SERR- <PERR- INTx-
Latency: 0
Capabilities: [e0] Vendor Specific Information: Len=0c <?>
Kernel driver in use: hsw_uncore
USBデバイス
-
特徴
- 最大127台のデバイスを接続
- 同一コネクタ
- ホットプラグ
-
プラグ&プレイ
- H/W、F/W、ドライバ、OS、アプリケーション間が自動的に協調し、
機器の組み込みと設定を自動的に行う
- H/W、F/W、ドライバ、OS、アプリケーション間が自動的に協調し、
- 電源供給
- バージョン差異
バージョン | 最大転送速度(bps) |
---|---|
1.0 | 12M |
1.1 | 12M |
2.0 | 480M |
3.0 | 5G |
3.1(Type-C) | 10G |
-
デバイスドライバ
- H/Wの利用に必要なやつ
-
分類
-
専用のドライバ
- ベンダーが提供するもの
-
クラスドライバ
- Linuxシステム提供の汎用ドライバ
- デバイスクラスに準拠したものはこれだけでOK
-
デバイスクラス | サポートするUSBデバイスの例 |
---|---|
HID: Human Interface Devices | kbd, mouse |
USB Mass Storage Device | USBメモリ、HDD、デジタルオーディオプレーヤー |
オーディオ | マイク、スピーカー、サウンドカード |
プリンタ | プリンタ |
ワイヤレスコントローラー | Wi-Fiアダプタ、Blutoothアダプタ |
- lsusbコマンドで情報表示可能
lsusb
-t
で階層表示
Bus 001 Device 002: ID 8087:8000 Intel Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 002: ID 8087:07dc Intel Corp.
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
lsusb -t
/: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/9p, 480M
|__ Port 7: Dev 2, If 0, Class=Wireless, Driver=btusb, 12M
|__ Port 7: Dev 2, If 1, Class=Wireless, Driver=btusb, 12M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/3p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/8p, 480M
-
やはり
-v
や-vv
でverbose表示-t
と併用はできないみたい
lsusb -vv
-
ベンダ名やらデバイスクラスやらが書いてある
Bus 001 Device 002: ID 8087:8000 Intel Corp. Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 9 Hub bDeviceSubClass 0 Unused bDeviceProtocol 1 Single TT bMaxPacketSize0 64 idVendor 0x8087 Intel Corp. idProduct 0x8000 bcdDevice 0.04 iManufacturer 0 iProduct 0 iSerial 0 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 25 bNumInterfaces 1 bConfigurationValue 1 iConfiguration 0 bmAttributes 0xe0 Self Powered Remote Wakeup MaxPower 0mA Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 1 bInterfaceClass 9 Hub bInterfaceSubClass 0 Unused bInterfaceProtocol 0 Full speed (or root) hub iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0002 1x 2 bytes bInterval 12 Hub Descriptor: bLength 11 bDescriptorType 41 nNbrPorts 8 wHubCharacteristic 0x0009 Per-port power switching Per-port overcurrent protection TT think time 8 FS bits bPwrOn2PwrGood 0 * 2 milli seconds bHubContrCurrent 0 milli Ampere DeviceRemovable 0x00 0x00 PortPwrCtrlMask 0xff 0xff Hub Port Status: Port 1: 0000.0100 power Port 2: 0000.0100 power Port 3: 0000.0100 power Port 4: 0000.0100 power Port 5: 0000.0100 power Port 6: 0000.0100 power Port 7: 0000.0100 power Port 8: 0000.0100 power Device Qualifier (for other device speed): bLength 10 bDescriptorType 6 bcdUSB 2.00 bDeviceClass 9 Hub bDeviceSubClass 0 Unused bDeviceProtocol 0 Full speed (or root) hub bMaxPacketSize0 64 bNumConfigurations 1 Device Status: 0x0001 Self Powered
…
## udev: Userspace DEVice management
- /dev以下のデバイスファイルを自動生成する仕組み
1. H/Wが接続される
1. カーネルが検知する
1. /sysディレクトリ以下にデバイス情報を作成する
- sysfs
- procfs同様、仮想的なファイルシステム
1. udevdが/sysディレクトリ以下のデバイス情報を参照し、
/devディレクトリ以下にデバイスファイルを作成する
- /etc/udev/rules.d/以下の設定ファイルが使われる
- あるUSBメモリを「/dev/usbmemory」とする、等
- D-Bus: Desktop Bus
- IPC: Inter-Process Communicatio実装のひとつ
- アプリケーション間でデバイス情報をやりとりするメッセージバス
- これによりアプリケーションからデバイスを利用できるようになる
```sh
ls /sys
block class devices fs kernel power
bus dev firmware hypervisor module
デバイスドライバのロード
-
デバイスドライバ
- デバイスを利用するために必要な制御プログラム
- Linuxではカーネルモジュールとして提供されている
- カーネルに取り込むことを「ロードする」という
lsmod
Module Size Used by
rfcomm 77824 16
ipt_MASQUERADE 16384 1
nf_nat_masquerade_ipv4 16384 1 ipt_MASQUERADE
nf_conntrack_netlink 40960 0
nfnetlink 16384 2 nf_conntrack_netlink
xfrm_user 32768 1
xfrm_algo 16384 1 xfrm_user
...
-v
とか-t
とかはない- 必要なデバイスドライバは普通自動でロードされる
- 手動でロードするには:
modprobe <modulename>
Linuxの起動とシャットダウン
-
一般的なPCのアーキテクチャ(x86/x86_64)における
システム起動の流れ(boot, bootstrap)-
BIOS/UEFI
- H/Wチェック・初期化
- 起動ドライブからブートローダを読み出す
-
ブートローダ
- 起動ドライブからカーネルをメモリ上に読み出す
-
カーネル
- メモリの初期化
- システムクロックの設定
-
initramfs(初期RAMディスク)をマウント
- 仮のルートファイルシステム
- システムの起動に必要なデバイスドライバが組み込まれている
- initまたはsystemdプロセスを実行
-
init/systemd
- 必要なサービス等を順次実行
- ログインプロンプトを表示
-
起動時のイベント確認
-
dmesgコマンド
- システム起動時にカーネルがどのような処理を行ったか確認できる
-
起動後もカーネルの出力メッセージが蓄えられていく
- 古いものは消えていく
[ 0.000000] microcode: microcode updated early to revision 0x24, date = 2018-04-02
[ 0.000000] Linux version 4.15.0-45-generic (buildd@lgw01-amd64-031) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #48-Ubuntu SMP Tue Jan 29 16:28:13 UTC 2019 (Ubuntu 4.15.0-45.48-generic 4.15.18)
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-4.15.0-45-generic root=UUID=ebba1a7e-ed76-43aa-b3cc-8f7baded52e9 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
-
ログファイル
-
置き場(ディストリビューションにより異なる)
- /var/log/messages
- /var/log/dmesg
-
/var/log/boot.log
- Ubuntuはこれだった
- catとかlessとかで見られる
-
システムのシャットダウンと再起動
shutdown --help
shutdown [OPTIONS...] [TIME] [WALL...]
Shut down the system.
--help Show this help
-H --halt Halt the machine
-P --poweroff Power-off the machine
-r --reboot Reboot the machine
-h Equivalent to --poweroff, overridden by --halt
-k Don't halt/power-off/reboot, just send warnings
--no-wall Don't send wall message before halt/power-off/reboot
-c Cancel a pending shutdown
-
shutdownコマンドのオプション
-
TIME
- 今からTIME分後
- 時刻
now
で今すぐ
-
-H, --halt
- すべてのプロセスを終了させ、CPUを止める
- 電源はついたまま
-
-P, --poweroff
- 電源を落とす
-
PSU: Power Supply Unitに
ACPI: Advanced Configuration and Power Interface
コマンドを送って電源を落とさせるらしい
-
-h
-P
と同じ
-
-hH
-
-H
が優先される- “overridden by —halt”
-
-
-HP
-H
が優先される
-
-f
- helpにないやつ
- 次回起動時のfsckをスキップ
-
-F
- helpにないやつ
-
次回起動時のfsckを強制
-rF
してみたけどとくに視認できなかった
-
- haltしたときの様子
[ 33.685942] reboot: System halted
-
他のシャットダウン手段
- haltコマンド
- rebootコマンド
- poweroffコマンド
- Ctrl + Alt + Del
- ↑ubuntuは全部あった
systemdとshutdownコマンド
- systemd採用システムではこう
systemctl reboot
systemctl poweroff
- shutdownコマンドはいつか使えなくなるかも
SysVinit: System Five Init
-
システム電源投入~Linux起動の手順
- 昔: SysVinit
- 現在: systemd
SysVinitによる起動
-
流れ
- initが
/etc/inittab
ファイルを読み込む - initが
/etc/rc.sysinit
nスクリプトを読み込む - initが
/etc/rc
スクリプトを実行する /etc/rc
スクリプトが/etc/rc<ランレベル>.d
ディレクトリ以下のスクリプトを実行する
- initが
-
手元のubuntuやcentos7コンテナには
/etc/inittab
はなかった- SysVinitを使っていない最近のシステムではそういうことがある
/etc/rc<ランレベル>.d
はある
-
弱点
-
サービスを順次起動
- 何か手こずると以降全サービスが待たされる
-
依存関係を適切に処理できない
- 管理者が管理する必要がある
-
-
弱点を克服したやつ
-
Upstart
- SysVinitを改善した新しいinitの仕組み
- 依存関係を適切に処理
- 並列起動
- イベント駆動
- systemdへの移行が進められている
-
systemd
- このあとでてくる
-
ランレベル
- 動作モード
ランレベル | Red Hat, CentOS, Fedra | Ubuntu, Debian |
---|---|---|
0 | 停止 | 停止 |
1 | シングルユーザー | シングルユーザー |
2 | マルチユーザー(テキストログイン、NFSサーバー停止) | マルチユーザー |
3 | マルチユーザー(テキストログイン) | マルチユーザー |
4 | 未使用 | マルチユーザー |
5 | マルチユーザー(グラフィカルログイン) | マルチユーザー |
6 | 再起動 | 再起動 |
S or s | シングルユーザーモード | シングルユーザーモード |
-
シングルユーザーモード
- rootユーザー独りしかログインしないモード
- = 一般ユーザーをログインさせないモード
- システムメンテナンス等で使う
ランレベルの確認と変更
-
確認
-
<前のランレベル> <現在のランレベル>
が表示されるrunlevel
-
-
ubuntu実機の結果
N 5
N
は未設定- 設定
init 4
- 実機ubuntuで実施したところ、いきなりテキストログインモードに突入した
runlevel
5 3
- 4が欠番で3(テキストログイン)が使われた??ubuntuなのに
-
いきなり1とかにすると一般ユーザが追い出されて困ってしまうので、
wall
コマンド等で通知してあげるshutdown -k
みたいな感じに通知される
起動スクリプトによるサービスの管理
-
/etc/rc<ランレベル>.d/
以下に起動スクリプトのシンボリックリンクがある- CentOS7コンテナでは
/etc/rc.d/rc<ランレベル>.d/
へのシンボリックリンクだった -
実体は
/etc/init.d/
にある- CentOS7コンテナではこれも
/etc/rc.d/init.d/
へのシンボリックリンクだった - CentOS7コンテナで見に行ったら「systemd使え」って書いてあるREADMEが置いてあった
- CentOS7コンテナではこれも
- CentOS7コンテナでは
- サービス起動・停止例
/etc/init.d/httpd start
/etc/init.d/httpd stop
- ↑テキスト通り。実際にはhttpdサービスは置いてなかった
デフォルトのランレベルの設定
-
/etc/inittab
に記述されてるらしい- ubuntuにもCentOS7コンテナにも無かったです
(略)
#
id:5:initdefault:
-
こんな感じに記述する
- inittabファイルのコメントに書いてあるが、0(停止)や6(再起動)を設定してはいけない
init, telinit
- initとtelinitは同じ
- initデーモンに仕事させるクライアント
オプション
-
<数字>
(0-6)- 現在のランレベル設定
-
s
,S
,1
- レスキューモード
- メンテとかで使うやつ
-
q
,Q
- 設定再読込
-
u
,U
- initデーモン再実行
systemd
systemdの概要
- initプロセスの代わりにsystemd
- 各種サービスを管理
-
各種デーモンプロセスが連携
-
systemd
- メイン
-
systemd-journald
- ジャーナル(ログ)管理
-
systemd-logind
- ログイン処理
-
systemd-udevd
- デバイス動的検知
-
- unit: systemdにおける処理単位
-
unitの種類
- service
- device
-
mount
- ファイルシステムをマウント
-
swap
- スワップ領域をマウント
-
target
- 複数のunitをグループ化
-
SysVinitの欠点を克服している
- unitの依存関係を表現できる
-
並列処理
- システム起動時間が短縮される
-
cgroups: control groups
- リソースを制限・隔離
- 当初はprocess containersといった
systemdの起動手順
-
default.target
Unitが処理される/etc/systemd/system/default.target
にあることになっている- ubuntuだと
/etc/systemd/system/default.target.wants
ディレクトリしかないぜ
/lib/systemd/system/graphical.target
へのシンボリックリンクになってると、
デフォルトでグラフィカルログインになる-
SysVinitでいうランレベルに対応するターゲットが用意されている
- 全単射にはなってない
initでいうランレベル | systemdのターゲット |
---|---|
0 | poweroff.target |
1 | rescue.target |
2,3,4 | multi-user.target |
5 | graphical.target |
6 | reboot.target |
- runlevelごとのシンボリックリンクも置いてあった
ls /lib/systemd/system -l | grep runlevel
lrwxrwxrwx 1 root root 15 2月 14 06:32 runlevel0.target -> poweroff.target
lrwxrwxrwx 1 root root 13 2月 14 06:32 runlevel1.target -> rescue.target
drwxr-xr-x 2 root root 4096 10月 4 2017 runlevel1.target.wants
lrwxrwxrwx 1 root root 17 2月 14 06:32 runlevel2.target -> multi-user.target
drwxr-xr-x 2 root root 4096 10月 4 2017 runlevel2.target.wants
lrwxrwxrwx 1 root root 17 2月 14 06:32 runlevel3.target -> multi-user.target
drwxr-xr-x 2 root root 4096 10月 4 2017 runlevel3.target.wants
lrwxrwxrwx 1 root root 17 2月 14 06:32 runlevel4.target -> multi-user.target
drwxr-xr-x 2 root root 4096 10月 4 2017 runlevel4.target.wants
lrwxrwxrwx 1 root root 16 2月 14 06:32 runlevel5.target -> graphical.target
drwxr-xr-x 2 root root 4096 10月 4 2017 runlevel5.target.wants
lrwxrwxrwx 1 root root 13 2月 14 06:32 runlevel6.target -> reboot.target
-rw-r--r-- 1 root root 797 2月 14 06:32 systemd-update-utmp-runlevel.service
-
graphical.target -> multi-user.target -> basic.target という依存関係がある
- graphical.target単体でグラフィカルログインできるわけではない
systemctlによるサービスの管理
systemctl --help
Unit Commands:
start NAME... Start (activate) one or more units
stop NAME... Stop (deactivate) one or more units
reload NAME... Reload one or more units
restart NAME... Start or restart one or more units
...
is-active PATTERN... Check whether units are active
is-failed PATTERN... Check whether units are failed
status [PATTERN...|PID...] Show runtime status of one or more units
...
Unit File Commands:
list-unit-files [PATTERN...] List installed unit files
enable [NAME...|PATH...] Enable one or more unit files
disable NAME... Disable one or more unit files
...
System Commands:
...
default Enter system default mode
rescue Enter system rescue mode
emergency Enter system emergency mode
halt Shut down and halt the system
poweroff Shut down and power-off the system
reboot [ARG] Shut down and reboot the system
...
- cronで試してみる
systemctl start cron.service # 拡張子serviceは省略可能
systemctl status cron.service
● cron.service - Regular background program processing daemon
Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-02-19 15:46:35 JST; 10s ago
Docs: man:cron(8)
Main PID: 6986 (cron)
Tasks: 1 (limit: 4915)
CGroup: /system.slice/cron.service
└─6986 /usr/sbin/cron -f
2月 19 15:46:35 wand-ThinkPad-X240s systemd[1]: Started Regular backgro…n.
2月 19 15:46:35 wand-ThinkPad-X240s cron[6986]: (CRON) INFO (pidfile fd…3)
2月 19 15:46:35 wand-ThinkPad-X240s cron[6986]: (CRON) INFO (Skipping @…p)
Hint: Some lines were ellipsized, use -l to show in full.
- 稼働確認
systemctl is-active cron
active
systemctl is-failed cron
-
yesかnoで答えようぜ
active
-
自動起動することになってますか
is-disabled
サブコマンドは存在しない
systemctl is-enabled cron
enabled
- システム起動時の自動起動無効化
sudo systemctl disable cron
Synchronizing state of cron.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable cron
- 設定反映確認
systemctl is-enabled cron
disabled
- 今動いているヤツが止まるわけではない
systemctl is-active cron
active
- 今動いているヤツを止める
systemctl stop cron
systemctl is-active cron
systemctl is-failed cron
- is-failedはis-activeの単なるエイリアスなのか??
inactive
inactive
- システム起動時に自動起動するように
sudo systemctl enable cron
Synchronizing state of cron.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable cron
- 直ちに立ち上がるわけではない
systemctl is-active cron
inactive
- 裏ではこのスクリプトが動いているよう
/lib/systemd/systemd-sysv-install
#!/bin/sh
# This script is called by "systemctl enable/disable" when the given unit is a
# SysV init.d script. It needs to call the distribution's mechanism for
# enabling/disabling those, such as chkconfig, update-rc.d, or similar. This
# can optionally take a --root argument for enabling a SysV init script
# in a chroot or similar.
set -eu
usage() {
echo "Usage: $0 [--root=path] enable|disable|is-enabled <sysv script name>" >&2
exit 1
}
ROOT=
# parse options
eval set -- "$(getopt -o r: --long root: -- "$@")"
while true; do
case "$1" in
-r|--root)
ROOT="$2"
shift 2 ;;
--) shift ; break ;;
*) usage ;;
esac
done
NAME="${2:-}"
run() {
if [ -n "$ROOT" ] && [ "$ROOT" != "/" ]; then
chroot "$ROOT" /usr/sbin/update-rc.d "$@"
else
/usr/sbin/update-rc.d "$@"
fi
}
[ -n "$NAME" ] || usage
case "$1" in
enable)
# call the command to enable SysV init script $NAME here..
run "$NAME" defaults
run "$NAME" enable
;;
disable)
run "$NAME" defaults
run "$NAME" disable
;;
is-enabled)
# exit with 0 if $NAME is enabled, non-zero if it is disabled
ls "$ROOT"/etc/rc[S5].d/S??"$NAME" >/dev/null 2>&1
;;
*)
usage ;;
esac
- さらに
/usr/sbin/update-rc.d
が実行されてるみたい /etc/init.d
とか/etc/rc<ランレベル>.d
とかをいじっているよう- ユニット一覧
systemctl list-unit-files | head -10
UNIT FILE STATE
proc-sys-fs-binfmt_misc.automount static
-.mount generated
boot-efi.mount generated
dev-hugepages.mount static
dev-mqueue.mount static
proc-sys-fs-binfmt_misc.mount static
snap-core-6405.mount enabled
snap-gnome\x2d3\x2d26\x2d1604-78.mount enabled
snap-gnome\x2dcalculator-260.mount enabled
【LPIC 101 Ver5.0差分】
journalctl
journalctl --help
journalctl [OPTIONS...] [MATCHES...]
Query the journal.
journalctl | head -n 5
head
等にパイプしないとエラいことになる
-- Logs begin at Sun 2019-02-10 11:34:33 JST, end at Tue 2019-02-19 16:18:29 JST. --
2月 10 11:34:33 wand-ThinkPad-X240s kernel: microcode: microcode updated early to revision 0x23, date = 2018-01-18
2月 10 11:34:33 wand-ThinkPad-X240s kernel: random: get_random_bytes called from start_kernel+0x42/0x4e9 with crng_init=0
2月 10 11:34:33 wand-ThinkPad-X240s kernel: Linux version 4.13.0-46-generic (buildd@lcy01-amd64-002) (gcc version 7.2.0 (Ubuntu 7.2.0-8ubuntu3.2)) #51-Ubuntu SMP Tue Jun 12 12:36:29 UTC 2018 (Ubuntu 4.13.0-46.51-generic 4.13.16)
2月 10 11:34:33 wand-ThinkPad-X240s kernel: Command line: BOOT_IMAGE=/boot/vmlinuz-4.13.0-46-generic.efi.signed root=UUID=ebba1a7e-ed76-43aa-b3cc-8f7baded52e9 ro quiet splash vt.handoff=7
-
最新側は
-n
,--lines
で件数指定できるjournalctl -n 5
-- Logs begin at Sun 2019-02-10 11:34:33 JST, end at Tue 2019-02-19 16:27:37 JST. --
2月 19 16:26:48 wand-ThinkPad-X240s gnome-shell[2633]: [AppIndicatorSupport-WARN] Item :1.64/org/ayatana/NotificationItem/clipit is already registered
2月 19 16:27:10 wand-ThinkPad-X240s gnome-shell[2633]: [AppIndicatorSupport-WARN] Attempting to re-register :1.64/org/ayatana/NotificationItem/clipit; resetting instead
2月 19 16:27:10 wand-ThinkPad-X240s gnome-shell[2633]: [AppIndicatorSupport-WARN] Item :1.64/org/ayatana/NotificationItem/clipit is already registered
2月 19 16:27:37 wand-ThinkPad-X240s gnome-shell[2633]: [AppIndicatorSupport-WARN] Attempting to re-register :1.64/org/ayatana/NotificationItem/clipit; resetting instead
2月 19 16:27:37 wand-ThinkPad-X240s gnome-shell[2633]: [AppIndicatorSupport-WARN] Item :1.64/org/ayatana/NotificationItem/clipit is already registered
tail -f
みたいなやつ
journalctl -f -n 5
-
-k
,--dmesg
dmesg
的な情報を得る
journalctl -k -n 5
-- Logs begin at Sun 2019-02-10 11:34:33 JST, end at Tue 2019-02-19 16:29:00 JST. --
2月 19 14:35:03 wand-ThinkPad-X240s kernel: wlp3s0: associated
2月 19 14:35:03 wand-ThinkPad-X240s kernel: wlp3s0: Limiting TX power to 30 (30 - 0) dBm as advertised by e4:7e:66:08:01:cc
2月 19 14:35:03 wand-ThinkPad-X240s kernel: IPv6: ADDRCONF(NETDEV_CHANGE): wlp3s0: link becomes ready
2月 19 16:01:40 wand-ThinkPad-X240s systemd[1]: Started CUPS Scheduler.
2月 19 16:05:03 wand-ThinkPad-X240s systemd[1]: Started CUPS Scheduler.
-
特定のUnitのログ見る
journalctl -u cron -n 5
-- Logs begin at Sun 2019-02-10 11:34:33 JST, end at Tue 2019-02-19 16:29:22 JST. --
2月 19 15:46:35 wand-ThinkPad-X240s systemd[1]: Started Regular background program processing daemon.
2月 19 15:46:35 wand-ThinkPad-X240s cron[6986]: (CRON) INFO (pidfile fd = 3)
2月 19 15:46:35 wand-ThinkPad-X240s cron[6986]: (CRON) INFO (Skipping @reboot jobs -- not system startup)
2月 19 16:03:26 wand-ThinkPad-X240s systemd[1]: Stopping Regular background program processing daemon...
2月 19 16:03:26 wand-ThinkPad-X240s systemd[1]: Stopped Regular background program processing daemon.
-
-e
,--pager-end
- ページャ使う
- bash on emacsだとうまくいかなかった
- 今日の分のイーサネット周りを拾ってみる
journalctl --since=today | grep eth0
2月 19 12:07:48 wand-ThinkPad-X240s kernel: e1000e 0000:00:19.0 eth0: (PCI Express:2.5GT/s:Width x1) 28:d2:44:ff:ad:ef
2月 19 12:07:48 wand-ThinkPad-X240s kernel: e1000e 0000:00:19.0 eth0: Intel(R) PRO/1000 Network Connection
2月 19 12:07:48 wand-ThinkPad-X240s kernel: e1000e 0000:00:19.0 eth0: MAC: 11, PHY: 12, PBA No: 1000FF-0FF
2月 19 12:07:48 wand-ThinkPad-X240s kernel: e1000e 0000:00:19.0 enp0s25: renamed from eth0
2月 19 12:49:57 wand-ThinkPad-X240s kernel: e1000e 0000:00:19.0 eth0: (PCI Express:2.5GT/s:Width x1) 28:d2:44:ff:ad:ef
2月 19 12:49:57 wand-ThinkPad-X240s kernel: e1000e 0000:00:19.0 eth0: Intel(R) PRO/1000 Network Connection
2月 19 12:49:57 wand-ThinkPad-X240s kernel: e1000e 0000:00:19.0 eth0: MAC: 11, PHY: 12, PBA No: 1000FF-0FF
2月 19 12:49:57 wand-ThinkPad-X240s kernel: e1000e 0000:00:19.0 enp0s25: renamed from eth0
- dmesgで同様の情報取る
dmesg | grep eth0
[ 2.217692] e1000e 0000:00:19.0 eth0: (PCI Express:2.5GT/s:Width x1) 28:d2:44:ff:ad:ef
[ 2.217695] e1000e 0000:00:19.0 eth0: Intel(R) PRO/1000 Network Connection
[ 2.217740] e1000e 0000:00:19.0 eth0: MAC: 11, PHY: 12, PBA No: 1000FF-0FF
[ 2.218583] e1000e 0000:00:19.0 enp0s25: renamed from eth0
ACPI
-
ACPI: Advanced Configuration and Power Interface
- APM: Advanced Power Managementに代わるやつ
-
仕様
- 電源管理
- 温度管理
- プラグ&プレイ
- などなど
- ACPIイベントをリッスンしているのがacpid
- 電源以外にもいろいろやってるみたい
- 手元のレノボでは、ボリューム設定等がある
cat /proc/acpi/ibm/volume
level: unsupported
mute: on