mail

How to get information on your system ?

Hardware

Hardware detection utilities :

One-liner to get CPU and RAM from a list of servers via SSH :

serverList='server1 server2'; sshLogin='bob'; for server in $serverList; do echo "$server"; ssh "$sshLogin@$server" 'echo -en "Physical CPU\t: "; grep physical\ id /proc/cpuinfo | sort -u | wc -l; echo -en "CPU Cores\t: "; grep -c ^processor /proc/cpuinfo; echo -en "CPU Model\t: "; grep model\ name /proc/cpuinfo | sort -u; echo -en "RAM\t\t: "; grep 'MemTotal:' /proc/meminfo'; echo; done

Notice the use of \ to grep expressions containing a space character. This is to avoid using quotes, which are numerous here, nested, and getting complex

Motherboard

  • Model reference : dmidecode -t baseboard | grep "Base Board Information" -A13
  • SATA capabilities (bandwidth of SATA versions, I:1.5Gb/s, II:3Gb/s, III:6Gb/s) : dmesg | grep -i sata

CPU

  • lscpu
  • less /proc/cpuinfo (Differentiate multi-core / multi-socket / hyperthreading CPUs)
  • dmidecode -t processor (requires root privileges)
  • Number of physical processors : grep 'physical id' /proc/cpuinfo | sort -u | wc -l
  • Number of cores :
    • grep -Ec '^processor' /proc/cpuinfo
    • top + 1
    • nproc
  • Whether the processor is a 32/64 bits :
    • method 1 : arch
    • method 2 : This command checks whether the kernel is 32 or 64 bit (source) : getconf LONG_BIT
      • 64 / ia64 / x86_64 : 64-bit mode
      • 32 / i386 : 32-bit mode
    • method 3 : perl -e 'print ~123;'; echo
      • 4294967172 : 32 bits
      • 18446744073709551492 : 64 bits

RAM

  • less /proc/meminfo
  • Total installed RAM :
  • the shell command free
  • dmidecode -t memory (requires root privileges)

video card / GPU (source) :

    1. lspci | grep VGA
      00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter
    2. lspci -v -s 00:02.0
      00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter (prog-if 00 [VGA controller])
      	Flags: fast devsel, IRQ 18
      	Memory at e0000000 (32-bit, prefetchable) [size=128M]
      	[virtual] Expansion ROM at 000c0000 [disabled] [size=128K]
      	Kernel driver in use: vboxvideo
      	Kernel modules: vboxvideo

HDD and storage devices

  • List storage (aka block) devices : lsblk
  • Manufacturer, model number, S/N, firmware and A LOT more :
    • hdparm -I /dev/sdb
      For details on all installed drives : for letter in {a..z}; do device="/dev/sd$letter"; [ -b "$device" ] && hdparm -I "$device" | head -8; done
    • smartctl -a /dev/sdb (this comes with smartmontools, more from Wikipedia, more from Ubuntu documentation)
  • List available partitions :
    • fdisk -l
    • or less /proc/partitions
    • or mount | grep sd
    • or grep sd /etc/mtab
  • Get device / filesystem metadata (type, last mount point, status, FS creation/last mount/last write/last check/next check, mount count, ...)
  • Get partitions size, usage, available space : df -h
  • Get device / partition size :
    • fdisk -l | grep -E '^Disk /'
    • Using the /sys pseudo filesystem :
      in sectors in GiB (1 sector = 512 B)
      • cat /sys/block/sda/size
      • cat /sys/block/sda/sda1/size
      • echo "$(cat /sys/block/sda/size)*512/1024/1024/1024" | bc
      • echo "$(cat /sys/block/sda/sda1/size)*512/1024/1024/1024" | bc
  • Total storage :

    Both methods give slightly different numbers. I guess this is because the df method sums formatted sizes whereas the /sys method gets device size.

  • Sector size :

SATA drives speed (source) :

As root :

for disk in $(find /dev -type b -name '*sd?' | sort); do echo $disk; hdparm -I "$disk" | grep -i speed; for i in {1..3}; do hdparm -tT "$disk"; done; done

Remarks :

  • find will list /dev/sd* drives. Not all of them are SATA drives : they can be USB drives, hence no speed parameter
  • The hdparm -tT test is run several times to get meaningful values
  • To do the same for IDE drive, let find search for /dev/hd*

SWAP usage in MB

free -m | awk '/Swap/ {print $3}'

LAN

mii-tool (comes from net-tools) : (as root) show the media-independent interface status :
  • mii-tool
  • mii-tool -v
  • mii-tool eth0

PCI devices

  • less /proc/pci (when available)
  • lspci lists all detected PCI devices (in a tree-like diagram with -tv : tree + verbose) :
    ...
    00:18.4 Host bridge: Advanced Micro Devices [AMD] Family 10h Processor Link Control
    01:00.0 VGA compatible controller: ATI Technologies Inc Juniper [Radeon HD 5700 Series]
    01:00.1 Audio device: ATI Technologies Inc Juniper HDMI Audio [Radeon HD 5700 Series]
    ...
    For more details on device (source) : lspci -v -s 01:00.0
    01:00.0 VGA compatible controller: ATI Technologies Inc Juniper [Radeon HD 5700 Series] (prog-if 00 [VGA controller])
    Subsystem: PC Partner Limited Device 1482
    Flags: bus master, fast devsel, latency 0, IRQ 27
    Memory at d0000000 (64-bit, prefetchable) [size=256M]
  • scanpci -vO (-v : verbose, -O : use the OS's specific mechanism to get information. details). The PCI bus 0x1 is the AGP port.

USB devices

lsusb lists all detected USB devices (in a tree-like diagram with -tv : tree + verbose)

Monitor (inspired by)

grep -E '(Monitor name|EDID vendor)' /var/log/Xorg.0.log | awk '{ $1=$2=$3=""; printf $0; print "" }' | uniq
	RADEON(0): Monitor name: PL1980
	RADEON(0): EDID vendor "IVM", prod id 18500
  • the awk + uniq commands are there to limit the number of displayed fields and avoid showing the same information twice since I actually have 2 identical monitors
  • the PL1980 monitor name refers to the ProLite B1980SD iiyama product and is mentioned on the product label : iiyama monitor product label
  • the Internets will list plenty of tools to get that information. I've tried only the simplest of them all (grep —not wanting to install an extra tool anyway ) and I've been lucky to get some data. Depending on :
    • the monitor manufacturer
    • the connection type (VGA, DVI, HDMI, ...)
    you may get more data.

Software

Kernel

  • all about the kernel (name, release, version, ...) : uname -a
    Linux hostname 4.18.0-0.bpo.1-amd64 #1 SMP Debian 4.18.6-1~bpo9+1 (2018-09-13) x86_64 GNU/Linux
    or : less /proc/version
    Linux version 4.18.0-0.bpo.1-amd64 (debian-kernel@lists.debian.org) (gcc version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1)) #1 SMP Debian 4.18.6-1~bpo9+1 (2018-09-13)
  • kernel release : uname -r
    4.18.0-0.bpo.1-amd64
  • kernel version : uname -v
    #1 SMP Debian 4.18.6-1~bpo9+1 (2018-09-13)
Install the kernel headers :

apt install linux-headers-$(uname -r)

Operating system

