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.
ls /sys/block
cat /sys/block/wda/size
cat /sys/block/wda/roThe 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.
lsblk
lsblk -d -o NAME,SIZE,RO,TYPEIn 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.
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
wda 254:0 0 24.1M 1 disk /run/kw-lower/kw/distroThe 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.
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.
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.