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.
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
So let’s proceed to the practical part and learn how to boot the Raspberry Pi from from such SSD device.
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) 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.
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.
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.
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 the next article of this 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.