linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Lessons
  • How it works
  • Simulator
  • Knowledge base
  • Interview prep
Index
Categories
All entries
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
home/linux/kb/File system/block-devices

kb/filesystem ── File system ── intermediate

Block devices: disks in Linux

A block device is read and written in fixed-size blocks (usually 512B or 4K). Disks, SSDs, and NVMe drives are all block devices in `/dev/`.

view as markdownaka: block-device, disks, dev-sd, dev-nvme

What it is

Linux exposes disks as block devices: files in /dev/ through which the kernel gives access to storage in blocks. Unlike character devices (terminals, /dev/null), block devices can seek by address, and I/O is requested in chunks of N bytes.

Device names

TypePrefixExample
SATA / SCSI / USB disk/dev/sd*/dev/sda, /dev/sdb1
NVMe (PCIe SSD)/dev/nvme*/dev/nvme0n1, /dev/nvme0n1p1
virtio (virtual machine)/dev/vd*/dev/vda
IDE (old)/dev/hd*/dev/hda
LVM logical volume/dev/<vg>/<lv> or /dev/mapper/.../dev/vg0/root
Loop (file as disk)/dev/loop*/dev/loop0
RAID (md)/dev/md*/dev/md0

The trailing number is the partition: /dev/sda1 is the first partition on /dev/sda. NVMe uses the scheme nvme0n1p1: controller 0, namespace 1, partition 1.

lsblk: the main command

bash
lsblk                              # tree of all block devices with partitions and mount points
lsblk -f                            # adds filesystem type, UUID, label
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT,UUID
lsblk -d                            # disks only, without partitions

Tree output:

NAME        SIZE  TYPE  FSTYPE  MOUNTPOINT
sda         512G  disk
├─sda1      512M  part  vfat    /boot/efi
├─sda2        1G  part  ext4    /boot
└─sda3      511G  part  LVM2    -
  └─vg0-root 50G  lvm   ext4    /

Stable identifiers

The names sda/sdb can change between boots (they depend on detection order). In /etc/fstab, use a UUID or a label:

bash
blkid                              # UUID and label of each partition
blkid /dev/sda1
ls -l /dev/disk/by-uuid/           # symlinks uuid → /dev/sd*
ls -l /dev/disk/by-label/
ls -l /dev/disk/by-id/             # stable per hardware (model + serial)

Size and geometry

bash
cat /proc/partitions               # size in 1K blocks
fdisk -l /dev/sda                  # partition table + size
blockdev --getsize64 /dev/sda      # size in bytes
cat /sys/block/sda/queue/rotational  # 1 = HDD, 0 = SSD
cat /sys/block/sda/queue/scheduler  # current I/O scheduler

Creating partitions

For GPT (the modern standard):

bash
sudo parted /dev/sda print                # current layout
sudo parted /dev/sda mklabel gpt          # create GPT (ERASES everything!)
sudo parted -a optimal /dev/sda mkpart primary ext4 0% 100%

For MBR (legacy, up to 2 TB):

bash
sudo fdisk /dev/sda                       # interactive
sudo sgdisk /dev/sda --print              # GPT-aware fdisk

After creating a partition you have to tell the kernel about it:

bash
sudo partprobe /dev/sda

I/O scheduler

The kernel orders I/O requests before sending them to the disk:

  • none / noop: for NVMe, which is its own good scheduler
  • mq-deadline: fair, the default on servers
  • bfq: for desktops, with per-process priorities
  • kyber: low latency, for SSDs
bash
cat /sys/block/sda/queue/scheduler
echo mq-deadline | sudo tee /sys/block/sda/queue/scheduler

Loop device: a file as a disk

bash
dd if=/dev/zero of=disk.img bs=1M count=100   # make a 100MB file
sudo losetup -f --show disk.img               # bind it to /dev/loopX
sudo mkfs.ext4 /dev/loop0                     # create a filesystem
sudo mount /dev/loop0 /mnt                    # mount it
sudo umount /mnt && sudo losetup -d /dev/loop0

This is how Docker used to build container filesystems, and it is how .iso images are mounted.

§ команды

bash
lsblk -f

All disks, partitions, filesystems, mount points, UUIDs: the main overview command

bash
blkid /dev/sda1

UUID and filesystem type of one partition, for /etc/fstab

bash
sudo fdisk -l

Detailed listing of all disks with partitions and geometry

bash
cat /sys/block/sda/queue/rotational

1 = HDD, 0 = SSD: tells you the disk type

bash
sudo partprobe /dev/sda

Re-read the partition table after editing with fdisk/parted

§ см. также

  • cmd-lsblk-blkidlsblk and blkid: block devices and UUIDslsblk shows the block device tree (disk -> partition -> LVM/crypt -> mountpoint). blkid prints UUID, LABEL, and filesystem type. Use them together to write a [[mount-and-fstab|/etc/fstab]] entry by UUID.
  • mount-and-fstabmount and /etc/fstab: attaching filesystems`mount` attaches a block device or filesystem to a mount point in the tree. `/etc/fstab` is the list of what to mount at boot.
  • lvmLVM: Logical Volume ManagerLVM is a layer between [[block-devices]] and the filesystem: it pools disks and carves out logical volumes of any size that you can grow, snapshot, and migrate live.
  • raidRAID: software RAID with mdadmRAID combines several [[block-devices]] into one logical device for redundancy or speed. On Linux you use `mdadm`. Hardware RAID is a separate story.
  • sparse-filesSparse files: holes and apparent sizeA sparse file has "holes", blocks the filesystem never allocated. They read back as zeros but take no space. ls shows the apparent size, du shows the real one. Used in qcow2, backups, sparse loop.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies