It’s been nearly a year since I ordered the parts to build my first Raspberry Pi project, the Raspibolt Bitcoin and Lightning node. Unfortunately, the availability has been decent at best. I often have trouble ssh-ing into it and the entire terminal freezes up and needs to be forced closed. Because things steadily got worse over spring, I thought it might have been a temperature problem and I ordered these cute little fans. Sadly they didn’t seem to do a whole lot.
One way to improve performance and reliability is to swap out the HDD I’ve been using for an SSD. I’ve been thinking about upgrading from the old HDD I just happened to have lying around to a shiny, new, and very compact SSD for a while now – the only problem is the price. It’s true that they are cheaper than ever now, but a 1TB SSD will still put you back about $100. However, after experiencing availability issues for the better half of a year, a $100 upgrade seemed appropriate.
What to buy
Here’s something they don’t tell you, an internal hard drive + a case = an external hard drive. You can save about $50 by purchasing these two separate items and assembling it yourself. A friend recommended the Sandisk SSD Plus (thanks Alex!) which I paired with this Sabrent hard drive enclosure. For the hardware illiterate, hard drives come in standard sizes so if you buy a 2.5″ hard drive, it will fit into any 2.5″ case.
The case I bought came with a USB cable but if you buy one that doesn’t you’ll obviously need to get one. Sadly the Raspberry Pi 3 only supports USB 2.0 port, making that a bottleneck in terms of speed but note that the newly released Raspberry Pi 4 does have USB 3.0 ports!
As far as power supply goes, the Pi is able to provide up to 1.2A total to external devices, or about 6W (1.2 A * 5V). According to the Amazon reviews, as well as a few other sites, an SSD needs anywhere from 0.5W to 3W so the Pi should have no problem powering the SSD.
Safely removing the old HDD
For the Raspibolt, you’ll first want to shut down LND, then bitcoind. After that, you can unmount the device. Find it using the fdisk -l
command, then unmount it with umount /path/to/drive
. It should now be safe to power off the HDD and unplug from the pi.
Copying the contents of the old HDD the new SSD
Copying the old HDD to the new SSD was a lot easier than I thought it would be. You actually don’t have to format the new SSD at all or do any kind of initialization which is awesome because those steps can be confusing.
UNIX’s dd command
dd
is a handy UNIX command that can be used to convert and copy files – be careful because it’s powerful. If you accidentally execute the wrong command you could end up writing to the wrong drive, thus erasing all you data. To accurately identify the drives, plug the drives into your computer one at a time, starting with the source drive that has the data you want to copy from (in my case this is the HDD).
After the first drive is plugged in, run diskutil list
(Mac) or fdisk -l
(Linux) to find it. Based on the size, I was able to identify the first drive as /dev/disk4
on my machine:
/dev/disk4 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: *1.0 TB disk4
Now do the same thing for the drive you want to copy the data to, the destination drive. Once you have identified both drives, you can prepare the dd command:
dd if=/path/to/source/drive of=/path/to/destination/drive bs=64k conv=noerror,sync
Remember, it is absolutely critical that the if
and the of
parameters are accurate. As for the other parts of the command,
bs
corresponds to the block size. This is set because the default is very small, 512k. Feel free to experiment with other values. It’s a trade off between speed and reliability. If you are using Linux, this parameter need to be tweaked to use an uppercase ‘K’:64K
.conv=noerror,sync
is “used to continue after read errors and to pad out bad reads“. This is important because if any read errors are encountered, data will be skipped, and that could corrupt the whole drive. This option ensues that every byte is copied to the same physical location.
Here’s what my command looked like:
sudo dd if=/dev/disk4 of=/dev/disk5 bs=64k conv=noerror,sync
Checking on the status of the copy
That dd
command above is what I ran, but it wasn’t until later that I realized I wanted to check up on the status of it. In terms of monitoring, this command is not going to provide very much information. Once it is executed there isn’t any feedback sent to the console and the only indicators that something is happening are the flashing lights on the hard drives. However, there is one useful command for checking the progress, CTRL+T
. If you do this from the same terminal that dd
is running in, you will see something like this:
load: 5.44 cmd: dd 50339 uninterruptible 77.13u 7267.59s
11531528+0 records in
11531528+0 records out
755730219008 bytes transferred in 38891.695338 secs (19431660 bytes/sec)
Other monitoring options: status and pv
While I can’t speak to these personally, I want to mention there are a few other options that can be added before executing the dd
command. First is status=progress
:
dd if=/path/to/source/drive of=/path/to/destination/drive bs=64k conv=noerror,sync status=progress
This should continually output the status as data is copied.
Another option is pv
, or ‘Pipe Viewer’ which will do the same. It can be inserted right in the middle of the dd
command:
dd if=/path/to/source/drive bs=64k conv=noerror,sync | pv | dd of=/path/to/destination/drive
How long does it take?
The amount of time it takes is going to depend on the disk size and speed. For me, it took about 12 hours to copy a 1TB drive with 300GB of used space. I did not partition the drive because I want to keep the unused space available for the growing Bitcoin blockchain. dd
will copy unused disk blocks so, if you can partition it will save a lot of time.
Final steps
The last thing to do is safely remove the drives and start using the new one:
To remove each drive:
umount /path/to/drive
- Power the drive off
- Unplug it from the computer
To start using the new SSD:
- Plug it into the Raspberry Pi
- Turn the SSD on
- Use
fdisk -l
to find it and mount it:mount /path/to/drive /destination/folder
- Start the services back up (bitcoind and then LND)
And that’s it! The SSD is now an exact replica of the old HDD and business can continue as usual. The rpi now has increased speed and reliability, and is more energy efficient 🎉