The disk read speed is good enough, but the write speed is not so good. That's because most of NAND flash drives (the most commonly used flash sticks) have 128k erase block size. Filesystems usually have 4k (4096 bytes) block size. And here we came into problem. If the filesystem blocks are not aligned to flash drive blocks, the performance overhead during disk writes will increase. So what we can do is to align filesystem properly. The best way to do this is to use 224 (32*7) heads and 56 (8*7) sectors/track. This produces 12544 (256*49) sectors/cylinder, so every cylinder is 49*128k.

# fdisk -H 224 -S 56 /dev/sdb

Now turn on expert mode with fdisk and force the partition to begin on 128k alignment. In my case I have set new beginning of data to 256. Create as many partitions as you need (I created only one - /dev/sdb1).Do not forget to save changes and write new layout to flash drive (all data on the flash disk will be lost)Now it's time to create the filesystem. I used ext4 because there is a way to tell it to specify a strip width to keep your filesystem aligned:

There are some quirks to do this under Windows XP. Take a look into the nice guide http://www.ocztechnologyforum.com/forum/showthread.php?48309-Partition-alignment-importance-under-Windows-XP-%2832-bit-and-64-bit%29-why-it-helps-with-stuttering-and-increases-drive-working-life

Also I didn't consider that for precise test we need to append `sync` mount option. This option disables write cache buffer. Moreover, today's tests show me extremely good performance with ntfs file system having 64k cluster size and aligned the same way as mentioned in the article (basically it is the same flash drive). Take a look at these values:

What I don't understand is why you haven't made the cylinder size 128K, eg:

# fdisk -H 32 -S 8 /dev/sda

If you start with cylinder 1 the partition will be at the first track: 4K, if you start at cylinder 2 or later the track will start at a multiple of 128K. You can leave the first cylinder (erase block) empty as now, or put an unaligned filesystem as partition 1.

Could you please explain what you are doing with the number of heads and sectors? Why are you changing them? Are you trying to get track size to be the same as the filesystem block size?

And what does the number of heads mean? I know it does not mean physical heads, but what does it mean? Is the track size derived from total disk capacity divided by number of heads divided by number of cylinders divided by number of sectors per track?

@Alex: Read "heads" as "tracks/ cylinder" in the computer outputs and explanations. Now re-read the third paragraph of the blog above that begins with:

"The disk read speed is good enough . . . "

and ends with:

". . . 49*128k."

Key concept is: "Adjusting disk geometry of flash drive to multiples of the 128k NAND flash erase block." The 4k OS read/ write size IS bound by disk geometry parameters, and the 128k erase block size IS NOT. This way any 4k write operation will be within one 128k erase block.

You have 16065 sectors/ cylinder total, which is8225280 bytes/ cylinder. 8225280 bytes is not evenly divisible by 128k (= 128*1024bytes): Actually, 8225280/ 128k= 62.753... You can't even begin to "align" the 4k read size to the 128k erase block size in this case.

I want to know the exact difference between cylinder and erase block.In the above article heads(---*7),from where that '7' factor comes from? help me at gokhalesushant65@gmail.com because I m in the final yr of engg. and we are doing project related with the usb.Also help me with the different articles if possible

Make sure you have the "sync" option ommited for flash drive mounts. There are two major disadvantages with the "sync" option on flash drives.1. It will do more erase/write cycles on your flash drive reducing its lifetime2. It will be very slow to write in to the flash file system (sometimes more than 100 times slower) because it keeps writing/re-writing sectors.

1. For the read-test you use "/dev/sdb" and for the write-test "/media/disk/test". Am I correct that this should also be /dev/sdb ?2. Shouldn't people be warned NOT to run dd on a stick containing data!?!?3. Can you explain a bit more about the fdisk/expert/begin partition please? Do I first create the partition and then hit 'x' for expert and then change to..... what? My default states 2048, do I change that to 256? Is that the same for every size stick?4. I tried this and the outcom is exactly the same speed.

Are you really serious with this "guide"? It's really impossible to repartitioning and reformating every USB stick I can use ;) Some of them doesn't belongs to me and I use them to write some data to anyone else... Why the Windows (2k,xp,++) can write 8-10 times faster than Linux? Linux have serious problem with USB sticks - yeah! it is unusable... I had hope that it will be fixed soon, but waiting about 5 years with no advance.Yes i tried all these tricks with ehci and others, sync and async options but still no change. My writing speed on flash disks is about 400kB/s - various HW with linux - the same poor results.Using the same HW with Windows work fine. But any other work in windows is much worse than in linux. Writing to SSD card in my (Samsung) mobile connected via USB is almost instant. Cannot find any difference in mounting parameters. It is much faster to burn data to DVD than copy data to flash disk. That's really poor and sad...

I have Kingstone DTSE9 32G usb stick and I've installed an linux operating system on it (Debian Wheezy) ... my question is what I can do to improve writing speed cause is really bad. A simple menu browse will cause system hang and it is simply unusable as hard drive.

I try to format like this tutorial said but with no success. I will very appreciate any help or an "step by step" noob tutorial :)

You should really try to use aufs on top of your rootfs in case you're using usb stick for Linux distribution. Try to read this article https://help.ubuntu.com/community/aufsRootFileSystemOnUsbFlash and see if it helps.

Your guide suggests measuring write speed by writing from /dev/urandom However, on a fast drive (e.g. USB3 or if one is testing an internal drive) the random number generator can become a bottleneck. On my machine it maxes out at 14 megs a second. It's best, therefore, to use /dev/zero as the source. e.g. dd if=/dev/zero of=tempfile bs=1M count=1024 conv=fdatasync,notrunc

