Upgrade Raspberry Pi 4 with an SSD drive

May 28, 2023
SSD drive surrounded by rubber duckies

SD cards can fail when used in a Raspberry Pi. Failure isn’t an option for me, since I use my Raspberry Pi 4 to run my smart home. In my older Raspberry Pi 2, the SD card failed and my whole smart home went offline. That was painful. To avoid making the same mistake again, I upgraded my Raspberry Pi 4 to use an SSD drive to improve improve reliability and speed, resulting in a more stable and responsive smart home.

I put off the upgrade for a long time because it seemed like a lot of work to figure out. In this post I hope to save you some time by outlining the things I bought and the setup procedure. I hit some speed bumps along the way, so I’m documenting my workarounds here for my future self and you.

Buying an SSD drive for the Raspberry Pi

You have two options here, an internal SSD drive or NVMe drive. Let’s look at the pros and cons of each.

NVMe drive2.5” SSD driveNotes
Max read speed3500MB/s500 MB/sSD card in Pi = ~2MB/s

RPI 4 doesn’t have a PCIe lane, will not be able to achieve max speed of either drive.
Cost for 500GB£27.99 
Crucial P3 500GB M.2 PCIe Gen3 NVMe
£23.75
Kingston A400 SSD Internal SSD 2.5” SATA Rev 3.0 480GB
Accessories required£18.53
UGREEN M.2 NVMe SSD Enclosure, USB 3.2 Gen 2 10Gbps NVMe External Enclosure, Aluminum Tool-free Hard Drive Enclosure Support UASP & TRIM, NVMe Pcie Adapter for M and M&B Key

£9.51
StarTech.com SATA to USB Cable – USB 3.0 to 2.5” SATA III Hard Drive Adapter – External Converter for SSD/HDD Data Transfer (USB3S2SAT3CB)
Total cost£46.52£33.26
Prices stated from Amazon UK on 28th May 2023

I bought the 2.5” 480 GB Kingston SSD drive with the StarTech USB 3 to SATA adapter. I’m not recommending any of the products above, just making a comparison and letting you know what I chose – the lowest price option.

Notes:

  • The Kingston drive does support UAS, but does not support TRIM.
  • The adapter you choose is important. Lower quality ones will require you set set up ‘quirks’ – because they’re not 100% compatible with the RPI 4 – which further limits the speed of the drive.
  • There isn’t much difference in the price between the two options. Choosing the NVMe drive might make sense if you plan to upgrade to a different setup later because you can repurpose the memory.

Configuring the Raspberry Pi to use the SSD drive

Presuming your Raspberry Pi is up and running, you need to connect to it and alter the boot order of the device. This means it’ll try to boot from the USB-attached SSD drive before trying to use the SD card.

ssh pi@192.168.0.2

Note: Your username and IP address may be different.

Update your OS:

sudo apt update && sudo apt-upgrade

Update your bootloader

Sudo raspi-config

Select Advanced options

Select bootloader version

Select latest

Press esc a few times to exit

Sudo reboot

Sudo rpi-eeprom-update

If an update is available, install it.

Sudo rpi-eeprom-update -a

Sudo reboot

View your eeprom configuration:

Sudo rpi-eeprom-config

Edit your eeprom config

sudo -E rpi-eeprom-config --edit

sudo reboot

Make sure your boot order is listed as above.

The boot order is read in reverse. 

4 means try usb 3

1 means try sd card

F means start over.

You want 0xf14 so it tries this order: USB3, SD, start over.

Cloning the SD card

There are several ways to clone your SD card. If your Raspberry Pi is already up and running you’ll need to decide if you want to clone it while it is running or not. It is not recommended to clone the SD card while it is running in your Pi. I totally ignored this and upgraded a live system. I’ll outline both approaches below so you can choose.

Cloning a live SD card

There are two approaches here. To be on the safe side, I stopped all docker containers. I don’t run anything outside of a docker container.

1. Use rpi-clone

I tried this, but it didn’t work for me. I suspect because by SD card had only 10% free space on it.  You can watch this video to see how to clone the card via rpi-clone.

sudo apt install git

git clone https://github.com/billw2/rpi-clone.git

cd rpi-clone

Sudo cp rpi-clone rpi-clone-setup /usr/local/sbin

lsblk

sudo rpi-clone sda 

sudo reboot

IMPORTANT: When you run sudo rpi-clone sda make sure SDA is your external drive or you may overwrite the wrong drive.

2. Use the SD card copier in raspbian.

This is the approach I ended up using. I had to connect the raspberry pi to a keyboard, mouse and monitor. 

