Go Down

Topic: Don't Format SD cards with OS utilities! (Read 26252 times) previous topic - next topic

fat16lib

Always format SD cards using SD Formatter https://www.sdcard.org/downloads/formatter_4/.

NEVER format SD card with OS utilities!

Here are some examples that show what can happen.  First is an extreme case for determining free space on an SD.  This type performance hit will also be true for seek.

Time to determine free space with a properly formatted card using the SdInfo sketch.  See http://forum.arduino.cc/index.php?topic=228128.msg1648437#msg1648437 for more details on code.

Time 0.302 seconds.
Quote

millis: 302
freeClusters: 63883
freeSpace: 2093.32 MB (MB = 1,000,000 bytes)


Same card formatted FAT32 with small clusters on Windows.
34.885 seconds.
Quote

millis: 34885
freeClusters: 4033302
freeSpace: 2065.05 MB (MB = 1,000,000 bytes)


Here are results running the SdFat bench sketch on this card.  Write takes about four times longer with FAT32 and small clusters.

Properly formatted card.
Quote

Type is FAT16
File size 5MB
Buffer size 100 bytes
Starting write test.  Please wait up to a minute
Write 358.47 KB/sec
Maximum latency: 58888 usec, Minimum Latency: 84 usec, Avg Latency: 273 usec

Starting read test.  Please wait up to a minute
Read 369.19 KB/sec
Maximum latency: 1912 usec, Minimum Latency: 84 usec, Avg Latency: 265 usec


Same card formatted FAT32 with small clusters on Windows.
Quote

Type is FAT32
File size 5MB
Buffer size 100 bytes
Starting write test.  Please wait up to a minute
Write 89.43 KB/sec
Maximum latency: 117636 usec, Minimum Latency: 84 usec, Avg Latency: 1113 usec

Starting read test.  Please wait up to a minute
Read 225.44 KB/sec
Maximum latency: 1920 usec, Minimum Latency: 80 usec, Avg Latency: 437 usec


These are extreme cases but I do often see this type problem so please use this formatter https://www.sdcard.org/downloads/formatter_4/.  It will always produce the optimum format for your card.

liudr


Wow, OS formatting really isn't very helpful!


liudr

This also helps with PC reading and writing the same SD card. I have a 32GB SD card that I put in my Dell venue 8 pro. I formatted it in NTFS and the performance of my Dell's video recording was bad. I then reformatted with the formatter and now the video recording is working fine. It's just the SD card performance issue.

pylon

I do use the OS utilities to format an SD card but I use a more flexible OS -> Linux. So your advice is correct for Windows users but Linux users should use the internal command as the SD card association doesn't provide a formatting tool for Linux.

So on Linux users may issue the command:

Code: [Select]
mkfs.vfat -F 32 -s 64 -S 512 /dev/sdb1

given that the card is available as /dev/sdb on the system.
This command does the same as the formatter from the SD card association (use 32kB clusters with a FAT32 file system).

fat16lib

#6
Oct 21, 2014, 12:50 am Last Edit: Oct 22, 2014, 05:02 pm by fat16lib Reason: Add example
Quote
So on Linux users may issue the command:
Linux does not correctly format SD cards.  You can only depend on the SD association's formatter to place file structures correctly to line up with flash chip boundaries.  This is done by placing reserved blocks in the correct places in the file system.

I use Linux but not to format SD cards.

Unfortunately the SD association's standard for formatting SD cards is only available to members.  I was able to access the standard as a consultant and implemented the SdFat formatter example according to this specification.

Here are results of using mkfs.vfat, the SD Association Formatter, and the SdFat formatter
Quote
Formatted with suggested mkfs.vfat command

Volume is FAT32
blocksPerCluster: 64
clusterCount: 973729
freeClusters: 973728
freeSpace: 31907.12 MB (MB = 1,000,000 bytes)
fatStartBlock: 64
fatCount: 2
blocksPerFat: 7616
rootDirStart: 2
dataStartBlock: 15296
Data area is not aligned on flash erase boundaries!
Download and use formatter from www.sdcard.org/consumer!


Formatted with SD Associations formatter

Volume is FAT32
blocksPerCluster: 64
clusterCount: 973584
freeClusters: 973581
freeSpace: 31902.30 MB (MB = 1,000,000 bytes)
fatStartBlock: 9362
fatCount: 2
blocksPerFat: 7607
rootDirStart: 2
dataStartBlock: 24576


Formatted with SdFat formatter

Volume is FAT32
blocksPerCluster: 64
clusterCount: 973584
freeClusters: 973583
freeSpace: 31902.37 MB (MB = 1,000,000 bytes)
fatStartBlock: 9362
fatCount: 2
blocksPerFat: 7607
rootDirStart: 2
dataStartBlock: 24576


I did more tests with Linux and Windows.  I don't have a new version of Mac OS X.

Windows 7/8 does a good job of reformatting a healthy SD card.  Windows just cleans the card and preserves the correct SD format.

Windows 7/8 formats an erased SD as a super floppy but if you choose the correct cluster size, file structures are aligned well.  The SD standard is for an MBR volume so this is not strictly correct.

Mac OS X adds lot of non-standard hidden files and directories.  I have had OS X format an SD card GPT instead of MBR which is unusable on Arduino.  I don't have a machine with a new version of OS X so I can't be sure if Mac OS X still formats SD cards incorrectly.

The mkfs.vfat command suggested by pylon is the worst case.  The card is not MBR and file structures are miss-aligned.  This command will not work for standard SD cards (2 GB or less).

Go Up