By default a Raspberry Pi boots from a microSD memory card. The microSD card will contain the Raspberry Pi 4 OS, required programs and data. A Raspberry Pi frequently reads and writes to the microSD card as for example the Linux based Raspberry Pi OS logs information to many log files and a lot of applications use a database to read/write information.
As microSD cards were not designed for frequent read/writes and hence are less reliable it is recommended to use a SSD, with the additional benefit of a read/write speed increase.
This article describes how to boot the Raspberry Pi 4 from a SSD instead of booting from the microSD card.
The following is required:
- Working Raspberry Pi 4
- microSD card (16GB or more)
- Laptop or desktop computer for VNC remote desktop access or SSH access to the Raspberry Pi 4
- PuTTY software for remote SSH access.
- Teamviewer software for Windows
- Teamviewer software for Raspberry Pi
The microSD card is only used to install the Raspberry OS on the SSD and will be removed when finished as we will boot the Raspberry Pi 4 from a SSD.
As SSD we use in our case a Samsung 2.5: 512Gb SATA3 SSD originating from an old Windows laptop. See article “Setup and configure a Geekworm NASPi v2.0 Raspberry Pi 4 case” for installing this SSD in a Geekworm NASPi v2,0 case. Other options are connecting a external SSD to the Raspberry PI USB port.
We will install the Raspberry Pi 4 such that we do not need a monitor/keyboard and hence can remotely access it.
3. Background details
This section gives more detailed background information which is handy to know before the installation/configuration steps are given how to boot the Raspberry Pi 4 from a SSD.
3.1 microSD cards
The microSD cards were not designed for frequent read/write operations in mind and hence this might impact the long-term reliability of a Raspberry Pi based system. This does not say you cannot use microSD cards, but you need to be aware it might suddenly fail somewhere in future.
Reliability is also depended on the microSD card brand bought. Buy microSD cards from brands like Sandisk or Samsung and not from cheaper brands as these are less reliable. Kingston for example does not manufacture the chips themselves, but buys from (cheaper) third parties. Sandisk (together with Toshiba) and Samsung design & manufacture the microSD cards themselves.
Be aware Linux has write caches to speed up file operations, so to prevent data corruption never just unplug power from the Raspberry Pi as you may lose the information in the write cache that has not yet been written to the microSD card.
Positive aspects of microSD cards are:
- Fits in the Raspberry Pi 4 microSD card slot
- Small so the footprint of your Raspberry Pi 4 remains small also
- Does not consume an USB port like other options
- Easy setup
Negative aspects of microSD cards:
- Low speed compared with a SSD (in real life around 40 MBps versus >150 MBps)
- Less reliable
- Raspberry Pi and the story of SD card corruption
- All about SD card / microSD card health on the Raspberry Pi
It is possible to boot the Raspberry Pi 4 from a SSD, for example a 2.5″ SATA SSD or a NVME SSD. The benefits are:
- Reliability as SSD’s are designed for frequent read/writes
Raspberry Pi 4 firmware supports USB boot. You can easily boot your favorite operating system on your Raspberry Pi 4 from a USB HDD, SSD, or a USB thumb drive instead of the traditional microSD card.
1) Cheaper Storage; USB HDD or USB SSD is cheaper than the same capacity microSD card. So, the cost of storage can be reduced.
2) Faster Boot Time; USB SSDs are a lot faster than the traditional microSD card. The operating system will boot faster from a USB SSD than a traditional microSD card.
3) Longevity; USB SSD or USB HDD has a much longer lifespan than a microSD card. There is a lower chance of hardware failure compared to a microSD card. Again, a USB SSD or USB HDD can handle heavy I/O workloads, unlike a microSD card.
3.2 Install 32- or 64-bit Raspberry Pi 4 OS?
There is a 32- and 64-bit Raspberry Pi 4 OS available. The 64-bit version was released as a beta in May 2020. Which one to install?
Benefits of 64-bit Raspberry Pi 4 Operating System:
- Improved performance (25% or more) as it leverages the full power of the 64-bit CPU
- Better use of the memory available as 32-but is limited to 4GB, while the 64-bit OS can use more RAM if available (for example on the Raspberry Pi 4 with 8GB RAM).
Drawbacks of the 64-bit OS:
- There might still be some bugs, but should normally work without any issues.
- Specific applications which don’t have a 64-bit build available cannot be installed.
So it’s a matter of figuring out if the applications you want too use are available for the 64-bit Raspberry Pi 4 OS. In our case the purpose of the Raspberry Pi 4 with 8GB RAM was to be used as a dedicated web server hosting multiple websites controlled via Webmin and Virtualmin. So we we decided to install the 64-bit OS.
3.3 Remote access (headless display)
It is possible to connect the Raspberry Pi 4 to a monitor, mouse and keyboard, but we will from the start access it remotely. This is also called headless display.
To configure a headless Raspberry Pi 4 it is essential that before first boot a default username and password has been set and SSH is enabled. Nowadays this can be done when writing the Raspberry Pi OS image to a microSD card with the Raspberry Pi Imager.
To access the Raspberry Pi 4 from a Windows desktop we will use the PuTTY software. So please make sure this is installed.
4. Installing Raspberry Pi 4 OS
Since April 2021 the Raspberry Pi OS versions have the necessary changes built-in to boot from a SSD. We will start from scratch, i.e. install a fresh Raspberry Pi 4 OS which will boot from the SSD and hence the microSD card is not required anymore.
These setup will be such that the Raspberry Pi 4 looks for a USB boot device, if not found it will boot from a micro SD card (if inserted).
4.1 Install bootloader USB
Follow the next steps:
- Download and install Raspberry Pi Imager from the Raspberry Pi website.
- Insert a spare microSD card into your computer. Note that this card will be erased.
- Launch the Raspberry Pi Imager and select “Operating System”
Scroll down to Misc Utility Images and select it
Select USB Boot. This will return us to the main menu
- Click on the “Chose storage” button and select the micro SD card. Double check that you have the right drive selected before proceeding!
- Click on the “Write” button and confirm to download and write a bootloader configuration image to the microSD card. When done remove the card from your computer.
- Insert the micro SD card into your Raspberry Pi 4 and power on. The green activity light will blink a steady pattern once the update has been completed. If you have an HDMI monitor attached, the screen will go green once the update is complete. Allow 10 seconds or more for the update to complete, do not remove the micro SD card until the update is complete.
- Power off the Raspberry Pi and remove the micro SD card.
4.2 Write the Raspberry Pi 4 OS to a microSD card
The next step is to install the Raspberry Pi 4 Operating System. On the microSD card just used we will write the Raspberry Pi 4 OS image. As explained earlier we will install the 64-bit OS.
- Start the Raspberry Pi Imager again and follow the steps a-b as indicated in the figure below.
a. Select “Raspberry Pi OS (other)” and then “Raspberry Pi OS (64-bit)”
b. Select the correct microSD card under storage.
DO NOT click the Write button yet!
- Click on the advanced settings icon
- The advanced options give the opportunity to make some Raspberry Pi 4 OS settings on forehand:
a. Set the hostname
b. Enable SSH (with password authentication); required for remote access
c. Set a default username and password
d. If used configure wireless LAN (WiFi)
e. Set timezone and keyboard layout
The other settings are for the Raspberry Pi Imager itself.
Note: If you use the Advanced Options menu in the Raspberry Pi Imager to configure your Raspberry Pi OS installation then the configuration wizard that normally runs on first boot will be skipped.
- Save the settings and click on the Write button and confirm.
4.3 Start the Raspberry Pi 4
Before further configuration can be done remotely the Raspberry Pi 4 needs to be started with the just create Raspberry Pi OS image on the microSD card.
- Insert the micro SD card into your Raspberry Pi 4 and turn the power on. It will take some minutes to boot/start the Operating System. This may take a little longer as the Raspberry Pi is looking for USB boot devices. But normally within a few minutes it should have started.
- Via your router figure out the IP address the Raspberry Pi 4 is using. In our case the IP-address is 192.168.1.51.
4.4 Setup remote access via Teamviewer
We will now make remotely contact with the Raspberry Pi 4 via SSH by making use of the WIndows PuTTY software to configure remote access via Teamviewer.
- On your Windows computer start PuTTY and configure a SSH connection:
- Click on the “Open” button to open the terminal window and enter the default username and password as defined earlier for the Raspberry Pi OS.
- Before we install Teamviewer we make sure the Raspberry Pi 4 is up to date by following the steps below:
a. Assure packages are up to date by using the commands:
12sudo apt update -ysudo apt full-upgrade -y
When updating the packages is finished reboot your Raspberry Pi 4:
b. Check if there is a new firmware available (distributed version, not the beta):
1sudo apt dist-upgrade
If a firmware update was available and installed, please reboot:
12sudo apt autoremovesudo apt clean
- Download the Teamviewer software package from their server:
1sudo wget https://download.teamviewer.com/download/linux/teamviewer-host_armhf.deb
- Install Teamviewer:
1sudo dpkg -i teamviewer-host_armhf.deb
Multiple dependency errors will be displayed. Fix these with the following command:
1sudo apt --fix-broken install
TeamViewer installation will be completed and should now be up and running on your Raspberry Pi. It will automatically start at each reboot.
- Reboot the system:
- Before you can access the Raspberry Pi from a TeamViewer client, we will first have to configure a Teamviewer password required to get remote access to the Raspberry Pi 4. Warning: Do net enter a password longer then 12 characters as this won’t work!
1sudo teamviewer passwd <password>
Wait till OK is displayed in the terminal window. Make sure you keep this password secure as it will allow someone access to your Raspberry Pi if they manage to get your TeamViewer ID and password.
- Retrieve the TeamViewer ID for your Raspberry Pi 4 via:
1sudo teamviewer info
- Copy the Teamviewer ID shown (select or double-click it and then right mouse button or Ctrl-C to copy) :
- Open Teamviewer on your Windows computer and click on “Add remote computer”. Enter the ID copied above and the password used in step 7. Give a name in “Alias” and select the a group and hit OK.
Your Raspberry Pi is now connected to your Windows Teamviewer.Note: sometimes the connection is refused without a clear root cause. If this happens search the web for possible solutions.
- Teamviewer remote connections with a Raspberry Pi 4 are very slow unless the VNC server on the Raspberry Pi 4 has been enabled. This can be enabled via the Raspberry Pi Software Configuration Tool. Start it via:
Select “Interface Options”.
Select “Yes” to enbale the VNC Servr.
Reboot the Raspberry Pi 4.
- To prevent issues with screen size used when remotely connecting to your Raspberry Pi 4 set the screen resolution for headless use. Start the software configuration tool again:
This time select “Display options”.Select “VNC Resolution”.Select the resolution you want to use.
- Best is to reboot now again:
- After reboot connect to your Raspberry Pi 4 via your Windows Teamviewer. Everything should work now.
4.5 Copy the microSD card to the SSD
We will now use Teamviewer to connect to the Raspberry Pi 4 to copy the microSD card to the SSD to prepare for booting from the SSD. Ensure that the SSD drive is connected to the Raspberry Pi 4 using a USB 3 port.
As I want to have the opportunity to connect the SSD drive to a Windows computer for full backup I decided to format the SSD as NTFS disk instead of Ext4 disk. This can be done from Raspberry Pi OS with for example Gparted. See the article “How To Install & Use Gparted On Raspberry Pi (Partition editor)” on the RaspberryTips site.
- Launch the SD Card Copier from the Accessories section of the start menu.
- Select the Copy From Device (micro SD card), and the Copy To Device (the SSD). Double check that the correct drives are selected and click Start to copy the files across. The process should take around ten minutes to complete.
- Check the boot order configuration:
Take note of the BOOT_ORDER code. The default code is 0xf41 and is read right to left to determine the boot order.
1 = Check SD card
4 = Check USB drive
f = Start again
This boot order is not what we want as we would like to have 0xf41, i.e. if a microSD card is inserted boot from it else boot from the SSD drive. This gives the opportunity to boot from microSD card in case of SSD issues. You can change the boot configuration using this command:
1sudo -E rpi-eeprom-config --edit
Then reboot with:
- Shutdown the Raspberry Pi and remove the microSD card.
- Power up the Raspberry Pi. It should now boot from the the SSD.
- You can get an indication of the SSD write speed by
1dd if=/dev/zero of=./speedTestFile bs=20M count=5 oflag=direct
The write speed is 283 MB/s. Next read the same file with the following command:
1dd if=./speedTestFile of=/dev/zero bs=20M count=5 oflag=dsync
This indicated read speed in our case wass 310 MB/s.
5. Possible issues
5.1 Teamviewer does not connect anymore after boot from SSD
Test PuTTY connection. If this still works network connection is ok. Reboot from the terminal and check again. In our case Teamviewer connection was working again.
5.2 SSD issues due to low power
An external drive might consume a lot of power from the bus, which can lead to issues (for example other USB connected devices do not work anymore). These often can be solved by using a drive that has its own power source or by using a powered USB hub.
5.3 Speed of SSD drops over time