LPIC201/202 あずき本 ch2 Linuxカーネル (3/3)

LPIC201勉強メモ資格勉強

出典: 

2.5 カーネルの管理と問題解決

2.5.1 /procの確認

カーネル内のデータへのインタフェースを疑似ファイルシステムとして提供

  • /proc/: プロセス情報
  • /proc/sys/: デバイス情報
ls -F /proc
1/     1270/  19/   235/  39/	50/   873/	 driver/      kpagecount    schedstat	   version
10/    1283/  190/  236/  4/	503/  878/	 execdomains  kpageflags    scsi/	   vmallocinfo
1020/  1294/  2/    237/  40/	504/  9/	 fb	      loadavg	    self@	   vmstat
1045/  13/    20/   238/  41/	51/   acpi/	 filesystems  locks	    slabinfo	   zoneinfo
1073/  14/    21/   239/  411/	52/   buddyinfo  fs/	      mdstat	    softirqs
1076/  1404/  22/   24/   42/	53/   bus/	 interrupts   meminfo	    stat
1092/  1413/  228/  25/   439/	55/   cgroups	 iomem	      misc	    swaps
1093/  147/   229/  26/   440/	6/    cmdline	 ioports      modules	    sys/
11/    15/    23/   27/   465/	630/  consoles	 irq/	      mounts@	    sysrq-trigger
12/    16/    230/  28/   468/	68/   cpuinfo	 kallsyms     mtrr	    sysvipc/
1219/  18/    231/  29/   471/	7/    crypto	 kcore	      net@	    timer_list
1222/  187/   232/  302/  472/	8/    devices	 key-users    pagetypeinfo  timer_stats
1223/  188/   233/  325/  476/	871/  diskstats  keys	      partitions    tty/
1261/  189/   234/  353/  5/	872/  dma	 kmsg	      sched_debug   uptime

有名どころ

数値/

PIDごとのプロセス情報

ls -F /proc/1/
attr/	    comm	     fd/       map_files/  net/		  pagemap      schedstat  statm    wchan
autogroup   coredump_filter  fdinfo/   maps	   ns/		  patch_state  sessionid  status
auxv	    cpuset	     gid_map   mem	   numa_maps	  personality  setgroups  syscall
cgroup	    cwd@	     io        mountinfo   oom_adj	  projid_map   smaps	  task/
clear_refs  environ	     limits    mounts	   oom_score	  root@        stack	  timers
cmdline     exe@	     loginuid  mountstats  oom_score_adj  sched        stat	  uid_map

bus/pci/

PCIバスのデバイス関連

ls -F /proc/bus/pci/
00  devices

bus/usb/

USBデバイス関連

手元の学習環境にはなかった

ls -F /proc/bus/usb/
ls: cannot access /proc/bus/usb/: No such file or directory

ide/

ideデバイスに関する情報

ls -F /proc/ide/
ls: cannot access /proc/ide/: No such file or directory

net/

ネットワークに関する情報

ls -F /proc/net/
anycast6      igmp		  ip_tables_matches  nf_conntrack_expect  rt_cache	udp6
arp	      igmp6		  ip_tables_names    packet		  snmp		udplite
connector     ip6_flowlabel	  ip_tables_targets  protocols		  snmp6		udplite6
dev	      ip6_mr_cache	  ipv6_route	     psched		  sockstat	unix
dev_mcast     ip6_mr_vif	  mcfilter	     ptype		  sockstat6	wireless
dev_snmp6/    ip6_tables_matches  mcfilter6	     raw		  softnet_stat	xfrm_stat
fib_trie      ip6_tables_names	  netfilter/	     raw6		  stat/
fib_triestat  ip6_tables_targets  netlink	     route		  tcp
icmp	      ip_mr_cache	  netstat	     rt6_stats		  tcp6
if_inet6      ip_mr_vif		  nf_conntrack	     rt_acct		  udp

scsi/

SCSIデバイスに関する情報

ls -F /proc/scsi/
device_info  scsi  sg/

sys/

システムに関する情報

ls -F /proc/sys/
abi/  crypto/  debug/  dev/  fs/  kernel/  net/  user/	vm/

cmdline

起動時にカーネルに渡された引数

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

cpuinfo

CPUしシステムアーキテクチャに関する情報

cat /proc/cpuinfo
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 79
model name	: Intel(R) Xeon(R) CPU @ 2.20GHz
stepping	: 0
microcode	: 0x1
cpu MHz		: 2200.000
cache size	: 56320 KB
physical id	: 0
siblings	: 2
core id		: 0
cpu cores	: 1
apicid		: 0
initial apicid	: 0
fpu		: yes
...

devices

カーネルが認識しているデバイス

