Part 1: Getting the most from Raspberry Pi 4
Integrating a M.2 SSD physical disk to power a 64 bits operating system with 4 Gb RAM

This is part 1 of the serie Hands on Development with Raspberry Pi 4, whose primary goal is to setup a workspace on a high performance and cost effective setup, intended both for rapid prototyping, as well as for fast transfer to a production environment. The scope is suitable for cluster management (using Docker, and even Kubernetes), as well as for IoT projects and High-Performance Computing (HPC):
- For cluster management because it lets us experiment with complex deployments without the cost overhead ofusing any cloud provider (like AWS or Google Cloud). Adding more physical machines to the cluster is as simple as adding new Raspberry Pi’s to the setup, whose cost is negligible with respect to using virtual machines in the cloud. This way we cut the development costs of the infraestructure, and we will only move to the cloud when the infraestructure is ready for deployment in production.
- For IoT projects because the tiny Raspberry Pi is the most common SBC board of choice (Single Board Computer) for adding edge computing capabilities to IoT infrastructures, as well as streaming data from sensor to cloud server for IoT consummers, i.e. end user applications.
- For High-Performance Computing (HPC) because we can quickly learn how to setup such an enviroment in a simpler network of several Raspberry Pi’s. HPC is used in the backend of IoT based services, Artificial Intelligence computation and Bioinformatics.
Before going into the specific content of this article, it is worth remebering the scope of the four parts that compose this serie:
- Part 1: Getting the most from Raspberry Pi 4 , whose concrete scope is to integrate a M.2 SSD physical disk with a 64 bits operating system running the Raspberry Pi, that provides 4Gb RAM.
- Part 2: Installing Docker in Raspberry Pi 4, that focuses in development methodology and shows the process to prepare a Docker ready development environment.
- Part 3: Deploying Theia IDE using Docker. In this part we will explain how to have a full featured IDE for editing code in a headless Raspberry Pi. This way we skip the need of a monitor, keyboard and mouse for the board. Hence we will confortably work from our laptop without the cumbersome need of additional hardware.
- Part 4: Monitoring Raspberry Pi 4 performance in real time. To finish the serie we provide a simple and powerful example of how to deploy an application using Docker Compose. We will build a Chronograf dashboard of top of InfluxDB and Telegraf using Docker Compose.
So let’s start with part 1.
After several years of practical learning with Raspberry Pi in all kind of projects (IoT, Robotics & DevOps infrastructure) it has come the time to share such background under the shape of practical pills. Following a low steep Learn by Example Path, i.e. you will be guided to build your own development environment step-by-step in the upcoming serie of articles.
The former goal is to setup a workspace, not only for rapid prototyping, but also for fast transfer to a production environment when you are happy with the maturity status of the current project you’ll be working on.
First is first, and so the scope of this article will be to create a both desktop & remote development environment based on the tiny, and also powerful Raspberry Pi 4. What do you need to build yours?
- A Raspberry Pi 4, preferably the version with 4 Gb RAM. Have a look to this recent blog post that provides precise guidelines to decide on the version. Model with 2Gb RAM costs about 40$, while the 4Gb rise up 60$. As soon as there supplies worldwide of the 8Gb RAM model, prices of the previous versions will drop by 5–10$.
- A M.2 SSD unit, that will improve drastically the read/write operations with respect to the classical micro SD card. You can get a 120 Gb unit for as low as 25$ in eBay or Aliexpress. Anyway you could also do everything that’s explained without it, using the classical microSD card.
- A M.2 to USB 3.0 adapter, of which you can find plenty of options in the market. There are also specific Raspberry Pi hats that makes the resulting assembly to be more compact. Its price is around 20$.
The next two sections focus on the hardware and how to setup the Pi 4 so that it boots from the M.2 unit.
Why using a M.2 SSD disk?
Using such a Solid State Device (SSD) will drastically improve the bottleneck that impose the read/write operations of the microSD. A typical class 10 microSD card theoretically provides 10 MB/s write speed.
Up to Raspberry Pi 3, its four USB ports implemented the standard 2.0, whose transfer speed is 60 MB/s. But with Pi 4 you have two out of the 4 USB ports upgraded to 3.0 specification, which means a factor10x transfer speed, i.e. 600 MB/s.
It has come the time when it makes sense to integrate a M.2 SSD unit, because its hardware interface provides SATA 600 MB/s, a speed that is in the order of magnitude of USB 3.0. Hence the result is that using a M.2 unit connected via one of the (blue) USB ports of Pi 4, you can achieve a speed factor of 10x respect to using microSD card. This means 10x less time waiting for intensive read/write operations on the disk. The upgrade is worth, I can assure it to you!
In the paragraphs above I have provided rough orders of magnitude, but if you wanted a detailed discussion about the performance of Pi4 with the M.2 you can read this excellent analysis on the topic: https://www.tomshardware.com/news/raspberry-pi-4-ssd-test,39811.html
So let’s proceed to the practical part and learn how to boot the Raspberry Pi from such a SSD device.
Booting Pi4 from a M.2 SSD
This is no different from doing it from any other USB device, be a flash drive or a common HDD diss. In any case, I will provide the guidelines to do so.
I found this recent tutorial (of 17 July 2020) https://jamesachambers.com/raspberry-pi-4-usb-boot-config-guide-for-ssd-flash-drives/ that provides all the details in order to boot a Raspberry Pi 4 for a USB device in general, and a M.2 SSD unit in particular. Here the author explains the process using Raspbian, the official operating system for Raspberry Pi. Doing it for Ubuntu is pretty similar, since both OS are based in Debian. So you can safely follow that blog post to setup your hardware.
In the picture below you can see he sample board addon (Raspberry Pi hat) where I attached the M.2, labelled with a green-white sticker. This hat provides a USB 3.0 port that you will use to attach the drive to the Pi 4 via one of its USB 3.0 ports.

