≡ Menu

memory information

This is an user contributed article.

When it is time to upgrade the memory on a Linux host, it is important to understand the existing memory information of the system, which will help to plan the memory upgrade appropriately without opening server chassis (especially, when you have Linux rack mount server).

What is the current total RAM used in the system?

This can be obtained using free command or from the /proc/meminfo file as shown below. In this example, the current RAM is 1GB.
# free
Sample output:

             total       used       free     shared    buffers     cached
Mem:       2074016    2002592      71424          0     480908     937296
-/+ buffers/cache:     584388    1489628
Swap:      1951888      79116    1872772

You can also display memory ram, info using /proc file, enteR:
# grep MemTotal /proc/meminfo
Sample output:

MemTotal:      1034624 kB

What is the maximum RAM supported by the system?

You can use dmidecode command to query all memory related information from the system DMI table. In this example, the maximum RAM supported by the system is 8 GB as shown below.

# dmidecode -t 16
Sample output:

# dmidecode 2.9
SMBIOS 2.3 present.
Handle 0x1000, DMI type 16, 15 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: Multi-bit ECC
Maximum Capacity: 8 GB
Error Information Handle: Not Provided
Number Of Devices: 4

How many memory slots are available for expansion?

# dmidecode -t 17 | grep Size
Sample output:

        Size: 512 MB
        Size: 512 MB
        Size: No Module Installed
        Size: No Module Installed

References:

dmidecode can also be used to identify details about several other hardware related information. dmidecode command reads the systems DMI table for the hardware and BIOS information. DMI stands for Desktop Management interface and SMBIOS stands for System Management BIOS.

Distributed Management Task Force maintains the DMI and SMBIOS specification:

biosdecode is a command line utility to parses the BIOS memory and prints information about all structures (or entry points) it knows of. You can find out more information about your hardware such as:
=> IPMI Device
=> Type of memory and speed
=> Chassis Information
=> Temperature Probe
=> Cooling Device
=> Electrical Current Probe
=> Processor and Memory Information
=> Serial numbers
=> BIOS version
=> PCI / PCIe Slots and Speed
=> Much more

biosdecode parses the BIOS memory and prints the following information about all structures :
=> SMBIOS (System Management BIOS)
=> DMI (Desktop Management Interface, a legacy version of SMBIOS)
=> SYSID
=> PNP (Plug and Play)
=> ACPI (Advanced Configuration and Power Interface)
=> BIOS32 (BIOS32 Service Directory)
=> PIR (PCI IRQ Routing)
=> 32OS (BIOS32 Extension, Compaq-specific)
=> VPD (Vital Product Data, IBM-specific)
=> FJKEYINF (Application Panel, Fujitsu-specific)

