In the previous post we kicked off this series as a DIY home data center project. This second post deals with installing an Operating System on the two Raspberry Pi. If we take a look at our shopping list from Part 1, we see two USB hard disk drives listed. I will attach each drive to a Raspberry Pi. They will host the OS and our server content. Remember, the same setup serves this very blog.
For setting up USB boot I will detail bash commands for a Linux system. You can also use Mac or Windows GUI tools to setup the Raspberry Pi. Macs can also run bash commands but there may be subtle differences in the way they function.
This post covers installing Ubuntu Server versions 20.04 and 22.04. The first part of the post deals with 20.04. This is because of a bug in that version that prevents the user from fully abandoning the SD card. It is still necessary to use it in order to serve the system partition.
Booting from USB – version 20.04
In the first step I will flash an SD card with an arm64 arch OS. You can use the Raspi Imager to accomplish the same thing over a GUI. It runs on Linux, Mac and Windows. Since the servers do not have a GUI, I opt to install Ubuntu Server 20.04. Every release version where the major number is divisible by two is a long-term release. Beware, if you use version 20.04, it has a bug in it that requires you to keep the SD card even when booting from USB.
Other choices offered that can serve our intended purpose include Raspbian. Raspbian is also a Debian-based distribution like Ubuntu. However, it comes packaged with some handy tools for interacting with the Raspberry Pi firmware. Don’t worry, all of these packages can be installed on Ubuntu via apt-get.
Updating the firmware
After the SD card has been flashed, insert it into the Raspberry Pi and boot it. The default user and password are Ubuntu. Next, proceed to install the package rpi-eeprom. You will use it to upgrade to the latest firmware. Please find a list of commands below.
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install rpi-eeprom
sudo rpi-eeprom-update -a ## looks for new firmware and installs if available
sudo reboot now
## after system has rebooted
## change BOOT_ORDER into 0xf41 - 1. USB, 2. SD CARD
sudo shutdown now
Transferring the images to the USB HDD
Now that the server has shutdown, remove the SD card. The SD card will consist of two partitions at that point – writable and system (root). System houses the Pi’s firmware and boot files. Writable houses the rest of the operating system. Next, insert the SD card into your installation machine. Finally, connect the USB hard disk to the installation machine too. Please see the list of commands below to transfer the images. We will be cloning only the system partition to the USB HDD.
lsblk # this will list all the mountable drives
## we assume that /dev/sda is the USB drive and /dev/mmcblk0 is the SD card
sudo dd if=/dev/mmcblk0p1 of=sdimage.img
sudo dd if=sdimage.img of=/dev/sda
At this point, both partitions have been transferred to the USB hard disk. The next step is to resize the root partition (writable) to include all the remaining space on your USB hard disk. I recommend using a GUI tool to minimize chance of error – ex. Gparted Finally, use either the CLI or the GUI tool to remove the writable partition from the SD card.
Booting from USB – version 22.04
If going for Ubuntu server version 22.04, the first major improvement you will notice is that I won’t be need to use the SD card at all when operating the system. Of course, I will need to use the SD card initially to install the latest firmware and set the boot order to favor USB. Same as before, with the SD card inserted into the installation machine, I will open the Imager tool and select “Misc Utility Images” -> “Bootloader” and finally “USB Boot”.
After the SD card has been flashed, I will insert it into the RPI, turn the machine on and wait for a few minutes. This is sufficient time for the firmware to be flashed and the boot order to be set to USB. Once this has passed, I shut down the RPI and removed the SD card. Next, I will install the operating system on to the USB HDD. I will simply connect the USB drive to my installation machine, selecting the appropriate OS from the list and the USB drive as the target storage. Once the transfer is done, I can connect the USB HDD to the RPI and power on the machine.
Finally, unmount the USB hard disk and connect it into one of the blue colored USB ports on the Raspberry Pi. Power on the machine. It will boot from the USB hard disk. You may now celebrate! Remember, Ubuntu Server will have a running SSH port 22 open by default. It will also have the default user and password installed. These are all things that need to changed before the machine can be put to production use and any services exposed to the web. Happy tinkering!
- @ 2022-12-24 19:21