Kahibaro
Discord Login Register

Devices and partitions

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:

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:

Key points:

NVMe SSDs: `/dev/nvmeXnYpZ`

Fast NVMe drives (common in modern laptops and servers) use:

Example:

Virtual disks: `/dev/vdX`

Virtual machines often use virtio disks, named:

Other device types (brief)

Regardless of the exact name, you always have:

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-uuid

Common subdirectories:

Example:

ls -l /dev/disk/by-uuid

You 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,UUID

Typical 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 /home

Important columns:

`blkid`: Filesystem IDs and Types

blkid shows filesystem-level information:

sudo blkid

Example:

/dev/sda1: UUID="1234-5678" TYPE="vfat" PARTLABEL="EFI System Partition"
/dev/sda2: UUID="abcd-ef01-2345-6789" TYPE="ext4" PARTUUID="..."

Useful for:

`fdisk` / `parted` (list only)

To list partition tables (without modifying anything):

sudo fdisk -l
sudo parted -l

They show:

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:

Signs of MBR:

GPT (GUID Partition Table)

Modern standard, required for UEFI boot, supports large disks:

Signs of GPT:

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:

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:

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 -f

Look at:

Using `fdisk -l` for sector-level info

sudo fdisk -l /dev/sda

You’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:

  1. Identify the disk
    Use lsblk and fdisk -l to ensure you’ve got the right device (e.g. /dev/sdb), and that it doesn’t contain data you care about.
  2. 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.
  3. Create one or more partitions
    Decide:
    • How many partitions you need.
    • Approximate sizes (e.g. 512M for ESP, 20G for root, rest for /home).
  4. Write changes to disk
    The partitioning tool writes the new table. This can destroy existing data on modified areas, so double-check.
  5. Inform the kernel of changes
    Often automatic when you exit tools, or use partprobe/partx to avoid reboot.
  6. Create filesystems or swap on the new partitions
    (Details and commands are in the filesystems chapter.)
  7. Mount and configure
    Add entries to /etc/fstab or mount manually.

Tools for Editing

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,MODEL

Example:

NAME   SIZE MODEL
sda  477G   Samsung_SSD_860
sdb    2T   WDC_WD20EZRZ-00

This helps correlate with physical labels or vendor documentation.

Using Serial Numbers and IDs

Look at /dev/disk/by-id:

ls -l /dev/disk/by-id

You’ll see entries like:

ata-WDC_WD20EZRZ-00_ABCDEF   -> ../../sdb
nvme-Samsung_SSD_980_1TB_1234ABCD -> ../../nvme0n1

These reflect exact devices and are often unique.

Using `udevadm` (advanced but useful for troubleshooting)

sudo udevadm info --query=all --name=/dev/sdb | less

This shows attributes including model, serial, bus, etc.

Hotplugged Devices (USB Sticks, External Drives)

USB drives, external SSDs, and similar devices:

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:

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:

In practice:

Safety Guidelines When Working with Devices and Partitions

Misidentifying a disk or partition can destroy data. Follow these practices:

  1. 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.
  2. Use listing commands first
    • lsblk, fdisk -l, blkid, parted -l are safe.
    • Learn what is currently in use before changing anything.
  3. 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).
  4. Back up important data
    • Partitioning changes can be destructive.
    • Even non-destructive operations can go wrong with power loss or mistakes.
  5. 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.

Views: 21

Comments

Please login to add a comment.

Don't have an account? Register now!