Boot Raspberry Pi 4 from USB 3.0 SSD

Raspberry Pi 4 is awesome for setting up personal projects and experimenting with various Linux distros! I have been hosting my personal Linux servers on Raspberry Pies for years and I always faced the same problem… corrupted filesystem on SD cards. To minimize the problem, I have been experimenting with USP boards to fight sudden power losses though, from time to time I had to repair the filesystem or reflash my SD cards.

To improve stability and eliminate the problem, it is now easier than ever to configure your Raspberry Pi 4 to boot from a USB. For this reason, in this article, we will go through the steps of configuring and botting our RPi4 from a USB 3.0 SSD.

Steps & Hardware

Before we start, let’s gather the appropriate hardware needed:

  • 1x Raspberry Pi 4 (duh…)
  • 1x SD Card to USB Adapter
  • 1x SD Card
  • 1x SATA to USB 3.0 Adapter
  • 1x SSD

There are the steps that we will take:

  1. Update Raspberry’s bootloader
  2. Burn Image on SSD
  3. First boot through USB 2.0
  4. Solving USB 3.0 problems (optional)
  5. Increase swap file

Update Bootloader

In order to easily update the bootloader of our Raspberry Pi 4, we will use the Raspberry Pi Imager. Download and install from the official Raspberry Pi site if you don’t have it already. Launch it and for the Operating System select:

CHOOSE OS > Misc utility images > Bootloader > USB Boot

Then insert the SD card into the SD card adapter and plug it into your PC. Select it under the “CHOOSE STORAGE” button and click write to flash it.

After the flashing completes, insert the SD card into your Raspberry, connect it optionally to a display, and power it up. Wait for it to update the bootloader and then turn it off and remove the SD card (we will not use it anymore).

Burn the Image on SSD & boot

Connect your SSD on your PC using the SATA to USB 3.0 adapter and using Raspberry Pi Imager, flash your operating system of choice.

After the write competes, if you are planning to run your RPi headless, don’t forget to create the appropriate wpa_supplicant.conf and ssh files inside the boot partition of the SSD.

Now you can unplug the SSD from your PC and plug it on one of your Raspberry Pi’s USB 2.0 ports. DO NOT PLUG IT ON THE USB 3.0 FOR THE FIRST BOOT. First, we will have to make sure the SSD is working as intended through the USB 2.0 port and then try booting it using the USB 3.0 port. If you get errors when using USB 3.0, check the next section on how to solve them.

Solving USB 3.0 problems

Some SATA to USB 3.0 adapters are using chips that may not support a USB 3.0 feature called “UAS” and this may result in slow transfer speeds and boot errors. You may check your adapter’s USB vendor ID and try to search online whether it supports UAS or not. After booting your SSD from USB 2.0, run lsusb to get your adapter’s USB ID. Here is an example:

pi@dinodevs:~ $ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 152d:0555 JMicron Technology Corp. / JMicron USA Technology Corp. JMS578 SATA 6Gb/s
Bus 001 Device 002: ID 2109:1234 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

If you want to do the same process offline on Windows, you can use the following Powershell command to recover the USB ID:

PS C:\Users\thanos>:~ $ Get-PnpDevice -PresentOnly | Where-Object { $_.InstanceId -match '^USB' } | Where-Object { $_.FriendlyName -match 'Storage' } | Format-List
...
DeviceID                    : USB\VID_152D&PID_0555\MSFT303812430D532111010
...

In my case, my JMicron adapter (with id 152d:0555) was not supporting UAS, thus I had to disable it so that I could get my SSD working through USB 3.0. To do so, I had to edit the boot parameters by running:

pi@dinodevs:~ $ sudo nano /boot/cmdline.txt

and editing the contents by prepending the usb-storage.quirks option listing the USB ID of our adapter. And here are the updated `cmdline.txt` contents:

usb-storage.quirks=152d:0555:u console=serial0,115200 console=tty1 root=PARTUUID=7535aa3a-02 rootfstype=ext4 fsck.repair=yes rootwait

Now, let’s sudo shutdown -h now , change the SSD from USB 2.0 to USB 3.0, and check power on the Raspberry Pi again.

You can find more info on the SATA adapter problem at the following resources:

Increase Raspberry’s swap file

Depending on the RPi version that you have, you may want to increase its swap file so that more (but slower) RAM is available to you.

First let’s stop the swap file usage temporarily by running:

pi@dinodevs:~ $ sudo dphys-swapfile swapoff

Then let’s edit its configuration and change its size from 100MB to 1024MB. Open the configuration in node:

pi@dinodevs:~ $ sudo nano /etc/dphys-swapfile

and change the CONF_SWAPSIZE=100 to CONF_SWAPSIZE=1024. You can then exit by pressing CTRL+x and accepting to save your changes by pressing y followed by ENTER.

Now you will have to recreate the swap file using:

pi@dinodevs:~ $ sudo dphys-swapfile setup

Lastly, re-enable the swap file usage and optionally reboot:

pi@dinodevs:~ $ sudo dphys-swapfile swapon
pi@dinodevs:~ $ sudo reboot

Conclusions