cat /proc/devices
Character devices:
  1 mem
  4 /dev/vc/0
  4 tty
  4 ttyS
  5 /dev/tty
  5 /dev/console
  5 /dev/ptmx
  7 vcs
 10 misc
 13 input
 21 sg
 29 fb
 99 ppdev
128 ptm
136 pts
162 raw
180 usb
188 ttyUSB
189 usb_device
202 cpu/msr
203 cpu/cpuid
246 hidraw
247 usbmon
248 bsg
249 hmm_device
250 watchdog
251 iio
252 rtc
253 dax
254 tpm

Block devices:
259 blkext
  8 sd
  9 md
 65 sd
 66 sd
 67 sd
 68 sd
 69 sd
 70 sd
 71 sd
128 sd
129 sd
130 sd
131 sd
132 sd
133 sd
134 sd
135 sd
254 mdp

dma

登録されているDMAチャネル

Direct Memory Channel

cat /proc/dma
 4: cascade

filesystems

カーネルに組み込まれているファイルシステム

cat /proc/filesystems
nodev	sysfs
nodev	rootfs
nodev	ramfs
nodev	bdev
nodev	proc
nodev	cgroup
nodev	cpuset
nodev	tmpfs
nodev	devtmpfs
nodev	debugfs
nodev	securityfs
nodev	sockfs
nodev	dax
nodev	bpf
nodev	pipefs
nodev	configfs
nodev	devpts
nodev	hugetlbfs
nodev	autofs
nodev	pstore
nodev	efivarfs
nodev	mqueue
nodev	selinuxfs
	xfs
	vfat

interrupts

IRQごとの割り込み番号

cat /proc/interrupts
           CPU0       CPU1       
  0:        189          0   IO-APIC-edge      timer
  1:         10          0   IO-APIC-edge      i8042
  4:       5654          0   IO-APIC-edge      serial
  8:          0          0   IO-APIC-edge      rtc0
  9:          0          0   IO-APIC-fasteoi   acpi
 10:       6017          0   IO-APIC-fasteoi   virtio2
 12:        153          0   IO-APIC-edge      i8042
 24:          0          0   PCI-MSI-edge      virtio0-config
 25:          0          0   PCI-MSI-edge      virtio0-control
 26:          0          0   PCI-MSI-edge      virtio0-event
 27:       6493          0   PCI-MSI-edge      virtio0-request
 28:          0          0   PCI-MSI-edge      virtio3-config
 29:          9          0   PCI-MSI-edge      virtio3-input
 30:          0          0   PCI-MSI-edge      virtio1-config
 31:       1507          0   PCI-MSI-edge      virtio1-input.0
 32:          1          0   PCI-MSI-edge      virtio1-output.0
 33:         33       1080   PCI-MSI-edge      virtio1-input.1
 34:          1          0   PCI-MSI-edge      virtio1-output.1
NMI:          0          0   Non-maskable interrupts
LOC:      63618      47823   Local timer interrupts
SPU:          0          0   Spurious interrupts
PMI:          0          0   Performance monitoring interrupts
IWI:        719        697   IRQ work interrupts
RTR:          0          0   APIC ICR read retries
RES:       6593      10322   Rescheduling interrupts
CAL:        436        384   Function call interrupts
TLB:        431        458   TLB shootdowns
TRM:          0          0   Thermal event interrupts
THR:          0          0   Threshold APIC interrupts
DFR:          0          0   Deferred Error APIC interrupts
MCE:          0          0   Machine check exceptions
MCP:         11         11   Machine check polls
ERR:          0
MIS:          0
PIN:          0          0   Posted-interrupt notification event
NPI:          0          0   Nested posted-interrupt event
PIW:          0          0   Posted-interrupt wakeup event

ioports

使用されているI/Oアドレス領域

cat /proc/ioports
0000-0cf7 : PCI Bus 0000:00
  0000-001f : dma1
  0020-0021 : pic1
  0040-0043 : timer0
  0050-0053 : timer1
  0060-0060 : keyboard
  0064-0064 : keyboard
  0070-0071 : rtc0
  0080-008f : dma page reg
  00a0-00a1 : pic2
  00c0-00df : dma2
  00f0-00ff : fpu
  02e8-02ef : serial
  02f8-02ff : serial
  03e8-03ef : serial
  03f8-03ff : serial
  0505-0505 : QEMU0001:00
0cf8-0cff : PCI conf1
0d00-ffff : PCI Bus 0000:00
  afe0-afe3 : ACPI GPE0_BLK
  b000-b03f : 0000:00:01.3
    b000-b003 : ACPI PM1a_EVT_BLK
    b004-b005 : ACPI PM1a_CNT_BLK
    b008-b00b : ACPI PM_TMR
    b010-b015 : ACPI CPU throttle
  c000-c03f : 0000:00:04.0
    c000-c03f : virtio-pci-legacy
  c040-c07f : 0000:00:03.0
    c040-c07f : virtio-pci-legacy
  c080-c09f : 0000:00:06.0
    c080-c09f : virtio-pci-legacy
  c0a0-c0bf : 0000:00:05.0
    c0a0-c0bf : virtio-pci-legacy

