Raspberry Pi SD Card Speed Test

Since we first launched Raspberry Pi, an SD card (or microSD card) has always been a vital component. Without an SD card to store the operating system, Raspberry Pi is pretty useless*! Over the ensuing eight years, SD cards have become the default removable storage technology, used in cameras, smartphones, games consoles and all sorts of other devices. Prices have plummeted to the point where smaller size cards are practically given away for free, and at the same time storage capacity has increased to the point where you can store a terabyte on your thumbnail.

SD card speed ratings, and why they matter

However, the fact that SD cards are now so commonplace sometimes conceals the fact that not all SD cards are created equal. SD cards have a speed rating – how fast you can read or write data to the card – and as card sizes have increased, so have speed ratings. If you want to store 4K video from your digital camera, it is important not just that the card is big enough to hold it, but also that you can write it to the card fast enough to keep up with the huge amount of data coming out of the camera.

The speed of an SD card will also directly affect how fast your Raspberry Pi runs, in just the same way as the speed of a hard drive affects how fast a conventional desktop computer runs. The faster you can read data from the card, the faster your Raspberry Pi will boot, and the faster programs will load. Equally, write speed will also affect how well any programs which save large quantities of data run – so it’s important to use a good-quality card.

What speed can I expect from my SD card?

The speed rating of an SD card should be printed either on the card itself or on the packaging.

The 32GB card shown below is Class 4, denoted by the 4 inside the letter C – this indicates that it can write at 4MB/s.

The 64GB card shown below is Class 10, and so can write at 10MB/s. It also shows the logo of UHS (“ultra high speed”) Class 1, the 1 inside the letter U, which corresponds to the same speed.

More recently, speeds have started to be quoted in terms of the intended use of the card, with Class V10 denoting a card intended for video at 10MB/s, for example. But the most recent speed categorisation – and the one most relevant to use in a Raspberry Pi – is the new A (for “application”) speed class. We recommend the use of Class A1 cards (as the one above – see the A1 logo to the right of the Class 10 symbol) in Raspberry Pi – in addition to a write speed of 10MB/s, these support at least 1500 read operations and 500 write operations per second. All the official Raspberry Pi microSD cards we sell meet this specification.

A new tool for testing your SD card speed

We’ve all heard the stories of people who have bought a large capacity SD card at a too-good-to-be-true price from a dodgy eBay seller, and found that their card labelled as 64GB can only actually hold 2GB of data. But that is at least fairly easy to spot – it’s much harder to work out whether your supposedly fast SD card is actually meeting its specified speed, and unscrupulous manufacturers and sellers often mislabel low quality cards as having unachievable speeds.

Today, as the first part of a new suite of tests which will enable you to perform various diagnostics on your Raspberry Pi hardware, we are releasing a tool which allows you to test your SD card to check that it performs as it should.

To install the new tool, from a terminal do

sudo apt update
sudo apt install agnostics

(“agnostics”? In this case it’s nothing to do with religion! I’ll leave you to work out the pun…)

Once installed, you will find the new application “Raspberry Pi Diagnostics” in the main menu under “Accessories”, and if you launch it, you’ll see a screen like this:

In future, this screen will show a list of the diagnostic tests, and you will be able to select which you want to run using the checkboxes in the right-hand column. But for now, the only test available is SD Card Speed Test; just press “Run Tests” to start it.

Understanding your speed test results

One thing to note is that the write performance of SD cards declines over time. A new card is blank and data can be written to what is effectively “empty” memory, which is fast; but as a card fills up, memory needs to be erased before it can be overwritten, and so writes will become slower the more a card is used. The pass / fail criteria in this test assume a new (or at least freshly formatted) card; don’t be alarmed if the write speed test fails when run on the SD card you’ve been using for six months! If you do notice your Raspberry Pi slowing down over time, it may be worth backing up your SD card using the SD Card Copier tool and reformatting it.

The test takes a minute or so to run on a Raspberry Pi 4 (it’ll take longer on older models), and at the end you’ll see a results screen with either (hopefully) PASS or (if you are less fortunate) FAIL. To see the detailed results of the speed test, press “Show Log”, which will open the test log file in a text editor. (The log file is also written to your home directory as rpdiags.txt.)

We are testing against the A1 specification, which requires a sequential write speed of 10MB/s, 500 random write operations per second, and 1500 random read operations per second; we run the test up to three times. (Tests of this nature are liable to errors due to other background operations accessing the SD card while the test is running, which can affect the result – by running the test multiple times we try to reduce the likelihood of a single bad run resulting in a fail.)

If the test result was a pass, great! Your SD card is good enough to provide optimum performance in your Raspberry Pi. If it failed, have a look in the log file – you’ll see something like:

Raspberry Pi Diagnostics - version 0.1
Mon Feb 24 09:44:16 2020

Test : SD Card Speed Test
Run 1
prepare-file;0;0;12161;23
seq-write;0;0;4151;8
rand-4k-write;0;0;3046;761
rand-4k-read;9242;2310;0;0
Sequential write speed 4151 kb/s (target 10000) - FAIL
Note that sequential write speed declines over time as a card is used - your card may require reformatting
Random write speed 761 IOPS (target 500) - PASS
Random read speed 2310 IOPS (target 1500) - PASS
Run 2
prepare-file;0;0;8526;16
...

You can see just how your card compares to the stated targets; if it is pretty close to them, then your card is only just below specification and is probably fine to use. But if you are seeing significantly lower scores than the targets, you might want to consider getting another card.



[*] unless you’re using PXE network or USB mass storage boot modes of course.

79 comments

Avatar

Hi,

is this Free Software? If yes, where can I find the code?

CU
Jens

Avatar

Just run the two lines of code given in the text “sudo apt update and sudo apt install agnostics” and it will load.

Avatar

The term ‘Free Software’ means open source. It’s a Linux thing.

Avatar

Free and Open Source are two different things.

Avatar

The word “free” in English has two subtly different meanings. Free as in speech, and free as in beer. In French, there are separate words for these: libre and gratis, respectively. Jens means free as in speech, not beer. Free Open Source Software is like this. A free download of closed source software is free as in beer.

https://en.wikipedia.org/wiki/Gratis_versus_libre

Avatar

Is there a source repo we can use if we want to contribute to it, or pull from if we want to build packages for other distributions?

Avatar

If you want the source, just get it from apt – “apt source agnostics”.

Avatar

apt info says the homepage of the package is at https://github.com/raspberrypi-ui/agnostics but this either doesn’t exist, or is private. Will it be making at appearance at some point? See my previous comments for a couple of ideas I had for minor improvements which I would like to contribute.

Avatar

We make some repos available in the raspberrypi-ui project of Github, but we do not guarantee that they will always be visible or accessible externally; it is sometimes necessary to keep work in progress confidential. The agnostics repo will probably be made accessible at some point, but it is possible that it is one of the repos which may need to be hidden from time to time, so people shouldn’t assume it will always be there.

apt should always be the primary means of access to our source code, not least because it reflects the software as actually released rather than including work-in-progress features.

Avatar

Thank you for the clarification. I’m always rather dubious about suggesting such minor changes without actually submitting a PR, as they seem a bit nit-picky, hence my query.

Avatar

good news

how about ssd direct boot on pi4

Avatar

I agree it is well overdue.

Avatar

How about keeping to the topic in hand rather than bringing up the same topic time after time on unrelated threads. When its done it will be announced. It’s not been announced in this blog post, so that means its not ready to be announced. Which means it’s not finished yet. Keeping asking for it does not make the work proceed any faster, and in some cases, just annoys the engineers enough to slow them down.

Avatar

You can use and execute from USB by booting initially from the SD card. There is a Youtube video by Andreas Spiess called Boot a pi4 with an SSD.

Avatar

direct USB-SSD boot is ready:
# hdparm -Tt /dev/sda
/dev/sda:
Timing cached reads: 1558 MB in 2.00 seconds = 779.50 MB/sec
Timing buffered disk reads: 898 MB in 3.00 seconds = 299.25 MB/sec
used howto: https://www.tomshardware.com/how-to/boot-raspberry-pi-4-usb

