Linux Hardware Enumeration and Disk Subsystem Administration
System Device Identification
In Linux, hardware components are abstracted as files within the system hierarchy. Primary methods for inventorying devices include scanning PCI buses and inspecting virtual filesystems.
Hardware Detection Commands
- Use
lspcito enumerate Peripheral Component Interconnect devices. - Execute
fdisk -lto retrieve details on storage partitions. - Inspect
/proc/cpuinfodirectly viacatfor CPU specifications. - Note that legacy tools like
kudzufor automatic hardware detection are deprecated in favor of udev.
Storage Nomenclature and Partitioning
Block devices follow distinct naming conventions based on the underlying interface controller. Legacy IDE interfaces typically appear as hd[a-z], while SATA and SCSI drives utilize sd[a-z]. Partitions are denoted by appending numeric suffixes to the device name. The first four numbers (1-4) designate primary partitions, whereas extensions start at number 5.
Disk Configuration Utility
The fdisk utility manages partition tables interactively.
# Invoke fdisk on the secondary SCSI drive
/sbin/fdisk /dev/sdb
Key interactive commands:
a: Toggle bootable flagd: Delete a partition entryn: Initialize a new partitionp: Print current partition tablew: Write changes and exitq: Quit without saving
Filesystem Creation and Mounting
Data volumes must be initialized with a specific filesystem structure before use.
# Format partition sdb1 to ext4
mkfs.ext4 /dev/sdb1
# Alternative for FAT32 compatibility
mkfs.vfat -F 32 /dev/sde2
Mounting operations attach these volumes to the directory tree.
# Standard mount command
mount -t ext4 /dev/sdb1 /mnt/storage
# Check usage statistics (human-readable)
df -hT
# Specific flags for inode or type filtering
df -i # Show inode usage
df -H # Use 1000-based units
df -l # Limit output to local filesystems only
To unmount a volume safely, use the reverse operation:
umount /mnt/storage
Persistent Mount and Automation
For permanent access across reboots, entries are defined in /etc/fstab.
/dev/sda1 /home/data ext4 defaults 0 2
Dynamic mounting is handled by the autofs service. This requires configuring a master map file (/etc/auto.master) to define root points and a specific map (e.g., /etc/auto.misc) for device parameters including timeout values.
# Master configuration entry
tmp/auto /etc/auto.misc --timeout=60
Virtual Memory Management
Swap space can be extended dynamically using sparse files rather than dedicated partitions.
# Generate a 1GB swap image
sudo dd if=/dev/zero of=/swapfile.img bs=1M count=1024
# Mark the file as swap space
sudo mkswap /swapfile.img
# Enable the new swap immediately
sudo swapon /swapfile.img
Persistence requires adding the activation line to the system boot scripts, typically /etc/rc.local or a systemd drop-in unit.
Software RAID Implementation
The mdadm tool manages software-defined Redundant Array of Independent Disks configurations.
# Create a Level 5 array with 3 disks
mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdc1 /dev/sdd1 /dev/sde1
# Verify status
cat /proc/mdstat
# Manage disk health
mdadm /dev/md0 --remove /dev/sdd1
mdadm /dev/md0 --add /dev/sdf1
# Format the RAID device
mkfs.ext4 /dev/md0
Optical Media Handling
Physical drives are accessed via symbolic links like /dev/cdrom. ISO images can also be mounted virtually using the loopabck device.
# Mount physical drive
mount /dev/cdrom /media/dvd
# Extract image from drive
dd if=/dev/cdrom of=/backup/image.iso bs=4M
# Mount ISO file locally
mount -o loop /backup/image.iso /mnt/archive