kcore

システムの物理メモリ

ls -l /proc/kcore
-r--------. 1 root root 140737486266368 Dec  8 13:41 /proc/kcore

うっかりcatすると標準出力が壊滅する

kmsg

カーネルのログメッセージ

$ head -n 10 /proc/kmsg
head: cannot open '/proc/kmsg' for reading: Permission denied
# head -n 10 /proc/kmsg
head: cannot reposition file pointer for '/proc/kmsg': Invalid argument
<6>[    0.000000] Initializing cgroup subsys cpuset
<6>[    0.000000] Initializing cgroup subsys cpu
<6>[    0.000000] Initializing cgroup subsys cpuacct
<5>[    0.000000] Linux version 3.10.0-1127.19.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ) #1 SMP Tue Aug 25 17:23:54 UTC 2020
<6>[    0.000000] Command line: 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
<6>[    0.000000] e820: BIOS-provided physical RAM map:
<6>[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x0000000000000fff] reserved
<6>[    0.000000] BIOS-e820: [mem 0x0000000000001000-0x0000000000054fff] usable
<6>[    0.000000] BIOS-e820: [mem 0x0000000000055000-0x000000000005ffff] reserved
<6>[    0.000000] BIOS-e820: [mem 0x0000000000060000-0x0000000000097fff] usable

dmesgjournalctl -kと同じもの

dmesg | head -n 10
[    0.000000] Initializing cgroup subsys cpuset
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct
[    0.000000] Linux version 3.10.0-1127.19.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ) #1 SMP Tue Aug 25 17:23:54 UTC 2020
[    0.000000] Command line: 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
[    0.000000] e820: BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x0000000000000fff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000001000-0x0000000000054fff] usable
[    0.000000] BIOS-e820: [mem 0x0000000000055000-0x000000000005ffff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000060000-0x0000000000097fff] usable
journalctl -k | head -n 10
-- Logs begin at Tue 2020-12-08 12:46:46 UTC, end at Tue 2020-12-08 13:42:56 UTC. --
Dec 08 12:46:46 localhost kernel: Initializing cgroup subsys cpuset
Dec 08 12:46:46 localhost kernel: Initializing cgroup subsys cpu
Dec 08 12:46:46 localhost kernel: Initializing cgroup subsys cpuacct
Dec 08 12:46:46 localhost kernel: Linux version 3.10.0-1127.19.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ) #1 SMP Tue Aug 25 17:23:54 UTC 2020
Dec 08 12:46:46 localhost kernel: Command line: 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
Dec 08 12:46:46 localhost kernel: e820: BIOS-provided physical RAM map:
Dec 08 12:46:46 localhost kernel: BIOS-e820: [mem 0x0000000000000000-0x0000000000000fff] reserved
Dec 08 12:46:46 localhost kernel: BIOS-e820: [mem 0x0000000000001000-0x0000000000054fff] usable
Dec 08 12:46:46 localhost kernel: BIOS-e820: [mem 0x0000000000055000-0x000000000005ffff] reserved

meminfo

物理メモリとスワップの情報

cat /proc/meminfo
MemTotal:        1013796 kB
MemFree:          615944 kB
MemAvailable:     695556 kB
Buffers:              28 kB
Cached:           203516 kB
SwapCached:            0 kB
Active:           185084 kB
Inactive:         107012 kB
Active(anon):      88924 kB
Inactive(anon):     6404 kB
Active(file):      96160 kB
Inactive(file):   100608 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:         88584 kB
Mapped:            33296 kB
Shmem:              6776 kB
Slab:              45064 kB
SReclaimable:      21228 kB
SUnreclaim:        23836 kB
KernelStack:        1984 kB
PageTables:         4296 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:      506896 kB
Committed_AS:     474504 kB
VmallocTotal:   34359738367 kB
VmallocUsed:        5412 kB
VmallocChunk:   34359730176 kB
Percpu:              504 kB
HardwareCorrupted:     0 kB
AnonHugePages:     30720 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       58588 kB
DirectMap2M:      989184 kB
DirectMap1G:           0 kB

modules

ロードされているカーネルモジュール