Booting a Raspberry Pi 4 from an SSD is now easier than ever. It improves your system’s stability and increases your Raspberry’s capabilities. One thing you should consider is to keep a backup of your important files so that extracting them from a corrupted SSD may be challenging.

Installing Gogs Git Server on Raspberry Pi

Git is a must-have utility for programmers. It allows you to track code changes and easily share your code with others enabling remote collaboration. Online git services like GitHub, GitLab, and Bitbucket are nowadays accessible for everyone, though sometimes the need to self-host a private service arises.

Gogs is an open-source git server, light enough to run on a Raspberry Pi. It is written in Go Lang and provides pre-compiled binaries for arm architectures.

In this tutorial, we will install Gogs on a Raspberry Pi 2. So, first, connect to your Raspberry, and let’s start!

Update your system

To start with, update our system and install any missing dependencies.

sudo apt update
sudo apt install wget unzip git -y

Prepare for installation

We will create a special user called git to operate the Gogs server. The following command will create the user and disable his password:

sudo adduser --system --shell /bin/bash --gecos "User for managing of gogs server" --group --disabled-password --home /home/git git

The next thing we will have to do is to download the pre-compiled Gogs package. Check the latest versions available at https://dl.gogs.io/. At the time of writing this report the latest version is 0.12.3 so we downloaded the gogs_0.12.3_linux_armv7.zip package (armv7architecture is compatible with Raspberry Pi 2, 3, and 4).

sudo su -c 'su git -c "wget https://dl.gogs.io/0.12.3/gogs_0.12.3_linux_armv7.zip -O ~/gogs_download.zip"'

After the download completes, unzip the package and then you may delete it.

sudo su -c 'su git -c "unzip ~/gogs_download.zip -d ~/"'
sudo su -c 'su git -c "rm ~/gogs_download.zip"'

Start the server

Now let’s setup the Gogs service to manage the server. Download the service script from the Gogs repo:

sudo wget https://raw.githubusercontent.com/gogs/gogs/main/scripts/systemd/gogs.service -O /lib/systemd/system/gogs.service

And then, enable the service and run it.

sudo systemctl enable gogs
sudo service gogs start

Follow the web installer

Now browse to the installation located at http://<your-raspbery-ip>:3000/install and complete the installation steps.

Setup your Argon One as a server

Argon One is one of the best Raspberry Pi cases, it combines decent cooling, easy access to the GPIO pins, and power button, and an awesome design.

By default, the built-in fan is inactive and the device does not automatically boot when plugged in power. Ideally, when running your Raspberry Pi as a server, you expect it to reboot after a blackout. For this, let’s go through some configuration on our Raspberry Pi to control to control the Argon One case for our server.

Installing Argon Config

The first thing to do is to install get and run the argon1.sh which installs a utility that helps us configure the case’s fan:

curl https://download.argon40.com/argon1.sh | bash

I also uploaded the script on GitHub as a Gist here in case the argon40 website is offline. Now the argonone-config command should be available on your system.

Configuring Argon’s Fan

If you want to change the fan behavior at a later time, you will be able to use the argonone-config command. Here is an example setting Fan to always on:

thanos@dinodevs:~$ argonone-config
--------------------------------------
Argon One Fan Speed Configuration Tool
--------------------------------------
WARNING: This will remove existing configuration.
Press Y to continue:y
Thank you.

Select fan mode:
  1. Always on
  2. Adjust to temperatures (55C, 60C, and 65C)
  3. Customize behavior
  4. Cancel
NOTE: You can also edit /etc/argononed.conf directly
Enter Number (1-4):1

Fan always on.
thanos@dinodevs:~$

By following the printed instructions you will also be able to configure a custom fan behavior.

Configuring Power & Power Button Behavior

The next step is to change the behavior of the case when plugged in so that our device boots automatically. To do that we have to run:

i2cset -y 1 0x01a 0xfe

To restore the power behavior back to the default one, where you have to press the power button for the device to boot, you can run:

i2cset -y 1 0x01a 0xfd

If for any reason you want to uninstall the argonone utility, run:

argonone-uninstall

So now you know how to set up your Raspberry Pi with the Argon One case as a server!

Argon One HDD / SSD case extender

Argon One is one of the best cases for the Raspberry Pi. It features a metallic body on the top that is also used as a heatsink and it also has a built-in fan.

Raspberry Pi 4 in Argon One case extended with model A2

Since I am planning to use Raspberry Pi as a NAS, I designed an HDD/SSD case extender compatible with the Argon One. The expansion features an opening to mount 2.5′ HDD or SSD drives with the ability to hot-swap drives!

Features:

  • The base is attached to the stock screws.
  • HDD to USB link is achieved with a simple SATA to USB 3 cable (the board is stripped from its casing).
  • 3 different versions are provided:
    • Model A: 12.5mm height drive (2.5′ HDD)
    • Model B: 9.5mm height drive (2.5′ HDD/SSD)
    • Model C: 7.0mm height drive (2.5′ HDD/SSD)
  • 2 different drive arrangements are provided:
    • Model 1: slot from the front with SATA-2-USB board support
    • Model 2: slot from the back
Available models

The models can be downloaded from: https://www.thingiverse.com/thing:4639316

The models have been designed with Rhino and have been test printed in Ender 3 (print with supports).

Ender 3 printing the case