Table des matières
Managing Integrated Peripherals
Special Files
In a PC, peripherals are connected to a controler which communicates with the processor via a bus. The controller and associated peripherals require specific drivers. Under Linux, these drivers are normally supplied as kernel modules. Each peripheral is represented by a special file in the /dev directory. Each special file contains the information required by the system in order for it to use the driver.
<note important> Peripherals that require the system to be halted prior to plugging or unplugging them are refered to as Cold Plug Devices. Peripherals that can be plugged/unplugged whilst the system is running are refered to as Hot Plug Devices. </note>
The following output shows the typical content of the /dev directory:
[root@centos ~]# ls -l /dev total 0 crw-rw----. 1 root root 10, 55 Apr 9 09:08 autofs drwxr-xr-x. 2 root root 620 Apr 9 09:07 block drwxr-xr-x. 2 root root 80 Apr 9 09:07 bsg drwxr-xr-x. 3 root root 60 Apr 9 09:07 bus lrwxrwxrwx. 1 root root 3 Apr 9 09:07 cdrom -> sr0 drwxr-xr-x. 2 root root 2740 Apr 9 09:08 char crw-------. 1 root root 5, 1 Apr 9 09:07 console lrwxrwxrwx. 1 root root 11 Apr 9 09:07 core -> /proc/kcore drwxr-xr-x. 3 root root 80 Apr 9 09:07 cpu crw-rw----. 1 root root 10, 61 Apr 9 09:07 cpu_dma_latency crw-rw----. 1 root root 10, 62 Apr 9 09:07 crash drwxr-xr-x. 5 root root 100 Apr 9 09:07 disk lrwxrwxrwx. 1 root root 3 Apr 9 09:07 dvd -> sr0 lrwxrwxrwx. 1 root root 3 Apr 9 09:07 fb -> fb0 crw-rw----. 1 root root 29, 0 Apr 9 09:07 fb0 lrwxrwxrwx. 1 root root 13 Apr 9 09:07 fd -> /proc/self/fd crw-rw-rw-. 1 root root 1, 7 Apr 9 09:07 full crw-rw-rw-. 1 root root 10, 229 Apr 9 09:08 fuse crw-rw----. 1 root root 10, 228 Apr 9 09:07 hpet drwxr-xr-x. 2 root root 40 Apr 9 09:07 hugepages crw-------. 1 root root 229, 0 Apr 9 09:07 hvc0 drwxr-xr-x. 3 root root 240 Apr 9 09:07 input crw-rw----. 1 root root 1, 11 Apr 9 09:07 kmsg srw-rw-rw-. 1 root root 0 Apr 9 09:07 log brw-rw----. 1 root disk 7, 0 Apr 9 09:07 loop0 brw-rw----. 1 root disk 7, 1 Apr 9 09:07 loop1 brw-rw----. 1 root disk 7, 2 Apr 9 09:07 loop2 brw-rw----. 1 root disk 7, 3 Apr 9 09:07 loop3 brw-rw----. 1 root disk 7, 4 Apr 9 09:07 loop4 brw-rw----. 1 root disk 7, 5 Apr 9 09:07 loop5 brw-rw----. 1 root disk 7, 6 Apr 9 09:07 loop6 brw-rw----. 1 root disk 7, 7 Apr 9 09:07 loop7 crw-rw----. 1 root lp 6, 0 Apr 9 09:07 lp0 crw-rw----. 1 root lp 6, 1 Apr 9 09:07 lp1 crw-rw----. 1 root lp 6, 2 Apr 9 09:07 lp2 crw-rw----. 1 root lp 6, 3 Apr 9 09:07 lp3 lrwxrwxrwx. 1 root root 13 Apr 9 09:07 MAKEDEV -> /sbin/MAKEDEV drwxr-xr-x. 2 root root 60 Apr 9 09:07 mapper crw-rw----. 1 root root 10, 227 Apr 9 09:07 mcelog crw-r-----. 1 root kmem 1, 1 Apr 9 09:07 mem drwxr-xr-x. 2 root root 60 Apr 9 09:07 net crw-rw----. 1 root root 10, 60 Apr 9 09:07 network_latency crw-rw----. 1 root root 10, 59 Apr 9 09:07 network_throughput crw-rw-rw-. 1 root root 1, 3 Apr 9 09:07 null crw-r-----. 1 root kmem 10, 144 Apr 9 09:07 nvram crw-rw----. 1 root root 1, 12 Apr 9 09:07 oldmem crw-r-----. 1 root kmem 1, 4 Apr 9 09:07 port crw-------. 1 root root 108, 0 Apr 9 09:07 ppp crw-rw-rw-. 1 root tty 5, 2 Jun 16 05:19 ptmx drwxr-xr-x. 2 root root 0 Apr 9 09:07 pts brw-rw----. 1 root disk 1, 0 Apr 9 09:07 ram0 brw-rw----. 1 root disk 1, 1 Apr 9 09:07 ram1 brw-rw----. 1 root disk 1, 10 Apr 9 09:07 ram10 brw-rw----. 1 root disk 1, 11 Apr 9 09:07 ram11 brw-rw----. 1 root disk 1, 12 Apr 9 09:07 ram12 brw-rw----. 1 root disk 1, 13 Apr 9 09:07 ram13 brw-rw----. 1 root disk 1, 14 Apr 9 09:07 ram14 brw-rw----. 1 root disk 1, 15 Apr 9 09:07 ram15 brw-rw----. 1 root disk 1, 2 Apr 9 09:07 ram2 brw-rw----. 1 root disk 1, 3 Apr 9 09:07 ram3 brw-rw----. 1 root disk 1, 4 Apr 9 09:07 ram4 brw-rw----. 1 root disk 1, 5 Apr 9 09:07 ram5 brw-rw----. 1 root disk 1, 6 Apr 9 09:07 ram6 brw-rw----. 1 root disk 1, 7 Apr 9 09:07 ram7 brw-rw----. 1 root disk 1, 8 Apr 9 09:07 ram8 brw-rw----. 1 root disk 1, 9 Apr 9 09:07 ram9 crw-rw-rw-. 1 root root 1, 8 Apr 9 09:07 random drwxr-xr-x. 2 root root 60 Apr 9 09:07 raw lrwxrwxrwx. 1 root root 4 Apr 9 09:07 root -> sda2 lrwxrwxrwx. 1 root root 4 Apr 9 09:07 rtc -> rtc0 crw-rw----. 1 root root 254, 0 Apr 9 09:07 rtc0 lrwxrwxrwx. 1 root root 3 Apr 9 09:07 scd0 -> sr0 brw-rw----. 1 root disk 8, 0 Apr 9 09:07 sda brw-rw----. 1 root disk 8, 1 Apr 9 09:07 sda1 brw-rw----. 1 root disk 8, 2 Apr 9 09:07 sda2 brw-rw----. 1 root disk 8, 3 Apr 9 09:07 sda3 crw-rw----. 1 root cdrom 21, 0 Apr 9 09:07 sg0 crw-rw----. 1 root disk 21, 1 Apr 9 09:07 sg1 drwxrwxrwt. 2 root root 160 Jun 11 15:47 shm crw-rw----. 1 root root 10, 231 Apr 9 09:07 snapshot drwxr-xr-x. 3 root root 180 Apr 9 09:07 snd brw-rw----+ 1 root cdrom 11, 0 Apr 9 09:07 sr0 lrwxrwxrwx. 1 root root 15 Apr 9 09:07 stderr -> /proc/self/fd/2 lrwxrwxrwx. 1 root root 15 Apr 9 09:07 stdin -> /proc/self/fd/0 lrwxrwxrwx. 1 root root 15 Apr 9 09:07 stdout -> /proc/self/fd/1 lrwxrwxrwx. 1 root root 4 Apr 9 09:07 systty -> tty0 crw-rw-rw-. 1 root tty 5, 0 Apr 9 09:07 tty crw--w----. 1 root tty 4, 0 Apr 9 09:07 tty0 crw--w----. 1 root tty 4, 1 Apr 9 09:08 tty1 crw--w----. 1 root tty 4, 10 Apr 9 09:07 tty10 crw--w----. 1 root tty 4, 11 Apr 9 09:07 tty11 crw--w----. 1 root tty 4, 12 Apr 9 09:07 tty12 crw--w----. 1 root tty 4, 13 Apr 9 09:07 tty13 crw--w----. 1 root tty 4, 14 Apr 9 09:07 tty14 crw--w----. 1 root tty 4, 15 Apr 9 09:07 tty15 crw--w----. 1 root tty 4, 16 Apr 9 09:07 tty16 crw--w----. 1 root tty 4, 17 Apr 9 09:07 tty17 crw--w----. 1 root tty 4, 18 Apr 9 09:07 tty18 crw--w----. 1 root tty 4, 19 Apr 9 09:07 tty19 crw-------. 1 root root 4, 2 Apr 9 09:08 tty2 crw--w----. 1 root tty 4, 20 Apr 9 09:07 tty20 crw--w----. 1 root tty 4, 21 Apr 9 09:07 tty21 crw--w----. 1 root tty 4, 22 Apr 9 09:07 tty22 crw--w----. 1 root tty 4, 23 Apr 9 09:07 tty23 crw--w----. 1 root tty 4, 24 Apr 9 09:07 tty24 crw--w----. 1 root tty 4, 25 Apr 9 09:07 tty25 crw--w----. 1 root tty 4, 26 Apr 9 09:07 tty26 crw--w----. 1 root tty 4, 27 Apr 9 09:07 tty27 crw--w----. 1 root tty 4, 28 Apr 9 09:07 tty28 crw--w----. 1 root tty 4, 29 Apr 9 09:07 tty29 crw-------. 1 root root 4, 3 Apr 9 09:08 tty3 crw--w----. 1 root tty 4, 30 Apr 9 09:07 tty30 crw--w----. 1 root tty 4, 31 Apr 9 09:07 tty31 crw--w----. 1 root tty 4, 32 Apr 9 09:07 tty32 crw--w----. 1 root tty 4, 33 Apr 9 09:07 tty33 crw--w----. 1 root tty 4, 34 Apr 9 09:07 tty34 crw--w----. 1 root tty 4, 35 Apr 9 09:07 tty35 crw--w----. 1 root tty 4, 36 Apr 9 09:07 tty36 crw--w----. 1 root tty 4, 37 Apr 9 09:07 tty37 crw--w----. 1 root tty 4, 38 Apr 9 09:07 tty38 crw--w----. 1 root tty 4, 39 Apr 9 09:07 tty39 crw-------. 1 root root 4, 4 Apr 9 09:08 tty4 crw--w----. 1 root tty 4, 40 Apr 9 09:07 tty40 crw--w----. 1 root tty 4, 41 Apr 9 09:07 tty41 crw--w----. 1 root tty 4, 42 Apr 9 09:07 tty42 crw--w----. 1 root tty 4, 43 Apr 9 09:07 tty43 crw--w----. 1 root tty 4, 44 Apr 9 09:07 tty44 crw--w----. 1 root tty 4, 45 Apr 9 09:07 tty45 crw--w----. 1 root tty 4, 46 Apr 9 09:07 tty46 crw--w----. 1 root tty 4, 47 Apr 9 09:07 tty47 crw--w----. 1 root tty 4, 48 Apr 9 09:07 tty48 crw--w----. 1 root tty 4, 49 Apr 9 09:07 tty49 crw-------. 1 root root 4, 5 Apr 9 09:08 tty5 crw--w----. 1 root tty 4, 50 Apr 9 09:07 tty50 crw--w----. 1 root tty 4, 51 Apr 9 09:07 tty51 crw--w----. 1 root tty 4, 52 Apr 9 09:07 tty52 crw--w----. 1 root tty 4, 53 Apr 9 09:07 tty53 crw--w----. 1 root tty 4, 54 Apr 9 09:07 tty54 crw--w----. 1 root tty 4, 55 Apr 9 09:07 tty55 crw--w----. 1 root tty 4, 56 Apr 9 09:07 tty56 crw--w----. 1 root tty 4, 57 Apr 9 09:07 tty57 crw--w----. 1 root tty 4, 58 Apr 9 09:07 tty58 crw--w----. 1 root tty 4, 59 Apr 9 09:07 tty59 crw-------. 1 root root 4, 6 Apr 9 09:08 tty6 crw--w----. 1 root tty 4, 60 Apr 9 09:07 tty60 crw--w----. 1 root tty 4, 61 Apr 9 09:07 tty61 crw--w----. 1 root tty 4, 62 Apr 9 09:07 tty62 crw--w----. 1 root tty 4, 63 Apr 9 09:07 tty63 crw--w----. 1 root tty 4, 7 Apr 9 09:07 tty7 crw--w----. 1 root tty 4, 8 Apr 9 09:07 tty8 crw--w----. 1 root tty 4, 9 Apr 9 09:07 tty9 crw-rw----. 1 root dialout 4, 64 Apr 9 09:07 ttyS0 crw-rw----. 1 root dialout 4, 65 Apr 9 09:07 ttyS1 crw-rw----. 1 root dialout 4, 66 Apr 9 09:07 ttyS2 crw-rw----. 1 root dialout 4, 67 Apr 9 09:07 ttyS3 crw-rw-rw-. 1 root root 1, 9 Apr 9 09:07 urandom crw-rw----. 1 root root 250, 0 Apr 9 09:07 usbmon0 crw-rw----. 1 root root 250, 1 Apr 9 09:07 usbmon1 crw-rw----. 1 vboxadd root 10, 57 Apr 9 09:07 vboxguest crw-rw-rw-. 1 vboxadd root 10, 56 Apr 9 09:07 vboxuser crw-rw----. 1 vcsa tty 7, 0 Apr 9 09:07 vcs crw-rw----. 1 vcsa tty 7, 1 Apr 9 09:07 vcs1 crw-rw----. 1 vcsa tty 7, 2 Apr 9 09:08 vcs2 crw-rw----. 1 vcsa tty 7, 3 Apr 9 09:08 vcs3 crw-rw----. 1 vcsa tty 7, 4 Apr 9 09:08 vcs4 crw-rw----. 1 vcsa tty 7, 5 Apr 9 09:08 vcs5 crw-rw----. 1 vcsa tty 7, 6 Apr 9 09:08 vcs6 crw-rw----. 1 vcsa tty 7, 128 Apr 9 09:07 vcsa crw-rw----. 1 vcsa tty 7, 129 Apr 9 09:07 vcsa1 crw-rw----. 1 vcsa tty 7, 130 Apr 9 09:08 vcsa2 crw-rw----. 1 vcsa tty 7, 131 Apr 9 09:08 vcsa3 crw-rw----. 1 vcsa tty 7, 132 Apr 9 09:08 vcsa4 crw-rw----. 1 vcsa tty 7, 133 Apr 9 09:08 vcsa5 crw-rw----. 1 vcsa tty 7, 134 Apr 9 09:08 vcsa6 crw-rw----. 1 root root 10, 63 Apr 9 09:07 vga_arbiter crw-rw-rw-. 1 root root 1, 5 Apr 9 09:07 zero
As you can see, certain files refer to block devices whilst others refer to character devices:
... brw-rw----. 1 root disk 8, 1 Apr 9 09:07 sda1 ... crw-rw-rw-. 1 root tty 5, 0 Apr 9 09:07 tty ...
The major difference between these two types lies in the way that the communication between the system and the peripheral takes place. In the case of a block file, that communication uses a buffer whilst in the case of a character file the communication takes place directly byte by byte.
The figures that can be seen immediately before the date of the special file are called respectively the major and the minor :
- the major identifies the peripheral's driver,
- the minor identifies the peripheral. For instance 8,1 indicates the first partition of the sda disk.
Commands
The lspci Command
This command show a list of the peripherals connected to the PCI, AGP and PCI express buses:
[root@centos ~]# lspci 00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02) 00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II] 00:01.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01) 00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter 00:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 02) 00:04.0 System peripheral: InnoTek Systemberatung GmbH VirtualBox Guest Service 00:05.0 Multimedia audio controller: Intel Corporation 82801AA AC'97 Audio Controller (rev 01) 00:06.0 USB controller: Apple Inc. KeyLargo/Intrepid USB 00:07.0 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08) 00:0d.0 SATA controller: Intel Corporation 82801HM/HEM (ICH8M/ICH8M-E) SATA Controller [AHCI mode] (rev 02)
To obtain peripheral specific information, use the -v or -vv switches whilst specifying the peripheral ID:
[root@centos ~]# lspci -v -s 00:03.0 00:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 02) Subsystem: Intel Corporation PRO/1000 MT Desktop Adapter Flags: bus master, 66MHz, medium devsel, latency 64, IRQ 10 Memory at f0000000 (32-bit, non-prefetchable) [size=128K] I/O ports at d010 [size=8] Capabilities: [dc] Power Management version 2 Capabilities: [e4] PCI-X non-bridge device Kernel driver in use: e1000 Kernel modules: e1000 [root@centos ~]# lspci -vv -s 00:03.0 00:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 02) Subsystem: Intel Corporation PRO/1000 MT Desktop Adapter 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: 64 (63750ns min) Interrupt: pin A routed to IRQ 10 Region 0: Memory at f0000000 (32-bit, non-prefetchable) [size=128K] Region 2: I/O ports at d010 [size=8] Capabilities: [dc] Power Management version 2 Flags: PMEClk- DSI+ D1- D2- AuxCurrent=0mA PME(D0-,D1-,D2-,D3hot-,D3cold-) Status: D0 NoSoftRst- PME-Enable- DSel=0 DScale=0 PME- Capabilities: [e4] PCI-X non-bridge device Command: DPERE- ERO+ RBC=512 OST=1 Status: Dev=ff:1f.0 64bit- 133MHz- SCD- USC- DC=simple DMMRBC=2048 DMOST=1 DMCRS=8 RSCEM- 266MHz- 533MHz- Kernel driver in use: e1000 Kernel modules: e1000
Command Line Switches
The command line switches of this command are:
[root@centos ~]# lspci --help lspci: invalid option -- '-' Usage: lspci [<switches>] 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 [[[[<domain>]:]<bus>]:][<slot>][.[<func>]] Show only devices in selected slots -d [<vendor>]:[<device>] Show only devices with specified ID's Other options: -i <file> Use specified ID database instead of /usr/share/hwdata/pci.ids -p <file> 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 <method> Use the specified PCI access method (see `-A help' for a list) -O <par>=<val> Set PCI access parameter (see `-O help' for a list) -G Enable PCI access debugging -H <mode> Use direct hardware access (<mode> = 1 or 2) -F <file> Read PCI configuration dump from a given file
The lsusb Command
This command show a list of the peripherals connected to the USB bus:
[root@centos ~]# lsusb Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
To obtain peripheral specific information, use the -d switch whilst specifying the peripheral ID:
Command Line Switches
The command line switches of this command are:
[root@centos ~]# lsusb --help lsusb: unrecognized option '--help' 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 Dump the physical USB device hierarchy as a tree -V, --version Show version of program
The dmidecode Command
The dmidecode Command reads the DMI (Desktop Management Interface) table, also called the SMBIOS (System Management BIOS) and provides information on:
- the current status of each peripheral,
- possible extensions.
[root@centos ~]# dmidecode # dmidecode 2.11 SMBIOS 2.5 present. 10 structures occupying 448 bytes. Table at 0x000E1000. Handle 0x0000, DMI type 0, 20 bytes BIOS Information Vendor: innotek GmbH Version: VirtualBox Release Date: 12/01/2006 Address: 0xE0000 Runtime Size: 128 kB ROM Size: 128 kB Characteristics: ISA is supported PCI is supported Boot from CD is supported Selectable boot is supported 8042 keyboard services are supported (int 9h) CGA/mono video services are supported (int 10h) ACPI is supported Handle 0x0001, DMI type 1, 27 bytes System Information Manufacturer: innotek GmbH Product Name: VirtualBox Version: 1.2 Serial Number: 0 UUID: Not Settable Wake-up Type: Power Switch SKU Number: Not Specified Family: Virtual Machine Handle 0x0008, DMI type 2, 15 bytes Base Board Information Manufacturer: Oracle Corporation Product Name: VirtualBox Version: 1.2 Serial Number: 0 Asset Tag: Not Specified Features: Board is a hosting board Location In Chassis: Not Specified Chassis Handle: 0x0003 Type: Motherboard Contained Object Handles: 0 Handle 0x0003, DMI type 3, 13 bytes Chassis Information Manufacturer: Oracle Corporation Type: Other Lock: Not Present Version: Not Specified Serial Number: Not Specified Asset Tag: Not Specified Boot-up State: Safe Power Supply State: Safe Thermal State: Safe Security Status: None Handle 0x0007, DMI type 126, 42 bytes Inactive Handle 0x0005, DMI type 126, 15 bytes Inactive Handle 0x0006, DMI type 126, 28 bytes Inactive Handle 0x0002, DMI type 11, 7 bytes OEM Strings String 1: vboxVer_4.3.0 String 2: vboxRev_89960 Handle 0x0008, DMI type 128, 8 bytes OEM-specific Type Header and Data: 80 08 08 00 B5 F9 22 00 Handle 0xFEFF, DMI type 127, 4 bytes End Of Table
Command Line Switches
The command line switches of this command are:
[root@centos ~]# dmidecode --help Usage: dmidecode [OPTIONS] Options are: -d, --dev-mem FILE Read memory from device FILE (default: /dev/mem) -h, --help Display this help text and exit -q, --quiet Less verbose output -s, --string KEYWORD Only display the value of the given DMI string -t, --type TYPE Only display the entries of given type -u, --dump Do not decode the entries --dump-bin FILE Dump the DMI data to a binary file --from-dump FILE Read the DMI data from a binary file -V, --version Display the version and exit
The /proc Directory
The /proc directory contains virtual files and directories wich are created dynamically when consulted. Only root can consult all of the information in /proc.
[root@centos ~]# ls /proc 1 1355 1492 1755 1829 1922 2052 2114 2139 2206 27 3 38 8 cpuinfo interrupts kpagecount mtrr stat vmallocinfo 10 1393 15 1771 1831 1931 2057 2115 2140 23 27466 30 388 9 crypto iomem kpageflags net swaps vmstat 11 1397 1512 1779 1838 1939 2060 2117 2141 2363 27467 300 39 971 devices ioports loadavg pagetypeinfo sys zoneinfo 1188 14 1574 1787 1839 1961 2085 2126 2142 2371 27468 31 4 972 diskstats ipmi locks partitions sysrq-trigger 12 1403 1586 1798 1840 1970 2093 2127 2144 2372 27482 31548 433 acpi dma irq mdstat sched_debug sysvipc 1230 1413 16 18 1855 1978 2098 2129 2147 2373 27488 31644 5 asound driver kallsyms meminfo schedstat timer_list 13 1438 1658 1811 1857 1979 21 2131 2151 2385 28 339 577 buddyinfo execdomains kcore misc scsi timer_stats 1325 1447 1666 1818 1875 2 2106 2133 2156 24 29 340 6 bus fb keys modules self tty 1336 1448 17 1825 1881 20 2110 2134 22 25 290 36 69 cgroups filesystems key-users mounts slabinfo uptime 1340 1479 1747 1827 19 2045 2111 2137 2202 26 291 377 7 cmdline fs kmsg mtd softirqs version
Sub-directories
ide/scsi
This sub-directory contains disk capacity, disk type and disk geometry information.
acpi
This sub-directory contains information on energy management, temperatures, fan speeds and battery levels.
bus
This sub-directory contains a sub-directory for each bus.
net
This sub-directory contains information concerning the network.
sys
This sub-directory contains files used by root to configure the kernel. For instance, the following command configiresthe kernel to ignore incoming pings:
# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all [Entrée]
The sysctl Command
Files in the /proc/sys can be administered by using the sysctl command.
The sysctl command applies rules at system boot that are defined in the /etc/sysctl.conf file:
[root@centos ~]# cat /etc/sysctl.conf # Kernel sysctl configuration file for Red Hat Linux # # For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and # sysctl.conf(5) for more details. # Controls IP packet forwarding net.ipv4.ip_forward = 0 # Controls source route verification net.ipv4.conf.default.rp_filter = 1 # Do not accept source routing net.ipv4.conf.default.accept_source_route = 0 # Controls the System Request debugging functionality of the kernel kernel.sysrq = 0 # Controls whether core dumps will append the PID to the core filename. # Useful for debugging multi-threaded applications. kernel.core_uses_pid = 1 # Controls the use of TCP syncookies net.ipv4.tcp_syncookies = 1 # Disable netfilter on bridges. net.bridge.bridge-nf-call-ip6tables = 0 net.bridge.bridge-nf-call-iptables = 0 net.bridge.bridge-nf-call-arptables = 0 # Controls the default maxmimum size of a mesage queue kernel.msgmnb = 65536 # Controls the maximum size of a message, in bytes kernel.msgmax = 65536 # Controls the maximum shared segment size, in bytes kernel.shmmax = 4294967295 # Controls the maximum number of shared memory segments, in pages kernel.shmall = 268435456
Command Line Switches
The command line switches of this command are:
[root@centos ~]# sysctl --help usage: sysctl [-n] [-e] variable ... sysctl [-n] [-e] [-q] -w variable=value ... sysctl [-n] [-e] -a sysctl [-n] [-e] [-q] -p <file> (default /etc/sysctl.conf) sysctl [-n] [-e] -A
Files
/proc/cpuinfo
[root@centos ~]# cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 37 model name : Intel(R) Core(TM) i5 CPU M 480 @ 2.67GHz stepping : 5 cpu MHz : 2647.112 cache size : 6144 KB fdiv_bug : no hlt_bug : no f00f_bug : no coma_bug : no fpu : yes fpu_exception : yes cpuid level : 5 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 syscall nx lm constant_tsc up pni monitor ssse3 lahf_lm bogomips : 5294.22 clflush size : 64 cache_alignment : 64 address sizes : 36 bits physical, 48 bits virtual power management:
/proc/interrupts
[root@centos ~]# cat /proc/interrupts CPU0 0: 122 XT-PIC-XT timer 1: 974 XT-PIC-XT i8042 2: 0 XT-PIC-XT cascade 8: 0 XT-PIC-XT rtc0 9: 38140 XT-PIC-XT acpi, vboxguest 10: 102335 XT-PIC-XT eth0 11: 51228 XT-PIC-XT ohci_hcd:usb1, ahci, Intel 82801AA-ICH 12: 1340 XT-PIC-XT i8042 14: 0 XT-PIC-XT ata_piix 15: 307485 XT-PIC-XT ata_piix NMI: 0 Non-maskable interrupts LOC: 3953311 Local timer interrupts SPU: 0 Spurious interrupts PMI: 0 Performance monitoring interrupts IWI: 0 IRQ work interrupts RES: 0 Rescheduling interrupts CAL: 0 Function call interrupts TLB: 0 TLB shootdowns TRM: 0 Thermal event interrupts THR: 0 Threshold APIC interrupts MCE: 0 Machine check exceptions MCP: 171 Machine check polls ERR: 0 MIS: 0
/proc/dma
[root@centos ~]# cat /proc/dma 4: cascade
/proc/ioports
[root@centos ~]# cat /proc/ioports 0000-001f : dma1 0020-0021 : pic1 0040-0043 : timer0 0050-0053 : timer1 0060-0060 : keyboard 0064-0064 : keyboard 0070-0071 : rtc_cmos 0070-0071 : rtc0 0080-008f : dma page reg 00a0-00a1 : pic2 00c0-00df : dma2 00f0-00ff : fpu 0170-0177 : 0000:00:01.1 0170-0177 : ata_piix 01f0-01f7 : 0000:00:01.1 01f0-01f7 : ata_piix 0376-0376 : 0000:00:01.1 0376-0376 : ata_piix 03c0-03df : vga+ 03f6-03f6 : 0000:00:01.1 03f6-03f6 : ata_piix 0cf8-0cff : PCI conf1 4000-4003 : ACPI PM1a_EVT_BLK 4004-4005 : ACPI PM1a_CNT_BLK 4008-400b : ACPI PM_TMR 4020-4021 : ACPI GPE0_BLK d000-d00f : 0000:00:01.1 d000-d00f : ata_piix d010-d017 : 0000:00:03.0 d010-d017 : e1000 d020-d03f : 0000:00:04.0 d100-d1ff : 0000:00:05.0 d100-d1ff : Intel 82801AA-ICH d200-d23f : 0000:00:05.0 d200-d23f : Intel 82801AA-ICH d240-d247 : 0000:00:0d.0 d240-d247 : ahci d250-d257 : 0000:00:0d.0 d250-d257 : ahci d260-d26f : 0000:00:0d.0 d260-d26f : ahci
<note warning> If two peripherals have the same port, both peripherals will be unusable. </note>
/proc/devices
[root@centos ~]# 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 14 sound 21 sg 29 fb 99 ppdev 116 alsa 128 ptm 136 pts 162 raw 180 usb 189 usb_device 202 cpu/msr 203 cpu/cpuid 226 drm 250 hidraw 251 usbmon 252 bsg 253 pcmcia 254 rtc Block devices: 1 ramdisk 259 blkext 7 loop 8 sd 9 md 11 sr 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 253 device-mapper 254 mdp
/proc/modules
[root@centos ~]# cat /proc/modules fuse 59447 0 - Live 0xf7f05000 vboxsf 35841 0 - Live 0xf7ffd000 autofs4 20373 3 - Live 0xf7eca000 sunrpc 212455 1 - Live 0xf8031000 8021q 20323 0 - Live 0xf7e5c000 garp 5703 1 8021q, Live 0xf7e48000 stp 1626 1 garp, Live 0xf7e3f000 llc 4258 2 garp,stp, Live 0xf7e1a000 ipt_REJECT 1867 2 - Live 0xf82b0000 nf_conntrack_ipv4 7694 2 - Live 0xf82a7000 nf_defrag_ipv4 1039 1 nf_conntrack_ipv4, Live 0xf829d000 iptable_filter 2173 1 - Live 0xf8295000 ip_tables 9567 1 iptable_filter, Live 0xf828c000 ip6t_REJECT 3987 2 - Live 0xf827e000 nf_conntrack_ipv6 7207 2 - Live 0xf8275000 nf_defrag_ipv6 8897 1 nf_conntrack_ipv6, Live 0xf826a000 xt_state 1064 4 - Live 0xf8260000 nf_conntrack 65620 3 nf_conntrack_ipv4,nf_conntrack_ipv6,xt_state, Live 0xf8243000 ip6table_filter 2245 1 - Live 0xf8224000 ip6_tables 10867 1 ip6table_filter, Live 0xf821a000 ipv6 264187 35 ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6, Live 0xf81c2000 ppdev 7297 0 - Live 0xf80d8000 parport_pc 19086 0 - Live 0xf808f000 parport 29925 2 ppdev,parport_pc, Live 0xf8077000 microcode 12216 0 - Live 0xf802d000 sg 24038 0 - Live 0xf801c000 i2c_piix4 11156 0 - Live 0xf7ed9000 i2c_core 25632 1 i2c_piix4, Live 0xf7f19000 snd_intel8x0 24281 2 - Live 0xf7efa000 snd_ac97_codec 95611 1 snd_intel8x0, Live 0xf7f84000 ac97_bus 968 1 snd_ac97_codec, Live 0xf7e87000 snd_seq 44709 0 - Live 0xf7edf000 snd_seq_device 5124 1 snd_seq, Live 0xf7e54000 snd_pcm 67800 2 snd_intel8x0,snd_ac97_codec, Live 0xf7e8e000 snd_timer 17152 2 snd_seq,snd_pcm, Live 0xf7e27000 snd 51792 10 snd_intel8x0,snd_ac97_codec,snd_seq,snd_seq_device,snd_pcm,snd_timer, Live 0xf7e6a000 soundcore 6390 1 snd, Live 0xf7e21000 snd_page_alloc 6882 2 snd_intel8x0,snd_pcm, Live 0xf7e17000 vboxguest 195019 7 vboxsf, Live 0xf8bff000 e1000 149778 0 - Live 0xf8743000 ext4 328781 2 - Live 0xf7fab000 jbd2 75154 1 ext4, Live 0xf7f24000 mbcache 6017 1 ext4, Live 0xf7f02000 sd_mod 34923 4 - Live 0xf7ef0000 crc_t10dif 1217 1 sd_mod, Live 0xf7edd000 sr_mod 13282 0 - Live 0xf7ed4000 cdrom 33416 1 sr_mod, Live 0xf7ec0000 ahci 34601 3 - Live 0xf7ea1000 pata_acpi 2513 0 - Live 0xf7e8c000 ata_generic 2805 0 - Live 0xf7e85000 ata_piix 20413 0 - Live 0xf7e78000 dm_mirror 11774 0 - Live 0xf7e66000 dm_region_hash 9644 1 dm_mirror, Live 0xf7e58000 dm_log 8322 2 dm_mirror,dm_region_hash, Live 0xf7e4c000 dm_mod 68819 2 dm_mirror,dm_log, Live 0xf7e2d000
/proc/diskstats
[root@centos ~]# cat /proc/diskstats 1 0 ram0 0 0 0 0 0 0 0 0 0 0 0 1 1 ram1 0 0 0 0 0 0 0 0 0 0 0 1 2 ram2 0 0 0 0 0 0 0 0 0 0 0 1 3 ram3 0 0 0 0 0 0 0 0 0 0 0 1 4 ram4 0 0 0 0 0 0 0 0 0 0 0 1 5 ram5 0 0 0 0 0 0 0 0 0 0 0 1 6 ram6 0 0 0 0 0 0 0 0 0 0 0 1 7 ram7 0 0 0 0 0 0 0 0 0 0 0 1 8 ram8 0 0 0 0 0 0 0 0 0 0 0 1 9 ram9 0 0 0 0 0 0 0 0 0 0 0 1 10 ram10 0 0 0 0 0 0 0 0 0 0 0 1 11 ram11 0 0 0 0 0 0 0 0 0 0 0 1 12 ram12 0 0 0 0 0 0 0 0 0 0 0 1 13 ram13 0 0 0 0 0 0 0 0 0 0 0 1 14 ram14 0 0 0 0 0 0 0 0 0 0 0 1 15 ram15 0 0 0 0 0 0 0 0 0 0 0 7 0 loop0 0 0 0 0 0 0 0 0 0 0 0 7 1 loop1 0 0 0 0 0 0 0 0 0 0 0 7 2 loop2 0 0 0 0 0 0 0 0 0 0 0 7 3 loop3 0 0 0 0 0 0 0 0 0 0 0 7 4 loop4 0 0 0 0 0 0 0 0 0 0 0 7 5 loop5 0 0 0 0 0 0 0 0 0 0 0 7 6 loop6 0 0 0 0 0 0 0 0 0 0 0 7 7 loop7 0 0 0 0 0 0 0 0 0 0 0 11 0 sr0 0 0 0 0 0 0 0 0 0 0 0 8 0 sda 33391 5791 1232722 251998 19357 267987 2298676 1462247 0 268156 1714173 8 1 sda1 783 351 49488 1249 22 6 68 141 0 975 1379 8 2 sda2 32102 5408 1178930 250304 19285 267981 2298608 1461984 0 267063 1712228 8 3 sda3 332 31 2904 333 0 0 0 0 0 333 333
/proc/partitions
[root@centos ~]# cat /proc/partitions major minor #blocks name 8 0 20971520 sda 8 1 102400 sda1 8 2 5120000 sda2 8 3 2096128 sda3
/proc/swaps
[root@centos ~]# cat /proc/swaps Filename Type Size Used Priority /dev/sda3 partition 2096120 0 -1
/proc/loadavg
[root@centos ~]# cat /proc/loadavg 0.00 0.00 0.00 1/231 32129
/proc/meminfo
[root@centos ~]# cat /proc/meminfo MemTotal: 1915472 kB MemFree: 662856 kB Buffers: 88732 kB Cached: 959116 kB SwapCached: 0 kB Active: 656708 kB Inactive: 483352 kB Active(anon): 92268 kB Inactive(anon): 4316 kB Active(file): 564440 kB Inactive(file): 479036 kB Unevictable: 0 kB Mlocked: 0 kB HighTotal: 1165256 kB HighFree: 109244 kB LowTotal: 750216 kB LowFree: 553612 kB SwapTotal: 2096120 kB SwapFree: 2096120 kB Dirty: 0 kB Writeback: 0 kB AnonPages: 92228 kB Mapped: 53416 kB Shmem: 4376 kB Slab: 91496 kB SReclaimable: 58008 kB SUnreclaim: 33488 kB KernelStack: 1840 kB PageTables: 5908 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 3053856 kB Committed_AS: 453216 kB VmallocTotal: 122880 kB VmallocUsed: 25776 kB VmallocChunk: 83448 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB DirectMap4k: 14328 kB DirectMap2M: 892928 kB
/proc/version
[root@centos ~]# cat /proc/version Linux version 2.6.32-358.23.2.el6.i686 (mockbuild@c6b9.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) ) #1 SMP Wed Oct 16 17:21:31 UTC 2013
Interpreting Information in /proc
The information found in files in the /proc filesystem can be interpreted using the following commands:
- free,
- uptime et w,
- iostat,
- vmstat,
- mpstat,
- sar.
Commands
free
The free command shows total, used, free, shared, buffered, cached and swapped memory:
[root@centos ~]# free -m total used free shared buffers cached Mem: 1007 617 389 0 37 359 -/+ buffers/cache: 220 787 Swap: 1999 0 1999
In the above example, you can see:
- 1007 MB of total physical memory,
- 617 MB of used physical memory and 389MB of free physical memory,
- 1999 MB of swap space with 0MB being used.
The -/+ buffers/cache: line indicates that applications are using 220 MB and that they have 787 MB of free memory (37+359+389).
The command line switches of this command are:
[root@centos ~]# free -h free: invalid option -- 'h' usage: free [-b|-k|-m|-g] [-l] [-o] [-t] [-s delay] [-c count] [-V] -b,-k,-m,-g show output in bytes, KB, MB, or GB -l show detailed low and high memory statistics -o use old format (no -/+buffers/cache line) -t display total for RAM + swap -s update every [delay] seconds -c update [count] times -V display version information and exit
uptime or w
Each of these commands show the load average over the past 1, 5 and 15 minutes:
[root@centos ~]# uptime 17:19:49 up 2 min, 2 users, load average: 0.35, 0.21, 0.08 [root@centos ~]# w 17:19:51 up 2 min, 2 users, load average: 0.35, 0.21, 0.08 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT trainee tty1 :0 17:18 1:56 2.25s 0.14s pam: gdm-password trainee pts/0 :0.0 17:18 0.00s 0.16s 0.64s gnome-terminal
The load average indicates the number of processes being executed and waiting to be executed for the period concerned.
If the load average of a single-core system was 3.48 4.00 3.85 this would indicate a bottleneck since, on average:
- 2.48 processes would have been waiting to be executed over the last minute,
- 3.00 processes would have been waiting to be executed over the last 5 minutes,
- 2.85 processes would have been waiting to be executed over the last 15 minutes,
The command line switches of these commands are:
[root@centos ~]# uptime --help usage: uptime [-V] -V display version [root@centos ~]# w --help w : option invalide -- '-' usage: w -hlsufV [user] -h skip header -l long listing (default) -s short listing -u ignore uid of processes -f toggle FROM field (default on) -V display version
iostat
The iostat command show disk, terminal and streamer statistics:
[root@centos ~]# iostat Linux 2.6.32-358.23.2.el6.i686 (centos.fenestros.loc) 06/16/2014 _i686_ (1 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 9.04 0.00 17.92 31.19 0.00 41.85 Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn sda 87.65 4300.73 297.09 331500 22900
The command line switches of this command are:
[root@centos ~]# iostat --help Usage: iostat [ options ] [ <interval> [ <count> ] ] Options are: [ -c ] [ -d ] [ -N ] [ -n ] [ -h ] [ -k | -m ] [ -t ] [ -V ] [ -x ] [ -z ] [ <device> [...] | ALL ] [ -p [ <device> [,...] | ALL ] ]
vmstat
The vmstat commands shows memory, pagination and processor statistics:
[root@centos ~]# vmstat 1 10 procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 0 0 0 1601536 26936 139004 0 0 2102 59 254 585 4 7 77 12 0 0 0 0 1601528 26936 139028 0 0 0 0 95 183 0 0 100 0 0 0 0 0 1601528 26936 139028 0 0 0 0 70 138 0 0 100 0 0 0 0 0 1601528 26936 139028 0 0 0 0 94 173 0 1 99 0 0 0 0 0 1601536 26936 139028 0 0 0 0 82 171 0 0 100 0 0 0 0 0 1601536 26944 139036 0 0 0 36 98 183 0 1 99 0 0 0 0 0 1601536 26944 139036 0 0 0 0 78 144 0 0 100 0 0 0 0 0 1601528 26944 139036 0 0 0 0 92 174 0 0 100 0 0 0 0 0 1601272 26944 139040 0 0 0 0 89 144 1 1 98 0 0 0 0 0 1601272 26944 139040 0 0 0 0 123 212 1 1 98 0 0
The command line switches of this command are:
[root@centos ~]# vmstat --help usage: vmstat [-V] [-n] [delay [count]] -V prints version. -n causes the headers not to be reprinted regularly. -a print inactive/active page stats. -d prints disk statistics -D prints disk table -p prints disk partition statistics -s prints vm table -m prints slabinfo -t add timestamp to output -S unit size delay is the delay between updates in seconds. unit size k:1000 K:1024 m:1000000 M:1048576 (default is K) count is the number of updates.
By default vmstat shows statistics from boot until current time.
mpstat
The mpstat command shows detailed statistics concerning CPUs :
[root@centos ~]# mpstat Linux 2.6.32-358.23.2.el6.i686 (centos.fenestros.loc) 06/16/2014 _i686_ (1 CPU) 05:24:40 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle 05:24:40 PM all 2.31 0.00 3.76 6.70 0.19 0.03 0.00 0.00 87.01
If there are several CPU's in the system, statistics can be viewed by core and as an average:
[root@centos ~]# mpstat -P ALL Linux 2.6.32-358.23.2.el6.i686 (centos.fenestros.loc) 06/16/2014 _i686_ (1 CPU) 05:24:52 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle 05:24:52 PM all 2.26 0.00 3.67 6.52 0.19 0.03 0.00 0.00 87.34 05:24:52 PM 0 2.26 0.00 3.67 6.52 0.19 0.03 0.00 0.00 87.34
Finally, mpstat is capable of showing statistics over time. In the following example you can see 5 data sets, one taken every 2 seconds:
[root@centos ~]# mpstat -P ALL 2 5 Linux 2.6.32-358.23.2.el6.i686 (centos.fenestros.loc) 06/16/2014 _i686_ (1 CPU) 05:25:20 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle 05:25:22 PM all 0.51 0.00 0.51 0.00 0.00 0.00 0.00 0.00 98.99 05:25:22 PM 0 0.51 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.49 05:25:22 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle 05:25:24 PM all 0.51 0.00 0.51 0.00 0.00 0.00 0.00 0.00 98.99 05:25:24 PM 0 0.51 0.00 0.51 0.00 0.00 0.00 0.00 0.00 98.99 05:25:24 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle 05:25:26 PM all 1.01 0.00 0.51 0.00 0.00 0.00 0.00 0.00 98.48 05:25:26 PM 0 1.01 0.00 0.51 0.00 0.00 0.00 0.00 0.00 98.48 05:25:26 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle 05:25:28 PM all 0.51 0.00 0.51 0.00 0.00 0.00 0.00 0.00 98.99 05:25:28 PM 0 0.51 0.00 0.51 0.00 0.00 0.00 0.00 0.00 98.99 05:25:28 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle 05:25:30 PM all 0.51 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.49 05:25:30 PM 0 0.51 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.49 Average: CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle Average: all 0.61 0.00 0.40 0.00 0.00 0.00 0.00 0.00 98.99 Average: 0 0.61 0.00 0.30 0.00 0.00 0.00 0.00 0.00 99.09
The command line switches of this command are:
[root@centos ~]# mpstat --help Usage: mpstat [ options ] [ <interval> [ <count> ] ] Options are: [ -A ] [ -I { SUM | CPU | ALL } ] [ -u ] [ -P { <cpu> [,...] | ON | ALL } ] [ -V ]
sar
The sar command can survey all system resources dependant upon the switch that is used. Several important switches are:
Switch | Description |
---|---|
-u | CPU usage in % |
-q | Number of processes in the process queue |
-r | Memory usage |
-w | Swap usage |
-p | Pagination usage |
-b | Buffer usage |
-d | Disk usage |
The /usr/lib/sa/sadc command is used to collect data:
[root@centos ~]# ls /usr/lib/sa sa1 sa2 sadc
The /usr/lib/sa/sa1 script calls the /usr/lib/sa/sadc command and can use two switches:
Switch | Description |
---|---|
-t | Interval |
-n | Count |
The /usr/lib/sa/sa2 script also creates a log at /var/log/sa/sar<dd>, where <dd> is the day of the month.
Both of these scripts should ideally be called by cron or anacron.
To see how these scripts work, use the following command:
[root@centos ~]# /usr/lib/sa/sa1 5 5
Once the script has completed, use the following commands:
[root@centos ~]# sar Linux 2.6.32-358.23.2.el6.i686 (centos.fenestros.loc) 06/17/2014 _i686_ (1 CPU) 07:40:01 AM CPU %user %nice %system %iowait %steal %idle 07:50:02 AM all 0.22 0.00 0.24 0.09 0.00 99.45 07:52:51 AM all 0.26 0.00 0.30 0.33 0.00 99.11 07:52:56 AM all 0.20 0.00 0.40 0.20 0.00 99.19 07:53:01 AM all 0.00 0.00 0.40 0.20 0.00 99.39 07:53:06 AM all 0.20 0.00 0.20 0.00 0.00 99.60 07:53:11 AM all 0.00 0.00 0.40 0.00 0.00 99.60 Average: all 0.23 0.00 0.26 0.14 0.00 99.37 [root@centos ~]# sar -u 5 3 Linux 2.6.32-358.23.2.el6.i686 (centos.fenestros.loc) 06/17/2014 _i686_ (1 CPU) 07:54:16 AM CPU %user %nice %system %iowait %steal %idle 07:54:21 AM all 0.20 0.00 0.40 0.00 0.00 99.39 07:54:26 AM all 0.40 0.00 0.60 0.00 0.00 98.99 07:54:31 AM all 0.20 0.00 0.20 0.00 0.00 99.60 Average: all 0.27 0.00 0.40 0.00 0.00 99.33 [root@centos ~]# sar -r 5 3 Linux 2.6.32-358.23.2.el6.i686 (centos.fenestros.loc) 06/17/2014 _i686_ (1 CPU) 07:54:50 AM kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit 07:54:55 AM 1595940 319532 16.68 27428 140012 423960 10.57 07:55:00 AM 1595956 319516 16.68 27428 140012 423960 10.57 07:55:05 AM 1595940 319532 16.68 27428 140012 423960 10.57 Average: 1595945 319527 16.68 27428 140012 423960 10.57 [root@centos ~]# sar -w 5 3 Linux 2.6.32-358.23.2.el6.i686 (centos.fenestros.loc) 06/17/2014 _i686_ (1 CPU) 07:55:31 AM proc/s cswch/s 07:55:36 AM 0.00 198.38 07:55:41 AM 0.00 170.56 07:55:46 AM 0.00 211.74 Average: 0.00 193.54 [root@centos ~]# sar -b 5 3 Linux 2.6.32-358.23.2.el6.i686 (centos.fenestros.loc) 06/17/2014 _i686_ (1 CPU) 07:55:50 AM tps rtps wtps bread/s bwrtn/s 07:55:55 AM 0.20 0.00 0.20 0.00 1.61 07:56:00 AM 0.81 0.00 0.81 0.00 9.70 07:56:05 AM 0.00 0.00 0.00 0.00 0.00 Average: 0.34 0.00 0.34 0.00 3.77 [root@centos ~]# sar -d 5 3 Linux 2.6.32-358.23.2.el6.i686 (centos.fenestros.loc) 06/17/2014 _i686_ (1 CPU) 07:56:39 AM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util 07:56:44 AM dev8-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 07:56:44 AM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util 07:56:49 AM dev8-0 0.81 0.00 9.72 12.00 0.00 1.25 0.75 0.06 07:56:49 AM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util 07:56:54 AM dev8-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 Average: DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util Average: dev8-0 0.27 0.00 3.23 12.00 0.00 1.25 0.75 0.02 [root@centos ~]# sar -p 5 3 Linux 2.6.32-358.23.2.el6.i686 (centos.fenestros.loc) 06/17/2014 _i686_ (1 CPU) 07:57:12 AM CPU %user %nice %system %iowait %steal %idle 07:57:17 AM all 0.20 0.00 0.40 0.00 0.00 99.39 07:57:22 AM all 0.40 0.00 0.60 0.20 0.00 98.79 07:57:27 AM all 0.20 0.00 0.40 0.00 0.00 99.39 Average: all 0.27 0.00 0.47 0.07 0.00 99.19 [root@centos ~]# sar -v 5 3 Linux 2.6.32-358.23.2.el6.i686 (centos.fenestros.loc) 06/17/2014 _i686_ (1 CPU) 07:57:53 AM dentunusd file-nr inode-nr pty-nr 07:57:58 AM 8284 4352 13857 4 07:58:03 AM 8284 4352 13857 4 07:58:08 AM 8284 4352 13857 4 Average: 8284 4352 13857 4
The command line switches of this command are:
[root@centos ~]# sar --help Usage: sar [ options ] [ <interval> [ <count> ] ] Options are: [ -A ] [ -b ] [ -B ] [ -C ] [ -d ] [ -h ] [ -m ] [ -p ] [ -q ] [ -r ] [ -R ] [ -S ] [ -t ] [ -u [ ALL ] ] [ -v ] [ -V ] [ -w ] [ -W ] [ -y ] [ -I { <int> [,...] | SUM | ALL | XALL } ] [ -P { <cpu> [,...] | ALL } ] [ -n { <keyword> [,...] | ALL } ] [ -o [ <filename> ] | -f [ <filename> ] ] [ -i <interval> ] [ -s [ <hh:mm:ss> ] ] [ -e [ <hh:mm:ss> ] ]
Production Environements
Identifying a System with a CPU Bottleneck
The use of the following commands should clearly show CPU bottlenecks:
- uptime or w
- vmstat
- mpstat -P ALL
- sar -u
- iostat -c
Identifying a Memory Problem
The use of the following commands should clearly show memory problems:
- free
- sar -B
Identifying I/O Bottlenecks
The use of the following command should clearly show I/O bottlenecks:
- iostat -d -x
USB Modules
The Universal Serial Bus can offer data transfer speeds of upto 480Mb/s for version 2.0 and upto 4.8 Gb/s for version 3.0. Under Linux the USB modules are:
USB Version | Module | Name |
---|---|---|
1.0\1.1 | UHCI | Universal Controller Host Interface |
OHCI | Open Controller Host Interface | |
2.0 | EHCI | Enhanced Host Controller Interface |
3.0 | XHCI | Extensible Host Controller Interface |
The following table shows a list of commonly used USB modules:
Module | Peripheral |
---|---|
usb_storage | Block devices |
usbhid | Human Interface Device |
snd-usb-audio | Sound cards |
usbvidéo | Video acquisition cards |
irda-usb | IR peripherals |
usbnet | NICs |
These modules can be loaded by any one of the following:
- Initramfs,
- The init process,
- kmod by using the /lib/modules/2.6.32-358.23.2.el6.i686/modules.usbmap file,
- udev,
- manually.
<note> Insert a USB stick and configure VirtualBox to mount it in your VM. </note>
udev
The 2.6 Kernel series is capable of hotplugging. Linux uses three componants to manage hotplugging:
- Udev,
- HAL,
- Dbus.
The roles of each componant are as follows:
- Udev dynamically creates/deletes nodes in the /dev directory,
- HAL obtains information from udev, creates a files in XML format representing the peripheral and then informs Nautilus by using Dbus,
- Dbus acts as a system bus and is used for inter-process communication.
When Linux is booted, udev plays an important role:
- at boot tmpfs is mounted on /dev,
- udev copies any statically configured nodes from /lib/udev/devices to /dev,
- the udevd daemon collects uevents from the kernel and looks for anappropriate rule in the /lib/udev/rules.d/ directory,
- udev creates the nodes and any required symbolic links specified in the rule previously identified,
- udev stores in RAM the rules from /lib/udev/rules.d/*.rules,
- when a change occurs udev updates the the rules in the RAM.
udev uses the sysfs filesystem mounted on /sys which renders the peripherals visible to udev in user space. For example when a USB stick is inserted, udev creates /dev/sdb1 automatically:
[root@centos ~]# ls /dev | grep sdb sdb sdb1 [root@centos ~]# ls /dev/.udev/db | grep sdb block:sdb block:sdb1 [root@centos ~]# ls /sys/block/sdb alignment_offset capability device ext_range inflight queue removable sdb1 slaves subsystem uevent bdi dev discard_alignment holders power range ro size stat trace
and then uses the information found in the /lib/modules/`uname -r`/modules.alias file to find the appropriate driver:
[root@centos ~]# more /lib/modules/`uname -r`/modules.alias # Aliases extracted from modules themselves. alias acpi acpi_cpufreq alias char-major-10-184 microcode alias aes-asm aes_i586 alias aes aes_i586 alias twofish-asm twofish_i586 alias twofish twofish_i586 alias salsa20-asm salsa20_i586 alias salsa20 salsa20_i586 alias crc32c-intel crc32c_intel alias crc32c crc32c_intel alias nls_tis-620 nls_cp874 alias nls_sjis nls_cp932 alias nls_gb2312 nls_cp936 alias nls_euc-kr nls_cp949 alias nls_big5 nls_cp950 alias nls_iso8859-8 nls_cp1255 alias nfs-layouttype4-1 nfs_layout_nfsv41_files alias char-major-10-229 fuse alias devname:btrfs-control btrfs alias char-major-10-234 btrfs alias cipher_null crypto_null alias digest_null crypto_null alias compress_null crypto_null alias sha256 sha256_generic alias sha224 sha256_generic alias sha512 sha512_generic alias sha384 sha512_generic alias wp256 wp512 alias wp384 wp512 alias tgr128 tgr192 alias tgr160 tgr192 alias rfc3686 ctr --More--(0%)
The contents of the /dev/.udev/db/block:sdb1 file is:
[root@centos ~]# cat /dev/.udev/db/block:sdb1 N:sdb1 S:block/8:17 S:disk/by-id/usb-_USB_DISK_2.0_0710433A0D8D6A52-0:0-part1 S:disk/by-path/pci-0000:00:06.0-usb-0:1:1.0-scsi-0:0:0:0-part1 S:disk/by-uuid/2B1E-1434 S:disk/by-label/USB\x20DISK W:45 E:ID_VENDOR_ENC=\x20\x20\x20\x20\x20\x20\x20\x20 E:ID_VENDOR_ID=13fe E:ID_MODEL=USB_DISK_2.0 E:ID_MODEL_ENC=USB\x20DISK\x202.0\x20\x20\x20\x20 E:ID_MODEL_ID=4200 E:ID_REVISION=PMAP E:ID_SERIAL=_USB_DISK_2.0_0710433A0D8D6A52-0:0 E:ID_SERIAL_SHORT=0710433A0D8D6A52 E:ID_TYPE=disk E:ID_INSTANCE=0:0 E:ID_BUS=usb E:ID_USB_INTERFACES=:080650: E:ID_USB_INTERFACE_NUM=00 E:ID_USB_DRIVER=usb-storage E:ID_PATH=pci-0000:00:06.0-usb-0:1:1.0-scsi-0:0:0:0 E:ID_PART_TABLE_TYPE=dos E:ID_FS_LABEL=USB_DISK E:ID_FS_LABEL_ENC=USB\x20DISK E:ID_FS_UUID=2B1E-1434 E:ID_FS_UUID_ENC=2B1E-1434 E:ID_FS_VERSION=FAT32 E:ID_FS_TYPE=vfat E:ID_FS_USAGE=filesystem E:LVM_SBIN_PATH=/sbin E:UDISKS_PRESENTATION_NOPOLICY=0 E:UDISKS_PARTITION=1 E:UDISKS_PARTITION_SCHEME=mbr E:UDISKS_PARTITION_NUMBER=1 E:UDISKS_PARTITION_TYPE=0x0c E:UDISKS_PARTITION_SIZE=8011186176 E:UDISKS_PARTITION_SLAVE=/sys/devices/pci0000:00/0000:00:06.0/usb1/1-1/1-1:1.0/host3/target3:0:0/3:0:0:0/block/sdb E:UDISKS_PARTITION_OFFSET=4128768 E:UDISKS_PARTITION_ALIGNMENT_OFFSET=0
This is the content of /dev:
[root@centos ~]# ls -lR /dev/disk /dev/disk: total 0 drwxr-xr-x. 2 root root 240 Jun 17 08:49 by-id drwxr-xr-x. 2 root root 60 Jun 17 08:49 by-label drwxr-xr-x. 2 root root 180 Jun 17 08:49 by-path drwxr-xr-x. 2 root root 120 Jun 17 08:49 by-uuid /dev/disk/by-id: total 0 lrwxrwxrwx. 1 root root 9 Jun 16 17:17 ata-VBOX_HARDDISK_VBc95fcb92-63983501 -> ../../sda lrwxrwxrwx. 1 root root 10 Jun 16 17:18 ata-VBOX_HARDDISK_VBc95fcb92-63983501-part1 -> ../../sda1 lrwxrwxrwx. 1 root root 10 Jun 16 17:18 ata-VBOX_HARDDISK_VBc95fcb92-63983501-part2 -> ../../sda2 lrwxrwxrwx. 1 root root 10 Jun 16 17:17 ata-VBOX_HARDDISK_VBc95fcb92-63983501-part3 -> ../../sda3 lrwxrwxrwx. 1 root root 9 Jun 16 17:17 scsi-SATA_VBOX_HARDDISK_VBc95fcb92-63983501 -> ../../sda lrwxrwxrwx. 1 root root 10 Jun 16 17:18 scsi-SATA_VBOX_HARDDISK_VBc95fcb92-63983501-part1 -> ../../sda1 lrwxrwxrwx. 1 root root 10 Jun 16 17:18 scsi-SATA_VBOX_HARDDISK_VBc95fcb92-63983501-part2 -> ../../sda2 lrwxrwxrwx. 1 root root 10 Jun 16 17:17 scsi-SATA_VBOX_HARDDISK_VBc95fcb92-63983501-part3 -> ../../sda3 lrwxrwxrwx. 1 root root 9 Jun 17 08:49 usb-_USB_DISK_2.0_0710433A0D8D6A52-0:0 -> ../../sdb lrwxrwxrwx. 1 root root 10 Jun 17 08:49 usb-_USB_DISK_2.0_0710433A0D8D6A52-0:0-part1 -> ../../sdb1 /dev/disk/by-label: total 0 lrwxrwxrwx. 1 root root 10 Jun 17 08:49 USB\x20DISK -> ../../sdb1 /dev/disk/by-path: total 0 lrwxrwxrwx. 1 root root 9 Jun 16 17:17 pci-0000:00:01.1-scsi-1:0:0:0 -> ../../sr0 lrwxrwxrwx. 1 root root 9 Jun 17 08:49 pci-0000:00:06.0-usb-0:1:1.0-scsi-0:0:0:0 -> ../../sdb lrwxrwxrwx. 1 root root 10 Jun 17 08:49 pci-0000:00:06.0-usb-0:1:1.0-scsi-0:0:0:0-part1 -> ../../sdb1 lrwxrwxrwx. 1 root root 9 Jun 16 17:17 pci-0000:00:0d.0-scsi-0:0:0:0 -> ../../sda lrwxrwxrwx. 1 root root 10 Jun 16 17:18 pci-0000:00:0d.0-scsi-0:0:0:0-part1 -> ../../sda1 lrwxrwxrwx. 1 root root 10 Jun 16 17:18 pci-0000:00:0d.0-scsi-0:0:0:0-part2 -> ../../sda2 lrwxrwxrwx. 1 root root 10 Jun 16 17:17 pci-0000:00:0d.0-scsi-0:0:0:0-part3 -> ../../sda3 /dev/disk/by-uuid: total 0 lrwxrwxrwx. 1 root root 10 Jun 17 08:49 2B1E-1434 -> ../../sdb1 lrwxrwxrwx. 1 root root 10 Jun 16 17:17 a1d6a043-6f10-4f60-bb9c-aaaac9632c57 -> ../../sda3 lrwxrwxrwx. 1 root root 10 Jun 16 17:18 c7b1d3e8-6471-4cba-947b-430db974e774 -> ../../sda2 lrwxrwxrwx. 1 root root 10 Jun 16 17:18 d8988475-7dc7-4a61-8081-6153b7c9551b -> ../../sda1
The main configuration file for udev is /etc/udev/udev.conf:
[root@centos ~]# cat /etc/udev/udev.conf # The initial syslog(3) priority: "err", "info", "debug" or its # numerical equivalent. For runtime debugging, the daemons internal # state can be changed with: "udevadm control --log-priority=<value>". udev_log="err"
Rules files can be foud in /lib/udev/rules.d/ :
[root@centos ~]# ls /lib/udev/rules.d/ 10-console.rules 60-persistent-v4l.rules 75-cd-aliases-generator.rules 85-regulatory.rules 10-dm.rules 60-wacom.rules 75-net-description.rules 88-clock.rules 11-dm-lvm.rules 61-mobile-action.rules 75-persistent-net-generator.rules 89-microcode.rules 13-dm-disk.rules 61-option-modem-modeswitch.rules 75-tty-description.rules 90-pulseaudio.rules 40-isdn.rules 61-persistent-storage-edd.rules 77-mm-ericsson-mbm.rules 91-drm-modeset.rules 40-libgphoto2.rules 61-uinput-stddev.rules 77-mm-longcheer-port-types.rules 95-devkit-power-battery-recall-dell.rules 40-redhat.rules 61-uinput-wacom.rules 77-mm-pcmcia-device-blacklist.rules 95-devkit-power-battery-recall-fujitsu.rules 42-qemu-usb.rules 64-device-mapper.rules 77-mm-platform-serial-whitelist.rules 95-devkit-power-battery-recall-gateway.rules 50-firmware.rules 64-md-raid.rules 77-mm-simtech-port-types.rules 95-devkit-power-battery-recall-ibm.rules 50-udev-default.rules 65-libsane.rules 77-mm-usb-device-blacklist.rules 95-devkit-power-battery-recall-lenovo.rules 60-alias-kmsg.rules 65-libwacom.rules 77-mm-zte-port-types.rules 95-devkit-power-battery-recall-toshiba.rules 60-cdrom_id.rules 65-md-incremental.rules 77-nm-olpc-mesh.rules 95-devkit-power-csr.rules 60-net.rules 69-dm-lvm-metad.rules 78-sound-card.rules 95-devkit-power-hid.rules 60-persistent-alsa.rules 70-acl.rules 79-fstab_import.rules 95-devkit-power-wup.rules 60-persistent-input.rules 70-cups-libusb.rules 80-drivers.rules 95-dm-notify.rules 60-persistent-serial.rules 70-hid2hci.rules 80-iosched.rules 95-keyboard-force-release.rules 60-persistent-storage.rules 70-printers.rules 80-mpath-iosched.rules 95-keymap.rules 60-persistent-storage-tape.rules 71-biosdevname.rules 80-udisks.rules 95-udev-late.rules
<note important> You can create your own rules by putting them in the 99-local.rules file. </note>
The default udev rule file is 50-udev-default.rules:
[root@centos ~]# cat /lib/udev/rules.d/50-udev-default.rules # do not edit this file, it will be overwritten on update SUBSYSTEM=="block", SYMLINK{unique}+="block/%M:%m" SUBSYSTEM!="block", SYMLINK{unique}+="char/%M:%m" KERNEL=="pty[pqrstuvwxyzabcdef][0123456789abcdef]", GROUP="tty", MODE="0660" KERNEL=="tty[pqrstuvwxyzabcdef][0123456789abcdef]", GROUP="tty", MODE="0660" KERNEL=="ptmx", GROUP="tty", MODE="0666" KERNEL=="tty", GROUP="tty", MODE="0666" KERNEL=="tty[0-9]*", GROUP="tty", MODE="0620" KERNEL=="console", MODE="0600" KERNEL=="vcs|vcs[0-9]*|vcsa|vcsa[0-9]*", GROUP="tty" # serial KERNEL=="tty[A-Z]*[0-9]|pppox[0-9]*|ircomm[0-9]*|noz[0-9]*|rfcomm[0-9]*", GROUP="dialout" KERNEL=="ppp", MODE="0600" KERNEL=="mwave", GROUP="dialout" KERNEL=="hvc*|hvsi*", GROUP="dialout" # virtio serial / console ports KERNEL=="vport*", ATTR{name}=="?*", SYMLINK+="virtio-ports/$attr{name}" # mem KERNEL=="null|zero|full|random|urandom", MODE="0666" KERNEL=="mem|kmem|port|nvram", GROUP="kmem", MODE="0640" # input KERNEL=="mouse*|mice|event*", MODE="0640" KERNEL=="ts[0-9]*|uinput", MODE="0640" KERNEL=="js[0-9]*", MODE="0644" # video4linux SUBSYSTEM=="video4linux", GROUP="video" KERNEL=="vttuner*", GROUP="video" KERNEL=="vtx*|vbi*", GROUP="video" KERNEL=="winradio*", GROUP="video" # graphics KERNEL=="agpgart", MODE="0600", GROUP="video" KERNEL=="pmu", GROUP="video" KERNEL=="nvidia*|nvidiactl*", GROUP="video" SUBSYSTEM=="graphics", GROUP="video" SUBSYSTEM=="drm", GROUP="video" # sound SUBSYSTEM=="sound", GROUP="audio" KERNEL=="mixer0", SYMLINK+="mixer" # DVB (video) SUBSYSTEM=="dvb", GROUP="video" # FireWire (firewire-core driver: IIDC devices, AV/C devices) SUBSYSTEM=="firewire", ATTR{units}=="*0x00a02d:0x00010*", GROUP="video" SUBSYSTEM=="firewire", ATTR{units}=="*0x00a02d:0x010001*", GROUP="video" # FireWire (deprecated dv1394 and video1394 drivers) KERNEL=="dv1394-[0-9]*", NAME="dv1394/%n", GROUP="video" KERNEL=="video1394-[0-9]*", NAME="video1394/%n", GROUP="video" # libusb device nodes SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", MODE="0664" # printer KERNEL=="parport[0-9]*", GROUP="lp" SUBSYSTEM=="printer", KERNEL=="lp*", GROUP="lp" SUBSYSTEM=="ppdev", GROUP="lp" SUBSYSTEM=="usb", KERNEL=="lp*", SYMLINK+="usb%k", GROUP="lp" KERNEL=="lp[0-9]*", GROUP="lp" KERNEL=="irlpt[0-9]*", GROUP="lp" # hplip and cups 1.4+ use raw USB devices, so permissions should be similar to # the ones from the old usblp kernel module SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}=="", IMPORT{program}="usb_id --export %p" SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}==":0701*:", GROUP="lp", MODE="0664" # block SUBSYSTEM=="block", GROUP="disk" # floppy KERNEL=="fd[0-9]", GROUP="floppy" KERNEL=="fd[0-9]", ACTION=="add", ATTRS{cmos}=="?*", RUN+="create_floppy_devices -c -t $attr{cmos} -m %M -M 0640 -G floppy $root/%k" KERNEL=="hd*", SUBSYSTEMS=="ide", ATTRS{media}=="floppy", OPTIONS+="all_partitions" # cdrom SUBSYSTEM=="block", KERNEL=="sr[0-9]*", SYMLINK+="scd%n", GROUP="cdrom" SUBSYSTEM=="block", KERNEL=="hd*", SUBSYSTEMS=="ide", ATTRS{media}=="cdrom", GROUP="cdrom" SUBSYSTEM=="scsi_generic", SUBSYSTEMS=="scsi", ATTRS{type}=="4|5", GROUP="cdrom" KERNEL=="pktcdvd[0-9]*", GROUP="cdrom" KERNEL=="pktcdvd", GROUP="cdrom" # tape KERNEL=="ht[0-9]*|nht[0-9]*", GROUP="tape" KERNEL=="pt[0-9]*|npt[0-9]*|pht[0-9]*", GROUP="tape" SUBSYSTEM=="scsi_generic|scsi_tape", SUBSYSTEMS=="scsi", ATTRS{type}=="1|8", GROUP="tape" # block-related KERNEL=="sch[0-9]*", GROUP="disk" SUBSYSTEM=="scsi_generic", SUBSYSTEMS=="scsi", ATTRS{type}=="0", GROUP="disk" KERNEL=="pg[0-9]*", GROUP="disk" KERNEL=="qft[0-9]*|nqft[0-9]*|zqft[0-9]*|nzqft[0-9]*|rawqft[0-9]*|nrawqft[0-9]*", GROUP="disk" KERNEL=="rawctl", GROUP="disk" SUBSYSTEM=="raw", KERNEL=="raw[0-9]*", GROUP="disk" SUBSYSTEM=="aoe", GROUP="disk", MODE="0220" SUBSYSTEM=="aoe", KERNEL=="err", MODE="0440" # network KERNEL=="tun", MODE="0666" KERNEL=="rfkill", MODE="0644" # CPU KERNEL=="cpu[0-9]*", MODE="0444" # miscellaneous KERNEL=="fuse", MODE="0666" SUBSYSTEM=="rtc", DRIVERS=="rtc_cmos", SYMLINK+="rtc" KERNEL=="mmtimer", MODE="0644" KERNEL=="rflash[0-9]*", MODE="0400" KERNEL=="rrom[0-9]*", MODE="0400" # do not delete static device nodes ACTION=="remove", NAME=="", TEST=="/lib/udev/devices/%k", OPTIONS+="ignore_remove" ACTION=="remove", NAME=="?*", TEST=="/lib/udev/devices/$name", OPTIONS+="ignore_remove"
Each rule has the following format:
KEY, [KEY, …] NAME [, SYMLINK]
The Key is a type=value pair which uniquely identifies a peripheral. The type can be one of the following:
Type | Description | Examples |
---|---|---|
BUS | Bus type | usb, scsi, ide |
KERNEL | The default name given to the peripheral by the kernel | hda, ttyUSB0, lp0 |
SUBSYSTEM | The default sub-system name given by the Kernel, generally identical to the BUS value | usb, scsi |
DRIVER | The name of the module used by the peripheral | usb-storage |
ID | The position of the peripheral on its bus | PCI bus id, USB id |
PLACE | The topological position of a USB oeripheral on its bus. | S/O |
SYSFS{filename} | The name of the peripheral file in /sys. This file contains the manufacturer's name, the label, the serial number and the UUID of the peripheral. Each rule can contains upto five references to files. | S/O |
PROGRAM | An eventual external program to be called in order to identify the peripheral | S/O |
RESULT | Value expected from PROGRAM | S/O |
NAME and SYMLINK are used to tell udev what to do with the peripheral:
Type | Description |
---|---|
NAME | The name of the peripheral in /dev |
SYMLINK | The eventual symbolic links that point to NAME |
The udevadm Command
To obtain information from udev on a particular peripheral, you can use the udevadm command which has replaced the udevinfo command available in Red Hat/CentOS 5:
[root@centos ~]# udevadm info --query=all -n /dev/sda P: /devices/pci0000:00/0000:00:0d.0/host2/target2:0:0/2:0:0:0/block/sda N: sda W: 38 S: block/8:0 S: disk/by-id/ata-VBOX_HARDDISK_VBc95fcb92-63983501 S: disk/by-id/scsi-SATA_VBOX_HARDDISK_VBc95fcb92-63983501 S: disk/by-path/pci-0000:00:0d.0-scsi-0:0:0:0 E: UDEV_LOG=3 E: DEVPATH=/devices/pci0000:00/0000:00:0d.0/host2/target2:0:0/2:0:0:0/block/sda E: MAJOR=8 E: MINOR=0 E: DEVNAME=/dev/sda E: DEVTYPE=disk E: SUBSYSTEM=block E: ID_ATA=1 E: ID_TYPE=disk E: ID_BUS=ata E: ID_MODEL=VBOX_HARDDISK E: ID_MODEL_ENC=VBOX\x20HARDDISK\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20 E: ID_REVISION=1.0 E: ID_SERIAL=VBOX_HARDDISK_VBc95fcb92-63983501 E: ID_SERIAL_SHORT=VBc95fcb92-63983501 E: ID_ATA_WRITE_CACHE=1 E: ID_ATA_WRITE_CACHE_ENABLED=1 E: ID_ATA_FEATURE_SET_PM=1 E: ID_ATA_FEATURE_SET_PM_ENABLED=1 E: ID_ATA_SATA=1 E: ID_ATA_SATA_SIGNAL_RATE_GEN2=1 E: ID_SCSI_COMPAT=SATA_VBOX_HARDDISK_VBc95fcb92-63983501 E: ID_PATH=pci-0000:00:0d.0-scsi-0:0:0:0 E: ID_PART_TABLE_TYPE=dos E: LVM_SBIN_PATH=/sbin E: UDISKS_PRESENTATION_NOPOLICY=0 E: UDISKS_PARTITION_TABLE=1 E: UDISKS_PARTITION_TABLE_SCHEME=mbr E: UDISKS_PARTITION_TABLE_COUNT=3 E: UDISKS_ATA_SMART_IS_AVAILABLE=0 E: DEVLINKS=/dev/block/8:0 /dev/disk/by-id/ata-VBOX_HARDDISK_VBc95fcb92-63983501 /dev/disk/by-id/scsi-SATA_VBOX_HARDDISK_VBc95fcb92-63983501 /dev/disk/by-path/pci-0000:00:0d.0-scsi-0:0:0:0
This caommand can also be used to obtain all information known to sys concerning specific peripheral:
[root@centos ~]# udevadm info -a -p /sys/class/input/mouse0/ Udevadm info starts with the device specified by the devpath and then walks up the chain of parent devices. It prints for every device found, all possible attributes in the udev rules key format. A rule to match, can be composed by the attributes of the device and the attributes from one single parent device. looking at device '/devices/virtual/input/input2/mouse0': KERNEL=="mouse0" SUBSYSTEM=="input" DRIVER=="" looking at parent device '/devices/virtual/input/input2': KERNELS=="input2" SUBSYSTEMS=="input" DRIVERS=="" ATTRS{name}=="Macintosh mouse button emulation" ATTRS{phys}=="" ATTRS{uniq}=="" ATTRS{modalias}=="input:b0017v0001p0001e0100-e0,1,2,k110,111,112,r0,1,amlsfw"
The command line switches of this command are:
[root@centos ~]# udevadm --help Usage: udevadm [--help] [--version] [--debug] COMMAND [COMMAND OPTIONS] info query sysfs or the udev database trigger request events from the kernel settle wait for the event queue to finish control control the udev daemon monitor listen to kernel and udev events test simulation run [root@centos ~]# udevadm info --help Usage: udevadm info OPTIONS --query=<type> query device information: name name of device node symlink pointing to node path sys device path property the device properties all all values --path=<syspath> sys device path used for query or attribute walk --name=<name> node or symlink name used for query or attribute walk --root prepend dev directory to path names --attribute-walk print all key matches while walking along the chain of parent devices --device-id-of-file=<file> print major:minor of device containing this file --export-db export the content of the udev database --help
The /sys Filesystem
The virtual filesystem /sys was introduced with the 2.6 Kernel. Its role is to identify and describe peripherals for udev:
[root@centos ~]# ls -l /sys total 0 drwxr-xr-x. 2 root root 0 Jun 17 08:49 block drwxr-xr-x. 17 root root 0 Jun 16 17:17 bus drwxr-xr-x. 40 root root 0 Jun 16 17:17 class drwxr-xr-x. 4 root root 0 Jun 16 17:17 dev drwxr-xr-x. 12 root root 0 Jun 16 17:17 devices drwxr-xr-x. 4 root root 0 Jun 16 17:17 firmware drwxr-xr-x. 4 root root 0 Jun 16 17:18 fs drwxr-xr-x. 2 root root 0 Jun 16 17:18 hypervisor drwxr-xr-x. 5 root root 0 Jun 16 17:17 kernel drwxr-xr-x. 102 root root 0 Jun 17 08:49 module drwxr-xr-x. 2 root root 0 Jun 16 17:18 power
Each directory contains specific information:
- block
- information concerning block devices
- bus
- information concerning buses
- class
- information concerning classes
- devices
- information concerning the posiion of devices on their bus
- firmware
- information concerning APCI
- module
- information concerning kernel modules
- power
- information concerning power management
- fs
- information concerning file systems
For example:
[root@centos ~]# cat /sys/block/sda/sda1/size 204800
The figure returned is in sectors.
Limiting Resources
Resources available to users can be limited by using the ulimit command.
The ulimit command manages two limits:
- a hard hard limit by specifying the -H switch,
- a soft soft limit by specifying the -S switch,
<note important> Only root can position a hard limit and only if the limit does not exceed real resource levels. </note>
The soft limit is the limit imposed on the user whilst the hard limit is the limit that a user can obtain once he has gone over the soft limit.
Root can define limits by editing the /etc/security/limits.conf file:
[root@centos ~]# cat /etc/security/limits.conf # /etc/security/limits.conf # #Each line describes a limit for a user in the form: # #<domain> <type> <item> <value> # #Where: #<domain> can be: # - an user name # - a group name, with @group syntax # - the wildcard *, for default entry # - the wildcard %, can be also used with %group syntax, # for maxlogin limit # #<type> can have the two values: # - "soft" for enforcing the soft limits # - "hard" for enforcing hard limits # #<item> can be one of the following: # - core - limits the core file size (KB) # - data - max data size (KB) # - fsize - maximum filesize (KB) # - memlock - max locked-in-memory address space (KB) # - nofile - max number of open files # - rss - max resident set size (KB) # - stack - max stack size (KB) # - cpu - max CPU time (MIN) # - nproc - max number of processes # - as - address space limit (KB) # - maxlogins - max number of logins for this user # - maxsyslogins - max number of logins on the system # - priority - the priority to run user process with # - locks - max number of file locks the user can hold # - sigpending - max number of pending signals # - msgqueue - max memory used by POSIX message queues (bytes) # - nice - max nice priority allowed to raise to values: [-20, 19] # - rtprio - max realtime priority # #<domain> <type> <item> <value> # #* soft core 0 #* hard rss 10000 #@student hard nproc 20 #@faculty soft nproc 20 #@faculty hard nproc 50 #ftp hard nproc 0 #@student - maxlogins 4 # End of file
<note important> The limit can be a number or the word unlimited. </note>
For example if root adds the two following lines to /etc/security/limits.conf:
... trainee soft nofile 1024 trainee hard nofile 4096 ...
the number of open files for trainee is limited to 1024. However trainee can increase this limit to 4 096 by using the following command:
$ ulimit -n 4096
To see the list of the current limits use the -a switch:
[root@centos ~]# ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 14843 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 10240 cpu time (seconds, -t) unlimited max user processes (-u) 14843 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
The command line switches of this command are:
[root@centos ~]# help ulimit ulimit: ulimit [-SHacdefilmnpqrstuvx] [limit] Modify shell resource limits. Provides control over the resources available to the shell and processes it creates, on systems that allow such control. Options: -S use the `soft' resource limit -H use the `hard' resource limit -a all current limits are reported -b the socket buffer size -c the maximum size of core files created -d the maximum size of a process's data segment -e the maximum scheduling priority (`nice') -f the maximum size of files written by the shell and its children -i the maximum number of pending signals -l the maximum size a process may lock into memory -m the maximum resident set size -n the maximum number of open file descriptors -p the pipe buffer size -q the maximum number of bytes in POSIX message queues -r the maximum real-time scheduling priority -s the maximum stack size -t the maximum amount of cpu time in seconds -u the maximum number of user processes -v the size of virtual memory -x the maximum number of file locks If LIMIT is given, it is the new value of the specified resource; the special LIMIT values `soft', `hard', and `unlimited' stand for the current soft limit, the current hard limit, and no limit, respectively. Otherwise, the current value of the specified resource is printed. If no option is given, then -f is assumed. Values are in 1024-byte increments, except for -t, which is in seconds, -p, which is in increments of 512 bytes, and -u, which is an unscaled number of processes. Exit Status: Returns success unless an invalid option is supplied or an error occurs.
~~DISCUSSION:off~~
<html> <center> Copyright © 2011-2014 Hugh Norris.<br><br> <a rel=“license” href=“http://creativecommons.org/licenses/by-nc-nd/3.0/”><img alt=“Creative Commons License” style=“border-width:0” src=“https://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png” /></a><br />This work is licensed under a <a rel=“license” href=“http://creativecommons.org/licenses/by-nc-nd/3.0/”>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a> </center> </html>