cat /proc/modules
ip6t_rpfilter 12595 1 - Live 0xffffffffc054b000
ip6t_REJECT 12625 2 - Live 0xffffffffc0546000
nf_reject_ipv6 13717 1 ip6t_REJECT, Live 0xffffffffc0541000
ipt_REJECT 12541 2 - Live 0xffffffffc053c000
nf_reject_ipv4 13373 1 ipt_REJECT, Live 0xffffffffc0537000
xt_conntrack 12760 8 - Live 0xffffffffc052b000
ebtable_nat 12807 1 - Live 0xffffffffc0526000
ebtable_broute 12731 1 - Live 0xffffffffc0532000
bridge 151336 1 ebtable_broute, Live 0xffffffffc0500000
stp 12976 1 bridge, Live 0xffffffffc04fb000
llc 14552 2 bridge,stp, Live 0xffffffffc04f2000
ip6table_nat 12864 1 - Live 0xffffffffc04ed000
nf_conntrack_ipv6 18935 5 - Live 0xffffffffc04e7000
nf_defrag_ipv6 35104 1 nf_conntrack_ipv6, Live 0xffffffffc04d9000
nf_nat_ipv6 14131 1 ip6table_nat, Live 0xffffffffc04d0000
ip6table_mangle 12700 1 - Live 0xffffffffc04cb000
...

lsmodはこれを整形して出力する

lsmod
Module                  Size  Used by
ip6t_rpfilter          12595  1 
ip6t_REJECT            12625  2 
nf_reject_ipv6         13717  1 ip6t_REJECT
ipt_REJECT             12541  2 
nf_reject_ipv4         13373  1 ipt_REJECT
xt_conntrack           12760  8 
ebtable_nat            12807  1 
ebtable_broute         12731  1 
bridge                151336  1 ebtable_broute
stp                    12976  1 bridge
llc                    14552  2 stp,bridge
ip6table_nat           12864  1 
nf_conntrack_ipv6      18935  5 
nf_defrag_ipv6         35104  1 nf_conntrack_ipv6
nf_nat_ipv6            14131  1 ip6table_nat
...

mounts

マウントされているファイルシステム

cat /proc/mounts
rootfs / rootfs rw 0 0
sysfs /sys sysfs rw,seclabel,nosuid,nodev,noexec,relatime 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
devtmpfs /dev devtmpfs rw,seclabel,nosuid,size=498768k,nr_inodes=124692,mode=755 0 0
securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0
tmpfs /dev/shm tmpfs rw,seclabel,nosuid,nodev 0 0
devpts /dev/pts devpts rw,seclabel,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /run tmpfs rw,seclabel,nosuid,nodev,mode=755 0 0
tmpfs /sys/fs/cgroup tmpfs ro,seclabel,nosuid,nodev,noexec,mode=755 0 0
cgroup /sys/fs/cgroup/systemd cgroup rw,seclabel,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd 0 0
pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0
efivarfs /sys/firmware/efi/efivars efivarfs rw,nosuid,nodev,noexec,relatime 0 0
cgroup /sys/fs/cgroup/net_cls,net_prio cgroup rw,seclabel,nosuid,nodev,noexec,relatime,net_prio,net_cls 0 0
cgroup /sys/fs/cgroup/devices cgroup rw,seclabel,nosuid,nodev,noexec,relatime,devices 0 0
cgroup /sys/fs/cgroup/blkio cgroup rw,seclabel,nosuid,nodev,noexec,relatime,blkio 0 0
cgroup /sys/fs/cgroup/perf_event cgroup rw,seclabel,nosuid,nodev,noexec,relatime,perf_event 0 0
cgroup /sys/fs/cgroup/pids cgroup rw,seclabel,nosuid,nodev,noexec,relatime,pids 0 0
cgroup /sys/fs/cgroup/memory cgroup rw,seclabel,nosuid,nodev,noexec,relatime,memory 0 0
cgroup /sys/fs/cgroup/freezer cgroup rw,seclabel,nosuid,nodev,noexec,relatime,freezer 0 0
cgroup /sys/fs/cgroup/hugetlb cgroup rw,seclabel,nosuid,nodev,noexec,relatime,hugetlb 0 0
cgroup /sys/fs/cgroup/cpuset cgroup rw,seclabel,nosuid,nodev,noexec,relatime,cpuset 0 0
cgroup /sys/fs/cgroup/cpu,cpuacct cgroup rw,seclabel,nosuid,nodev,noexec,relatime,cpuacct,cpu 0 0
configfs /sys/kernel/config configfs rw,relatime 0 0
/dev/sda2 / xfs rw,seclabel,relatime,attr2,inode64,noquota 0 0
selinuxfs /sys/fs/selinux selinuxfs rw,relatime 0 0
systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=30,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=12613 0 0
mqueue /dev/mqueue mqueue rw,seclabel,relatime 0 0
debugfs /sys/kernel/debug debugfs rw,relatime 0 0
hugetlbfs /dev/hugepages hugetlbfs rw,seclabel,relatime 0 0
/dev/sda1 /boot/efi vfat rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=ascii,shortname=winnt,errors=remount-ro 0 0
tmpfs /run/user/0 tmpfs rw,seclabel,nosuid,nodev,relatime,size=101380k,mode=700 0 0
tmpfs /run/user/1000 tmpfs rw,seclabel,nosuid,nodev,relatime,size=101380k,mode=700,uid=1000,gid=1001 0 0

