logo smart home family kruse

Kruse Smart Home

Easy living in our smart home & Garden

How to boot the Raspberry Pi 4 from a SSD?

How to boot the Raspberry Pi 4 from a SSD?

24 April 2023

Jan-Willem

1. Introduction

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.

2. Requirements

The following is required:

  • Working Raspberry Pi 4
  • microSD card (16GB or more)
  • SSD
  • 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.

Geekworm NASPi V2.0 front

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
  • Cheap

Negative aspects of microSD cards:

  • Low speed compared with a SSD (in real life around 40 MBps versus >150 MBps)
  • Less reliable

See also:

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
  • Speed

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:

  1. Download and install Raspberry Pi Imager from the Raspberry Pi website.
  2. Insert a spare microSD card into your computer. Note that this card will be erased.
  3. Launch the Raspberry Pi Imager and select “Operating System”

    Scroll down to Misc Utility Images and select it
    Select Bootloader

    Select USB Boot. This will return us to the main menu
  4. Click on the “Chose storage” button and select the micro SD card. Double check that you have the right drive selected before proceeding!

  5. 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.

  6. 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.
  7. 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.

  1. 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!
  2. Click on the advanced settings icon
  3. 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.
  4. 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.

  1. 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.
  2. 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.

  1. On your Windows computer start PuTTY and configure a SSH connection:
  2. 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.
  3. 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:

    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):

    If a firmware update was available and installed, please reboot:

    c. Cleanup
  4. Download the Teamviewer software package from their server:
  5. Install Teamviewer:

    Multiple dependency errors will be displayed. Fix these with the following command:

    TeamViewer installation will be completed and should now be up and running on your Raspberry Pi. It will automatically start at each reboot.
  6. Reboot the system:
  7. 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!

    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.
  8. Retrieve the TeamViewer ID for your Raspberry Pi 4 via:
  9. Copy the Teamviewer ID shown (select or double-click it and then right mouse button or Ctrl-C to copy) :
  10. 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.
  11. 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 “VNC”
    Select “Yes” to enbale the VNC Servr.

    Reboot the Raspberry Pi 4.
  12. 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.
  13. Best is to reboot now again:
    sudo reboot
  14. 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.

  1. Launch the SD Card Copier from the Accessories section of the start menu.
  2. 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.
  3. 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:

    Then reboot with:
  4. Shutdown the Raspberry Pi and remove the microSD card.
  5. Power up the Raspberry Pi. It should now boot from the the SSD.
  6. You can get an indication of the SSD write speed by


    The write speed is 283 MB/s. Next read the same file with the following command:

    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

https://www.jeffgeerling.com/blog/2020/enabling-trim-on-external-ssd-on-raspberry-pi?page=1

https://github.com/muhkuh-sys/raspberry_enable_trim

 

Article by <a href="https://smarthome.familykruse.eu/author/iamjwk/" target="_self">Jan-Willem</a>

Article by Jan-Willem

Position

Writen by the website owner

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *