October 2, 2008

Discover Linux System Resources

You’ve just inherited a Linux machine and you need to know how many CPUs it has, what speed they go at, how many memory slots there are and what’s in them, not to mention finding out what video card is installed so you can install a closed-source driver from the card manufacturer, but you don’t want to shut down everything and open the case. What can you do? Linux provides a few very useful utilities to discover exactly what’s inside the box.

lspci

This command lists all of the devices attached to the system’s PCI bus. Use it to discover what video card is installed, for example. It has several verbosity levels - see the man page. lspci is provided by the package pciutils.i386.

$ /sbin/lspci
00:00.0 Host bridge: Broadcom CMIC-LE Host Bridge (GC-LE chipset) (rev 33)
00:00.1 Host bridge: Broadcom CMIC-LE Host Bridge (GC-LE chipset)
00:00.2 Host bridge: Broadcom CMIC-LE Host Bridge (GC-LE chipset)
00:03.0 VGA compatible controller: ATI Technologies Inc Rage XL (rev 27)
00:04.0 System peripheral: Compaq Computer Corporation Integrated Lights Out Controller (rev 01)
00:04.2 System peripheral: Compaq Computer Corporation Integrated Lights Out Processor (rev 01)

dmidecode

Use dmidecode to find out exactly what what memory is installed in your computer, which banks it’s in, how many banks you have and the speed and type of that memory. dmidecode is pretty verbose by default, so pipe its output through less. You need to be root (or have sudo privileges) to run dmidecode. You can also use dmidecode to enumerate all of the CPUs in your system, even if one or more are disabled. dmidecode is provided by the package kernel-utils.i386.

$ sudo /usr/sbin/dmidecode | less

Handle 0x1100
DMI type 17, 23 bytes.
Memory Device
Array Handle: 0x1000
Error Information Handle: Not Provided
Total Width: 72 bits
Data Width: 64 bits
Size: 1024 MB
Form Factor: DIMM
Set: 1
Locator: DIMM 01
Bank Locator: Not Specified
Type: DDR
Type Detail: Synchronous
Speed: 266 MHz (3.8 ns)

/proc/cpuinfo

To find out exactly what CPUs are currently enabled and what speed they’re running at, take a look at the contents of the proc filesystem file /proc/cpuinfo. Note the rated speed (model name) and the actual speed (cpu MHz) at which it’s running. /proc/cpuinfo is installed as part of the kernel. There are other useful virtual files under proc which can be explored.

$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 15
model : 2
model name : Intel(R) Xeon(TM) CPU 2.80GHz
stepping : 9
cpu MHz : 2792.114
cache size : 512 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe cid xtpr
bogomips : 5585.80

lshal

/usr/bin/lshal is a very useful command which provides information about every device visible to the Hardware Abstraction Layer, which on most Linuxes is every bit of hardware in your system. Use this to find exact details of Ethernet cards, hard disks, DVD-ROM drives… The utility is provided as part of the package hal.i386. Here’s a snippet which shows my exact motherboard make and model:

$  /usr/bin/lshal | head -52

