util-linux — Collection Overview
util-linux is the grab-bag kernel-adjacent userland package: everything
that talks to block devices, terminal lines, process attributes, system
clocks, and login sessions but is not part of coreutils or the C library.
mount, fdisk, lsblk, dmesg, cfdisk, taskset, unshare,
hwclock — the tools you reach for at the storage layer, the scheduler
layer, and the boot layer all come from here. This collection gives each
binary its own page; this overview carries the package-level picture, the
inventory, and the shared concepts.
Package Shape and Lineage
util-linux grew out of the 1993 merge of assorted Linux utilities that had
no other home, absorbed the 4BSD-derived tools (col, hexdump, look,
ul, write, wall lineage) over the 2010s, and is today maintained
upstream on GitHub. Debian then re-splits it into binary packages by
operational role: util-linux (the core), util-linux-extra (newer or
niche tools such as fincore, lsirq, hwclock docs), mount (the
mount/umount/losetup/swapon/swapoff set), fdisk (the three partitioning
tools), uuid-runtime (uuidgen, uuidparse, uuidd), eject, and
bsdextrautils (the absorbed BSD terminal tools). A minimal container can
have one slice without the others — that fact alone answers a family of
interview questions about thin images.
The package is one of the most conservative in Linux: the mount/fdisk
option grammar of 20 years ago still works, and each release adds a
handful of new tools (setpriv, uclampset, hardlink) rather than
changing old ones. Modern releases moved aggressively toward libmount-based
table output (findmnt-style JSON), which is why so many pages here show
--json options.
Two tools that upstream once shipped are gone: raw(8) was removed in
util-linux 2.37 (deprecated block raw devices — bind mounts and O_DIRECT
replaced the use case), and pg(1) left Debian packaging years ago. They
appear here only as history notes because interviews occasionally mention
them.
The Inventory
Storage: identify, inspect, freeze (10)
| Binary | One-liner | Page |
|---|---|---|
blkid | Locate/print block device attributes | blkid |
blkdiscard | Discard sectors on an SSD | blkdiscard |
blkzone | Report/send zoned-block-device commands | blkzone |
blockdev | ioctls for block devices | blockdev |
findfs | Find a filesystem by label/UUID | findfs |
findmnt | Find/list mounted filesystems | findmnt |
lsblk | List block devices as a tree | lsblk |
fincore | Which pages are in page cache | fincore |
fsfreeze | Freeze/thaw a filesystem | fsfreeze |
wdctl | Watchdog status | wdctl |
Storage: partition and wipe (8)
| Binary | One-liner | Page |
|---|---|---|
fdisk | Interactive MBR/GPT partitioning | fdisk |
sfdisk | Scriptable partitioning | sfdisk |
cfdisk | curses partitioning UI | cfdisk |
partx | Tell kernel about partition table | partx |
resizepart | Resize a partition in-kernel | resizepart |
addpart | Register a partition manually | addpart |
delpart | Unregister a partition | delpart |
wipefs | Wipe filesystem/RAID signatures | wipefs |
Storage: filesystems, loop, swap (13)
| Binary | One-liner | Page |
|---|---|---|
mount | Attach filesystems | mount |
umount | Detach filesystems | umount |
fsck | Filesystem check dispatcher | fsck |
fsck.cramfs | Check cramfs images | fsck.cramfs |
fsck.minix | Check minix images | fsck.minix |
mkfs | Build filesystems (dispatcher) | mkfs |
mkfs.bfs | Build BFS images | mkfs.bfs |
mkfs.cramfs | Build cramfs images | mkfs.cramfs |
mkfs.minix | Build minix images | mkfs.minix |
mkswap | Set up swap area | mkswap |
swapon | Enable swap | swapon |
swapoff | Disable swap | swapoff |
swaplabel | Change swap label/UUID | swaplabel |
losetup | Set up loop devices | losetup |
fstrim | TRIM mounted filesystems | fstrim |
zramctl | Control zram devices | zramctl |
isosize | ISO image size | isosize |
Scheduling, privileges, namespaces (15)
| Binary | One-liner | Page |
|---|---|---|
taskset | Set CPU affinity | taskset |
uclampset | Set utilization clamping | uclampset |
chrt | Real-time scheduling policy | chrt |
choom | Adjust OOM score | choom |
ionice | I/O scheduling class/priority | ionice |
nice (coreutils) | CPU niceness | sibling collection |
setpriv | Run with modified privileges | setpriv |
setsid | Run in a new session | setsid |
setarch | Personality wrappers (linux32…) | setarch |
prlimit | Get/set resource limits | prlimit |
nsenter | Enter namespaces of a process | nsenter |
unshare | Run with new namespaces | unshare |
flock | Advisory file locks | flock |
kill | Signal by PID | kill |
runuser | Run as another user (no PAM session) | runuser |
su | Switch user | su |
Terminals and sessions (17)
| Binary | One-liner | Page |
|---|---|---|
agetty | TTY login prompt (getty) | agetty |
mesg | Control write access to your TTY | mesg |
setterm | Terminal attributes | setterm |
more | Pager | more |
col | Reverse-line-feed filter | col |
colcrt | Filter nroff for CRTs | colcrt |
colrm | Remove columns | colrm |
column | Columnate input | column |
hexdump | ASCII/decimal/hex dump | hexdump |
look | Dictionary/lines lookup | look |
ul | Underline filter for terminals | ul |
rev | Reverse characters per line | rev |
namei | Follow a pathname element-wise | namei |
mountpoint | Is this a mountpoint? | mountpoint |
whereis | Locate binary/source/man | whereis |
utmpdump | Dump utmp/wtmp records | utmpdump |
mcookie | Generate magic cookies (xauth) | mcookie |
System, clock, hardware (18)
| Binary | One-liner | Page |
|---|---|---|
dmesg | Kernel ring buffer | dmesg |
hwclock | Hardware clock sync | hwclock |
rtcwake | Suspend until RTC time | rtcwake |
chcpu | Enable/disable CPUs | chcpu |
chmem | Online/offline memory | chmem |
lsmem | List memory blocks | lsmem |
lscpu | CPU topology display | lscpu |
readprofile | Read kernel profiling | readprofile |
ctrlaltdel | Set Ctrl-Alt-Del handling | ctrlaltdel |
eject | Eject removable media | eject |
fallocate | Preallocate file space | fallocate |
getopt | Parse options in scripts | getopt |
hardlink | Consolidate duplicate files | hardlink |
rename | Rename multiple files | rename |
ldattach | Line discipline attach | ldattach |
last | Login history from wtmp (lastb) | last |
pivot_root | Change root mount | pivot_root |
switch_root | Switch to a new rootfs (initramfs) | switch_root |
cal | Calendar (FreeBSD ncal heritage) | cal |
uuidgen | Generate UUIDs (uuidd) | uuidgen |
uuidparse | Parse UUIDs | uuidparse |
Shared Concepts
- libmount table output:
findmnt,lsblk,lscpu,lsipc,lsnsshare the--json/--list/export output machinery — scripts should pick one stable format and stick to it. - Namespace pair:
unsharecreates new namespaces and runs a command;nsenterenters another process’s namespaces. Container debugging is mostly these two plussetpriv— see Process Management and Linux Internals for kernel context. - Partition kernel-vs-disk state:
partx/resizepart/addpart/delpartmanipulate the kernel’s view without rewriting the table; the fdisk family rewrites it. Knowing which side a tool operates on is the classic partitioning interview trap. - The su family:
su(PAM session),runuser(no PAM session), and the login-collection’s sulogin differ in session setup and audit trail — the su page holds the comparison. - Boot path: initramfs hands off through
switch_root; chroot-era tooling usedpivot_root; both pages trace the handoff. - Debian package splits listed above — a tool’s absence from a minimal image is a packaging question, not an upstream one.
Reading Order For Interview Prep
- Storage core: mount, umount, lsblk, findmnt, fdisk, wipefs.
- Process/namespace core: taskset, chrt, nsenter, unshare, setpriv, flock.
- Boot/repair: dmesg, hwclock, switch_root, fsck, agetty.
- Breadth: the tables above; the BSD-terminal tools (
col,ul,colcrt) are low-yield trivia except at old-school shops.
Interview Questions
Q: Why does lsblk show a partition the kernel does not actually have?
lsblk reads sysfs; after you rewrite a partition table on a disk that is
in use, the kernel’s view may be stale until you run partx -u (or
partprobe from a different package). The fdisk family warns “re-reading
the partition table failed” for exactly this reason. Kernel view vs
on-disk table vs userspace display are three different states — the
partitioning pages cover the reconciliation commands.
Q: What is the difference between unshare and nsenter?
unshare starts a command in NEW namespaces (creation); nsenter
attaches to EXISTING namespaces referenced by /proc/<pid>/ns/* (entry).
Debugging inside a container without a shell is the canonical nsenter
use; building a test isolation sandbox is the canonical unshare use.
Both need matching capabilities, and neither mounts a rootfs by itself —
that is pivot_root/switch_root territory.
Q: Which util-linux tools would you use to prove a disk is the bottleneck?
blkid/lsblk to identify topology, blockdev --getra and
--setra for readahead, fsfreeze to take a consistent snapshot point,
fstrim maintenance on SSDs, and dmesg to catch device errors. The
expected follow-up is iostat — procps and sysstat territory — so this
page set deliberately hands off to
procps.
Q: Why does flock exist when fcntl locks exist?
flock(2) locks are per open-file-description, advisory, and simple to
use from shell pipelines (flock /tmp/lock cmd); fcntl/lockf record
locks are byte-range, survive across fork differently, and are what NFS
historically supported. The flock page walks the failure
modes; the one-line cron-mutex idiom is the interview favorite.