Using /dev/zero to test is actually a bad idea (usually*), as filesystems such as ext4 will store files full of zero using "sparse blocks", meaning that they don't actually write the data to the disk. (Instead, they will just write a small amount of data saying, effectively, "this is a 2GB file full of zeros".) This is why John above observed such a fast write speed with /dev/zero -- because it wasn't actually writing the data.

I'd suggest running dd count=100 bs=1M if=/dev/urandom of=/dev/null and checking how fast it goes -- if your drive is slower than this, then you should be right with urandom for input. Otherwise, I'd suggest that the next best bet is to create a 100MB file on a fast storage device (another flash drive?) and use that as the input file, so that you're not generating the randomness on-the-fly.

* Of course, if you're using an older/simpler filesystem such as FAT32, that doesn't support sparse blocks, then using /dev/zero is not a problem.

I've tested this out, and found that at least with Ubuntu 12.04, following these steps gives no speed increase compared to just creating and formatting the partition with gparted. I also found that the stripe_width parameter to mke2fs didn't make any noticeable different to write speed for me.

In fact, I'm not sure that making these changes should even in principle speed up your drive. While it's true that flash drives use large (eg 128k) erase-block sizes, my understanding is that they still write data in sector-sized blocks (512 bytes), and therefore aligning your partition to 128k will not make a difference to write speeds, at least on a fresh drive. It should only make a difference when the drive starts deleting blocks of data, which only happens once the drive gets full. (And even then, partition alignment has very little to do with the speed.)

So I don't think that following these steps will actually make your drive any faster. My suspicion is that the only reason the OP found that his drive ran 2x faster than before, is because he changed the filesystem from FAT32 to ext4, and ext4 is a much faster filesystem than FAT. (Or, at a minimum, the linux ext4 driver is faster than the linux VFAT driver.)

Postscript: I think I've confirmed this theory. I reformatted with FAT32 on the exact same disk I was testing on before, and found that my write speed went from ~ 7MB/s down to ~ 4.4MB/s. So, moral of the story: if you want it to work faster (at least under Linux), reformat it with ext4 instead of FAT32.

For testing with random data, just store the data in memory (eg a very small ramdrive.) To keep it noob-friendly, I'd say just run from a live CD distro and you're pretty much starting up essentially with a ramdrive right off. You don't need a huge file anyway. Probably just 100MiB is sufficient for performance testing. This eliminates the CPU bottleneck without having a dependency on the host media being fast enough to properly test.

On the subject of FAT32, let's not forget that the default format parameters are wrong. In particular it seems you generally need 32K cluster sizes from what I understand, but the best thing to do purportedly is to format it with the Panasonic SD formatter (which of course is Windows only.) Before testing its speeds, try that. As far as aligning things properly goes though, if nothing else it might help decrease the actual number of erases and therefore improve the lifetime of the memory card.

BTW, it seems most people feel that turning off journalization is the way to go for the best performance. Though honestly, I think it depends on what you're doing with it. For operations where the data on it is unimportant (say videos thrown onto a card to watch later for instance) performance might be the most important. But for more important stuff the compromise might be necessary. I think this could also be impacting people's results though potentially as it increases the bottleneck somewhat.

Ok, so I'm trying to make ext4 work as well as possible with SDHC cards and I ran across this. There are a few things I'm wondering though. Firstly, it says "Now turn on expert mode with fdisk and force the partition to begin on 128k alignment. In my case I have set new beginning of data to 256." How do you know exactly what number to put in? Do we just put 256 for anything, or does it vary? And I'm assuming you mean the "b" command in expert mode. Most of us don't exactly use the expert mode options in fdisk very much though (in fact, this is the first time ever that I've seen anything using it.) I'm hoping I can use this to optimize for the Raspberry Pi especially because it so foolishly uses multiple partitions with one being FAT32 and another being Linux-based rather than just one single partition (I guess they chose FAT32 for the sake of being friendlier towards Windows users, but that's kind of silly no matter how I look at it since directly booting Windows on a Raspberry Pi is quite beyond impossible and any Windows users are still going to have to ultimately learn how to use Linux a little bit...) This made it impossible for me to find a way to make the actual Linux partition properly optimized. To this end, I'm guessing when doing the second partition you need to align it as well, but I'm not really sure how to do that (yeah, I don't mess with fdisk much as far as actually aligning things. It's usually just creating and deleting partitions really.)

Is this enough though? I originally was trying to figure out how to do what this article describes: http://blogofterje.wordpress.com/2012/01/14/optimizing-fs-on-sd-card/ Unfortunately, the flashbench command just tells me "invalid argument" and I'm beginning to suspect that the -a command was removed within a very very short time after that article was written (the last commits say two years ago, so the project is kind of dead I guess) though oddly the readme still shows using the -a command first thing... (But I'm not 100% sure if it's that or maybe something else. For instance, you'll note that they are using /dev/mmcblk0 which means an integrated card reader system. Unfortunately, you can't really do all this stuff on the Raspberry Pi since it runs from its SD card reader, so I have no clue how to od it that way. Perhaps you have to access the device a certain way for it to work and it won't accept stuff like /dev/sdb though?) Anyway, it seems the point of that article is that the erase boundary could be different depending on the card. Is there any other way we can find out and adapt the partitions to reflect this on a standard PC without a memory card reader built into the motherboard directly (which would likely break legacy compatibility quite a lot anyway)?

thx for the tutorial.im a new user too on ubuntu.but not the first time.im not sure to try this because too many mistake i made since using ubuntu.i will looking for other information about this tutorial on another.