/etc/mtabと同一のものを指しているsymlink

ls -l /proc/mounts
lrwxrwxrwx. 1 root root 11 Dec  8 13:52 /proc/mounts -> self/mounts
ls -l /etc/mtab
lrwxrwxrwx. 1 root root 17 Nov 10 18:06 /etc/mtab -> /proc/self/mounts

partitions

カーネルが認識しているパーティション

cat /proc/partitions
major minor  #blocks  name

   8        0   20971520 sda
   8        1     204800 sda1
   8        2   20764672 sda2

stat

カーネルおよびシステムの統計情報

cat /proc/stat
cpu  1228 11 922 797242 1104 0 14 205 0 0
cpu0 570 4 506 398267 660 0 11 125 0 0
cpu1 658 6 416 398975 443 0 3 79 0 0
intr 190856 189 10 0 0 5679 0 0 0 0 0 6929 0 153 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7166 0 9 0 1990 1 1325 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ctxt 247833
btime 1607431601
processes 1641
procs_running 2
procs_blocked 0
softirq 202137 0 97234 1 3317 7159 0 1 59117 0 35308

swaps

使用中のスワップ領域

cat /proc/swaps
Filename				Type		Size	Used	Priority

使用中のものがある場合、swapon -sと同じ出力を得る

cat /proc/swaps
Filename				Type		Size	Used	Priority
/swap/file                              file		7340032	0	-2
swapon -s
Filename				Type		Size	Used	Priority
/swap/file                             	file    	7340032	0	-2

uptime

起動してからの経過時間

cat /proc/uptime
4389.12 8704.37
uptime
 13:59:53 up  1:13,  1 user,  load average: 0.00, 0.01, 0.05

第 1 の値は、システムが起動してから経過した合計時間を示しています。 第 2 の値は、各コアがアイドル状態で経過した合計時間の秒数です。

参考: https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/6/html/deployment_guide/s2-proc-uptime

cat /proc/cpuinfo | grep 'cpu cores'
cpu cores	: 1
cpu cores	: 1

コアが2つなので、 4389.12秒x2がだいたい 8704.37秒

ほぼほぼアイドル状態だとして計算が合う

version

カーネルバージョン

cat /proc/version
Linux version 3.10.0-1127.19.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ) #1 SMP Tue Aug 25 17:23:54 UTC 2020

lsdev

/proc/以下を効率よく表示するコマンド

CentOS6/7では提供なし

lsdev
-bash: lsdev: command not found
yum provides lsdev
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ty1.mirror.newmediaexpress.com
 * centos-sclo-rh: ty1.mirror.newmediaexpress.com
 * centos-sclo-sclo: ty1.mirror.newmediaexpress.com
 * epel: d2lzkl7pfhq30w.cloudfront.net
 * extras: ty1.mirror.newmediaexpress.com
 * updates: ty1.mirror.newmediaexpress.com
No matches found

Ubuntuだとprocinfoインストールで入る

  • CentOS5, Debianもそうらしい
apt-cache search lsdev
procinfo - tools to display information from /proc and /sys
lsdev
Device            DMA   IRQ  I/O Ports
------------------------------------------------
ACPI                         0000-0000 0000-0000 0000-0000 0000-0000
acpi                      9 
cascade             4       
dma                          0000-0000
dma1                         0000-0000
dma2                         0000-0000
fpu                          0000-0000
keyboard                     0000-0000 0000-0000
pic1                         0000-0000
pic2                         0000-0000
rtc0                      8  0000-0000
timer0                       0000-0000
timer1                       0000-0000
virtio0-config           24 
virtio0-requests         25 
virtio1-config           26 
virtio1-requests         27 
virtio2-config           28 
virtio2-requests         29 
virtio3-config           30 
virtio3-requests         31 
virtio4-config           32 
virtio4-requests         33 
virtio5-config           34 
virtio5-requests         35 

lspci

システムのすべてのPCIバスと接続されているPCIデバイスに関する情報表示

lspci
-bash: lspci: command not found
yum provides lspci
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ty1.mirror.newmediaexpress.com
 * centos-sclo-rh: ty1.mirror.newmediaexpress.com
 * centos-sclo-sclo: ty1.mirror.newmediaexpress.com
 * epel: d2lzkl7pfhq30w.cloudfront.net
 * extras: ty1.mirror.newmediaexpress.com
 * updates: ty1.mirror.newmediaexpress.com
pciutils-3.5.1-3.el7.x86_64 : PCI bus related utilities
Repo        : base
Matched from:
Filename    : /usr/sbin/lspci

pciutilsで入ってくる

lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 03)
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
00:03.0 Non-VGA unclassified device: Red Hat, Inc. Virtio SCSI
00:04.0 Ethernet controller: Red Hat, Inc. Virtio network device
00:05.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon
00:06.0 Unclassified device [00ff]: Red Hat, Inc. Virtio RNG

-v: verbose

lspci -v
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
	Subsystem: Red Hat, Inc. Qemu virtual machine
	Flags: bus master, medium devsel, latency 0

00:01.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 03)
	Physical Slot: 1
	Flags: bus master, fast devsel, latency 0

00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
	Physical Slot: 1
	Flags: bus master, fast devsel, latency 0, IRQ 9
	Kernel modules: i2c_piix4

00:03.0 Non-VGA unclassified device: Red Hat, Inc. Virtio SCSI
	Subsystem: Red Hat, Inc. Device 0008
	Physical Slot: 3
	Flags: bus master, fast devsel, latency 0, IRQ 11
	I/O ports at c040 [size=64]
	Memory at 80001000 (32-bit, non-prefetchable) [size=128]
	Capabilities: <access denied>
	Kernel driver in use: virtio-pci
	Kernel modules: virtio_pci

00:04.0 Ethernet controller: Red Hat, Inc. Virtio network device
	Subsystem: Red Hat, Inc. Device 0001
	Physical Slot: 4
	Flags: bus master, fast devsel, latency 0, IRQ 10
	I/O ports at c000 [size=64]
	Memory at 80000000 (32-bit, non-prefetchable) [size=128]
	Capabilities: <access denied>
	Kernel driver in use: virtio-pci
	Kernel modules: virtio_pci

00:05.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon
	Subsystem: Google, Inc. Device 0005
	Physical Slot: 5
	Flags: bus master, fast devsel, latency 0, IRQ 10
	I/O ports at c0a0 [size=32]
	Kernel driver in use: virtio-pci
	Kernel modules: virtio_pci

00:06.0 Unclassified device [00ff]: Red Hat, Inc. Virtio RNG
	Subsystem: Red Hat, Inc. Device 0004
	Physical Slot: 6
	Flags: bus master, fast devsel, latency 0, IRQ 11
	I/O ports at c080 [size=32]
	Memory at 80002000 (32-bit, non-prefetchable) [size=64]
	Capabilities: <access denied>
	Kernel driver in use: virtio-pci
	Kernel modules: virtio_pci

もっとverbose

lspci -vv
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
	Subsystem: Red Hat, Inc. Qemu virtual machine
	Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV+ VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
	Status: Cap- 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
	Latency: 0

00:01.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 03)
	Physical Slot: 1
	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

00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
	Physical Slot: 1
	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
	Interrupt: pin A routed to IRQ 9
	Kernel modules: i2c_piix4

00:03.0 Non-VGA unclassified device: Red Hat, Inc. Virtio SCSI
	Subsystem: Red Hat, Inc. Device 0008
	Physical Slot: 3
	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
	Interrupt: pin A routed to IRQ 11
	Region 0: I/O ports at c040 [size=64]
	Region 1: Memory at 80001000 (32-bit, non-prefetchable) [size=128]
	Capabilities: <access denied>
	Kernel driver in use: virtio-pci
	Kernel modules: virtio_pci

00:04.0 Ethernet controller: Red Hat, Inc. Virtio network device
	Subsystem: Red Hat, Inc. Device 0001
	Physical Slot: 4
	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
	Interrupt: pin A routed to IRQ 10
	Region 0: I/O ports at c000 [size=64]
	Region 1: Memory at 80000000 (32-bit, non-prefetchable) [size=128]
	Capabilities: <access denied>
	Kernel driver in use: virtio-pci
	Kernel modules: virtio_pci

00:05.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon
	Subsystem: Google, Inc. Device 0005
	Physical Slot: 5
	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
	Interrupt: pin A routed to IRQ 10
	Region 0: I/O ports at c0a0 [size=32]
	Kernel driver in use: virtio-pci
	Kernel modules: virtio_pci

00:06.0 Unclassified device [00ff]: Red Hat, Inc. Virtio RNG
	Subsystem: Red Hat, Inc. Device 0004
	Physical Slot: 6
	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
	Interrupt: pin A routed to IRQ 11
	Region 0: I/O ports at c080 [size=32]
	Region 1: Memory at 80002000 (32-bit, non-prefetchable) [size=64]
	Capabilities: <access denied>
	Kernel driver in use: virtio-pci
	Kernel modules: virtio_pci

-t: tree

lspci -t
-[0000:00]-+-00.0
           +-01.0
           +-01.3
           +-03.0
           +-04.0
           +-05.0
           \-06.0

verboseと併用可能