Dumping 123 device(s) from the Global Device List:
————————————————-
udi = ‘/org/freedesktop/Hal/devices/computer’
  info.addons = {‘hald-addon-cpufreq’, ‘hald-addon-acpi’} (string list)
  info.bus = ‘unknown’  (string)
  info.callouts.add = {‘hal-acl-tool –remove-all’, ‘hal-storage-cleanup-all-mountpoints’} (string list)
  info.callouts.session_active = {‘hal-acl-tool –reconfigure’} (string list)
  info.callouts.session_add = {‘hal-acl-tool –reconfigure’} (string list)
  info.callouts.session_inactive = {‘hal-acl-tool –reconfigure’} (string list)
  info.callouts.session_remove = {‘hal-acl-tool –reconfigure’} (string list)
  info.interfaces = {‘org.freedesktop.Hal.Device.SystemPowerManagement’} (string list)
  info.product = ‘Computer’  (string)
  info.subsystem = ‘unknown’  (string)
  info.udi = ‘/org/freedesktop/Hal/devices/computer’  (string)
  org.freedesktop.Hal.Device.SystemPowerManagement.method_argnames = {‘num_seconds_to_sleep’, ‘num_seconds_to_sleep’, ’‘,’‘,’‘, ’enable_power_save’} (string list)
  org.freedesktop.Hal.Device.SystemPowerManagement.method_execpaths = {‘hal-system-power-suspend’, ‘hal-system-power-suspend-hybrid’, ‘hal-system-power-hibernate’, ‘hal-system-power-shutdown’, ‘hal-system-power-reboot’, ‘hal-system-power-set-power-save’} (string list)
  org.freedesktop.Hal.Device.SystemPowerManagement.method_names = {‘Suspend’, ‘SuspendHybrid’, ‘Hibernate’, ‘Shutdown’, ‘Reboot’, ‘SetPowerSave’} (string list)
  org.freedesktop.Hal.Device.SystemPowerManagement.method_signatures = {‘i’, ‘i’, ’‘,’‘,’‘, ’b’} (string list)
  power_management.acpi.linux.version = ‘20070126’  (string)
  power_management.can_hibernate = true  (bool)
  power_management.can_suspend = true  (bool)
  power_management.can_suspend_hybrid = false  (bool)
  power_management.can_suspend_to_disk = true  (bool)
  power_management.can_suspend_to_ram = true  (bool)
  power_management.is_powersave_set = false  (bool)
  power_management.type = ‘acpi’  (string)
  smbios.bios.release_date = ‘03/22/2008’  (string)
  smbios.bios.vendor = ‘Dell Inc.’  (string)
  smbios.bios.version = ‘A02’  (string)
  smbios.chassis.manufacturer = ‘Dell Inc.’  (string)
  smbios.chassis.type = ‘Tower’  (string)
  smbios.system.manufacturer = ‘Dell Inc.’  (string)
  smbios.system.product = ‘Precision WorkStation T5400’  (string)
  smbios.system.serial = ‘BBXFP3J’  (string)
  smbios.system.uuid = ‘44454C4C-4200-1058-8046-C2C04F50334A’  (string)
  system.chassis.manufacturer = ‘Dell Inc.’  (string)
  system.chassis.type = ‘Tower’  (string)
  system.firmware.release_date = ‘03/22/2008’  (string)
  system.firmware.vendor = ‘Dell Inc.’  (string)
  system.firmware.version = ‘A02’  (string)
  system.formfactor = ‘desktop’  (string)
  system.hardware.primary_video.product = 1039  (0x40f)  (int)
  system.hardware.primary_video.vendor = 4318  (0x10de)  (int)
  system.hardware.product = ‘Precision WorkStation T5400’  (string)
  system.hardware.serial = ‘BBXFP3J’  (string)
  system.hardware.uuid = ‘44454C4C-4200-1058-8046-C2C04F50334A’  (string)
  system.hardware.vendor = ‘Dell Inc.’  (string)
  system.kernel.machine = ‘x86_64’  (string)
  system.kernel.name = ‘Linux’  (string)
  system.kernel.version = ‘2.6.25.14-69.fc8’  (string)

hdparm

Use hdparm to discover a wealth of information about installed disks. You need root access or sudo privileges to run the command, and it’s pretty verbose. hdparm worn’t work for devices connected to a SMART array (a type of disk controller) (Use smartctl if hdparm returns the error HDIO_GET_MULTCOUNT failed: Inappropriate ioctl for device)

$ sudo /sbin/hdparm -I /dev/sda

/dev/sda:

ATA device, with non-removable media
        Model Number:       Hitachi HDP725050GLA360                
        Serial Number:      GEA550RE27DYHL
        Firmware Revision:  GM4OA5BA
        Transport:          Serial, ATA8-AST, SATA 1.0a, SATA II Extensions, SATA Rev 2.5; Revision: ATA8-AST T13 Project D1697 Revision 0b
Standards:
        Supported: 8 7 6 5
        Likely used: 8
Configuration:
        Logical         max     current
        cylinders       16383   16383
        heads           16      16
        sectors/track   63      63
        –
        CHS current addressable sectors:   16514064
        LBA    user addressable sectors:  268435455
        LBA48  user addressable sectors:  976773168
        device size with M = 10241024:      476940 MBytes
        device size with M = 1000
1000:      500107 MBytes (500 GB)

dumpe2fs

This invaluable command is one of the only ways to discover your disk’s block size - essential for being able to figure out what vmstat’s blocks per second” counter is trying to tell you.

$ sudo dumpe2fs /dev/sda1 | grep -i “block size”

dumpe2fs 1.39 (29-May-2006)
Block size:               1024

The answer tells you how many bytes in a block.

smarctl

Essential for finding out about connected SCSI devices. Right now I’m not using any boxes that use a SMART array controller. Take a look at the smartmontools article on the Gentoo wiki.


Previous post
Welcome and Contact This blog is about Linux, testing and tech. I hope you find the solution to your problem here. I’ve worked as a QA Engineer in a variety of software
Next post
Using Oracle Import and Export This is a description on how to use Oracle’s and utilities to move tables between databases. It transfers the data over the network, which avoids