On Debianoids :
cat /etc/debian_version outputs 7.8
On Red Hatoids :
cat /etc/redhat-release outputs Red Hat Enterprise Linux Server release 6.2 (Santiago)
Common :
  • hostnamectl
     Static hostname: myPC
           Icon name: computer-laptop
    	 Chassis: laptop
          Machine ID: 9a2d7d69f5e741219fab104d8935fc41
    	 Boot ID: fd51500fbcef4dc1c431907d377ace13
    Operating System: Debian GNU/Linux 9 (stretch)
    	  Kernel: Linux 4.9.0-4-amd64
        Architecture: x86-64
  • cat /etc/os-release
    PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
    NAME="Debian GNU/Linux"
    VERSION_ID="9"
    VERSION="9 (stretch)"
    ID=debian
    HOME_URL="https://www.debian.org/"
    SUPPORT_URL="https://www.debian.org/support"
    BUG_REPORT_URL="https://bugs.debian.org/"
  • all of Linux Standard Base information : lsb_release -a
    Distributor ID:	Debian
    Description:	Debian GNU/Linux 7.8 (wheezy)
    Release:	7.8
    Codename:	wheezy
    Distributor ID:	RedHatEnterpriseServer
    Description:	Red Hat Enterprise Linux Server release 6.2 (Santiago)
    Release:	6.2
    Codename:	Santiago
    Consider the command flags to get single field information, in either long/short format ( for details)
  • cat /proc/version outputs :
    Linux version 2.6.32-042stab108.8 (root@kbuild-rh6-x64.eng.sw.ru) (gcc version 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC) ) #1 SMP Wed Jul 22 17:23:23 MSK 2015
  • cat /etc/issue outputs :
    Debian GNU/Linux 7 \n \l
    This can be customized and may not be up-to-date.

Operating system installation date (source)

  • as root : tune2fs -l $(mount | awk '/ \/ / {print $1}') | grep 'Filesystem created:'
    This hack assumes the operating system was installed the same day the / filesystem was created, which is true unless you've added a new disk, created a new / filesystem and moved files around.
  • on Debianoids : ll /var/log/installer/syslog
    This file (if still there) was created during install. This method is still approximate.
  • Find the oldest file in /etc :
    ls -lact --full-time /etc | tail
    Other commands (such as ls -lt /etc | tail) may return even older files, but this ignores ctime.
    On old Unices (AIX), try (source) :
    ls -l /var/adm/ras/bosinstlog

List daemons / services

Current shell

Environment variables

Files

  • get the file type : file myFile
  • information on file times : stat myFile
  • information (type, dimension, colors) of image files : identify myFile

Miscellaneous

  • Investigate (cat / more / less) the /proc/ directory
  • dmesg | less displays the kernel messages.
  • Read logs :
    • /var/log/messages
    • /var/log/boot.log
    To read logs in real time : tail -f /var/log/messages
  • List the loaded kernel modules (details) : lsmod
mail

Install and configure WiFi

Identify which controller you're using :

lspci | egrep -i "(lan|network|ethernet|wireless)"

Using a Broadcom BCM4306 (rev 03) controller

  1. By typing dmesg, you may notice a message such as b43-phy0 ERROR : Firmware file "B43/ucode5.fw" not found or load failed. This means the WiFi controller firmware is missing.
  2. So let's install it : apt install b43-fwcutter (source). The installer will ask whether to unpack it all : accept.
  3. unload and reload the kernel module : rmmod b43 && modprobe b43
  4. NB : the LEDs of the PCMCIA WiFi controller should light up once the module is loaded.

Using an Intel Pro Wireless 2200 B/G with WPA (source : see III-B)

  1. The 1st thing you'll need is the Intel firmware ipw2200-bss.fw (alternate source). This firmware is required during the system setup.
  2. Some packages to install :
    • wireless-tools
    • wpasupplicant
  3. Let's encrypt our WPA passphrase : wpa_passphrase mySsid myClearPassphrase, which outputs :
    network={
    ssid="mySsid"
    #psk="myClearPassphrase"
    psk=600792632e29fc6c69f04e82d1290a28bf1bffff58294ca6ddaf48062c36f311
    }
  4. Then, let's save this into /etc/network/interfaces
    • static version :
      # Static configuration
      auto wlan0
      iface wlan0 inet static
      address 192.168.0.2
      netmask 255.255.255.0
      network 192.168.1.0
      broadcast 192.168.1.255
      gateway 192.168.0.1
      wpa-conf managed
      wpa-ap-scan 1
      wpa-scan-ssid 1
      wpa-ssid mySsid
      wpa-key-mgmt WPA-PSK
      wpa-psk 600792632e29fc6c69f04e82d1290a28bf1bffff58294ca6ddaf48062c36f311
    • DHCP version :
      # DHCP configuration
      auto wlan0
      iface wlan0 inet dhcp
      wpa-conf managed
      wpa-ap-scan 1
      wpa-scan-ssid 1
      wpa-ssid mySsid
      wpa-key-mgmt WPA-PSK
      wpa-psk 600792632e29fc6c69f04e82d1290a28bf1bffff58294ca6ddaf48062c36f311
  5. Then, restart the network to load changes : /etc/init.d/networking restart

    In some circumstances, it may be required to allow broadcasting the SSID so that the wireless host can discover it. Once the wireless host has been registered to the access point, SSID broadcasting can be turned off.

    This may also be related to MAC addresses filtering : while SSID broadcasting was off, my own wireless network was invisible to scanning.

