Disk

  • We refer to Block Devices
  • Non-volatile memory: It retains data permanently when the power is turned off
  • Random Access: It expose its storage space as a flat, sequential array of fixed-size blocks (Sectors/LBAs) that can be read or written to in any order
  • It can host a partition table
  • It cannot transfer random size data, it transfers in terms of block size

Storage

Physical Layer

  • Physical Sector
    • The smallest physical unit on the hardware (managed by the disk controller)
    • 512-bytes: Legacy hardware standard
    • 4096-bytes (4Kn): Modern standard for better efficiency
  • Disk Controller
    • The physical microchip embedded directly on the drive’s circuit board

Translation Layer

  • Disk Controller Firmware
    • The embedded software running inside the controller that manages all hardware operations
    • Intercepts logical host commands and translates them into physical electrical signals, magnetic changes, or flash states
  • 512e (512 Emulation)
    • Drives that have physical 4KB physical sectors but report 512-byte logical sectors to the OS for backward compatibility
    • This is handled by Disk Controller Firmware

Logical Layer

  • Logical Sector
    • The unit of storage used for LBA addressing between the OS and the disk controller
    • What the OS thinks the hardware sector size is
  • Block
    • The smallest logical unit used by the Operating System
    • Must be a multiple of the logical sector size
  • Cluster
    • aka Allocation Unit
    • The smallest logical unit used by the Filesystem
    • Determined during Filesystem formatting
    • Must be multiple of logical Block size
  • So the general relationship is
    • 1 Logical Sector 1 Block (OS) 1 Cluster (FS)
  • In modern computing
    • 1 Block (OS) = 1 Logical Sector = 4 KB
    • 1 Cluster (FS) = multiple of Logical Block size (commonly 4 KB up to 64 KB)
    • This rule is not followed in macOS APFS (Apple Filesystem) on Apple Silicon
      • OS Block size = 16384 (16 KB)
      • Cluster size = 4096 (4 KB)
  • Linear Block Addressing (LBA)
    • A linear addressing scheme numbering logical units sequentially from zero (LBA 0, LBA 1, etc.) to abstract away physical disk geography.
    • Naming Disambiguation: Hardware specifications use the word “Block” here as a generic term for a disk’s Logical Sector. An LBA address points to a Logical Sector, NOT an OS Block

Checking disk info

  • Windows
# Physical Sector size: "PhysicalBytesPerSector"
# Logical Sector size: "LogicalBytesPerSector"
fsutil fsinfo sectorinfo C:
 
# OS Block size
Get-Disk | Select-Object Number, FriendlyName, SectorSize
 
# FS Cluster size: "Bytes Per Cluster"
fsutil fsinfo ntfsinfo C:
  • Linux
# Physical/Logical Sector size: "Sector size (logical/physical)"
sudo fdisk -l
 
# OS Block size
sudo blockdev --getbsz /dev/sda1
 
# FS Cluster size (ext4 filesystem)
sudo tune2fs -l /dev/sda1 | grep "Block size"
  • macOS
# Physical Sector size
ioreg -r -d 1 -k "Physical Block Size" | grep "Physical Block Size" | head -n 1
 
# Logical Sector size
diskutil info / | grep "Device Block Size"
 
# OS Block size
# On Apple Silicon: 16384 (16KB) 
sysctl hw.pagesize
 
# FS Cluster size
diskutil info / | grep "Allocation Block Size"