Phase 2. Lesson 3 of 4. About 30 minutes.
Plain entry
You do not need a screwdriver to know what is in a computer. Linux will tell you, down to the serial number, if you ask it the right way. This is how technicians inventory a hundred machines without opening one, and how you confirm a part is actually being used. Here are the commands, one per part, with what to look for.
Terms
- Command-line tool: a program you run by typing its name in the terminalThe window or screen where you type text commands and read their output, connected to a shell that runs those commands. Read more →.
- sudoA Linux command that runs a single command with administrator (root) privileges, after checking that your account is allowed to do so. Read more →: runs a command with administrator rights. Some hardware details need it because they can include serial numbers.
- Flag (option): extra letters after a command that change what it does, like
-hfor human-readable sizes. - SwapDisk space the operating system uses as overflow when physical memory (RAM) fills up, at the cost of being much slower than RAM. Read more →: disk space Linux uses as overflow when RAMRandom Access Memory: the fast, temporary working memory that holds the programs and data a computer is using right now, cleared when power is lost. Read more → is full. Much slower than RAM.
Depth: one command per part
CPU
lscpu | head -20
Look for these lines (VMA software-based emulation of a complete computer that runs its own operating system and applications, isolated from the host hardware. Read more → example):
Architecture: x86_64
CPU(s): 2
Model name: AMD Ryzen 7 5800X 8-Core Processor
Thread(s) per core: 1
Core(s) per socket: 2
Hypervisor vendor: KVM
Virtualization type: full
The model name is the real host CPU, passed through. The CPU count is what you gave the VM. “HypervisorSoftware that creates and manages virtual machines by abstracting physical hardware resources and allocating them to isolated guest operating systems. Read more → vendor” appears only inside a VM; VirtualBox often reports KVMA Linux kernel module that turns the Linux operating system itself into a Type 1 hypervisor, enabling hardware-accelerated virtual machines. Read more → here because it uses that paravirtualization interface (example, not tested in VirtualBox for this lesson; a QEMU/KVM guest shows Hypervisor vendor: KVM and hypervisor in the flags), see KVM.
Memory
free -h
total used free shared buff/cache available
Mem: 3.8Gi 1.4Gi 1.1Gi 45Mi 1.5Gi 2.4Gi
Swap: 3.8Gi 0B 3.8Gi
Read available, not free. Linux uses spare RAM as disk cache and gives it back on demand, so “free” looks low on a healthy machine. Total shows a bit under what you assigned because the kernel reserves some.
RAM sticks, speed, and slots (bare metal; mostly blank in a VM):
sudo dmidecode --type memory | grep -E "Size|Speed|Type:|Locator" | head
Storage
lsblk
df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 29G 9.8G 18G 36% /
lsblk shows disks and partitions. df shows how full each mounted filesystem is.
Disk health (bare metal):
sudo apt install -y smartmontools
sudo smartctl -H /dev/sda
SMART overall-health self-assessment test result: PASSED is what you want. For NVMe use /dev/nvme0. In a VM this usually fails with “Unable to detect device type.” That is expected.
Motherboard and firmware
sudo dmidecode -s system-manufacturer
sudo dmidecode -s system-product-name
sudo dmidecode -s bios-version
VM output:
innotek GmbH
VirtualBox
VirtualBox
Everything at once
sudo lshw -short
H/W path Device Class Description
================================================
system VirtualBox
/0 bus VirtualBox
/0/0 memory 128KiB BIOS
/0/1 memory 4GiB System memory
/0/2 processor AMD Ryzen 7 5800X 8-Core Processor
/0/100/3 enp0s3 network 82540EM Gigabit Ethernet Controller
/0/100/d/0 /dev/sda disk 32GB VBOX HARDDISK
lshw is the single best inventory command. Save a full report with sudo lshw -html > hardware.html and open it in a browser.
Network card
ip -br link
lo UNKNOWN 00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP>
enp0s3 UP 08:00:27:3a:1c:9e <BROADCAST,MULTICAST,UP,LOWER_UP>
The middle column is the MAC address. 08:00:27 is VirtualBox’s prefix. Phase 5 explains interface names like enp0s3.
Going further
All of these tools read the same source: the kernel’s virtual filesystems. Try cat /proc/cpuinfo, cat /proc/meminfo, and ls /sys/class/net. Nothing there is a real file on disk; the kernel builds it the moment you read it. Knowing this lets you query hardware in a script with no extra packages installed.
Why it works this way
Linux exposes hardware as files under /proc and /sys, and the tools in this lesson mostly read and tidy those files. That is why they agree with each other, and why they work on a server with no screen. When two tools seem to disagree, check what each one counts. free and top count memory the same way, but a VM reports what the hypervisor gave it, not what the host has.
Self-check
- In
free -h, which column tells you how much memory programs can still use? - Which command gives a one-screen summary of every part?
- Why does
smartctlfail in a VM? - Where do
lscpuandfreeget their information?
Answers: (1) available. (2) sudo lshw -short. (3) The virtual disk does not expose real SMART data. (4) The kernel, through /proc and /sys.
Sources
lscpu: https://man7.org/linux/man-pages/man1/lscpu.1.htmlfree: https://man7.org/linux/man-pages/man1/free.1.htmldmidecode: https://manpages.ubuntu.com/manpages/resolute/man8/dmidecode.8.htmllshw: https://manpages.ubuntu.com/manpages/resolute/man1/lshw.1.html- smartmontools: https://www.smartmontools.org/
procfilesystem: https://man7.org/linux/man-pages/man5/proc.5.html