lspci -tv
-[0000:00]-+-00.0  Intel Corporation 440FX - 82441FX PMC [Natoma]
           +-01.0  Intel Corporation 82371AB/EB/MB PIIX4 ISA
           +-01.3  Intel Corporation 82371AB/EB/MB PIIX4 ACPI
           +-03.0  Red Hat, Inc. Virtio SCSI
           +-04.0  Red Hat, Inc. Virtio network device
           +-05.0  Red Hat, Inc. Virtio memory balloon
           \-06.0  Red Hat, Inc. Virtio RNG

verbose verboseは効かない

lspci -tvv
-[0000:00]-+-00.0  Intel Corporation 440FX - 82441FX PMC [Natoma]
           +-01.0  Intel Corporation 82371AB/EB/MB PIIX4 ISA
           +-01.3  Intel Corporation 82371AB/EB/MB PIIX4 ACPI
           +-03.0  Red Hat, Inc. Virtio SCSI
           +-04.0  Red Hat, Inc. Virtio network device
           +-05.0  Red Hat, Inc. Virtio memory balloon
           \-06.0  Red Hat, Inc. Virtio RNG

-b: カーネルではなくPCIバスの認識にしたがって表示

lspci -b
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 03)
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
00:03.0 Non-VGA unclassified device: Red Hat, Inc. Virtio SCSI
00:04.0 Ethernet controller: Red Hat, Inc. Virtio network device
00:05.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon
00:06.0 Unclassified device [00ff]: Red Hat, Inc. Virtio RNG

-s: パス、スロット、機能のデバイスのみ表示

-s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]]	Show only devices in selected slots
lspci -s 00:01.3
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)

Ubuntu18.04 (WSL2)でもやってみる

ls -F /proc/bus/pci/
81e0:00/  8d78:00/  957d:00/  9df2:00/  9f5d:00/  a694:00/  devices
lspci
81e0:00:00.0 SCSI storage controller: Red Hat, Inc. Virtio filesystem (rev 01)
8d78:00:00.0 SCSI storage controller: Red Hat, Inc. Virtio filesystem (rev 01)
957d:00:00.0 SCSI storage controller: Red Hat, Inc. Virtio filesystem (rev 01)
9df2:00:00.0 SCSI storage controller: Red Hat, Inc. Virtio filesystem (rev 01)
9f5d:00:00.0 SCSI storage controller: Red Hat, Inc. Virtio filesystem (rev 01)
a694:00:00.0 SCSI storage controller: Red Hat, Inc. Virtio filesystem (rev 01)

-d: ベンダーID、デバイスID指定

-d [<vendor>]:[<device>][:<class>]		Show only devices with specified ID's

lsusb

yum provides lsusb
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ty1.mirror.newmediaexpress.com
 * centos-sclo-rh: ty1.mirror.newmediaexpress.com
 * centos-sclo-sclo: ty1.mirror.newmediaexpress.com
 * epel: d2lzkl7pfhq30w.cloudfront.net
 * extras: ty1.mirror.newmediaexpress.com
 * updates: ty1.mirror.newmediaexpress.com
usbutils-007-5.el7.x86_64 : Linux USB utilities
Repo        : base
Matched from:
Filename    : /usr/bin/lsusb

usbutilsで入る

何も繋がってないので終了

lsusb
(空)

2.5.2 デバイスファイル

ls -l /dev/sda{,1,2}
brw-rw----. 1 root disk 8, 0 Dec  8 12:46 /dev/sda
brw-rw----. 1 root disk 8, 1 Dec  8 12:46 /dev/sda1
brw-rw----. 1 root disk 8, 2 Dec  8 12:46 /dev/sda2
ls -l /dev/{ttyS0,input/mice,zero,null}
crw-rw----. 1 root input 13, 63 Dec  8 12:46 /dev/input/mice
crw-rw-rw-. 1 root root   1,  3 Dec  8 12:46 /dev/null
crw--w----. 1 root tty    4, 64 Dec  8 12:47 /dev/ttyS0
crw-rw-rw-. 1 root root   1,  5 Dec  8 12:46 /dev/zero
  • 8, 0とか 13, 63とか: メジャー番号,マイナー番号

    • カーネルがデバイスを識別するための番号
    • カーネルソースのDocumentation/devices.txtで確認できるらしいが手元のlinux-5.9.12には入ってなかった
  • brw-rw----: ブロックデバイス(b)
  • crw-rw----: キャラクタデバイス(c)
ブロックデバイス キャラクタデバイス
ランダムアクセス 可能 不可能
バッファ ある ない
読み書き単位 ブロック バイト

2.5.3 udev

sysfsと連携して/dev/以下デバイスファイルを動的に管理する

  • udev自体はユーザ空間で動作するのでカーネル内部情報に直接アクセスできない
  • sysfs (/proc/sys/)インタフェースでカーネル内部のデバイス情報を得る