Using an Intel PRO/Wireless 3945ABG [Golan] with WEP :

  1. To "see" the system complain, run /etc/init.d/network-manager restart && dmesg. You may notice an output like :
    [109694.622325] firmware: requesting iwlwifi-3945-1.ucode
    [109694.631281] iwl3945: iwlwifi-3945-1.ucode firmware file req failed: Reason -2
    [109694.631281] iwl3945: Could not read microcode: -2
    We need the firmware file iwlwifi-3945-1.ucode.
  2. Let's get it from intellinuxwireless.org (alternate source)
  3. copy it into /lib/firmware/
  4. edit /etc/network/interfaces :
    auto wlan0
    iface wlan0 inet dhcp
    	wireless-essid myEssid
    	wireless-key myWepKey
  5. enable the interface with ifup wlan0

Tip to get the full data rate (Ubuntu 9.04 + Ralink RT2500)

  1. normal setup is done with : iwconfig wlan0 essid mySsid freq 2447000000 ap accessPointMacAddress rate 54M
  2. then, as root : iwconfig wlan0 rate 54M
  3. ... and it should work ! (source)

When dmesg complains : phy0 -> rt2500pci_set_device_state: Error - Device failed to enter state 1 (-16) (source)

Run (as root) : iwconfig wlan0 power off

Notes

Wireless interfaces are not listed by ifconfig when they are down. Use iwconfig instead.
mail

Swap management and swappiness

Facts and definitions :

Linux has a parameter called swappiness which determines how much the kernel is likely to swap out runtime memory rather than dropping pages from the system cache (more details). It defaults to 60.

There's a popular belief saying that the swappiness is the RAM usage threshold beyond which some of the contents of the RAM is moved to the SWAP partition. Based on the 60 default value, it's said that, if the free RAM goes below 60%, the SWAP will be used.

This is sooo WRONG !!!

Myths about Swap (source) :

  1. Swap space does not inherently slow down your system. In fact, not having swap space doesn't mean you won't swap pages. It merely means that Linux has fewer choices about what RAM can be reused when a demand hits. Thus, it is possible for the throughput of a system that has no swap space to be lower than that of a system that has some.
  2. Swap space is used for modified anonymous pages only. Your programs, shared libraries and filesystem cache are never written there under any circumstances.
  3. Given items 1 and 2 above, the philosophy of "minimization of swap space" is really just a concern about wasted disk space.

For more details and definitions :

Change the threshold temporarily :

echo 10 > /proc/sys/vm/swappiness

This command will work fine (it will cause no error, no silenced warning will be generated) but it's mostly pointless unless PERFECTLY understanding how the swap works. Again, changing the swappiness value has NOTHING to do with any amount of used RAM after which swapping starts. Read links above.

Make a permanent change :

Add into /etc/sysctl.conf :
vm.swappiness=10
Then reboot (or sysctl -p) to apply changes.

Performance indicators (source) :

