Raspberry Pi 4 - Adding an SSD to improve performance and longevity

From Sensors in Schools
Jump to navigation Jump to search

The Raspberry Pi 4 provides a couple of USB3.0 ports (the two centre blue ports). These can provide much higher speeds, which is not very useful for a mouse and keyboard, but very beneficial for storage devices.

Whenever the Raspberry Pi feels slow, it's often a result of the computer waiting for IO requests to finish, and therefore the SD storage card's speed is holding up the rest of the CPU. Since 2020, there have been firmware updates to the Raspberry Pi 4 which allow reliable booting from an attached USB drive. An SSD will also last almost forever, and is more reliable than an SD card which will wear out after a number of years.

Note that the Raspberry Pi 3 doesn't have the blue USB3.0 ports, so it won't benefit as much from the speed upgrade.

The total cost for this sort of project is around AUD$75-80, less if you are able to salvage an old SSD or reuse an existing one.


A couple of notes before starting:


  • When choosing the SSD for this project, the goals are a bit different than your home PC. We don't want high power and high performance - instead we want efficient, low power and high compatibility.

The SSD best for this is a SATA-based M.2 (B+M key) (left image, above) or 2.5" SATA SSD (right image, above). SATA is the older protocol; most newer SSD's use NVMe which is faster and also more power hungry. It's possible to use NVMe drives with the Raspberry Pi, however the additional speed will be wasted as the USB3 connection is the bottleneck still. Also, since NVMe requires more power, this will create more heat, require more cooling and in some cases requires an additional USB powered hub and/or upgraded 3.5A Pi power supply in order to function. If you already have an NVMe drive you want to reuse, you can experiment to see if it will work. But otherwise, stick to a SATA-based drive instead, it's superior for this project.


  • The enclosure MUST match the form-factor (shape) and type of SSD you are using. If you're using a 2.5" drive, you need an enclosure for this shape. If you're using an M.2 drive, you need one for M.2 devices, and it ALSO needs to match the protocol of your drive (SATA or NVMe). There are some enclosures that can support both types, but often it's one or the other.
  • Even though the Pi 4 has a USB-C port, don't be tempted to use a USB-C to USB-C cable! The USB-C port on the Pi is only USB2.0 - for high speeds you need to use the blue rectangular USB port on the side.


  • The enclosure should support UASP and TRIM functionality. Not all enclosures support this! Sometimes the product page will specify this, otherwise there are some other hints that may help:
    • If the enclosure supports USB3.2 (sometimes written as USB3.1 rev.2) then it likely supports both.
    • If the enclosure specifications show the controller chip used, this can be googled to find out if it supports those features or not.


Shopping List:

  • SATA-based SSD of your choice (I chose Kingston A400M, the M.2 version, 240GB). Estimated cost: around $50 or less.
  • A matching enclosure, WITH support for UASP and TRIM functions (I chose an Archgon MSD-211 enclosure). Estimated cost: $20-30.
  • (Optional): A USB3 cable if not included with the enclosure. Mine came with it and I think most do.

  • ALTERNATIVE: Argon ONE M.2 case for Raspberry Pi 4. Holds both the Raspberry Pi 4 and an M.2 SATA SSD. Note that you still need to buy the SSD separately.

