Installing Ubuntu Server (Raspberry Pi)
The Raspberry Pi has become quite a valuable asset in the industry. These tiny computers, now with four cores and 1 GB of RAM, are extremely useful in running one-off tasks and even offering a great place to test code without disrupting existing infrastructure. In my lab, I have three Pis on my network, each one responsible for performing specific tasks or functions. It's a very useful platform.
Thankfully, Ubuntu Server is quite easy to install on a Raspberry Pi. In fact, it's installed in much the same way as Raspbian, which is the distribution most commonly used on the Pi. Ubuntu Server is available for Raspberry Pi models 2 and 3. All you'll need to do is download the SD card image and then copy it directly to your SD card. Once you've done that, you can boot the Pi and log in. The default username and password is ubuntu
for both.
Note
At the time of writing, the version of Ubuntu Server for the Raspberry Pi 3 is not officially supported but should work. The Pi 2 version is fully supported. The Pi 3 version is expected to be fully supported at some point.
To install Ubuntu on the Pi, perform the following steps:
- To get started, you'll first download the SD card image from here: https://wiki.ubuntu.com/ARM/RaspberryPi and check that it is compatible with your model of Raspberry Pi.
- In order to write the image to an SD card, first extract it and then use
dd
to do the actual copying. This is very similar to the process we used to create bootable USB media. In fact, it is the same; the only difference is the source and target. From a Linux system, you can perform the process with the following command:# dd if=/path/to/downloaded/file of=/dev/sdX bs=1M
- As before, replace
if=
andof=
with the path to the downloaded and extracted file and the target respectively. If you are unsure about which device your SD card is on your system, execute:# fdisk -l
- In my case, this process can take some time to complete. Often, the command prompt will return even before the syncing process is actually finished. This means you'll more than likely see the access indicator LED on your card reader continue to flash for a while before the process is truly complete. It goes without saying, but make sure you remove your SD card only once the LED has stopped flashing. If you'd rather have the command prompt NOT return until after the process is complete, add the sync option, like the following:
# dd if=/path/to/downloaded/file of=/dev/sdX bs=1M; sync
- So for example, on my system, the command will be:
# dd if=/home/jay/downloads/ubuntu-server-16.04.img of=/dev/sdc bs=1M; sync
Depending on the speed of your card reader, this process will likely take at least 5 minutes to complete, if not longer. Once you're finished and you start up your Pi, you're likely to notice an issue straight away. If we execute:
df -h
We'll see that regardless of the size of our SD card, we'll have quite a bit of space that is not being utilized. This is because the SD card image will be the size of the SD card it was captured from, which will most likely not equal the size of yours. This will result in wasted space. What we'll need to do is resize the installation to match our SD card.
First, from the Pi after it's started up, enter fdisk
by executing the following command:
# fdisk /dev/mmcblk0
Next, we'll need to delete the second partition, by pressing d + 2.
With the partition deleted (and while still within the fdisk
console), we'll recreate the partition we deleted by pressing n + p + 2 and Enter (twice) +w.
With those commands executed, execute the reboot
command to restart the Pi. However, we have one more command to execute. Once it starts backup, we can do the actual resizing with:
# resize2fs /dev/mmcblk0p2
After the resize procedure, you should be all set and able to utilize all the space of your SD card. You should also be able to use your Pi as a means of following along with the activities of this book. One last thing, though. If you execute this, you'll notice that your Pi doesn't have a swap partition:
free -m
This is normal, and while you can create a swap
file to fill the role of a swap
partition, I recommend you don't. SD cards are much too slow for swap
, so you'd be better off without it. Since the Raspberry Pi 2 and Pi 3 only have about 1 GB of RAM, make sure whatever processes you plan on running fit within that restraint and you should be fine.