Am I swapping ?
  • Superb : no swap space even has been allocated (free shows 0 swap in use), and RAM usage is low. Unless you benefit from a huge filesystem cache, you may have spent too much on RAM. Run more stuff.
  • Great : swap space is allocated, but there is almost no I/O on the swap partition.
  • OK : swap space is allocated, and there is some I/O on the swap partition. System throughput is still OK. For example, the CPUs are busy, and most of that is in the User or Nice categories. If you see CPU Wait, it indicates a disk bottleneck (possibly on swapping), and system time could mean the OS is frantically looking for memory to reuse (page scanning).
  • Not OK (too much swapping) : lots of I/O on the swap partition. CPU is spending a lot of time in Sys or Wait, and swap disk service times exceed the average disk access times.
  • Not OK (too little swap space) : system is running very well, but new programs refuse to start due to lack of virtual memory.

Report swap usage per process (source) :

  • separator=','; for file in /proc/*/status; do grep -q 'VmSwap' $file && awk -v separator="$separator" '/Name/ {printf $2""separator} /VmSwap/ {print $2""separator""$3}' $file; done | sort -t "$separator" -k 2 -nr | head -20 | column -s "$separator" -t
  • for file in /proc/*/status; do awk '/VmSwap|Name/ { printf $2 " " $3 } END { print "" }' $file; done | sort -k 2 -nr | head -20
It is also possible to view swap usage per process with top.
mail

How to setup a ramdisk ?

The good news is : you don't have to, since most distributions create one for you. It used to be available at /dev/shm (shared memory) but /run/shm should be used instead since Wheezy (source).

On Debianoids, /run/shm actually symlinks to /dev/shm.

Find yours : df -h /run/shm
Filesystem	Size	Used	Avail	Use%	Mounted on
tmpfs		2.0G	12K	2.0G	1%	/dev/shm
This space can be used for temporary data.

More on tmpfs (Debian documentation, Wikipedia, kernel.org) :

  • tmpfs volumes can be read/written like any other filesystem type, but they are on volatile memory instead of a persistent storage device : their contents is not reboot-proof.
  • The memory used by tmpfs grows and shrinks to accommodate the files it contains and can be swapped out to swap space. By default, swapping is triggered by data on the tmpfs volume using more than half of the physical RAM.
  • Depending on distributions, /tmp itself can be a tmpfs volume

Usage

Create a custom ramdisk (source) :

mount -t tmpfs -o size=512M tmpfs /mount/point

Create a custom ramdisk at boot time :

Add into /etc/fstab :
none	/mount/point	tmpfs	defaults,size=512M	0	0
To save a reboot and apply settings NOW! : mount -o remount /mount/point

Change ramdisk size :

mount -o remount,size=8G /dev/shm
mail

How to disable the annoying PC speaker beep ?

Quick solution (not reboot-proof) :

As root : rmmod pcspkr

Definitive solution : Kernel Module Blacklisting (sources : 1 (for Debian Etch), 2) :

As root :
  1. echo blacklist pcspkr > /etc/modprobe.d/pcspkr.conf
  2. depmod -a
  3. update-initramfs -u
  4. reboot

Answers indicating to create a /etc/modprobe.d/blacklist.conf (or /etc/modprobe.d/blacklist) file containing blacklist pcspkr have no effect : naming modules there does not affect autoloading of modules by the kernel.

mail

Fiddling with the MBR

With Linux, there is no "brute force" way to reinitialize the MBR like the MS-DOS fdisk /mbr. However, it is possible to save/restore it with dd.

Some preliminary details on the Master Boot Record (source) :

On hard disks (and many other mass storage media), the boot sector is called the Master Boot Record. It consists of 512 bytes at the first sector of the hard disk. It is important to note that it is not located inside any partition. The Master Boot Record precedes the first partition. Its layout is as follows :
  • First 446 bytes contain bootable code.
  • Next 64 bytes contain partition information for 4 partitions (16×4). That is why the hard disks can have only 4 primary partitions, as the MBR can store information for 4 partitions only. So if you need more than 4 partitions on the hard disk, one of the primary partition has to be made extended, and out of this extended partition, logical partitions are created.
  • Last 2 bytes are for MBR signature, also called magic number.
Thus total of 446 + 64 + 2 = 512 bytes :
|=================|======|======|======|======|===|
| 446             | 16   | 16   | 16   | 16   | 2 |
|=================|======|======|======|======|===|
The first 446 bytes of MBR contain the code that locates the partition to boot from. The rest of booting process takes place from that partition. This partition contains a software program for booting the system called the bootloader.

