Building a Raspberry PI Cluster – Part II: Operating system installation

As per our first part, you now have your cluster all assembled and ready and want to install it. Do something with it already. For this we will have to download
Raspbian Stretch Lite – a Linux distribution based on Debian and made especially for the Raspberry Pi. The ”Lite” version has an image file of 1,8GB and contains only the base system. We will not need an X server or a GUI to make our cluster functional and with Raspbian Lite we also save some space on the 16GB MicroSDHC card.

In this tutorial you will learn:

  • How to write the Raspbian image file to a MicroSD card
  • How to install Raspbian Lite
  • How to configure your first node of the cluster

Your cluster should look something like this after you install Raspbian Lite.

With an optional 7 inch monitor your cluster should look something like this after you install Raspbian Lite.

Building Raspberry Pi Series:

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Raspbian Lite
Software Etcher
Other Privileged access to your Linux system as root or via the sudo command. An SSH client (optional)
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Installing Raspbian Lite

Download the zip containing the latest Raspbian Lite image file and install Etcher. The latter is also in a zip file that contains an AppImage.



You have to make this executable with:

$ chmod +x balenaEtcher-1.5.24-x64.AppImage 

To start the balenaEtcher application run:

$ ./balenaEtcher-1.5.24-x64.AppImage
With Etcher you can easily burn an IMG or ISO image to your MicroSD card.

With Etcher you can easily burn an IMG or ISO image to your MicroSD card.

Etcher is an easy to use image burner that can also handle the .img format of the Raspbian image file without you needing to convert it to an ISO image. It also automatically detects an inserted SD or MicroSD card and will burn Raspbian to the first card easily. After the image was burned to the MicroSD card take it out of you computer and re-insert it so that the partitions will automount. Open up a console or a Terminal window and type

$ su -

and enter your password to become root. Now navigate to where the card is mounted (usually /media) and enter the boot partition. SSH is not activated by default in Raspbian and we will need SSH access, so we will have to create an empty file called ssh on the root of the MicroSD card’s /boot partition:

# touch ssh

To get Internet access you have to specify your network settings in a file named wpa_supplicant.conf, located on the rootfs partition of the MicroSD card. Enter said partition and edit the file:

# nano /path/to/microsd/root/partition/etc/wpa_supplicant/wpa_supplicant.conf

At the end of the file add the following:

network={
        ssid="your_ssid"
        psk="your_password"
}

Where your_ssid is your router’s SSID and your_password is your WiFi password. Now edit the /etc/network/interfaces file on the same MicroSD card to look like this:

auto lo
iface lo inet loopback

iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet dhcp
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet dhcp
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

This will allow your router to pass DHCP-assigned IP addresses to the nodes in your cluster so you won’t have to manually configure a static address for each of them. It will save you some time for now.



Now you can unmount the MicroSD card and insert it into the first node of the cluster, right below the Raspberry Pi board, in its dedicated slot. Connect and HDMI-capable monitor to that particular Raspberry Pi and also connect an USB keyboard to one of the four USB 2.0 slots. Finally connect only this Raspberry Pi to the Power Hub via one of the MicroUSB cables and power it up.

You will be greeted shortly by a command prompt asking you to log in. The default username is pi and the default password is raspberry. You should later change these to something of your liking. Optionally you can do all these through SSH by connecting to your Raspberry Pi via its IP address. You can find out what IP address your node has by either checking your router log or by scanning the network for available hosts. Since we activated SSH on this particular Raspberry Pi by creating the ssh file you can now connect to it from another computer on the LAN with

$ ssh -l pi 192.168.1.166

where 192.168.1.166 – for the sake of this tutorial – is the DHCP IP address provided by your router.

Configuration

Now that we are logged in and have a prompt we need to configure Raspbian the way we want it to be. You can invoke the ncurses configuration dialog with

$ sudo raspi-config
This is the main screen of the Raspberry Pi Configuration Tool.

This is the main screen of the Raspberry Pi Configuration Tool.

You can select menu items with Enter and mark checkboxes with the Spacebar. From here you can change your password, hostname and basically set up the system the way you want it to be. Change your user password then go to Advanced Options and pick Expand Filesystem. This will make more room on the MicroSD card the next time you boot Raspbian.

In the same menu pick Memory Split and change the amount of RAM the graphic card gets. Since we will only work in command line from now we can set this to 16 to ensure your Pi board gets more RAM. Exit this menu, enter the Boot Options menu, pick the Desktop / CLI submenu and choose Console. This way the Pi will always boot into CLI making the boot process faster and lighter on the RAM. From the Localisation Options menu in the root of the configuration screen you can pick your locale (US for example), change the timezone, select the country you’re using the Pi in.



Enter Desktop / CLI to set a command line-only boot mode.

Enter Desktop / CLI to set a command line-only boot mode.

Save these settings and the system will ask for a reboot. Do this and when you get to the CLI prompt again you can use this to see the remaining free space on the MicroSD card:

$ df -haT

Only 8% of the available 16GB is used, leaving you with 13GB to work with. The next thing is to update Raspbian to the latest packages:

$ sudo apt update
$ sudo apt upgrade

Conclusion

Now you have Raspbian Lite on your first cluster node. You can do one of two things next: either repeat this process for every MicroSD card you have or create an image of the MicroSD card you have just installed and flash it with Etcher unto each card. The latter will save you some time but you will have to manually set a different hostname to each node, so as not to confuse them. Use something like rpi1, rpi2, rpi3. You can change the hostname with

sudo hostname rpi1

for example. Set the same username and password for each of the nodes. In part III of this series we’ll configure the required tools to make the cluster do work with all nodes at the same time and see how we can further configure it.



Comments and Discussions
Linux Forum