box.matto.nl
Enjoying Open Source Software

Raspberry Pi OS Lite on Raspberry Pi 3 Model A plus

Raspberry Pi OS Lite is the new name of Raspbian, think Debian ported to the Rapsberry Pi.

The Raspberry Pi 3 Model A+ is an economic version of the Raspberry Pi. The board has a smaller size than the "normal" Raspberries. Also it has no wired network interface, but only WiFi.

For many applications this board is good enough and as it requires less power and is also cheaper, this board can be a economical sound choice.

Remember that the WiFi-only option may make it harder to put this board in a network DMZ, so for outward facing servers this might not be the best solution.

Headless setup

We are going to set up this board to run headless, meaning without keyboard and monitor.

Remember that the serial port of the Raspberry Pi can only accept 3.3 Volts, so applying a 5 Volts or 12 Volts serial connection will kill your Raspberry Pi. I use a so called F-cable, this is a cable with, on the end that you connect to your computer or laptop, comes with an USB connector and on the other end is has three wires, each with a small connector to put on the appropriate pin on the Raspberry Pi.

Preparing the micro SD card

As this board has only WiFi we have to do some preparations to make the initial start up as easy as possible.

We try to prepare the micro SD card in such a way that we have a WiFi-connection and a running SSH-server right from the very first boot.

Our goals:

  • Start the console on the serial port
  • Setup the network
  • Start sshd

We can do this on our workstation by preparing the micro SD card, before the initial boot of the board.

Unzip the downloaded file and dd it to your micro SD card.

Now, mount the boot partition to change some settings.

  • to start SSH-server, touch ssh
  • to enable the serial port, add a line to config.txt
  • configure wpa_supplicant
  • configure the network interfaces file

Touch ssh

Raspberry Pi OS Lite doesn't start SSH automatically. You can make it start from the very first boot, by adding a file with the filename 'ssh' into the boot directory.

So, in the mounted boot partition issue the command

touch ssh

Add a line to config.txt to start the serial console

Append the following line to the file config.txt

enable_uart=1

Without this, you won't be able to connect to the serial console.

Configure wpa_supplicant

Mount the second partition of the micro SD card.

Go to the etc directory on the micro SD card and into the wpa_supplicant directory.

Enter the command:

wpa_passphrase SSID Password

Replace 'SSID' with your local SSID and 'Password' with your local password.

Paste the output of the command at the end of the wpa_supplicant.conf.

Also add a line to configure your country code:

country=NL

Replace 'NL' with the two-character ISO 3166-1 international code of your country.

Your /etc/wpa_supplicant/wpa_supplicant.conf file should look like this:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

country=NL

network={
        ssid="YOUR_SSID"
        psk=a-very-long-string-created-by-wpa_passphrase 
        key_mgmt=WPA-PSK
}

Copy the wpa_supplicant.conf file to the boot partition of the Raspberry Pi. This will setup everything fine at the next boot and after this the copy in the boot partition will be vanished.

Configure the network interfaces file

Go to the etc directory on the micro SD card and into the network directory.

Append the following lines to the file /etc/network/interfaces:

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

Test the configuration, add a user and remove the pi user

Umount the micro SD card partitions, run "sync" to be sure everything is up to date and put the micro SD card into the Raspberry and boot the board.

Keep an eye on the output of your DHCP-server, to see what IP address your Raspberry Pi has, if any. The file dhcpd.leases can be useful for this.

Hopefully everything went fine and you don't need the serial console.

When you do have to use the serial console, and you use minicom on your Linux workstation, set both hardware and software flowcontrol to "no".

Add a user, remove the pi user

Log in with user "pi" and password "raspberry".

First, add a new user and make this member of the sudo group:

sudo adduser username
sudo usermod -a -G sudo username  

Replace "username" with an appropriate name.

Now, test that you can log in with this user and do some sudo stuff.

Next, remove the pi user.

sudo userdel pi

And make sure you harden sshd as you would on any server.

Put some directories in ramdisk

Put some directories in ramdisk, to prevent the micro SD card from wearing out. For example, put a line like the following in your /etc/fstab file.

tmpfs   /var/log    tmpfs    defaults,nosuid,mode=0755,size=10m    0 0

Finish configuration with a system update, set timezone, locales and so on

Now, bring your system up to date.

sudo apt-get update
sudo apt-get upgrade

Next we are going to set the right timezone and install the proper locales. You can use the usual Debian commands for this, or run raspi-config. With raspi-config you can also reduce the amount of RAM that is reserved for the GPU.

Enjoy your new server!

Tags:

⇽ Taskwarrior holiday calendar for 2021 for the Netherlands Tag and kill several Tmux windows ⇾