With all that out of the way, you should end up with something similar to this:


  1. (Optional, recommended) If you have a computer with a spare M.2 or SATA slot, it's best to first install your new SSD there. This will allow you to update the firmware to the latest version, which can't be done while it's in the USB enclosure.
    If using an M.2 drive, these are installed at an angle and then flattened against the spacer to be horizontal, and then a small screw is added from the top to keep it in place.


    The firmware update is done with a tool from the manufacturer - this is what the Kingston one looks like:

    In my case, the drive already had the latest firmware installed, so no updates were necessary.

  2. Switch off the PC and remove the drive, then install it in the portable enclosure.
  3. Download the Raspberry Pi imager software: https://downloads.raspberrypi.org/imager/imager_latest.exe
  4. Connect the SSD enclosure to your PC, then run the imager software.
  5. Don't choose the default OS - select "Raspberry Pi OS (Other)". Then choose "Raspberry Pi OS (64-bit)". This will install the 64-bit version instead.
  6. Select the matching USB storage device from the list (make sure to select the correct one! Disconnect other devices if you're not 100% sure). Then click "Write" and wait for it to download, flash and verify.
    If everything went well, you should see a message similar to this:
  7. Now you can unplug the SSD drive, set up the Raspberry Pi 4, plug in the SSD to one of the blue USB3 ports and then plug in the power. Attach a screen, keyboard and mouse to the Raspberry Pi and then go through the basic configuration steps.

Remember to remove the microSD card from the Raspberry Pi. The Pi needs to boot from the SSD inserted in the USB 3.0 port

Once you get to the basic Pi desktop, there are a number of configurations which need to be checked.

  1. (Optional) You can enable VNC server (Raspberry Icon -> Preferences -> Raspberry Pi Configuration -> Interfaces -> enable VNC) and set up your Raspberry Pi's IP address, then do the rest of these steps remotely over VNC.
  2. Firstly, do a full update of all software via the terminal: sudo apt update, and then sudo apt upgrade.
  3. Check UASP: Open up a new terminal and type the following: lsusb -t.
    You should see a couple of results, and one of them should show 'Driver=uas'. If this is the case, then the drive is successfully connected with UASP.
  4. Check TRIM: In the terminal, type the following command: sudo fstrim -v /. This will probably return a message of "fstrim: /: the discard operation is not supported."
    This means that TRIM isn't enabled for the drive, and is usually the default setting. If this is the case, it needs to be enabled for the drive.
  5. Check for TRIM support: Run the command lsblk -D. Have a look for the 'sda' drive, and the two columns 'DISC-GRAN' and 'DISC-MAX'. If both of these are NOT zero, then your drive is capable of TRIM!
  6. Enable TRIM support: In the terminal, type sudo su. This is a bit like a permanent version of the sudo command - everything from now on will be run as super user (admin), until you close this terminal. The command prompt should have also changed to show "root@raspberrypi".
  7. Run the following line: find /sys/ -name provisioning_mode -exec grep -H . {} + | sort. It's probably easier to copy and paste this one. You should have one result. At the end of the (very long!) line, there should be "provisioning_mode". It's likely set to "full", but we need it set to "unmap". If yours shows "unmap" already, you can skip this next step.
  8. Run the following line. Make sure you replace the long path with the one in the terminal from the previous step (leave off the ":full" but keep everything else): echo unmap > /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-1/2-1:1.0/host0/target0:0:0/0:0:0:0/scsi_disk/0:0:0:0/provisioning_mode.
  9. After running that command, run the find command again (press the up key twice in the terminal) to check that the provisioning_mode has been changed to "unmap".
  10. Now you can try running fstrim -v / again. This time it should hopefully give a different message:
  11. If you get a similar output, then TRIM is working on the drive! However when you reboot the Pi, it will revert back. To set the TRIM setting permanently, there are only a few more steps you need to do.
  12. Run lsusb in the terminal. This will list all attached USB devices. You may have a few, especially if you have a USB mouse and keyboard attached. Find the one associated with the storage drive. There are two important codes here, separated by a colon (:). Keep these handy, we will need them in the next step.
  13. Type the following in the terminal: mousepad /etc/udev/rules.d/10-trim.rules. Make sure to type it exactly as shown. Mousepad is the text editor on Raspberry Pi and it should pop up with a new, blank file.
  14. Copy and paste this line into the empty text file: ACTION=="add|change", ATTRS{idVendor}=="174c", ATTRS{idProduct}=="55aa", SUBSYSTEM=="scsi_disk", ATTR{provisioning_mode}="unmap".
  15. IMPORTANT! Change the vendor and product IDs in this line of code to match the ones from the terminal output a few steps earlier. the vendor ID is the code before the colon (:), and the product ID is the code after. They should both be 4 characters long. Close mousepad and save the file.
  16. This code will enable TRIM by changing the provisioning mode to "unmap", just like we did manually earlier. Now we just need to schedule the TRIM process to be run periodically. Type sudo systemctl enable fstrim.timer into the terminal. This will enable a weekly timer, which is the preferred way to TRIM SSDs on Linux distributions (as opposed to continuous TRIM).
  17. We're done! To test the performance, you can run the following benchmark in a terminal: sudo curl https://raw.githubusercontent.com/TheRemote/PiBenchmarks/master/Storage.sh | sudo bash. This will give your drive a performance score, and if you fill in the prompts at the end, it will be published publicly on pibenchmarks.com.

Here are my benchmarking results:

The benchmarking site incorrectly identifies my SSD as an NVMe drive, but it's not. You should get a result similar to mine if everything is set up correctly. If the number is significantly less then you should double check all of the above settings, your firmware versions and verify that you are connected via UASP.

The Raspberry Pi should now feel much more responsive and be significantly faster when updating software, loading programs, or copying files.