Search
Close this search box.

How to migrate Raspberry Pi SD card to a USB SSD + SpeedTest

You’ve probably heard that SD cards have a limited lifespan. And running your RPi on not so reliable piece of hardware gives you worries. Well, it did to me too.
So I needed to resolve this issue.
How? I’ve migrated the whole SD card to a USB3 thumb drive as part of a quick backup solution.
And then I migrated the whole pi to a new SSD drive which I deemed to be reliable enough.
And as a bonus, I’ve measured the write speeds of these types of drives for you.

Welcome!

In this guide I’m going to show you how to seamlessly migrate your Raspberry Pi from an SD card to a USB thumb drive and or to a solid state drive. And you will see the difference in write speeds on these drives.

 

Steps:

For starters let me show you write speed on the stock Raspberry Pi’s SD card.

				
					dd if=/dev/zero of=/tmp/speedtest1.img bs=20M count=5 oflag=direct
				
			

Basically, this will create a dummy file just to measure how quick the write was.

  • bs = block size
  • count = number of these blocks
  • oflag = direct means it will write directly to medium avoiding using cache as much as possible

 

You will probably be able to achieve something around 10 MB per second write speed.

Well now, how to migrate our pi to a USB thumb drive without the need to reinstall everything from scratch? Even without the need to turn off the pie, back it up somewhere else, and restore it to a new medium?

We’ll use a script named rpi-clone from GitHub user billw2. Thank you for this.

We’ll need git to get it:

				
					sudo apt install git
				
			

Now clone the script to your Raspberry Pi:

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

Change directory to this new folder and copy the scripts to /usr/local/sbin

				
					cd rpi-clone
sudo cp rpi-clone rpi-clone-setup /usr/local/sbin
				
			

List your block devices to see what are you working with:

				
					lsblk
				
			

You see mmcblk0 is the name of the sd card on Raspberry Pi. We want to migrate everything from this disk to a new destination, for now just to a USB thumb drive. If you wonder how difficult this can be it’s easier than you think.

Go ahead, attach your USB drive to your rpi. And run lsblk once again.

				
					lsblk
				
			

You see there’s a new drive with designation sda – that’s our thumb drive

So we want to clone our SD card to this new drive. We do that with a simple command:

				
					sudo rpi-clone sda
				
			

The script will probably ask you to initialize and clone to the destination disk SDA. Answer Yes and Skip the system label with Enter.

Wait a while to finish the cloning process and after that just power off the Raspberry Pi with 

				
					sudo poweroff
				
			

Disconnect power to your Raspberry Pi. Remove the sd card from your Raspberry pi, and let only the USB drive be attached.

And power up your rpi again.
If everything went according to plan your pi will boot up from the USB thumb drive and you can connect to it just as before.

The migration is done.

 

So now you can boot up from a USB thumb drive and let’s check the write speed again:

				
					dd if=/dev/zero of=/tmp/speedtest2.img bs=20M count=5 oflag=direct
				
			

I was able to achieve speeds around 32MB/s and that’s just USB 2.0 on Raspberry Pi 3. So about 3 times faster than with an sd card.

 

But by now we’re only halfway through. We want to use our SSD, or solid-state drive, to be used in Raspberry Pi.
We will attach it to Raspberry Pi in a USB case.

And migrate our pi once again.

Let’s check our devices:

				
					lsblk
				
			

Attach your SSD drive in a USB case to your rpi. lsblk again.

				
					lsblk
				
			

You see, there should be shown a new drive named SDB – our SSD drive. We want to migrate to this device. Easy enough, run the clone command once more:

				
					sudo rpi-clone sdb
				
			

Wait for the process to finish cloning and after that turn off the Pi.

				
					sudo poweroff 

				
			

Disconnect the power supply to Raspberry. Detach the USB thumb drive a let only the SSD drive connected to your rpi. On rpi4 preferably to usb3 port – the blue one. 

 

Power up your rpi and if you’re lucky and have a good USB case for your SSD drive you’re done. Everything works fine.

“Quirks”:

But not everyone is this lucky, like me. I was cheap on that SSD case and that caused me a little bit of headache.

My SSD drive was not working reliably. Better to say, it wasn’t working at all in USB3 ports. But it did work fine on USB2 ports.

You can imagine – that isn’t good enough. After some digging around I found the explanation and solution to this.

The issue here is that some USB cases for SSD drives do not support UAS, which is an abbreviation for USB-attached SCSI.

Lucky enough, there is a solution to this.
After you attach this kind of device to your Raspberry Pi running from sd card, USB thumb drive or any other device run this command

				
					sudo dmesg | grep usb 

				
			

and look for lines similar to these:

				
					[    2.146302] usb 1-1.4: new high-speed USB device number 3 using xhci_hcd
[    2.327810] usb 1-1.4: New USB device found, idVendor=152d, idProduct=1337, bcdDevice= 5.08
				
			

You’ll need those idVendor and idProduct strings – copy or save them somewhere.

Now we need to edit /boot/cmdline.txt and add so-called quirks to the beginning of that file.

				
					sudo nano /boot/cmdline.txt
				
			

At the start of the line of parameters, add the text
usb-storage.quirks=aaaa:bbbb:u where

aaaa=idVendor 
bbbb=idProduct.

For me, the string looked like this

usb-storage.quirks=152d:1337:u

Save the file.

Now you can start your Raspberry Pi with only your SSD drive attached to USB3 and it should start up just fine.

Check the write speeds again.

				
					dd if=/dev/zero of=/tmp/speedtest3.img bs=20M count=5 oflag=direct

				
			

Even with Quirks enabled on Raspberry Pi 4 and USB3 the write speed I achieved for somewhere around 226MB/s which is much much faster than anything before.

According to USB3 specifications, without quirks with a high-quality drive and case, your writing speed could be reaching numbers close to 600MB/s.

 

I think that’s quite a big step forward regarding the reliability and speed of your Raspberry Pi setup.

That’s it for today. Now you know how to live clone your Raspberry Pi. Hope it helped!

If you find these guides at least a little bit helpful please do check out my YouTube channel.

Share the Post:

Related Posts