In this tip you will learn about decoding BIOS data (dumping a computer's DMI ) and getting all information about computer hardware without rebooting the server.
[click to continue…]

If you are developing an application for Linux desktop and would like to automatically find out more information about system, use the following commands in shell scripts to gather information about system. Recently I was involved in project where I need to collect information about running GUI, browser and other information such as disk space, running kernel etc.

Find out KDE Desktop version:

konqueror --version

Find out Gnome Desktop version:

gnome-panel --version

Find out Mozilla browser version:

mozilla --version

Find out Firefox browser version:

firefox --version

Find out current Language:

set | egrep '^(LANG|LC_)'

Find out disk space usage:

df -h

Find/Estimate file space usage:

du -h

Find out version of Linux glibc:

ls -l /lib/libc-*.so /lib/libc.so*

Find out user limits:

ulimit -a

Find out installed device drivers (modules)

lsmod

Find out information about an X server:

xdpyinfo

It can find out:

  • Name of display:
  • Version number
  • Vendor name (such as The XFree86 Project)
  • Vendor release number
  • And XFree86 version number

Find out information about Linux CPU

cat /proc/cpuinfo

Find out information about Linux Memory

cat /proc/meminfo

OR

free -m

OR

free -g

Find out user shell name:

ps -p $$ | tail -1 | awk '{ print $4 }'

Dump Linux kernel variables

/sbin/sysctl -a

Find out running Linux kernel version:

uname -mrs
uname -a
cat /proc/version

Dump or display memory information and swap information:

free -m

Network card and IP address information:

ifconfig -a
ifconfig -a|less

Debian / Ubuntu Linux network configuration file (all interface eth0,eth1,...ethN)

more /etc/network/interfaces

Redhat / CentOS / Fedora Linux network configuration file (eth0)

more  /etc/sysconfig/network-scripts/ifcfg-eth0

Note replace eth1 for 2nd network card and so on.

Display routing information

route -n
route

Display list of all open ports

netstat -tulpn

View login related logs

tail -f /var/log/secure
vi /var/log/secure
grep 'something' /var/log/secure

View mail server related logs

tail -f /var/log/maillog
vi /var/log/maillog
grep 'something' /var/log/maillog

Find how long the system has been running

uname
w

Show who is logged on and what they are doing

w
who

Display list of tasks

top

Display all running process

ps aux
ps aux | grep process-name

Display list of all installed software on Redhat / CentOS / Fedora

rpm -qa
rpm -qa | grep 'software-name'
rpm -qa | less

Display list of all installed software on Debian / Ubuntu

dpkg --list

Once information collected it can be easily send as an email to help desk. You can use all above command to gathers information about a remote Linux system over secure ssh session (see related functions that gathers up information about a Linux and FreeBSD system). Best part is all above commands runs in non privileged mode.

Running Commands on a Remote Linux / UNIX Host

You would like to execute a command on a remote Linux/FreeBSD/Solaris/UNIX host and have the result displayed locally. Once result obtained it can be used by local script or program. A few examples:
=> File system and disk information

=> Get user information

=> Find out all running process

=> Find out if particular service is running or not etc

You can use rsh or ssh for this purpose. However, for security reason you should always use the ssh and NOT rsh. Please note that remote system must run the OpenSSH server.

Syntax for running command on a remote host:
ssh [USER-NAME]@[REMOTE-HOST] [command or script]

Where,

  • ssh: ssh (SSH client) is a program for logging into a remote machine and for executing commands on a remote machine.
  • USER-NAME: Remote host user name.
  • REMOTE-HOST: Remote host ip-address or host name, such as fbsd.cyberciti.biz.
  • command or script: Command or shell script is executed on the remote host instead of a login shell.

Examples

(A) Get disk information from a server called www1.cyberciti.biz:
$ ssh vivek@www1.cyberciti.biz df -h

(B) List what ports are open on remote host
$ ssh vivek@www1.cyberciti.biz netstat -vatn

(C) Reboot remote host:
$ ssh root@www1.cyberciti.biz reboot

(D) Restart mysql server (please note enclosed multiple command line arguments using a single or double quotes)
$ ssh root@www1.cyberciti.biz '/etc/init.d/mysql restart'

(E) Get memory information and store result/output to local file /tmp/memory.status:
$ ssh vivek@www1.cyberciti.biz 'free -m' > /tmp/memory.status

(G) You can also run multiple command or use the pipes, following command displays memory in format of "available memory = used + free memory" :
$ ssh vivek@debian.test.com free -m | grep "Mem:" | awk '{ print "Total memory (used+free): " $3 " + " $4 " = " $2 }'

See how to configure ssh for password less login using public key based authentication.

=> Related: shell script to get uptime, disk usage, cpu usage, RAM usage,system load,etc. from multiple Linux servers and output the information on a single server in a html format.

FreeBSD comes with different utilities, which can be use to gathered the information as per your needs. uname command is use to print system information. dmesg command is use to print kernel ring buffer information. sysctl command is use to configure kernel parameters at runtime as well as to read hardware information.

Following list summaries, all the command you need to gather FreeBSD hardware information.

1) Determining the Hardware Type/platform:
# uname -m
2) Determining machine processor architecture:
# uname -p
3) Determining FreeBSD release level:
# uname -r
Generally, following command is use to get all info at a time:
# uname -mrs
Output:

FreeBSD 5.0-RELEASE i386

4) Determining CPU information such as speed, make etc
# dmesg | grep CPU
Output:

CPU: Pentium 4 (1716.41-MHz 686-class CPU)
acpi_cpu0:  on acpi0
acpi_cpu: CPU throttling enabled, 8 steps from 100% to 12.5%

5) Determining real and available memory to FreeBSD:
# dmesg | grep memory
Output:

real memory  = 201326592 (192 MB)
avail memory = 188555264 (179 MB) 

Alternatively, try following command to grab memory information:
# sysctl -a | grep hw.*mem
# sysctl -a | grep mem

Output:

hw.physmem: 194985984
hw.usermem: 167641088
hw.cbb.start_memory: 2281701376

Note systcl has more info, just type the sysctl command to see rest of all information:
# sysctl -a | less
6) Determining how long a system has been up:
# uptime
7) Determining when a system was last rebooted or shutdown:
# last -1 reboot
# last -1 shutdown

8) Determining swap file system usage
# swapinfo -k
9) Determining who is logged in and what they are doing. Following all commands can be used. users command displays the list of all logged in users only.
# w
# who
# users

10) Find out when user was last logged in - You can use last command as follows:
# last user-name
(a) To find out user vivek was last logged, enter:
# last vivek

See FreeBSD getsysinfo.bash script. It is use to find general FreeBSD system information such as, hostname, OS version, Kernel version, Processor/CPU, Total RAM, System load, network interface, total logged in users, Hard disks, Runlevel etc. Make sure your read the detailed installation instruction.