Avatar

cool

Avatar

Coincidentally, Explaining Computers published this related video a few days ago :-)
https://www.youtube.com/watch?v=oLQ8A_vcBqU

Avatar

Wouldn’t bonnie work as well? At least on the console?

Avatar

Piagnostics?

Avatar

Is there a command line version?

Avatar

Yes – all the tests in agnostics are shell scripts which are called from the GUI shell. Run /usr/share/agnostics/sdtest.sh from the command line.

Avatar

Incidentally that installed here with the wrong permissions – no X bit. There’s also a warning on line 34 “can only return from function or sourced script”

Avatar

That’s not actually wrong – the script is executed by the /usr/bin/agnostics binary by calling /bin/sh directly – it ignores the shebang line altogether. The shebang line in the script should probably point to /bin/sh as well, rather than /bin/bash though, or be removed altogether, since the agnostics binary ignores it. (/bin/sh on Raspbian Buster seems to be dash by default, rather than bash).

The warning is a bashism – dash doesn’t complain that the return value is ignored.

So if you want to run sdtest.sh on its own, invoke it like this:

sh sdtest.sh

Avatar

Ah, OK, thanks!

Avatar

?

Avatar

Tried to run on Raspbian Buster Lite

It started but exited with error
fio: job startup hung? exiting.

Avatar

thank you for all your helpful post!

Avatar

How to run this outside of Raspberry Pi? So I can test a few sd cards before choosing one to flash the system.

Avatar

A well established, comprehensive and free disk test for the PC world is CrystalDiskMark
https://crystalmark.info/en/software/crystaldiskmark/
It can test removable memory (SD card, USB stick, Compact Flash, XQD…) and will also give you figures for hard disk drives and SSDs, whether they’re connected via USB, FireWire, SATA or pieces of damp string.
(Spoiler alert: damp string isn’t a generally recognised interface type).
I’m not associated with the software provider.

Avatar

This is a great addition..if it fails does reformatting bring it back to a usable state. At what point should the card be thrown away? Also how large of an SD card can the pi support?
Thanks again.

Avatar

Reformatting should make a significant difference to write speed on an old card; if it doesn’t, your card has probably had it!

Avatar

I’m not sure that just reformatting will help, it will of course depend on how clever the FTL (flash translation layer) is. But I believe if you write zeros to the whole flash, it will then know that every sector is empty and therefore it’s use of free space will improve

Avatar

I’ve long noticed that heavily used SD cards in Raspberry Pis degrade their speed over time, and can vouch for a full overwrite format usually restoring them.

