Linux – How to correctly partition usb flash drive and which filesystem to choose considering wear leveling


Two problems. First one: how to partition the flash drive?

I shouldn't need to do this, but I'm no longer sure if my partition is properly aligned since I was forced to delete and create a new partition table after gparted complained when I tried to format the drive from FAT to ext4.

The naive answer would be to say "just use default and everything is going to be alright". However if you read the following links you'll know things are not that simple: and

Then there is also the issue of cylinders, heads and sectors. Currently I get this:

$sfdisk -l -uM  /dev/sdd
Disk /dev/sdd: 30147 cylinders, 64 heads, 32 sectors/track
Warning: The partition table looks like it was made
   for C/H/S=*/255/63 (instead of 30147/64/32).
For this listing I'll assume that geometry.
Units = mebibytes of 1048576 bytes, blocks of 1024 bytes, counting from 0
Device Boot Start   End    MiB    #blocks   Id  System
/dev/sdd1         1  30146  30146   30869504   83  Linux

$fdisk -l /dev/sdd
Disk /dev/sdd: 31.6 GB, 31611420672 bytes
255 heads, 63 sectors/track, 3843 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00010c28

So from my current understanding I should align partitions at 4 MiB (currently it's at 1 MiB). But I still don't know how to set the heads and sectors properly for my device.

Second problem: file system.

From the benchmarks I saw ext4 provides the best performance, however there is the issue of wear leveling. How can I know that my Transcend JetFlash 700's microcontroller provides for wear leveling? Or will I just be killing my drive faster?

I've seen a lot of posts on the web saying don't worry the newer drives already take care of that. But I've never seen a single piece of backed evidence of that and at some point people start mixing SSD with USB flash drives technology.
The safe option would be to go for ext2, however a serious of tests that I performed showed horrible performance!!!

These values are from a real scenario and not some synthetic test:

42 files: 3,429,415,284 bytes copied to flash drive
original fat32: 15.1 MiB/s
ext4 after new partition table: 10.2 MiB/s
ext2 after new partition table:  1.9 MiB/s

Please read the links that I posted above before answering. I would also be interested in answers backed up with some references because a lot is said and re-said but then it lacks facts.

Thank you for the help.

Best Answer

Don't worry about cylinders, heads and sectors and only ever work with sectors. The easiest way to align the filesystem is to simply not have a partition table (i.e. create the filesystem on /dev/sdX directly). Most Linux systems will handle this fine, but Windows will freak out and you also won't be able to make it bootable. If you need a partition table, work out how many 512 byte sectors make up an erase block. Erase blocks are around 128-512KiB so if you can't find out what your flash drive uses go with 1024 sectors. Make sure that partitions start on a multiple of this number.

You also want to tell ext2/3/4 about the erase block size so it can avoid unnecessarily modifying blocks. Set both stride and stripe-width to the number of filesystem blocks which make up an erase block, so working on a 512KiB erase block use the following:

mkfs.ext4 -b 4096 -E stride=128,stripe-width=128

In terms of performance, not having a journal should improve performance (but increase the chance of data corruption if operation is interrupted). However, ext4's extents should improve performance because less metadata needs to be modified for large files. I would probably use ext4 with the journal disabled:

tune2fs -O ^has_journal
Related Question