LinuxXIII · Disks and Block DevicesSectors and alignment
Sector sizes and partition alignment - 512n, 512e, and 4Kn
What you'll learn
- Distinguish logical sector size, physical sector size, and filesystem block size
- Read a device topology with lsblk, blockdev and sysfs
- Explain the read-modify-write penalty on a 512e device and what misalignment does to it
- Verify partition alignment with parted align-check
- Recognise the failures that appear when a filesystem moves between 512-byte and 4K-sector devices
Prerequisites
Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-11
“Sector” means two different things and the difference is the whole lesson. There is the unit the kernel is allowed to address, and there is the unit the media can actually read or write. When those two numbers differ, every write smaller than the physical unit costs a read first - and a partition that starts in the wrong place makes every write smaller than the physical unit.
The symptom is not an error. It is a disk that delivers a fraction of its rated write throughput, on a host nobody has touched in two years.
Three numbers, three layers
| Number | Set by | Reported as | Typical |
|---|---|---|---|
| Logical sector size | The device firmware | LOG-SEC, blockdev --getss | 512 or 4096 |
| Physical sector size | The media | PHY-SEC, blockdev --getpbsz | 512 or 4096 |
| Filesystem block size | mkfs | blockdev --getbsz, tune2fs -l | 4096 |
That gives three device classes:
- 512n (native) - logical 512, physical 512. Old spinning disks and most virtual disks.
- 512e (emulated) - logical 512, physical 4096. The majority of enterprise SATA and SAS drives shipped in the last decade. The drive accepts 512-byte writes and internally performs a read-modify-write cycle on the 4096-byte sector that contains them.
- 4Kn (native 4K) - logical 4096, physical 4096. No emulation, no penalty, and a set of compatibility problems instead.
$ lsblk -o NAME,SIZE,TYPE,PHY-SEC,LOG-SEC,MIN-IO,OPT-IO,ALIGNMENT,ROTANAME SIZE TYPE PHY-SEC LOG-SEC MIN-IO OPT-IO ALIGNMENT ROTA
sda 1.8T disk 4096 512 4096 0 0 1
├─sda1 1G part 4096 512 4096 0 0 1
└─sda2 1.8T part 4096 512 4096 0 0 1
nvme0n1 3.5T disk 4096 4096 4096 262144 0 0
mpatha 10T disk 4096 512 65536 524288 0 0Illustrative output
The same values come from sysfs, which is where scripts should read them because the column names have changed over lsblk versions and the sysfs paths have not:
$ grep . /sys/block/sda/queue/logical_block_size /sys/block/sda/queue/physical_block_size /sys/block/sda/queue/minimum_io_size /sys/block/sda/queue/optimal_io_size /sys/block/sda/alignment_offset/sys/block/sda/queue/logical_block_size:512
/sys/block/sda/queue/physical_block_size:4096
/sys/block/sda/queue/minimum_io_size:4096
/sys/block/sda/queue/optimal_io_size:0
/sys/block/sda/alignment_offset:0Illustrative output
The read-modify-write penalty
A 512e drive cannot write 512 bytes. Nothing can - the media works in 4096-byte units. When the kernel sends a 512-byte write, the drive reads the enclosing 4096-byte sector into its buffer, patches 512 bytes of it, and writes all 4096 back.
That is fine, because Linux filesystems use 4096-byte blocks and issue 4096-byte writes. As long as those blocks line up with the drive’s physical sectors, one filesystem block write is one physical sector write and the emulation costs nothing.
Misalignment breaks the line-up. If the partition starts at sector 63 - the old MBR cylinder convention - then filesystem block 0 starts 63 × 512 = 32256 bytes into the disk, which is not a multiple of 4096. Every 4096-byte filesystem block now straddles two physical sectors:
The 1 MiB convention
Every current partitioning tool starts the first partition at LBA 2048 - one mebibyte in. That number is not about 4K sectors specifically; it is chosen because 1 MiB is a multiple of every alignment anyone cares about: 4096-byte physical sectors, RAID chunk sizes up to 1 MiB, and SSD erase blocks.
$ sudo parted /dev/sda align-check optimal 11 alignedCheck every partition rather than assuming the first one is representative - a disk repartitioned in stages can have one aligned partition and three that are not:
for n in $(lsblk -no PARTN /dev/sda | tr -d ' '); do
printf 'partition %s: ' "$n"
sudo parted -s /dev/sda align-check optimal "$n"
done
When sector size stops being a performance question
Moving a filesystem between devices with different logical sector sizes is a correctness problem, not a tuning one.
XFS records its sector size in the superblock at mkfs time,
and it cannot be mounted on a device whose logical sector size
is larger than that value. An XFS created on a 512-byte-logical
disk and then presented on a 4Kn device fails to mount:
XFS (sdb1): device supports 4096 byte sectors (not 512)
mount: /srv/data: mount(2) system call failed: Function not implemented.
The image is intact. The filesystem is fine. It simply cannot be addressed on that device. There is no in-place conversion - the fix is to recreate the filesystem with a matching sector size and restore into it, which means this must be discovered when the replacement hardware is specified, not during the restore.
The same shape of problem appears when a device-mapper or LVM stack combines devices with different logical sector sizes: the resulting device takes the largest logical block size of its members, so adding a 4Kn PV to a volume group full of 512-byte PVs can change the block size seen by filesystems that were built against the smaller one.
Stripe geometry on RAID and SAN
MIN-IO and OPT-IO are how a RAID device advertises its
geometry. mkfs.xfs queries the block device for sunit and
swidth automatically when the device reports them, and
mke2fs sets stride and stripe_width from the same source.
The case that needs attention is the device that reports
nothing - OPT-IO of 0 on a LUN you know is striped. The
controller is not passing the geometry up, so mkfs has nothing
to auto-detect, and the filesystem is laid out as if the device
were a single disk. Supply the values from the array
documentation instead:
# chunk 64 KiB, 8 data disks: su=64k, sw=8
sudo mkfs.xfs -d su=64k,sw=8 /dev/mapper/mpatha
# the ext4 equivalent, in filesystem blocks of 4096 bytes:
# stride = 65536/4096 = 16, stripe_width = 16 * 8 = 128
sudo mkfs.ext4 -E stride=16,stripe_width=128 /dev/mapper/mpatha
Both of those create a filesystem and destroy whatever was on
the device. Run them only against a LUN you have confirmed is
empty, by its WWID rather than by its /dev/mapper alias.
Knowledge check
Knowledge check · 4 questions
Q1. lsblk reports LOG-SEC 512 and PHY-SEC 4096 for a disk. What kind of device is it and what does that imply?
Q2. Which of these are read-only ways to inspect sector geometry on a live host? Select all that apply.
Q3. An XFS filesystem created on a device with 512-byte logical sectors cannot be mounted on a device with 4096-byte logical sectors.
Q4. A legacy host has its first partition starting at LBA 63 on a 512e drive. What is the correct response?
Passing score: 75%. Answers are checked in this browser.