Using HDTUNE Free version ( https://www.hdtune.com/ ) to plot a graph of transfer speed and access time across the whole card is interesting – a good new card should have a flat line, heavily used cards will show wild fluctuations.

I usually then use the SD Card association format tool ( https://www.sdcard.org/downloads/formatter/ ) with options set to Format Type : Full Overwrite and Format Size Adjustment to ON (removes partitions!)

This can take a while as it writes zeros to the entire card, but upon re-running HDTUNE and observing the graph, a noticable improvement can usually be seen.

These tools are Windows only (HDTUNE) and Windows/Mac (SDFormat) so I would be interested in Unix and especially Pi-specific tools or scripts that perform these tasks.

Thanks for this Speed Test Tool, it’s a handy little thing!

Avatar

A lot of mixing oranges with apples here. There are two layers involved: first, the card’s own wear leveling mechanism together with its flash cell hardware. Second, the file system you’ve formatted on top of it.

For (1), no formatting in the world will make your worn out flash cells return back to factory-new conditions. If it would, we wouldn’t need wear leveling.

This brings us to (2): the file system. Unless you use FAT and then mount a kernel-supported bootable file system on top, the existing file systems do not degrade to much over time. The lazarus-like speed improvements reported here can happen only on especially degraded FAT(xx) file systems, where a clean fs performs much better than a fragmented old one.

This matches from what my colleagues here see with sd cards degrading over time and no reformatting brings them back to initial performance.

But maybe you all here want to buy this incredible electromagnetic necklace which controls your mood by playing electromagnetic sound wave files and reformatting your brain’s neurons?

Avatar

Reformatting the card may or may not bring it back to performance that meets the A1 specs. Some cards just don’t have the raw performance to begin with.

The official limit of the size of microSD cards supported by the Raspberry Pi is 32GB. The reason is that larger cards require SDXC support. Compliance with that spec requires support of the exFAT file system, which has to be licensed from Microsoft. Microsoft approved royalty-free inclusion of exFAT in the Linux kernel in 2019 and the code is now part of recent kernels, but the specifications of the Pi have not yet been updated to reflect that. (Also note that the inclusion in the kernel is not a license to use exFAT royalty-free in all cases; commercial sale of products in categories where royalties are required will still have to pay.)

Even before availability of exFAT code in Linux, the Raspberry Pi 3 and 4 already supported larger SD cards if they were formatted with other file systems such as ext4. I can personally verify that a 512GB microSD card will work in a Raspberry Pi 4, though I only tried it out to see if it would work; none of my normal uses for the Pi require that much space.

Avatar

Can you change the script to clarify the units slightly? Currently it says the sequential write is measured in kb/s, which is slightly ambiguous (could be bits or bytes). KB/sec would be a more standard way of writing that.

Avatar

I watched the video Andrew mentioned ..excellent..I am looking forward to the next video, #4 in the series where he shows the performance on single board computers..

Avatar

Could you explain the pun please?

Avatar

On RPi3B with Stretch, “sudo apt update; sudo apt install agnostics” results in “E: Unable to locate package agnostics”.

Then “wget http://rpi.rutgers.edu/archive.raspberrypi.org/debian/pool/main/a/agnostics/
tar -xvf *.xz
cd agnostics
./autogen.sh
results in “./autogen.sh: 4: ./autogen.sh: autoreconf: not found”

Me thinks to stop here and let the masters cogitate.

Avatar

It’s not in the stretch repo; only in the buster repo. We’ve not tested it on stretch; it ought to work, but we don’t have the resource to test new programs against old versions of the OS.

Avatar

I also find f2fs speeds up read/write access on SD cards. Maybe with this tool I can finally quantify this!

Avatar

Sorry for the noob question, but does writing a new disk image to the MicroSD card with Etcher make it “freshly formatted” card? That is, does it clear out the previously written data and speed the card back up? Or do we need to do a full format first, then write the disk image? Thanks

Avatar

Great news indeed! I think the article lacks a clarification: should agnotic be used on the sdcard you just installed raspbian on, or on a different sdcard (e.g. plugged into the usb port using an adapter)?

Avatar

This doesn’t appear to be in the stretch repo’s yet? Is this accidental or is this program only intended for Buster?

Avatar

Since the launch of buster, we’ve only been adding new programs to the buster repos. It’s too time-consuming to test everything on old versions of the OS; we always recommend keeping your OS up to date, unless there’s a really compelling reason not to do so.

Avatar

Is there an equivalent of TRIM to tell an SD card that a block is unused? Or do you have to write all-zeros or all FFs to a block to do that?

Avatar

Yes, the blkdiscard tool can do this (it’s called erase for SD cards). It only works with non-USB card readers (PCIe or the Pi’s reader will work).

But be careful with this tool. You can destroy data on entire drives (like SSDs or SD cards) withing seconds with this!

Avatar

Yes, a lot of SD cards support TRIM or some equivalent. fstrim should work on your SD card.

Avatar

I would suggest that the trim function may work, but it is very much SD card specific (and since trim is an MMC command, most SD cards won’t support it).

Writing zeros to the card is the best way to ‘tell’ the card that a sector is unused

Avatar

If I copy a Raspbian image to a fresh sd-card using dd, and then boot it which will then expand the root partition to fill the sd-card, would it then be sensible to do something like “dd if=/dev/zero of=/zero.bin; rm /zero.bin” to make sure all the free space is known to be free to the card?

And I suppose following on from that, would creating/deleting a “zero.bin” file be enough to freshen-up a card that’s in use?

Avatar

it is mention to use a new formated SD card.
is it only for performance reason or will the test “destroy” data on the SD card.

Avatar

will executing
sudo e4defrag /
help to increase performance on a long time used SD card or is it only relevant on mechanical HDD’s?

Avatar

Defragmentation isn’t as much of an issue with flash based devices because they have a ‘virtual addressing’ system anyway (the flash translation layer). But since the granularity of the virtual addressing (the equivalent of page size in virtual memory) is unlikely to be the same as the sector size on the filesystem then it is possible it may make a small difference.

But the biggest difference would be created by writing zeros to all unused sectors of the card…

Gordon

Avatar

Is agnostic only testing the sdcard you installed raspbian on in the sd card slot, or can it be used on a different sdcard (e.g. plugged into the usb port using an adapter)? If so, how – there seems to be no choice of what sd card to choose (I had one plugged in with a usb card reader in addition to the operating system sd card). It simply tested the sd card with the operating system as far as I could tell (pass, btw).

Avatar

It tests whatever device currently containst the directory /var/tmp. If you want to test another device, modify the relevant line in sd_bench.fio to select a directory on the device you want to test.

Avatar

I have had some problems with specifying the target directory on a SD card plugged into a USB adapter. Specifying the UID of a Dos formatted and otherwise blank disk worked and gave sensible (and good) results, but specifying one of the directories on the main partition of a Pi system copy did not – the test failed immediately with an error indicating that it could not connect to the disk. Any suggestions?

Avatar

sd_bench.fio can be found in the /usr/share/agnostics directory, along with the sdtest.sh script which executes it.

(sdtest.sh is in turn run by the /usr/bin/agnostics binary, which is the GUI app).

Avatar

Is there a CLI option to run the tool? A lot of people, including me, never use the GUI much.

Avatar

It’s quite simple

apt-get install fio -y
mkdir /usr/share/agnostics/
curl https://raw.githubusercontent.com/raspberrypi-ui/agnostics/master/data/sd_bench.fio -o /usr/share/agnostics/sd_bench.fio
curl https://raw.githubusercontent.com/raspberrypi-ui/agnostics/master/data/sdtest.sh -o /usr/share/agnostics/sdtest.sh
chmod +x /usr/share/agnostics/sdtest.sh
/usr/share/agnostics/sdtest.sh

Avatar

Well, running from SSD gave an easy PASS :)

Raspberry Pi Diagnostics – version (unknown)
Fri Mar 6 13:21:38 2020

Test : SD Card Speed Test
Run 1
prepare-file;0;0;313569;612
seq-write;0;0;313569;612
rand-4k-write;0;0;69057;17264
rand-4k-read;77557;19389;0;0
Sequential write speed 313569 kb/s (target 10000) – PASS
Random write speed 17264 IOPS (target 500) – PASS
Random read speed 19389 IOPS (target 1500) – PASS
Test PASS

… but I would like the option of testing the actual SD card (which is still there, because it’s a Pi4). Have you considered this? Thanks.

Avatar

You can read the info from Simon on the post below,
https://www.raspberrypi.org/blog/sd-card-speed-test/#comment-1523686

I have tested my usb stick by changing the parameter ‘Directory=’ in sd_bench.fio and it works.

Avatar

My SD card SanDisk gives a result of 19349 kb/s in writing which makes about 20Mo/s, is it a good performance for a class 10 card ?

Thank you in advance

A great fan of Raspberry Pi.

Avatar

* I have occasionally used a Pi zero as a micro-USB to pinheader power adapter which works best without a micro-SD-card.

Avatar

what other diagnostic tests are in pipeline?

Avatar

Thanks for this!

It would be great if there were a “Details” button after the test, to reveal in the GUI, the measured IOPS, etc, should the user be the geekier type who wants to see more than just “Pass” or “Fail”.

Avatar

Oops, I guess you do have the “Show Log” button. My bad.

Avatar

Is this package only for Buster?
I tried this with Raspbian Stretch.
Result:
E: Unable to locate package agnostics

Avatar

pushing this up …
Will it be available for Raspbian stretch?? (Raspi 3b+)

Avatar

I took a brand new Samsung EVO Select 32GB card, loaded up Raspbian (FULL). Stuck it in an RPi4B (4GB) and booted it. after answering the start-up questions I installed agnostics and ran the test – PASSED, then I did an apt-get upgrade -y, & reran the test and it FAILED. Since these steps are normal to my install procedure, I question the value of the tests. I tried other cards (cheap ones always FAILED). Now I’m ordering several different models of cards (All SanDisk) and see if I can find any that pass this simple test. OBTW the upgrade only hit 4 packages, so there was little upgrading that was done. I imagine if I wait a month or so and rerun upgrade, the test will fail misserably. So I ask… Is this test even worth running?

Avatar

OK, I had some marginal cards (well known brand, same as for my 3/27/20 posting), yet failed my basic test (1-format the card; 2-use imager to install largest version of Raspbian; 3- install/boot in an TPi 4B; run the SD speed test several times, noting the values). Now I’m confused. The marginal cards I was using for mostof my systems fail 3 or 4 times in a row, then they miraculously pass. The first test after the miracle failed on run 1, then passed on run2. I reran it again, and it passed on Run 1. Now I’m seriously doubting the value of this diagnostic, or am I the only person who’s getting erratic values???

Avatar

It sounds as if you have cards whose performance is very close to the pass/fail threshold; it’s worth looking in the log file to see exactly what results you got. In any test like this, the results are going to be variable – numerous factors impact the speed of reading and writing, from other loads on the system to whether you hit bad or good sectors on the card. Our recommendation is that if a card passes the test at least once, it’s good enough – when we run the test, we run it until it either passes or has failed three times. If a card repeatedly fails, then it’s probably bad; if it passes at least once, then it is at least capable of the speeds required; which is not a guarantee that you will always get those speeds…

Avatar

Hello,
it seems that SD Card Speed Test tests any device booted from, not only at the SD card slot. So with an empty SD slot I’ve just tested USB 3.1 flash drives and a Toshiba Hard drive after having USB-MSB boot installed. Are the test results reliable for those devices ? It would be a nice feature, when a device select would be integrated in the tool.
What does the magic 4 number sequence prepare etc. in the log mean?

Regards
Heimo

Avatar

Thanks Simon and others. This is a great diagnostic addition to the system. Given the way this test is packaged, I sense that there are more agnostics treats in the pipe.

Avatar

is there a difference between the hardware of the card reader of RPi3 and RPi4. what sd cards can the RPi 4 handle? i’m looking at a sandisk 128 extreme pro https://tweakers.net/pricewatch/1246987/sandisk-extreme-pro-128gb-microsdxc-uhs-i.html.. or is this overkill

Avatar

Where can I find instructions on how to upgrade from Stretch to Buster without losing all my working files and web pages?

Avatar

My setup leaves this one in the dust. Might be that I ran it on a Pi 4 B, booting into an SSD. Here’s the specifics:
https://docs.google.com/presentation/d/1erqr11yZ56mPvcTauow5nGDP2CsHTv0oNWImo9bFiyU/edit?usp=sharing

Avatar

I bought a U3 high speed micro sd card and speed test results:
———————
Raspberry Pi Diagnostics – version (unknown)
Fri May 22 06:02:47 2020

Test : SD Card Speed Test
Run 1
prepare-file;0;0;313569;43
seq-write;0;0;313569;48
rand-4k-write;0;0;69057;542
rand-4k-read;6146;19389;0;0
Sequential write speed 24730 kb/s (target 10000) – PASS
Random write speed 542 IOPS (target 500) – PASS
Random read speed 1536 IOPS (target 1500) – PASS
Test PASS
———————

https://amzn.to/3cnH2g8

Avatar

Hi, any similar tool for ubuntu ?

Leave a Comment

Comments are closed