Nine Steps to Void Linux on Raspberry Pi

 

How I Almost Lost This Post

I recently switched from ranger to lf . Muscle memory caused me to treat lf’s rename like ranger’s. It wasn’t and ended up deleting my file instead of renaming it.

In the process of trying to recover the file and going through a couple of sophisticated programs that didn’t work, I came upon a single command:

grep -a -C 200 -F <unique-string> <filesystem> > OutputFile

More info here

It simply greps for a string on the raw filesystem (/dev/sdX or whatever yours is), and if you are trying to recover a text file this can work. The -C 200 prints 200 lines of context before and after the <unique-string>.

I had an external HDD backup that was a few tens of revisions behind the version you are reading now. It wouldn’t have been the end of the world, but the archwiki saved me a few hours.

Back to the Regularly Scheduled Programming

Basic Void Linux RPI configuration intended for GNU/Linux novices; tested with RPI 3B+ with both sdcard boot and more recently with HDD boot. The void wiki install guide can be found here, and here’s the void handbook

This was supposed to be a multipart series on setting up all sorts of functionality (email server, CUPS printing, etc) on an RPI void server, but I decided to install raspbian on my main RPI for a number of reasons.

I hated raspbian so I decided to re-install void. At the time I first wrote this guide I tested it with sdcard boot, more recently I installed with HDD boot. I made some changes since then if you’re doing sdcard boot be advised.

This guide will get you from a bare raspberry pi to a lightly configured system with ssh access from which you can comfortably do what you need to do. You won’t need to know too much about linux or runit to follow along other than basics (symlinks, basic vi, etc).

Look out for a blog post on getting Xorg running in the near future.

The Guide

  1. Ingredients List

  2. Install void to your pi boot drive

    • use one of the following methods:
      1. follow the rootfs install guide, or
      2. use my void linux setup script to install the rootfs (USE WITH CAUTION)
    • I used the raspberry pi 3 musl PLATFORMFS image (aarch64), but the 32-bit raspberry pi 2 images (armv7l) should also work with the 3
    • The single optional commandline argument is the version number of the image (‘2’ for armv7l and the default option ‘3’ for aarch64, both should work with the rpi 3).
    • The binary packages available for the different images might vary
  3. Insert the microsd card / usb HDD, hook the pi up, and turn it on

    • Login as ‘root’ (password is ‘voidlinux’)
    • The default login shell is dash, switch to bash for niceties like tab completion
      • bash
    • Change the root password
      • passwd
    • Set the hostname of the pi server to <host>
      • echo <host> > /etc/hostname
    • reboot
      • sudo poweroff now
    • login and start the bash shell again
  4. Set up the wifi internet connection

    • Get the wireless network <device> (mine is ‘wlan0’)
      • ip link
    • Move to the wpa_supplicant directory
      • cd /etc/wpa_supplicant
    • Make a copy of default wpa_supplicant config to use
      • cp wpa_supplicant.conf wpa_supplicant-<device>.conf
    • Add network details, the following is for WPA-PSK encryption (WPA Personal):
      • wpa_passphrase <MYSSID> <key> >> wpa_supplicant-<device>.conf
    • Initialize wpa_supplicant as daemon (note the lack of space after the -i and -c flags)
      • wpa_supplicant -B -i<device> -cwpa_supplicant-<device>.conf
    • Enable the dhcpcd service
      • ln -s /etc/sv/dhcpcd /var/service
    • Test the connection by pinging a website (might take a couple tries)
      • ping example.com
  5. Enable the system time daemon (required for package updates)

    • Enable the ntpd service
      • ln -s /etc/sv/ntpd /var/service
    • You may need to reconfigure chrony because chrony user and group may not exist
      • xbps-reconfigure -f chrony
    • Test if it works properly (might take some time)
      • date
  6. Sync+Update all packages and install new ones

    • Sync and update packages (run this command twice)
      • xbps-install -Su
    • Install a few useful packages, these are the basic ones I wanted, you install whatever you want:
      • xbps-install -S neovim htop nnn st-terminfo <other packages>
    • Reboot, login, enable the wpa_supplicant service, and reboot again
      • ln -s /etc/sv/wpa_supplicant /var/service
  7. (Optional) Set up NetworkManager and disable dhcpcd/wpa_supplicant

    • I stuck to wpa_supplicant in the end, you may want NetworkManager if you move your RPI around a lot.
    • Install NetworkManager
      • xbps-install -S NetworkManager
    • Create /etc/polkit-1/rules.d/50-org.freedesktop.NetworkManager.rules with the following contents
      • nvim /etc/polkit-1/rules.d/50-org.freedesktop.NetworkManager.rules
    polkit.addRule(function(action, subject) {
    		if (action.id.indexOf("org.freedesktop.NetworkManager.") == 0
    			&& subject.isInGroup("network")) {
    			return polkit.Result.YES;
    		}
    });
    
    • Add yourself to the network group (not sure I need to do this because I’m root, but I did it anyway)
      • gpasswd -a $USER network
    • Disable dhcpcpd/wpa_supplicant
      • rm -rf /var/service/dhcpcd
      • rm -rf /var/service/wpa_supplicant
    • Enable NetworkManager and dbus services
      • ln -s /etc/sv/NetworkManager /var/service
      • ln -s /etc/sv/dbus /var/service
    • Add profiles for wired and wireless networks using nmtui
      • nmtui
    • You may need to reboot to activate these connections
      • reboot now
  8. Enable LAN ssh connection

    • Enable the sshd service if it’s not already enabled (config via the ‘/etc/ssh/sshd_config’ file)

      • ln -s /etc/sv/sshd /var/service
    • Get and note the pi ip address, using one of the following methods

      1. remote machine arp-scan:
        • sudo arp-scan -l | grep 'Pi' | awk '{print $1}'
      2. remote machine local area subnet scan (such as 192.168.0.0 or 10.0.0.0)
        • nmap -sn <subnet>/24
      3. running ip addr on pi:
        • ip addr | grep --regexp=inet.*<device> | awk '{print $2}'
    • Add the pi hostname to your remote machine /etc/hosts (vim /etc/hosts)

        <host>    <ip_address>
      
    • Test ssh by logging in as root from your remote machine

      • ssh root@<host>
  9. Create and configure the standard user

    • Create the user

      • useradd -m -s /bin/bash -g users -G wheel,network,audio,video <user>
    • Add password

      • passwd <user>
    • Give wheel ability to run all commands

      • visudo
    • Uncomment the following line (delete the leading ‘#’)

        # %wheel ALL=(ALL) ALL
      
    • Add your default key to be used as authentication on your remote machine (if you don’t have one, generate a keypair with ssh-keygen)

      • ssh-copy-id <user>@<host>
    • Test ssh by logging in as the new user

      • ssh <user>@<host>
    • (Optional) Make whatever changes you want to your dotfiles or clone mine

      • git clone https://github.com/kpatel28/KRVR
    • (Optional) Add whatever you want to motd (message of the day)

      • nvim /etc/motd