Using the menu, find the SD card copier app

Select the SD card as ‘copy from device’

Select the SSD drive as the ‘copy to device’

Check the box for ‘new partition UUIDs’

Start

After waiting a little while the drive will be copied. 

sudo reboot

Cloning a not-in-use SD card (recommended)

Grab yourself another machine. Connect the SSD drive and SD card.

Follow these commands:

lsblk

to list your drives

Mirror the SD card to the SSD drive:

sudo time dd if=/dev/sdb of=/dev/sdc bs=1M

IMPORTANT: Make sure your if=/dev/XXX location is your SD card and your of=/dev/xxx location is your SSD drive, or you might accidentally overwrite the machine you’re using to do the migration. That would be bad.

Resolving errors

SSD Drive is only working in usb2 port

If you have a cheaper USB to SATA adapter, it may not work un the USB3 (blue) slot. It may only work in the USB2 slot. To resolve this you need to set up ‘quirks’. Follow these steps:

sudo dmesg | grep usb

You’ll see something like this:

[    2.141242] usb 2-2: New USB device found, idVendor=174c, idProduct=55aa, bcdDevice= 1.00

[    2.141264] usb 2-2: New USB device strings: Mfr=2, Product=3, SerialNumber=1

[    2.141279] usb 2-2: Product:  SA400S37480G

[    2.141293] usb 2-2: Manufacturer: KINGSTON

Make a note of the idVendor and idProduct

sudo vim /boot/cmdline.txt

At the start of the file add:

 usb-storage.quirks=xxxx.yyyy.u

Replace xxxx with the idVendor and replace yyyy with idProduct. For example

usb-storage.quirks=174c.55aa.u console=serial0,115200 console=tty1 root=/dev/sda7 rootfstype=ext4 fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles

the mmc1 controller never released inhibit bit(s) boot error

The raspberry pi gets stuck and shows the following error on the screen. 

mmc1 controller never released inhibit bit(s)

Unplug the SSD drive and boot from the SD card.

Once the device has booted, plug in the SSD drive.

sudo lsblk 

Look for the line which reads:

-sda7 8:7    0  444G  0 part /media/pi/root

Remmber the first part ‘sda7’ in this case.

sudo vim /media/pi/boot/cmdline.txt 

This edits the cmdline.txt file on the SSD drive. Make sure you do not edit the file on the SD card, which is located at /boot/cmdline.txt.

Once the file is open look for root=/dev/mmcblk0p7 or something along those lines. Edit the value with the one we got in the previous step:

root=/dev/sda7
:wq 

to save and close the file in vim.

For good measure, you can also edit the fstab file.

sudo vim /media/pi/etc/fstab

You will see the following:

proc            /proc           proc    defaults          0       0

/dev/mmcblk0p6  /boot           vfat    defaults,flush    0       2

/dev/mmcblk0p7  /               ext4    defaults,noatime  0       1

# a swapfile is not a swap partition, no line here

#   use  dphys-swapfile swap[on|off]  for that

You will want to edit the values with the ones you found when you ran lsblk. These are the values for root and boot.

Your file might look like this after editing

proc            /proc           proc    defaults          0       0

/dev/sda6  /boot           vfat    defaults,flush    0       2

/dev/sda7  /               ext4    defaults,noatime  0       1

# a swapfile is not a swap partition, no line here

#   use  dphys-swapfile swap[on|off]  for that
sudo reboot

Note: My device still doesn’t boot if the SD card is not in the device. So I’ve left it in. It gets mounted as an external storage.

Testing the Raspberry Pi with SSD drive

OK let’s test our setup.

sudo lsblk

You can see that sda6 and sda7 are set as / and /boot. This means we’re using the SSD drive via USB.

You can also see that mmcblk0p6 and mmcblk0p7 are mounted in the /media directory as external storage. This is actually a useful state if you want to grab any files from the old system.

Now let’s test the speed!

 dd if=/dev/zero of=/tmp/test7.bmp bs=1048576 count=500

Our new drive is giving us 281 MB/s which is about 100x faster than the SD card was.

We’re done! Running Home Assistant, Zigbee2MQTT, Node Red and more is already feeling a lot snappier than it did on the old SD card.

By Chirag

I'm a Product Manager here on products like this. On this site, I share what I know about product management, technology (especially home automation), productivity and travel. I don’t claim to be an expert. Take what I say with a pinch of salt. I hope I can learn from you too. If you find a better way to think about or do something, please let me know!

Related Articles

No Results Found

The page you requested could not be found. Try refining your search, or use the navigation above to locate the post.

Like this post? I can email you when I post something new

0 Comments