$_ CLI In Depth
Learning progress 0%
lesson disks mounts archives

Block Devices & Partitions

6 min read Module 12: Disks, Mounts & Archives Updated Dec 5, 2026
Cheat Sheet
0:00 / 3:19

Storage as a list of blocks

A block device is a device that the kernel reads and writes in units called blocks, usually 512 bytes or 4 KiB each. A solid-state drive, a USB stick, a virtual disk, and a loop device made from a file all look the same from user space once the kernel has registered them. Each one appears as a device node that you can name, read, and in some cases write. Reading a block device directly is possible, but almost nothing does it by hand, because the kernel and the filesystem layer normally sit between your program and the disk.

The important idea is that a block device has no names, no directories, and no file contents of its own. It is a flat sequence of numbered blocks. A filesystem such as ext4 or XFS is a structure written onto those blocks that gives them meaning: which blocks hold which file, where each directory entry lives, and which blocks are free. The disk does not know your files exist. The filesystem does.

Where the kernel shows disks

Two places expose block devices. The first is /dev, where each device has a node with a name such as sda or wda. The second is /sys, a virtual filesystem in which the kernel describes its devices as small text files. Each whole disk has a directory under /sys/block, and that directory holds attributes you can read with cat.

BASH3 lines
ls /sys/block
cat /sys/block/wda/size
cat /sys/block/wda/ro

The size attribute counts 512-byte sectors, so multiply it by 512 to get bytes. The ro attribute is 1 when the kernel marks the device read-only and 0 when it is writable. These numbers are the kernel talking about the device, not the filesystem on it, which is why they are a reliable way to check the hardware layer first.

Partitions and partition tables

Most disks are divided into partitions. A partition is a contiguous range of blocks that the system treats as its own device, for example /dev/sda1 for the first partition on /dev/sda. The division is recorded in a partition table written at the very start of the disk. The two common formats are the MBR, which is old and limited to small disks, and the GPT, which uses unique identifiers and supports very large disks. The partition table is only a map. It says where each partition starts and how long it is, and it says nothing about what is inside.

A disk does not have to be partitioned at all. A filesystem can occupy an entire disk, and a virtual disk image often contains a single filesystem with no table. This is one reason the lab disk is so simple: the whole device holds one image, and there is no partition table to read.

Reading the layout with lsblk

lsblk lists block devices and their partitions as a tree. It reads the same information from /sys and prints it in columns. The -d flag hides partitions and shows only whole disks, and -o chooses the columns you want.

BASH2 lines
lsblk
lsblk -d -o NAME,SIZE,RO,TYPE

In the lab, the output of the second command has one row for the disk wda, a size of about 24 MiB, the read-only flag set, and the type disk. The first column of the full lsblk output also lists the mount points of each device. Those mount points are where the disk is attached to the directory tree, which is the subject of the next lesson.

TEXT2 lines
NAME MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
wda  254:0    0 24.1M  1 disk /run/kw-lower/kw/distro

The columns are worth memorizing. MAJ:MIN is the major and minor number that the kernel uses internally to identify the device. RM is 1 for removable media. RO is the read-only flag. TYPE says whether the row is a disk, a partition, or a loop device. When something is wrong with a disk, these columns usually tell you the first thing to check.

Why the layout matters

Knowing the layout tells you what a tool is actually touching. If you run a command against /dev/sda instead of /dev/sda1, you are working on the whole disk, including the partition table. If a partition is marked read-only in /sys, no amount of permission changes on the files inside it will make them writable. The kernel checks the device before the filesystem is consulted.

Warning

Writing to a whole-disk device such as /dev/sda with a tool like dd overwrites the partition table and every filesystem on the disk. Read from block devices freely, but treat any write as a deliberate, root-only operation.

Names are assigned, not promised

Device names also follow a pattern. The prefix sd is used for SCSI and SATA disks, nvme for NVMe drives, and vd for virtio disks in virtual machines. The letters are assigned in the order the kernel discovers the devices, which can change between boots. Scripts that must refer to a specific disk should use a stable identifier such as a filesystem UUID or a label rather than the device name.

Hot plugging adds another wrinkle. A USB disk attached after boot appears in /sys/block at that moment and disappears when it is removed. A listing is therefore a snapshot of the kernel state at one instant, and a second listing taken later can differ from the first. When you see a surprising device, list again before you act on it.

Hands-on: inventory the disk

Start by listing the names the kernel knows, then compare the size that lsblk reports with the raw attribute in /sys. The raw attribute is a count of sectors, so the byte value is that number times 512. You can calculate it with shell arithmetic.

BASH2 lines
ls /sys/block
echo $(( $(cat /sys/block/wda/size) * 512 ))

The second command prints the size of the disk in bytes. It is a good habit to derive a number two ways before you trust it, because the tool you normally use may format the value for people and hide the raw figure.

Terminal lab · 3 steps · real Linux in your browser

Inventory a block device

Read the kernel view of the lab disk and save facts about it in /workspace.

01
Save the whole-disk list
The kernel lists every whole disk as a directory under /sys/block. Save the names in a file called disks.txt in /workspace, one name per line. Plain ls prints one name per line when its output goes to a file. ``bash ls /sys/block > disks.txt ``
Show hint for step 1
Use a redirect with ls. Do not type the names by hand.
02
Convert the sector count to bytes
The file /sys/block/wda/size holds a count of 512-byte sectors. Multiply it by 512 with shell arithmetic and save the result in wda-bytes.txt. ``bash echo $(( $(cat /sys/block/wda/size) * 512 )) > wda-bytes.txt ``
Show hint for step 2
The attribute is in sectors, not bytes. Multiply by 512, and use $(( )) for the arithmetic.
03
Record the read-only flag
lsblk can print the NAME and RO columns for every whole disk. Filter for the row named wda with awk, print only its RO value, and save the result in wda-ro.txt. ``bash lsblk -d -n -o NAME,RO | awk '$1 == "wda" { print $2 }' > wda-ro.txt ``
Show hint for step 3
Print field 2 when field 1 is wda. Use -d so that only whole disks appear.
Check yourself Question 1 of 4
Concept Check Unit of the size attribute recall

What unit does the size attribute in /sys/block/NAME/size count?

Recap & Key Takeaways

A block device is a flat sequence of numbered blocks; names and files come from the filesystem written on top of it.
The kernel exposes each disk under /dev and describes it under /sys/block, where size counts 512-byte sectors and ro is 1 for read-only.
A partition table is a map of where each partition starts and ends, stored at the start of the disk, and it is separate from any filesystem.
lsblk reads the same kernel data and prints the tree, the sizes, the read-only flag, and the mount points of each device.
Was this lesson helpful? Spot an issue or have a suggestion? Let us know on GitHub.
Report an issue