Table of Contents
Understanding Storage Devices in Linux
Linux sees disks and other storage hardware as device files under /dev. Partitions are “slices” of these devices that can hold filesystems, swap space, or other data structures.
This chapter focuses on how Linux represents devices and partitions, and how to inspect and manipulate them safely.
Block Devices vs Character Devices (Quick Context)
Storage devices that hold data in blocks (disks, SSDs, USB sticks) appear as block devices in /dev.
You can see them with:
ls -l /dev | head
lsblk
In ls -l output:
- Block devices show up with a leading
b(e.g.brw-rw----). - Character devices show up with a leading
c(e.g.crw-rw----).
This chapter focuses on block devices.
Device Naming: `/dev/sdX`, `/dev/nvmeXnY`, `/dev/vdX`
Linux uses several naming schemes depending on the type of device and driver. The most common:
SCSI/SATA/USB disks: `/dev/sdX`
Traditional and many modern disks appear as:
- Whole disk:
/dev/sda,/dev/sdb,/dev/sdc, ... - Partitions:
/dev/sda1,/dev/sda2,/dev/sdb3, ...
Key points:
- The letter (
a,b,c, ...) is assigned by detection order, not by physical port. - The number is the partition index on that disk.
NVMe SSDs: `/dev/nvmeXnYpZ`
Fast NVMe drives (common in modern laptops and servers) use:
- Whole device:
/dev/nvme0n1,/dev/nvme1n1, ... 0– controller indexn1– namespace index (most systems usen1)- Partitions:
/dev/nvme0n1p1,/dev/nvme0n1p2, ...
Example:
/dev/nvme0n1p3= 3rd partition on the first NVMe namespace on controller 0.
Virtual disks: `/dev/vdX`
Virtual machines often use virtio disks, named:
- Whole disk:
/dev/vda,/dev/vdb, ... - Partitions:
/dev/vda1,/dev/vdb2, ...
Other device types (brief)
- MMC/SD cards:
/dev/mmcblk0,/dev/mmcblk0p1, ... - Old IDE (rare now):
/dev/hda,/dev/hdb, ...
Regardless of the exact name, you always have:
- A base device (the disk): e.g.
/dev/sda,/dev/nvme0n1 - Partition devices: the disk name + partition number (often with
pfor NVMe/MMC)
Safer, Stable Names: `/dev/disk/by-*`
/dev/sdX and similar names can change if hardware or boot order changes. Linux offers persistent names via symlinks in /dev/disk:
ls -l /dev/disk
ls -l /dev/disk/by-id
ls -l /dev/disk/by-uuidCommon subdirectories:
/dev/disk/by-id/– based on hardware IDs (model, serial, etc.)./dev/disk/by-uuid/– based on filesystem UUID./dev/disk/by-partuuid/– based on partition table UUID./dev/disk/by-label/– based on filesystem label (if set).
Example:
ls -l /dev/disk/by-uuidYou might see:
lrwxrwxrwx 1 root root 10 ... 1234-ABCD -> ../../sda1
lrwxrwxrwx 1 root root 13 ... 5678-90EF -> ../../nvme0n1p2
These UUID-based names are often used in /etc/fstab because they remain stable even if device letters change.
Listing Disks and Partitions
Several tools help you inspect devices and partitions. Each is good for slightly different tasks.
`lsblk`: Overview of Block Devices
lsblk shows a tree of devices, partitions, and their mountpoints:
lsblk
lsblk -f
lsblk -o NAME,MAJ:MIN,SIZE,TYPE,FSTYPE,MOUNTPOINT,UUIDTypical output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 477G 0 disk
├─sda1 8:1 0 512M 0 part /boot
└─sda2 8:2 0 476G 0 part /
sdb 8:16 0 2T 0 disk
└─sdb1 8:17 0 2T 0 part /data
nvme0n1 259:0 0 256G 0 disk
├─nvme0n1p1 259:1 0 100M 0 part /boot/efi
└─nvme0n1p2 259:2 0 255G 0 part /homeImportant columns:
NAME– device or partition name.TYPE–diskfor whole device,partfor partition, others for LVM/RAID (covered elsewhere).FSTYPE– filesystem type (if recognized).MOUNTPOINTS– where it is currently mounted.
`blkid`: Filesystem IDs and Types
blkid shows filesystem-level information:
sudo blkidExample:
/dev/sda1: UUID="1234-5678" TYPE="vfat" PARTLABEL="EFI System Partition"
/dev/sda2: UUID="abcd-ef01-2345-6789" TYPE="ext4" PARTUUID="..."Useful for:
- Getting UUIDs to use in
/etc/fstab. - Confirming filesystem types on partitions (ext4, xfs, vfat, swap, etc.).
`fdisk` / `parted` (list only)
To list partition tables (without modifying anything):
sudo fdisk -l
sudo parted -lThey show:
- Partition table type (MBR/“dos” vs GPT).
- Exact start/end sectors and sizes.
- Flags (e.g. boot, esp).
Use these in read-only/list mode when first learning; interactive editing requires care.
Partition Table Types: MBR vs GPT
The partition table defines how a disk is divided into partitions.
MBR (DOS) Partition Table
Older scheme, still seen on many BIOS-based or legacy systems:
- Stores partition info in the first sector (MBR).
- Up to 4 primary partitions.
- Or 3 primaries + 1 extended partition, which can contain logical partitions.
- Maximum usable size around 2 TiB with standard 512-byte sectors.
Signs of MBR:
fdisk -lshows:Disklabel type: dos.- Partition names:
/dev/sda1to/dev/sda4primary;/dev/sda5and up logical.
GPT (GUID Partition Table)
Modern standard, required for UEFI boot, supports large disks:
- Supports up to 128 partitions (often more) without primary/extended/logical distinction.
- Handles very large disks (ZB range in theory).
- Stores partition table at both the beginning and end of the disk for redundancy.
- Each partition has a GUID type and unique ID.
Signs of GPT:
fdisk -lshows:Disklabel type: gpt.- No extended/logical distinction; partitions usually numbered from 1 upwards (e.g.
/dev/sda1,/dev/sda2,/dev/sda3).
Modern systems typically use GPT unless there is a strong reason not to.
Partition Types and Typical Uses
Each partition has a type, indicating intended use. Tools like fdisk, gdisk, and parted show and set these.
Common partition purposes:
- Root filesystem (e.g.
/dev/sda2mounted on/). - EFI System Partition (ESP) – required on UEFI systems; FAT filesystem, type
EFI System. - Boot partition – sometimes separate
/boot. - Home partition – e.g.
/dev/sda3mounted on/home. - Swap partition – used as virtual memory.
- Data partitions – e.g.
/data,/var, etc.
On GPT, partition type GUIDs precisely encode purpose (e.g. “Linux filesystem”, “EFI System Partition”, “Linux swap”). On MBR, “partition type codes” (hex numbers like 83, 82) serve a similar role.
From a beginner’s perspective, the key is understanding:
- Each partition is its own “region” of the disk.
- Each region can be formatted with its own filesystem type or used for swap/LVM/RAID.
Details on filesystems, LVM, RAID, and encryption are covered in their own chapters.
Inspecting Partition Layout Safely
Before making any changes, you should know what is already on the disk.
Using `lsblk` for a quick map
lsblk -fLook at:
- Which partitions exist.
- Their mountpoints.
- Filesystem types.
Using `fdisk -l` for sector-level info
sudo fdisk -l /dev/sdaYou’ll see output like:
Disk /dev/sda: 477 GiB, ...
Disklabel type: gpt
Device Start End Sectors Size Type
/dev/sda1 2048 534527 532480 260M EFI System
/dev/sda2 534528 1000214527 999679... 476G Linux filesystem
Start and End are in sectors (commonly 512 bytes each). This is useful when aligning or resizing partitions but you normally don’t need to do the math manually.
Using `parted` for aligned partitions (list only)
sudo parted /dev/sda print
parted uses human-readable sizes (MiB, GiB) and is aware of modern alignment constraints.
Creating and Modifying Partitions (Conceptual Overview)
The exact “how-to” for each tool (e.g. fdisk, parted) belongs in practical labs or later chapters, but it’s useful to understand the workflow conceptually.
General Workflow
Typical steps to prepare a new disk:
- Identify the disk
Uselsblkandfdisk -lto ensure you’ve got the right device (e.g./dev/sdb), and that it doesn’t contain data you care about. - Create or convert a partition table
- For new disks: create GPT (usually recommended) or MBR as needed.
- On an existing disk: converting may be destructive; this is advanced and requires backups.
- Create one or more partitions
Decide: - How many partitions you need.
- Approximate sizes (e.g. 512M for ESP, 20G for root, rest for
/home). - Write changes to disk
The partitioning tool writes the new table. This can destroy existing data on modified areas, so double-check. - Inform the kernel of changes
Often automatic when you exit tools, or usepartprobe/partxto avoid reboot. - Create filesystems or swap on the new partitions
(Details and commands are in the filesystems chapter.) - Mount and configure
Add entries to/etc/fstabor mount manually.
Tools for Editing
fdisk– classic interactive tool for MBR and GPT disks, text-mode, widely available.cfdisk– curses-based, menu-driven variant offdisk.parted– supports managing GPT/MBR with more scripting and size options.gdisk– GPT-only equivalent offdisk(good for GPT-specific operations).
In all cases: writing changes is the dangerous step; list/print operations are safe.
Identifying Which Disk Is Which
On systems with multiple disks, it’s crucial to link each /dev/* name to a physical disk.
Using Size and Model Information
lsblk and udevadm can show model names:
lsblk -o NAME,SIZE,MODELExample:
NAME SIZE MODEL
sda 477G Samsung_SSD_860
sdb 2T WDC_WD20EZRZ-00This helps correlate with physical labels or vendor documentation.
Using Serial Numbers and IDs
Look at /dev/disk/by-id:
ls -l /dev/disk/by-idYou’ll see entries like:
ata-WDC_WD20EZRZ-00_ABCDEF -> ../../sdb
nvme-Samsung_SSD_980_1TB_1234ABCD -> ../../nvme0n1These reflect exact devices and are often unique.
Using `udevadm` (advanced but useful for troubleshooting)
sudo udevadm info --query=all --name=/dev/sdb | lessThis shows attributes including model, serial, bus, etc.
Hotplugged Devices (USB Sticks, External Drives)
USB drives, external SSDs, and similar devices:
- Appear as new block devices when plugged in (e.g.
/dev/sdc,/dev/sdd). - May be automatically mounted by your desktop environment.
To see them as they appear:
lsblk
# Plug in device
lsblk
You’ll see a new disk (and possibly part entries) show up.
If auto-mount is disabled or you’re on a server:
- Use
lsblk -forsudo blkidto find the new device and partition. - Then mount the partition (not the whole disk) to an appropriate directory (mount commands are covered elsewhere).
Remember that unplugging a device without unmounting it can cause data loss.
Kernel and Device Nodes
Device files like /dev/sda are not “real” files on disk; they’re special nodes representing the kernel’s view of hardware.
Key concepts:
- The kernel detects hardware and creates corresponding block devices.
udev(the device manager) then creates and maintains/dev/entries and symlinks in/dev/disk/by-.- If a disk is removed, its device node is removed too.
In practice:
- You normally don’t create or delete device nodes manually.
- If a device doesn’t appear, the issue is usually kernel/driver/udev-related, not “missing file”.
Safety Guidelines When Working with Devices and Partitions
Misidentifying a disk or partition can destroy data. Follow these practices:
- Always verify the target device
- Compare size, model, and existing partitions using
lsblk,fdisk -l. - Double-check that it’s not your system disk unless you are absolutely sure.
- Use listing commands first
lsblk,fdisk -l,blkid,parted -lare safe.- Learn what is currently in use before changing anything.
- Unmount before modifying
- Don’t resize or delete partitions that are mounted or in active use.
- Many tools will warn, but it’s better to check yourself (
lsblk). - Back up important data
- Partitioning changes can be destructive.
- Even non-destructive operations can go wrong with power loss or mistakes.
- Prefer slow, careful steps over shortcuts
- Especially when you’re still learning, go through each confirmation consciously.
- If a command looks unfamiliar or dangerous, look it up first.
Understanding how Linux represents devices and partitions is the foundation for later topics like filesystems, LVM, RAID, and encryption. Once you’re comfortable reading lsblk and fdisk -l output, you’ll be far better equipped to reason about storage layouts on any Linux system.