We're technologically informed, and we would love to take you along.

Tuesday, 1 September 2015

Collecting Ubuntu Linux System Information

For new computer or Laptop or server, I need to collect the information about its hardware. This is also useful when you need to replace a disk or memory with a vendor. In order to replace hardware you need all information in advance. In this post, I'm going to list commands that you can use to collect the hardware information.






All of the following commands are tested on Ubuntu Linux LTS 14.04, but should work with any modern distro too such as Debian or Fedora Linux.

Find the system host name

Display the system's host name:
$ hostname
$ cat /etc/hostname
server1

Display the system's DNS domain name:
$ dnsdomainname
cyberciti.biz

Display the system's Fully Qualified Domain Name (FAQN):
$ hostname -f
server1.cyberciti.biz

Find the system serial number, manufacturer of the system and model name

$ sudo dmidecode -s system-serial-number
$ sudo dmidecode -s system-manufacturer
$ sudo dmidecode -s system-product-name
$ sudo dmidecode | more

OR use the lshw command:
# lshw | more
$ sudo lshw -short

Display information about installed hardware

$ sudo lsdev

Find the system CPU info

$ cat /proc/cpuinfo
OR
$ lscpu

Display CPU (processors) related statistics

$ sudo mpstat
$ sudo mpstat 1
$ sudo mpstat -A

Find the system main memory (RAM) info

Show statistics about memory usage on the system including total installed and used RAM:
$ less /proc/meminfo
Show amount of free and used memory in the system:
free
## Display the amount of memory in megabytes ##
free -m
 
## Display the amount of memory in gigabytes ##
free -g
 
## Display the amount of memory in terabytes ##
free --tera
 
## Display human readable output ##
free -h

Show the system swap space usage

$ swapon -s
$ cat /proc/swaps
$ cat /proc/meminfo
$ top
$ vmstat
$ for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less
$ smem

Show the system virtual memory statistics

$ sudo vmstat
$ sudo vmstat 1
$ sudo vmstat 2

Find the Ubuntu Linux distribution version and related information

$ lsb_release -a

Find the system kernel version number

$ uname -r
OR
$ uname -a

Find the system kernel parameters

$ cat /proc/cmdline
$ sysctl -a | more

Find the system kernel architecture (32 bit or 64 bit)

$ uname -m
$ getconf LONG_BIT
$ arch

Find the system disk information

Show all installed disks and size:
# fdisk -l | grep '^Disk /dev'

List all partitions of /dev/sda disk:

To read a disk label for /dev/sda:
# fdisk -l /dev/sda
To label a disk:
$ sudo fdisk /dev/sda
$ sudo e2label /dev/sda1
$ sudo cfdisk /dev/sda

Show block device attributes:

# blkid

List all block devices:

# lsblk

Display file system disk space usage:

$ df
$ df -H
$ df -HT

Estimate file space usage:

$ du
$ du /home

Display mounted file system:

$ cat /proc/mount
$ mount

Display SCSI devices (or hosts) and their attributes on Linux:

$ lsscsi

Display I/O statistics

$ sudo iostat
$ sudo iostat 2

Find the system PCI devices information

$ lspci
$ lspci -vt
$ lspci | grep -i 'something'
$ lspci -vvvn| less

Find the system USB devices information

$ lsusb
$ lsusb -vt

Find the system Wireless devices information

$ iwconfig
$ watch -n 1 cat /proc/net/wireless
$ wavemon

Find the system VGA/Graphics devices information

$ lspci | grep -i vga
$ lspci -vvnn | grep VGA

OR
$ sudo lshw -class display

Find the system NVIDIA Graphics devices information

The following commands only works with Nvidia's binary Linux driver:
$ nvidia-smi
OR
$ nvidia-settings

Find the system AMD/ATI Graphics devices information

The following command only works with AMD's binary Linux driver called catalyst:
$ fglrxinfo

Which version of Unity am I running?

$ unity --version

Find the system audio devices information

$ lspci | grep -i audio
OR
$ cat /proc/asound/cards
OR
$ arecord -l

Display the system/laptop battery status & thermal temperature

$ upower -i /org/freedesktop/UPower/devices/battery_BAT0
$ acpi -V

Find out how long the system has been running

$ uptime
$ who
$ w

Find the system load

$ uptime
$ cat /proc/loadavg
$ sudo top
$ sudo htop
$ sudo atop

Show the system reboot and shutdown history

$ last reboot
$ last shutdown

Show runlevel

$ runlevel
$ who -r

Display kernel ring buffer (boot time) messages

Use the following command to see boot time message including hardware configuration
$ sudo less /var/log/dmesg
$ sudo grep 'regx' /var/log/dmesg
$ sudo grep '[h|s]d' /var/log/dmesg

Display the system drivers (modules)

$ sudo lsmod
$ sudo modinfo {driver_name}
$ sudo modinfo kvm

Find the system IP address and related information

You need to use the ip command:
## Info about all interfaces. Must be run as root via sudo command ##
sudo ip a
sudo ip
sudo ip link ls up
sudo ifconfig -a
 
## Only show eth1 interface info ##
sudo ip a show eth0
sudo ifconfig eth0

Display the system routing table

## You can use any one of the following command ##
## Must be run as root ##
sudo ip r
sudo route -n
sudo netstat -nr
 

Display the system ethernet bridge

$ sudo brctl show
$ sudo bridge link

Display the system DNS server and related information

Display the system name server IP address (ISP or your dns server IP should be listed here):
# cat /etc/resolv.conf
Display the system resolver configuration file. This is useful to find out how host lookups are to be performed:
# cat /etc/host.conf
Use above two files to configure name resolution.

Display information about the system ports and socket

## Must run as root via sudo ##
sudo ss
## Display all listing ports ##
sudo ss -l
sudo netstat -tulpn
sudo netstat -tulpn | grep LISTEN
 
## Display all TCP sockets
sudo ss -t -a
 
## Display all UDP sockets.
sudo ss -u -a
 
## List all open files
lsof | more
lsof | grep something
lsof /dev/sda2
lsof /path/to/file
 

Display the list of running services

### SYS V ###
$ sudo service --status-all

OR
## UPSTART ##
$ sudo initctl list

Find out if service is enabled:

## UPSTART ##
$ sudo initctl status service-name
$ sudo initctl status smbd

OR
## SYS V
$ sudo service serviceName status
$ sudo service nginx status

View log files

$ cd /var/log
$ ls -l
$ tail -f /var/log/fileName
$ grep 'something' /var/log/fileNameHere

Find file by name

$ locate fileName
$ locate htpasswd
$ locate passwd
$ locate my.resume.doc

Find file by given condition

$ find {/dir/to/search} -name {file-to-search} -print
$ find /etc/ -name /etc/passwd -print
$ find $HOME -name '*.doc' -print

View user account details

$ less /etc/passwd
$ grep userName /etc/passwd
$ getent passwd

View group account details

$ less /etc/group
$ getent group
$ grep group-name /etc/group
$ groups userName

View password policy

$ chage -l userName
$ chage -l root
$ chage -l vivek

View system usage

$ sudo top
$ sudo htop
$ sudo atop
$ sudo ps auxwww
$ sudo netstat [options]
$ sudo iostat
$ sudo mpstat 1
$ sudo sar [options]

Trace system call

$ strace -o output.txt /bin/foo
$ strace -p 22254 -s 80 -o debug.nginx.txt

Trace library call

$ sudo ltrace /usr/sbin/httpd
$ sudo ltrace /sbin/chroot /usr/sbin/httpd

View process info

$ sudo pstree
$ sudo pstree | less
$ sudo ps auxwwwm
$ ps alxwww
$ ps auxwww
$ lsof -b M -n -l

Change process priority

$ sudo /bin/nice -n -1 command-name-here
$ sudo /bin/nice -n -1 pid
$ sudo renice {priority} pid

View process's CPU affinity

$ sudo taskset -p {pid-here}
$ sudo taskset -p 42

Display the system listing of all package installed

$ dpkg -l
$ dpkg -l | less
$ dpkg -l nginx

Display the system listing of all patches installed

$ sudo apt-show-versions -a | grep -i "security"

Display the list of needed runtime libraries to run file

$ ldd file

Find what package a file belongs to

$ dpkg -S /path/to/file
$ dpkg -S /bin/ls

Create a backup list of all installed software

$ sudo dpkg --get-selections > /root/installed.pkgs.txt
Want to restore it again?
$ sudo dpkg --set-selections < /root/installed.pkgs.txt

Display the system firewall configuration

$ sudo iptables -L -n -v
$ sudo ufw status numbered
$ sudo ufw status verbose
$ sudo ufw app list

Do not forget to read man pages featured in this post:
$ man dpkg
$ man htop
$ man ...

Finally, make a backup - it cannot be stressed enough how important it is to make a backup of your system. A good backup plan allow you to recover from disk failure, accidental file deletion, file corruption, or complete server destruction, including destruction of on-site backups.

No comments:

Post a Comment