33
Format a 512e drive to 4096 on Linux
(piefed.blahaj.zone)
From Wikipedia, the free encyclopedia
Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).
Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.
Community icon by Alpár-Etele Méder, licensed under CC BY 3.0
TL;DR: Everything should work well with default settings, no special actions required.
First of all, partitions must be aligned to sector size (multiples of 4096). Most partitioning tools align partitions to 1MiB by default nowadays, so this shouldn't be a problem, however if the disk is already partitioned, check the partition offset. For ext4, as well as most modern filesystems, default block size is 4KiB, so you don't need to pass optional parameters to
mkfs. Forcryptsetup luksFormatthere are also two things that must be set correctly:--align-payload(2048 512-byte sectors by default, equal to 256 4096-byte sectors, no need to change), and--sector-size(for 512e device it should be set to 4096 bytes automatically, no need to set manually).Sweet! I feel this kind of "proves" Seagate's stance, in other words, that a quick format will suffice, since most tools these days defualt to 4096 byte sectors. Although one has to read between the lines a bit...
Thanks for your help!
Except for leaving things default, almost none of that comment is true.
4k is default for most disks today. Some transition-era ssds used 8k blocks.
Do not worry about emulated block size, because ssds only use that to report to the filesystem, no sectors exist on solid state media.
Well SSDs have flash pages, which are essentially sectors as they are the smallest unit you can read/write, and they're usually 4096 bytes on NAND flash. My understanding is to write to a flash page you have to erase the whole block of 32+ pages before writing, so if a 512e SSD doesn't receive the rest of the page in time (e.g. with IO scheduling, 512 byte fs sectors, unaligned partitions, or bad luck), then the controller has to do a read-erase-program across the whole block of pages (although wear leveling will probably read + copy the modified page to elsewhere instead), instead of just a single program operation on one page (assuming a properly trimmed SSD).
So IMO, 4Kn is more important on SSDs, yet every vendor sets 512e by default. Luckily quite a few NVMe SSDs (not Samsung), let you change the logical block size with an nvme format command.
But more related to the OP, HDDs are a lot slower and don't have to erase multiple sectors before a write, so it's not as important, however partition alignment is still important but usually handled automatically in every modern partitioning tool. Sometimes you can switch a HDD to 4Kn with
hdparm, but this isn't common, and you've said your HDD is dead anyway, so it won't help.Also, sorry about bringing you into this, I have strong opinions against 512e SSDs haha.
I think we're talking past each other here: You are talking about blocks as physical delineations in an ssd, containing many pages with erase cycles. Op is talking about the filesystem view of blocks, which is different altogether. ZFS, for instance, should have its block size aligned with what a disk presents to the HAL, or you end up with lots of wasted space or terrible performance.
For SSDs (you're right, outside op's problem), the internal block size is usually much bigger than the emulated block size, often 128K. But we don't use filesystems with 128K block sizes, or we couldn't reasonable run databases or store small files.
There was a brief time in the wild west of SSDs being new where some shipped with 8k blocks, but this caused a bunch of problems for storage drivers because no one had yet decided if the translation of FS blocks to should be handled by filesystems or by disk firmware. We now let manufacturers decide how they should r/w to media, and trust the firmware's presented block size.
That block size is now 4k for most disks, spinning or ssd. We still see some weird layouts in high-performance or high-endurance disks, but they are exceptions.
I'm not sure what this means, pages are a concept in an ssd's physical structure, they don't mean anything to a filesystem (except in volatile memory).
Although this post is about an HDD 🫣
Edit: but if I can leave things at default and not touch
hdparmeither REGARDLESS, I'm happy 🤣