Now let's play with dd :

Save the MBR :
dd if=/dev/sda of=/path/to/file bs=446 count=1
Save the MBR + partition table :
dd if=/dev/sda of=/path/to/file bs=512 count=1
Restore one of those :
dd if=/path/to/file of=/dev/sda bs=446|512 count=1
mail

How to monitor the CPU temperature ?

  1. apt install lm-sensors
  2. load the i2c-dev kernel module : modprobe i2c-dev
  3. then detect sensors and configure the tool :
    sensors-detect
    To load everything that is needed, add this to /etc/modules:
    #----cut here----
    # Chip drivers
    w83627hf
    #----cut here----
  4. Then, once the chip kernel module is loaded, you can read sensor information : sensors
  5. To monitor CPU temperature easily in a terminal : watch -n 10 -d "sensors | grep 'Core'"
mail

How to set the CPU frequency ?

  1. install the required packages : cpufrequtils, sysfsutils (is the latter useful ?)
  2. identify your CPU : grep model /proc/cpuinfo
  3. you can also get its current frequency : cpufreq-info
  4. now you need a kernel module to manage the frequency scaling :
    CPU family kernel module
    Pentium 4, Celeron D, Pentium D, Celeron M p4_clockmod
    Pentium M, Core Duo, Core 2 Duo speedstep_centrino
    AMD K6 powernow_k6
    AMD K7 (Athlon, Duron, Sempron 32) powernow_k7
    AMD K8 (Athlon 64, Turion 64, Sempron 64, Opteron 64) powernow_k8
    None of above acpi_cpufreq (with NO warranty that it works, whatsoever!)
    To list all available modules :
    • ls -l /lib/modules/$(uname -r)/kernel/arch/x86/kernel/cpu/cpufreq/
    • ls -l /lib/modules/$(uname -r)/kernel/arch/i386/kernel/cpu/cpufreq/ ("i386" | "x86" in the path)
  5. load the chosen module : modprobe p4_clockmod
  6. now it's time to setup the policy governor (governors are listed in /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors) :
    governor usage module
    performance sets the frequency statically to the highest possible value within the configured MIN/MAX range cpufreq_performance
    powersave sets the frequency statically to the lowest possible value within the configured MIN/MAX range cpufreq_powersave
    userspace allows the users (or any application running as "root") to set the CPU frequency
    ondemand adjusts the CPU speed dynamically, depending on the usage cpufreq_ondemand
    conservative similar to ondemand, adjusts the frequency dynamically. It differs in behavior in that it gracefully increases and decreases the CPU speed rather than jumping to max speed upon CPU load. This is more suitable in a battery powered environment. cpufreq_conservative
  7. load the chosen module : modprobe cpufreq_powersave
  8. now, find the range of supported frequencies by your CPU :
    • min/max values only : cpufreq-info -l
    • list of all supported values : cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
      3200000 2500000 2100000 800000
  9. edit /etc/init.d/cpufrequtils and set values for GOVERNOR, MAX_SPEED and MIN_SPEED :
    ENABLE="true"
    GOVERNOR="ondemand"
    MAX_SPEED="1000000"
    MIN_SPEED="800000"
    The CPU frequency can be chosen only from the values listed above. Using another value for MAX_SPEED will cause no error, but the CPU won't be able to go faster than the nearest smaller accepted value.
  10. restart cpufrequtils : /etc/init.d/cpufrequtils restart
  11. make sure it works :
    • min max governor : cpufreq-info -p
    • verbose : cpufreq-info
    • cpufreq-info | grep "fréquence actuelle"
  12. load the CPU and governor modules at startup :
    1. echo p4_clockmod >> /etc/modules
    2. echo cpufreq_powersave >> /etc/modules
  13. [for fun] load you CPU at 100% : while [ 1 -eq 1 ]; do echo 1>/dev/null; done
  14. Enjoy !