In questo articolo esamineremo i comandi Linux per controllare e gestire l’hardware.
Il più comune di tutti è il famoso dmesg, che di fatto permette di avere una disanima completa dell’hardware riconosciuto e delle fasi di boot in cui ciò avviene. E’ molto utile ad esempio quando inserite una periferica usb, tipo un disco esterno o una chiavetta, poiché si potrà capire come viene vista e su quale /dev interno viene caricato.
Questo comando ha un sacco di opzioni:
Usage:
dmesg options
Display or control the kernel ring buffer.
Options:
-C, --clear clear the kernel ring buffer
-c, --read-clear read and clear all messages
-D, --console-off disable printing messages to console
-E, --console-on enable printing messages to console
-F, --file use the file instead of the kernel log buffer
-f, --facility restrict output to defined facilities
-H, --human human readable output
-k, --kernel display kernel messages
-L, --color[=] colorize messages (auto, always or never)
colors are enabled by default
-l, --level restrict output to defined levels
-n, --console-level set level of messages printed to console
-P, --nopager do not pipe output into a pager
-r, --raw print the raw message buffer
-S, --syslog force to use syslog(2) rather than /dev/kmsg
-s, --buffer-size buffer size to query the kernel ring buffer
-u, --userspace display userspace messages
-w, --follow wait for new messages
-x, --decode decode facility and level to readable string
-d, --show-delta show time delta between printed messages
-e, --reltime show local time and time delta in readable format
-T, --ctime show human readable timestamp (may be inaccurate!)
-t, --notime don't print messages timestamp
--time-format show time stamp using format:
[delta|reltime|ctime|notime|iso]
Suspending/resume will make ctime and iso timestamps inaccurate. -h, –help display this help and exit -V, –version output version information and exit Supported log facilities: kern – kernel messages user – random user-level messages mail – mail system daemon – system daemons auth – security/authorization messages syslog – messages generated internally by syslogd lpr – line printer subsystem news – network news subsystem Supported log levels (priorities): emerg – system is unusable alert – action must be taken immediately crit – critical conditions err – error conditions warn – warning conditions notice – normal but significant condition info – informational debug – debug-level messages
Sicuramente una delle più importanti, visto che il comando senza parametri non lo include, è l’opzione -e che di fatto mette un timestamp all’evento registrato, in questo modo ad esempio facendo seguire un filtro (grep) come ulteriore opzione, si riesce a capire quando tale evento è avvenuto.
CPU, Memoria e device.. info
eseguendo il cat di /proc/cpuinfo si otterranno le informazioni del processore divise per singolo core. Identico per Memoria e interrutps, ovvero componenti della scheda madre.
cat /proc/cpuinfo
cat /proc/meminfo
cat /proc/interrupts
LSHW
lshw è un comando che mostra in modo più organico, ovvero diviso in modalità ad albero, le informazioni viste in precedenza, ed andando più nello specifico ad esempio sul numero di porte pci, ethernet eccetera.
Sono previste varie opzioni utili, come l’esportazione in xml o html:
usage: lshw [-format] [-options ...]
lshw -version
-version print program version (B.02.17)
format can be
-html output hardware tree as HTML
-xml output hardware tree as XML
-short output hardware paths
-businfo output bus information
options can be
-class CLASS only show a certain class of hardware
-C CLASS same as '-class CLASS'
-c CLASS same as '-class CLASS'
-disable TEST disable a test (like pci, isapnp, cpuid, etc. )
-enable TEST enable a test (like pci, isapnp, cpuid, etc. )
-quiet don't display status
-sanitize sanitize output (remove sensitive information like serial numbers, etc.)
-numeric output numeric IDs (for PCI, USB, etc.)
Visto l’enorme mole di dati mostrata si può restringere il suo utilizzo, ad esempio per vedere solo la parte display daremo:
lshw -c display
le classi sono ben in evidenza sul lshw senza parametri.
Tutto sul disco.
Se lshw mostra molto della macchina, non mostra quasi nulla sulla parte storage, questo perché esiste il comando lsblk, molto molto utilizzato proprio per capire lo stato ad esempio di una chiavetta o un disco una volta riconosciuto. Il comando infatti mostra, se il device è stato montato, anche il punto di mountpoint, ad esempio:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 223,6G 0 disk
├─sda1 8:1 0 215,7G 0 part /
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 7,9G 0 part [SWAP]
sr0 11:0 1 1024M 0 rom
Altre opzioni di lsblk sono:
Usage:
lsblk options device
List information about block devices.
Options:
-a, --all print all devices
-b, --bytes print SIZE in bytes rather than in human readable format
-d, --nodeps don't print slaves or holders
-D, --discard print discard capabilities
-e, --exclude exclude devices by major number (default: RAM disks)
-f, --fs output info about filesystems
-i, --ascii use ascii characters only
-I, --include show only devices with specified major numbers
-J, --json use JSON output format
-l, --list use list format output
-m, --perms output info about permissions
-n, --noheadings don't print headings
-o, --output output columns
-O, --output-all output all columns
-p, --paths print complete device path
-P, --pairs use key="value" output format
-r, --raw use raw output format
-s, --inverse inverse dependencies
-S, --scsi output info about SCSI devices
-t, --topology output info about topology
-x, --sort sort output by
-h, --help display this help and exit
-V, --version output version information and exit
Bus pci
Abbiamo visto che con lshw si possono vedere tra le varie cose i bus pci, ma se vogliamo entrare nello specifico con maggiori dettagli il comando lspci è nostro alleato. Anche questo ha molte opzioni, di solito la più utilizzata è la modalità
lspi -tvv
che mostrerà il vostro bus pci in modalità ad albero. Altre opzioni sono:
Usage: lspci []
Basic display modes:
-mm Produce machine-readable output (single -m for an obsolete format)
-t Show bus tree
Display options:
-v Be verbose (-vv for very verbose)
-k Show kernel drivers handling each device
-x Show hex-dump of the standard part of the config space
-xxx Show hex-dump of the whole config space (dangerous; root only)
-xxxx Show hex-dump of the 4096-byte extended config space (root only)
-b Bus-centric view (addresses and IRQ's as seen by the bus)
-D Always show domain numbers
Resolving of device ID's to names:
-n Show numeric ID's
-nn Show both textual and numeric ID's (names & numbers)
-q Query the PCI ID database for unknown ID's via DNS
-qq As above, but re-query locally cached entries
-Q Query the PCI ID database for all ID's via DNS
Selection of devices:
-s [[[[]:]]:][][.[]] Show only devices in selected slots
-d []:[][:] Show only devices with specified ID's
Other options:
-i Use specified ID database instead of /usr/share/misc/pci.ids.gz
-p Look up kernel modules in a given file instead of default modules.pcimap
-M Enable `bus mapping' mode (dangerous; root only)
PCI access options:
-A Use the specified PCI access method (see `-A help' for a list)
-O = Set PCI access parameter (see `-O help' for a list)
-G Enable PCI access debugging
-H Use direct hardware access ( = 1 or 2)
-F Read PCI configuration dump from a given file
Tutto sull’usb.
Simile alla modalità pci, ne esiste una specifica e molto più di frequente utilizzo che riguarda l’usb.
lsusb -tvv
mostrata nelle opzioni -tvv in modalità ad albero e nella massima verbosità di informazioni.
Altre opzioni per questo comando sono:
Usage: lsusb [options]...
List USB devices
-v, --verbose
Increase verbosity (show descriptors)
-s [[bus]:][devnum]
Show only devices with specified device and/or
bus numbers (in decimal)
-d vendor:[product]
Show only devices with the specified vendor and
product ID numbers (in hexadecimal)
-D device
Selects which device lsusb will examine
-t, --tree
Dump the physical USB device hierarchy as a tree
-V, --version
Show version of program
-h, --help
Show usage and help
Quanta RAM è installata?
Una delle domande classiche, spesso si utilizza un comando che vedremo in un altra puntata, ma in modo errato poiché in realtà servirebbe ad altro, ma come accade sovente in Linux molti comandi “sbordano” in settori adiacenti. Per conoscere il quantitativo di RAM installata, oltre al sopra citato cat di /proc/meminfo si può utilizzare free
free -tm
Ulteriori opzioni di free sono:
[text 1=”free” 2=”[options” language=”Usage:”]
Options:
-b, –bytes show output in bytes
-k, –kilo show output in kilobytes
-m, –mega show output in megabytes
-g, –giga show output in gigabytes
–tera show output in terabytes
-h, –human show human-readable output
–si use powers of 1000 not 1024
-l, –lohi show detailed low and high memory statistics
-t, –total show total for RAM + swap
-s N, –seconds N repeat printing every N seconds
-c N, –count N repeat printing N times, then exit
-w, –wide wide output
–help display this help and exit
-V, –version output version information and exit
Tutto e di più sul tuo disco
Prima abbiamo visto che il comando lsblk è molto utile per identificare dischi e partizioni. Partendo da questo comando conosceremo dove è montato il disco principale, come dall’esempio visto sopra è (e di solito è sempre il principale) /dev/sda. Se vogliamo conoscere ad esempio modello ed altre capacità del disco installato potremo dare il comando:
sudo hdparm -i /dev/sda
In questo caso il comando sudo (elevazione a root) è necessario, il risultato sarà interessante perché avremo modello, serial number e firmware del disco, più tutta un’altra serie di informazioni.
Il comando hdparm in realtà è molto potente, e anche pericoloso. Se guardassimo tra le opzioni offerte infatti possiamo scoprire che si possono andare a forzare informazioni sul disco, o modificare alcune peculiarità, alcune retaggio del passato, altre più moderne. Di tutte quelle fornite faccio solo menzione a ” -tT ” che effettua un speed test in lettura e scrittura sul disco:
sudo hdparm -tT /dev/sda
/dev/sda:
Timing cached reads: 6500 MB in 2.00 seconds = 3250.81 MB/sec
Timing buffered disk reads: 600 MB in 3.00 seconds = 199.69 MB/sec
Molto utile per avere un’idea dello stato del disco qual’ora sorga qualche dubbio sulla sua efficienza.
Un ottimo componente, di cui avevo parlato in uno specifico articolo, è sicuramente badblocks che di fatto è similare allo scandisk di Windows, ovvero permette di scoprire e sistemare imperfezioni del disco rotativo.
Temperatura disco
Se vogliamo conoscere la temperatura di esercizio corrente del disco fisso, in particolare i rotativi rispetto agli SSD possono scaldare parecchio, esiste il comando hddtemp
sudo hddtemp /dev/sda
/dev/sda: CT240BX200SSD1: 33°C
Bios e varie
Cito per ultimo, visto che è un doppione di quasi tutto quanto visto, la possibilità di leggere le informazioni del bios. Si tratta di un elenco piuttosto lungo di informazioni che più o meno sono già riportate negli esempi precedenti. Si tratta del comando:
dmidecode
Con l’opzione -s si può effettuare un filtro delle informazioni, tuttavia il sistema non è molto efficace, e anche con un filtro esterno (il classico grep) non si riuscirà mai ad avere una buona efficacia poiché le informazioni sono su righe diverse. Ad ogni modo è un comando utile per conoscere il firmware del bios, stato della batteria e delle temperature del sistema.