Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Linux Hardware Enumeration and Disk Subsystem Administration

Tech May 23 9

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 lspci to enumerate Peripheral Component Interconnect devices.
  • Execute fdisk -l to retrieve details on storage partitions.
  • Inspect /proc/cpuinfo directly via cat for CPU specifications.
  • Note that legacy tools like kudzu for 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 flag
  • d: Delete a partition entry
  • n: Initialize a new partition
  • p: Print current partition table
  • w: Write changes and exit
  • q: 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

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.