Lesson  in  Linux for SRE / DevOps - Beginner Level

Know Your Machine: Hardware & Resources at a Glance

on Linux
lscpu, free, df/lsblk, lsusb/lspci - figuring out what you're actually working with before you touch anything.

You've been handed access to a box you've never seen before. Before you install anything, restart anything, or trust anything a colleague told you about it, answer one question: what actually is this machine?

CPU

nproc
4

nproc prints one number: how many CPUs the shell can actually use right now. On a shared or virtualized box, that can be less than the physical hardware has, so trust nproc over any assumption. For more detail, lscpu prints a much longer report:

lscpu
Architecture:                            x86_64
CPU op-mode(s):                          32-bit, 64-bit
Address sizes:                           46 bits physical, 48 bits virtual
Byte Order:                              Little Endian
CPU(s):                                  4
On-line CPU(s) list:                     0-3
Vendor ID:                               GenuineIntel
Model name:                              Intel(R) Xeon(R) Processor
CPU family:                              6
Model:                                   183
Thread(s) per core:                      1
Core(s) per socket:                      4
Socket(s):                               1
Stepping:                                1
BogoMIPS:                                3993.60

A few lines worth actually reading: CPU(s) matches what nproc told you - the count the OS sees. Model name tells you the actual chip, which matters when you're chasing a performance difference between two boxes. Thread(s) per core being 1 (instead of 2) tells you this CPU isn't using hyperthreading - each core is one real thread, not two logical ones sharing it.

Memory

free -h
               total        used        free      shared  buff/cache   available
Mem:           9.8Gi       445Mi       9.4Gi       996Ki        87Mi       9.4Gi
Swap:             0B          0B          0B

The -h flag means "human-readable" - without it, free prints raw byte counts, which is hard to read at a glance. Two columns matter more than the others: free is memory nothing is using at all, and available is what's actually available to a new process, including memory currently used for disk cache that the kernel will happily give back if asked. available is almost always the number you actually want - a low free value with a high available value is completely normal and not a problem, the kernel is just using spare RAM to cache files for speed. Swap: 0B means there's no swap space configured on this box at all - if RAM runs out here, the kernel has nowhere else to go.

Disks

lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
vda  253:0    0  80G  0 disk /

Read this left to right: NAME is the device name (vda, found at /dev/vda). SIZE is its total capacity - 80G here. TYPE says what kind of block device it is (disk - a whole disk, as opposed to part for a partition of one). MOUNTPOINTS shows where it's attached into the filesystem tree - / here means this entire disk is the root filesystem, with no separate partitions carved out of it.

df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        79G  1.8G   73G   3% /
tmpfs           4.9G     0  4.9G   0% /dev/shm
tmpfs           2.0G  228K  2.0G   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs          1003M   12K 1003M   1% /run/user/1001

lsblk told you what storage exists. df -h answers a completely different question: how full is each mounted filesystem right now. Look at the first row: /dev/root has 79G total, 1.8G used, 73G available, and is 3% full - mounted at /. These are not the same question as lsblk's - a disk can exist and still report 100% full in df, and df would never tell you that on its own.

The other rows, the tmpfs ones, aren't disks at all - they're RAM being used as if it were a filesystem, for things like /dev/shm (shared memory) and /run (runtime state). They vanish completely on reboot.

Attached devices

lspci
lsusb

On a fresh Ubuntu box these two commands may not even exist yet - they come from separate packages (pciutils and usbutils) that aren't always preinstalled:

sudo apt install -y pciutils usbutils

Once installed:

$ lspci
00:00.0 Host bridge: Intel Corporation Device 0d57
00:01.0 Mass storage controller: Red Hat, Inc. Virtio 1.0 block device (rev 01)
00:02.0 Ethernet controller: Red Hat, Inc. Virtio 1.0 network device (rev 01)
00:03.0 Unassigned class [ffff]: Red Hat, Inc. Virtio 1.0 socket (rev 01)
00:04.0 Unassigned class [ffff]: Red Hat, Inc. Virtio 1.0 RNG (rev 01)

$ lsusb

Notice every device here says Virtio - that's the standard interface virtual machines use to talk to their host's real hardware without emulating a specific physical chip. Seeing Virtio everywhere in lspci, on any box, is itself a fact worth knowing: it confirms you're inside a VM, not on bare metal. lsusb came back completely empty, and that's expected, not broken - this playground has no USB devices attached, virtual or otherwise.

Write it down

Build the habit of recording what you found before you change anything. Create ~/machine-report.txt with two lines:

cpus=<the number nproc printed>
rootdev=<the device name from df --output=source /, with the /dev/ prefix stripped>
lsblk and df don't agree on the name - which one is right?

Both are. lsblk shows the real underlying device (vda). df --output=source / can show a kernel-level alias instead, like /dev/root, which points at the same disk under a different name. This isn't a bug in either tool - it's normal on plenty of real systems, cloud VMs included, and it's exactly the kind of "why don't these two commands agree" moment worth getting used to early. For this report, use whatever df --output=source / prints.