I like many who visit this sub-forum, do so because they, or a program they used, formatted their USB stick at some point - afterwards noticing a substantial decrease in write performance on the drive. You can fix this by aligning the FAT32 file system to the 128K "blocks" or "cells" that flash memory uses. After much trial and error, and not being an expert in file systems, I was able to read up on the subject and figure out how to align my file system on the drive. The tools you need to perform these operations should be readily available in most any Linux distribution - don't let that scare you away, you can burn a Linux install CD and boot off of it to perform all of these commands without even needing to install Linux on your computer, for any that support a "Live CD" or "Try First before Install" feature, for instance Ubuntu is a popular distro that supports this feature. People who already understand aligning partitions, but want to align a FAT32 format to the aligned partition, can learn how in Step 3.
Following this procedure will destroy all contents on your USB stick, back up important files BEFORE starting - you have been warned.
Step One: Identify the drive and the device
Insert the stick into your computer after booting into Linux. Most distributions will automatically mount
the file system currently on the drive. Mounting is like when Windows detects your drive and gives it a drive letter, same thing. Linux does not use drive letters, instead it uses a system of folders, which is much cleaner and more organised. Depending on your distro, you fill most likely find the drive mounted under /media/USBstickname
. Many distros will name the folder of the USB stick whatever the volume label was set to, i.e. "Patriot" for a stock formatted USB stick.
Next, open a terminal window if you are using a GUI, most modern Linux will be using a GUI, if you need this HOWTO: then you probably will be using a GUI. Find Terminal or Command Line or similar on the menus.
using the command df
, which stands for 'disk free' we can see our drives free space, but it is also a convenient way to find the device name and mount point for our drive. It is important to identify the proper disk here
; you don't want to format your hard drive now do you?
We will use df
with a option, -h
- this will produce so-called human readable information, in terms of Gigabytes and Megabytes, and not just long strings of bytes. Lets try:
username@computername:~$ df -h
Produces the following display: (simplified here)
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 78G 37G 37G 50% /
/dev/sdd1 15G 2.3G 13G 15% /media/MultiBoot <<< My USB Drive
Here we can see a few key things:
- My USB device is /dev/sdd (/dev/sdd1 is the first partition of /dev/sdd)
- My drive is mounted at /media/MultiBoot
- The drive size is reported as 15G, which matches up to my Patriot Xporter XT Boost 16GB
This is all the information we need to move on to the next step.
Step 2: Unmount and prepare the partitions
First we unmount the drive, so that we don't have any files open and we can modify the drive at will.
username@computername:~$ umount /media/MultiBoot
If the command is a success, it will return you to the prompt without saying anything usually.
Note:Now we can use a cool program called fdisk to modify the partition table on the usb drive - this is sometimes referred to as the Master Boot Record or MBR for short, although technically, the partition table is only one part of the entire MBR itself. fdisk is a powerful and somewhat advanced program, but don't let that scare you: the worst that could happen is you could inadvertently destroy the contents of your entire hard disk(s) in your computer if you are not careful. As long as you pay attention to what you are typing, and don't blindly type in commands without understanding what each command does, you are in little danger.
If you had a drive window open in the GUI with the files on the USB showing, it will close, or sometimes change to another path, since you just removed the path it was using.
Why are we changing partitions? Formatting doesn't usually change partitions!
We are, because the standard partition table that Patriot has used is not 'aligned', at least not for our purposes. For instance, I checked my friends stock Patriot USB drive and it was quite 'odd' and none of the units lined up to a 128K boundary. To make our jobs easier, we will align the drive from the ground up so to speak, so that we KNOW where everything is while lining up data on our disks.
Please read The Ted Ts'o article on SSD alignment
before you start, so you can understand a bit of what it is we are doing here! He has more information in there about LVM and EXT4 file systems, which we won't be using on a USB stick (we could use EXT2/3/4 on a stick if it is for Linux use ONLY)
A neat trick is to make our heads and sectors per track line up by using 224 heads and 56 sectors per track. A USB stick is not a hard drive and it does not have sectors, tracks, OR heads - but it pretends to be a hard drive, and so, it has a drive geometry just like any hard drive would. This geometry business of heads/sectors/tracks and so on has no physical relationship to actual physical properties on our USB stick, it just helps to make a convenient way to talk about how data is organised on the drive. Note that there are other combinations that also make 128K alignment easy, but this is the one mentioned in several SSD and flash articles around the web. You will get different speed results by using different geometries, so if you are the inquisitive type, try several and see what you like best.
Understand the "Sector"
The sector is something that you need to understand to proceed. It is the lowest or smallest size chunk of a disk that you access at the lowest levels while doing these things we are doing. A sector holds 512 bytes of information (very small). This small paragraph contains 372 bytes of information, and would just fit into one sector of a disk!
We will be using sudo
along with fdisk
in order to give the program 'super user' or in Windows speak 'admin' privileges. Sudo will often ask you for your password to continue.
user@host:~$ sudo fdisk -H 224 -S 56 /dev/sdxxx
That command does:
- sudo: use admin rights
- fdisk: start the fdisk partition program
- -H 224 : set the heads geometry to 224 heads
- -S 56 : use 56 sectors per track
- /dev/sdxxx : the device we wish to change, in this case you fill in the xxx with your device from step one.
The command will display something similar to:
[sudo] password for username:
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): p
We type 'p' at this prompt to display or 'print' the current partition table: You may want to type 'm' here so you can see a listing of all commands available in fdisk. Here's an example of 'p':
Disk /dev/sdd: 16.0 GB, 16030629888 bytes
224 heads, 56 sectors/track, 2496 cylinders
Units = cylinders of 12544 * 512 = 6422528 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x9a8001cf
Device Boot Start End Blocks Id System
/dev/sdd1 * 1 2496 15654784 c W95 FAT32 (LBA)
Command (m for help):
Your display will be different, this shows a drive that has already been configured for the 224/56 alignment.
You will need to perform the following steps in fdisk:
- Delete the existing partition
- Create a new partition that starts at cylinder 1 and ends at the end of the disk
- Mark the partition as a FAT32 (LBA) partition type, which is hex type "0x0C".
- Enter expert mode and change the beginning of data to sector 256. (Sector 256 x 512 bytes/sector = 128K (131,072 bytes)
- Return from expert mode and write the changes to disk.
- Press q to quit at any time while in fdisk before writing your changes if you feel uncomfortable or don't understand what you are doing.
I don't want to provide a step by step here, since it would be too easy to just blindly type it all in and mess something up. Read, learn and understand what you are doing before you jump in! Research fdisk (man fdisk) and get to know the program. It's easy, but it takes a little learning to grasp the concepts. The information above will guide you easily along once you know fdisk.
Once you have written the changes, your partition table is aligned and you can begin formatting...
It seems someone deleted the 2nd post with the critical information about the FAT32 alignment process!