Linuxでコマンドラインからマシンスペックを確認する方法

Linux環境でコマンドラインからマシンのハードウェア構成を表示する方法と，その結果例．
できるだけ追加パッケージのインストールなしで．
Ubuntu 16.04, Ubuntu 17.04，CentOS6，CentOS7等で確認．

# CPU
```shell-session
$ cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 94
model name      : Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
stepping        : 3
microcode       : 0x74
cpu MHz         : 1156.875
cache size      : 8192 KB
physical id     : 0
siblings        : 8
core id         : 0
cpu cores       : 4
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 22
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
bugs            :
bogomips        : 8015.88
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:
~~
```

# Memory
```shell-session
$ cat /proc/meminfo
MemTotal:       65917944 kB
MemFree:        51289844 kB
MemAvailable:   57042336 kB
Buffers:          659852 kB
Cached:          5827560 kB
SwapCached:            0 kB
Active:          9988476 kB
Inactive:        3241888 kB
Active(anon):    6809604 kB
Inactive(anon):   962860 kB
Active(file):    3178872 kB
Inactive(file):  2279028 kB
~~
```

ベンダー名等より詳細な情報が必要な場合は，[dmidecode](http://www.nongnu.org/dmidecode/)コマンドが便利．

```shell-session
$ sudo dmidecode -t memory
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.

Handle 0x0014, DMI type 17, 40 bytes
Memory Device
        Array Handle: 0x0013
        Error Information Handle: Not Provided
        Total Width: 64 bits
        Data Width: 64 bits
        Size: 16384 MB
        Form Factor: DIMM
        Set: None
        Locator: ChannelA-DIMM0
        Bank Locator: BANK 0
        Type: DDR4
        Type Detail: Synchronous
        Speed: 3000 MHz
        Manufacturer: 0215
        Serial Number: 00000000
        Asset Tag: 9876543210
        Part Number: CMK32GX4M2B3000C15
        Rank: 2
        Configured Clock Speed: 3000 MHz
        Minimum Voltage: Unknown
        Maximum Voltage: Unknown
        Configured Voltage: 1.35 V
~~
```

# マザーボード M/B
```shell-session
$ sudo dmidecode -t baseboard
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.

Handle 0x0002, DMI type 2, 15 bytes
Base Board Information
        Manufacturer: ASRock
        Product Name: Z170 Extreme4
        Version:
        Serial Number: 000000000
        Asset Tag:
        Features:
                Board is a hosting board
                Board is replaceable
        Location In Chassis:
        Chassis Handle: 0x0003
        Type: Motherboard
        Contained Object Handles: 0
```

# グラフィックカード
```shell-session
$ lspci | grep VGA
01:00.0 VGA compatible controller: NVIDIA Corporation GM206 [GeForce GTX 960] (rev a1)
```

## NVIDIA
NVIDIAのドライバがインストール済みの場合は，以下の方法でより詳細な情報が取得できる

```shell-session
$ nvidia-smi
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 375.39                 Driver Version: 375.39                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 960     Off  | 0000:01:00.0      On |                  N/A |
| 10%   46C    P8    10W / 130W |    298MiB /  1995MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|    0      1223    G   /usr/lib/xorg/Xorg                             251MiB |
|    0      2373    G   cinnamon                                        45MiB |
+-----------------------------------------------------------------------------+
```

# HDD/ストレージ
## マウントポイントや容量のみ

```shell-session
$ df
Filesystem      1K-blocks       Used  Available Use% Mounted on
/dev/nvme0n1p2 1902364780   87206412 1718500756   5% /
/dev/nvme0n1p1     523248       3540     519708   1% /boot/efi
```

## モデル名等含めてディスク単位で知りたい場合

```shell-session
$ sudo parted -l
Model: ATA WDC WD6001FZWX-0 (scsi)
Disk /dev/sda: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: loop
Disk Flags:

Number  Start  End     Size    File system  Flags
 1      0.00B  6001GB  6001GB  ext4


Model: ATA WDC WD60EFRX-68L (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: loop
Disk Flags:

Number  Start  End     Size    File system  Flags
 1      0.00B  6001GB  6001GB  ext4
```

## パーティションの階層構造を調べたい場合
```shell-session
$ lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0  5.5T  0 disk /data
sdb           8:16   0  5.5T  0 disk /backup
nvme0n1     259:0    0  1.9T  0 disk
├─nvme0n1p1 259:1    0  512M  0 part /boot/efi
├─nvme0n1p2 259:2    0  1.8T  0 part /
└─nvme0n1p3 259:3    0   64G  0 part [SWAP]
```

## `/etc/fstab`用にUUIDを知りたい場合

```shell-session
$ ls -la /dev/disk/by-uuid
total 0
drwxr-xr-x 2 root root 140 May  2 19:51 .
drwxr-xr-x 8 root root 160 May  2 19:51 ..
lrwxrwxrwx 1 root root  15 May 10 19:46 ????????-8648-4905-bdbb-???????????? -> ../../nvme0n1p2
lrwxrwxrwx 1 root root   9 May 10 19:46 ????????-5d7e-4a49-b36c-???????????? -> ../../sdb
lrwxrwxrwx 1 root root  15 May 10 19:46 ????????-43ed-4cbb-9706-???????????? -> ../../nvme0n1p3
lrwxrwxrwx 1 root root   9 May 10 19:46 ????????-cf1b-4033-98cc-???????????? -> ../../sda
```

# ネットワークカード
```shell-session
$ lspci | grep Ethernet
00:1f.6 Ethernet controller: Intel Corporation Ethernet Connection (2) I219-V (rev 31)
01:00.0 Ethernet controller: Intel Corporation Ethernet Controller 10-Gigabit X540-AT2 (rev 01)
01:00.1 Ethernet controller: Intel Corporation Ethernet Controller 10-Gigabit X540-AT2 (rev 01)
```

# OS

## カーネルバージョン

```shell-session
$ uname -a
Linux hostname 4.4.0-75-generic #96-Ubuntu SMP Thu Apr 20 09:56:33 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
```

## ディストリビューションのバージョン
Ubuntu 16.04の16.04や，Linux Mint 18.1の18.1等．

```shell-session
$ lsb_release -r
Release:        18.1
```

## RedHat/CentOS

```shell-session
$ cat /etc/redhat-release
CentOS release 6.9 (Final)
```

## Debian/Ubuntu

```shell-session
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.2 LTS"
```



# 参考
- [Man page of PROC | https://linuxjm.osdn.jp](https://linuxjm.osdn.jp/html/LDP_man-pages/man5/proc.5.html)
- [dmidecode | http://www.nongnu.org](http://www.nongnu.org/dmidecode/)
- [HWの情報を取得できるdmidecodeコマンドが結構便利だと思った - 完熟トマト](http://kanjuku-tomato.blogspot.jp/2013/08/hwdmidecode.html)
- [Linuxで載ってるメモリ（DDR）の種類を調べるコマンド - Qiita](http://qiita.com/aokomoriuta/items/74a807300f644d623a02)
- [lspci(8) — manpages-ja — Debian unstable — Debian Manpages](https://manpages.debian.org/unstable/manpages-ja/lspci.8.ja.html)
- [lsb_release | http://refspecs.linuxbase.org](http://refspecs.linuxbase.org/LSB_3.0.0/LSB-PDA/LSB-PDA/lsbrelease.html)