systemctl list-units '*udev*'
UNIT                         LOAD   ACTIVE SUB     DESCRIPTION
systemd-udev-trigger.service loaded active exited  udev Coldplug all Devices
systemd-udevd.service        loaded active running udev Kernel Device Manager
systemd-udevd-control.socket loaded active running udev Control Socket
systemd-udevd-kernel.socket  loaded active running udev Kernel Socket

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

4 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

udevdデーモンが必要なデバイスファイルを動的に作成し、udevadmクライアントで問い合わせる

/etc/udev/rules.d/

/etc/fstab のデバイス版みたいなやつ

ls /etc/udev/rules.d/
75-persistent-net-generator.rules

手元の学習用環境では空だった…

cat /etc/udev/rules.d/75-persistent-net-generator.rules
(空)

udevadm

sysfsがどのようにデバイスを扱っているかを調べられる

udevadm info -q path -n /dev/sda1
/devices/pci0000:00/0000:00:03.0/virtio0/host0/target0:0:1/0:0:1:0/block/sda/sda1
lspci -s 00:03.0
00:03.0 Non-VGA unclassified device: Red Hat, Inc. Virtio SCSI

PCIバスのデバイスの00:03.0が/dev/sda1として使われているんだなと

より詳細な情報

udevadm info -q env -n /dev/sda1
DEVLINKS=/dev/disk/by-id/google-lpic2-study-1-part1 /dev/disk/by-id/scsi-0Google_PersistentDisk_lpic2-study-1-part1 /dev/disk/by-partlabel/EFI\x20System\x20Partition /dev/disk/by-partuuid/28483af6-b921-45a7-88cc-6684862860b8 /dev/disk/by-path/pci-0000:00:03.0-scsi-0:0:1:0-part1 /dev/disk/by-uuid/6879-2FAF
DEVNAME=/dev/sda1
DEVPATH=/devices/pci0000:00/0000:00:03.0/virtio0/host0/target0:0:1/0:0:1:0/block/sda/sda1
DEVTYPE=partition
ID_BUS=scsi
ID_FS_TYPE=vfat
ID_FS_USAGE=filesystem
ID_FS_UUID=6879-2FAF
ID_FS_UUID_ENC=6879-2FAF
ID_FS_VERSION=FAT16
ID_MODEL=PersistentDisk
ID_MODEL_ENC=PersistentDisk\x20\x20
ID_PART_ENTRY_DISK=8:0
ID_PART_ENTRY_NAME=EFI\x20System\x20Partition
ID_PART_ENTRY_NUMBER=1
ID_PART_ENTRY_OFFSET=2048
ID_PART_ENTRY_SCHEME=gpt
ID_PART_ENTRY_SIZE=409600
ID_PART_ENTRY_TYPE=c12a7328-f81f-11d2-ba4b-00a0c93ec93b
ID_PART_ENTRY_UUID=28483af6-b921-45a7-88cc-6684862860b8
ID_PART_TABLE_TYPE=gpt
ID_PATH=pci-0000:00:03.0-scsi-0:0:1:0
ID_PATH_TAG=pci-0000_00_03_0-scsi-0_0_1_0
ID_REVISION=1
ID_SCSI=1
ID_SERIAL=0Google_PersistentDisk_lpic2-study-1
ID_SERIAL_SHORT=lpic2-study-1
ID_TYPE=disk
ID_VENDOR=Google
ID_VENDOR_ENC=Google\x20\x20
MAJOR=8
MINOR=1
SUBSYSTEM=block
TAGS=:systemd:
USEC_INITIALIZED=127724

パーティションじゃなくてディスクの方だと:

udevadm info -q env -n /dev/sda
DEVLINKS=/dev/disk/by-id/google-lpic2-study-1 /dev/disk/by-id/scsi-0Google_PersistentDisk_lpic2-study-1 /dev/disk/by-path/pci-0000:00:03.0-scsi-0:0:1:0
DEVNAME=/dev/sda
DEVPATH=/devices/pci0000:00/0000:00:03.0/virtio0/host0/target0:0:1/0:0:1:0/block/sda
DEVTYPE=disk
ID_BUS=scsi
ID_MODEL=PersistentDisk
ID_MODEL_ENC=PersistentDisk\x20\x20
ID_PART_TABLE_TYPE=gpt
ID_PATH=pci-0000:00:03.0-scsi-0:0:1:0
ID_PATH_TAG=pci-0000_00_03_0-scsi-0_0_1_0
ID_REVISION=1
ID_SCSI=1
ID_SERIAL=0Google_PersistentDisk_lpic2-study-1
ID_SERIAL_SHORT=lpic2-study-1
ID_TYPE=disk
ID_VENDOR=Google
ID_VENDOR_ENC=Google\x20\x20
MAJOR=8
MINOR=0
SUBSYSTEM=block
TAGS=:systemd:
USEC_INITIALIZED=127685

udevadm monitorコマンドでデバイスの検知をモニタリングできる