Linux Filesystems, Part 1 – Block Device and Filesystem

It explains how files are split into blocks and how the filesystem acts as an abstraction layer between files (seen by applications) and blocks (physically written on disks). It also says why disks are called block devices.

1.1 Splitting Up Files Into Blocks

A block device is a storage media, like a hard disk. You can use ‘blkid’ and ‘fdisk -l’ to show a list of block devices attached to your system.

In the following example, ‘sda’ is a disk with 2 partitions ‘sda1′ and ‘sda2′, and ‘sr0′ is a compact disc.
A filesystem can be created on a partition and also on a whole partitionless disk, as both partition and disk are valid block devices.

  /dev/sda1: UUID="5b0e4487-b5aa-4186-81fd-f561308f4cf1" TYPE="swap"
  /dev/sda2: UUID="ec851750-9854-4227-8898-d5695dbd297e" TYPE="ext3"
  /dev/sr0: LABEL="VBOXADDITIONS_4.2.16_86992" TYPE="iso9660"

fdisk -l
  Disk /dev/sda: 12.9 GB, 12884901888 bytes
  255 heads, 63 sectors/track, 1566 cylinders, total 25165824 sectors
  Units = sectors of 1 * 512 = 512 bytes
  Sector size (logical/physical): 512 bytes / 512 bytes
  I/O size (minimum/optimal): 512 bytes / 512 bytes
  Disk identifier: 0x000be060

  Device Boot Start End Blocks Id System
  /dev/sda1 2048 786431 392192 82 Linux swap / Solaris
  /dev/sda2 * 786432 25165823 12189696 83 Linux

In order to use the hardware efficiently and to increase the addressing limit the disk read and write operations are not processing the data byte by byte. Instead these operations are using a larger unit called a block (also called a sector), which is usually 512 Bytes.

Read more