Once the hardware is ready we can proceed to download and setup latest Ubuntu version.
Setting up Ubuntu 20.04 Focal
When choosing an Ubuntu desktop environment for Raspberry Pi, Ubuntu Mate is the common choice, and that’s what we’ll install. The steps to make it work are pretty standard:
- Download the image, from the Ubuntu Mate site,
- Burn it to a microSD card using Etcher,
- Insert it into the slot in tthe Raspberry Pi, and
- Power on the Pi 4
For the first step, we provide now the relevant information.
Where to Download Ubuntu Mate
You have available both the 32 bits version (armhf CPU architecture) and the 64 bits one. For the last the CPU architecture is identified as arm64, also known as AArch64, that is the 64-bit state introduced in the Armv8-A architecture, the one that is currently implemented in Raspberry Pi 4.
These are the download links:
- 32 bits OS Ubuntu Mate (armhf architecture) https://ubuntu-mate.org/download/armhf/focal/
- 64 bits OS Ubuntu Mate (arm64 architecture) https://ubuntu-mate.org/download/arm64/focal/
Since we have a Raspberry Pi 4 with at least 2 Gb RAM (4 Gb recommended anyway), we should take advantage of the increased power of 64 bits processors, so better download the 64 bits OS version.
Integrating the M.2 Unit
What’s told in the four steps above refers to the classical boot from a micro SD card. So how do we make Ubuntu 20.04 runs from the M.2?
Well, if you read the post I suggested above, what you should do is to burn Ubuntu 20.04 to the M.2 Unit as well using Etcher, i.e. exactly the same process you followed for the microSD card.
For the Raspberry Pi to boot from the M.2 disk, what there is to modify is the file cmdline.txt hosted in the microSD card so that it points to M.2 device. To read the file just type from a bash terminal this command:
$ cat /boot/firmware/cmdline.txt
In my case the following line is its content:
console=serial0,115200 console=tty1 root=PARTUUID=d34db33f-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh
The string “root=PARTUUID=d34db33f-02” specifies that the board shall boot from partition 2 of the disk whose identifier is d34db33f, i.e. the M.2 disk.
If everything is right, you should now be presented with the Ubuntu configuration to select language, keyboard layout, machine name, username and password. Having stablished all these option, the system will be automatically configured for the first use. After waiting some minutes you will be able to start working with it.
In part 2 of the serie, we will complete the development infraestructure by installing and testing Docker & Docker Compose. Why? Because we are intending to setup environment, not only for rapid prototyping, but also for fast transfer to a production enviroment when you are happy with the result of your development projects.