Debian

Author: Jase Batchelor

Notes for Debian configuration on the following boards and VMs:

  • Radxa Rock 5B
  • Radxa Zero
  • Lima VM

Sections


Setup Wired Ethernet

On the Radxa Rock 5B boards use wired ethernet

 sudo vi /etc/network/interfaces

Add the following, changing IP address as required

# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback
 
# The primary network interface
auto enP4p65s0
iface enP4p65s0 inet static
address 10.0.0.20
netmask 255.255.255.0
gateway 10.0.0.1
#dns-domain nakame.dev
dns-nameservers 10.0.0.1 1.1.1.1 8.8.8.8

Bring up the network interface

sudo ip link set enP4p65s0 up

Configure the networking service

sudo systemctl enable networking.service
sudo systemctl status networking.service

Check resolv.conf

cat /etc/resolv.conf 
# search lan
# nameserver 8.8.8.8

 


Setup WIFI with wpa_supplicant

Setup WIFI using wpa_supplicant on headless Debian system.

Based on this article

If using Debian desktop edition then disable NetworkManager. We will remove it later.

sudo systemctl stop NetworkManager
sudo systemctl disable NetworkManager-wait-online NetworkManager-dispatcher NetworkManager

Install wpa_supplicant

sudo apt-get install wpasupplicant

Stop the wpa_supplicant (if running), and configure.

sudo systemctl stop wpa_supplicant

Generate hashed configuration with wpa_passphrase

wpa_passphrase MY_SSID PASSWORD     

Configure /etc/wpa_supplicant/wpa_supplicant.conf using output from the wpa_passphrase command

ctrl_interface=/run/wpa_supplicant
ap_scan=1

network={
  	ssid="MY_SSID"
  	#psk="PASSWORD"
  	psk=deadbeefdeadbeefdeadbeefdeadbeefdeadbeef
    key_mgmt=WPA-PSK
}

Validate the configuration

ip link set wlan0 up
wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf

If that runs with no errors, but you do not have an IP address, run

dhcpcd wlan0

 


Configure wpa_supplicant to start at boot
sudo cp /lib/systemd/system/wpa_supplicant.service /etc/systemd/system/wpa_supplicant.service

Edit /etc/systemd/system/wpa_supplicant.service

sudo vi /etc/systemd/system/wpa_supplicant.service

Amend the line beginning with ExecStart as follows:

ExecStart=/sbin/wpa_supplicant -u -s -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlan0

Example /etc/systemd/system/wpa_supplicant.service

[Unit]
Description=WPA supplicant
Before=network.target
After=dbus.service
Wants=network.target
IgnoreOnIsolate=true

[Service]
Type=dbus
BusName=fi.w1.wpa_supplicant1
ExecStart=/sbin/wpa_supplicant -u -s -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlan0
Restart=always

[Install]
WantedBy=multi-user.target
Alias=dbus-fi.w1.wpa_supplicant1.service

Enable the service

sudo systemctl daemon-reload
sudo systemctl enable wpa_supplicant.service

 


Setup Static IP with wpa_supplicant

Note: this can also be setup via /etc/network/interfaces.

sudo systemctl disable dhclient.service
sudo mv /etc/systemd/system/dhclient.service ./

Add the following to the end of /etc/dhcpcd.conf

sudo vi /etc/dhcpcd.conf

/etc/dhcpcd.conf

interface wlan0
static ip_address=10.0.0.20
static routers=10.0.0.1
ip add show wlan0
# zero-05:> ip add show wlan0
# 2: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq state UP group default qlen 1000
#     link/ether d4:9c:dd:a0:a4:e6 brd ff:ff:ff:ff:ff:ff
#     inet 10.0.0.20/8 brd 10.255.255.255 scope global noprefixroute wlan0
#        valid_lft forever preferred_lft forever

# https://www.cyberciti.biz/faq/add-configure-set-up-static-ip-address-on-debianlinux/
sudo systemctl restart networking.service
sudo systemctl status networking.service

 


Configure IPv4

Configure system to only use IPv4 (link)

sudo vi /etc/sysctl.conf

Add to last line:

net.ipv6.conf.all.disable_ipv6 = 1
#net.ipv6.conf.default.disable_ipv6 = 1
#net.ipv6.conf.lo.disable_ipv6 = 1

Apply the changes

sudo sysctl -p

 


Set hostname

View current hostname

hostnamectl

Change hostname

sudo hostnamectl set-hostname nakame

Amend /etc/hosts entry 127.0.1.1 with the new hostname

sudo vi /etc/hosts
# Change 127.0.1.1 to value set above. Eg.
# 127.0.1.1 nakame

 


Configure Avahi

sudo apt-get install libnss-mdns
sudo service avahi-daemon restart

Test: eg. ping nas.local

ping $(hostname)

 


Add user and setup SSH

Add user jase

# https://linuxize.com/post/how-to-add-user-to-sudoers-in-debian/
sudo adduser jase
sudo usermod -aG sudo jase

Logout and login using new user

Delete the default Radxa user

sudo userdel -r rock

Copy SSH from laptop to Radxa ~/.ssh/authorized_keys

mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys
chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys
vi .ssh/authorized_keys

Test the SSH connection from laptop

ssh nakame.local
# Linux nakame 5.10.110-37-rockchip-g74457be0716d #rockchip SMP Mon Feb 6 09:18:21 UTC 2023 aarch64
# 
#           |
# ,---.,---.|__/ ,---.,-.-.,---.
# |   |,---||  \ ,---|| | ||---'
# `   '`---^`   ``---r5b' '`---'
# 
# Last login: Sun Jun  4 03:06:24 2023 from 10.0.0.72
nakame:> 

 


Set locale

Install locales package

sudo apt-get update && sudo apt-get install -y locales

Configure locale en_US.UTF-8

# Uncomment en_US.UTF-8 for inclusion in generation
sudo sed -i 's/^# *\(en_US.UTF-8\)/\1/' /etc/locale.gen
# Generate locale
sudo locale-gen

 


Set environment variables

Configure system wide

sudo vi /etc/environment

Add the following:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export TZ=UTC

Or, optionally configure for user (using Bash)

echo "export LC_ALL=en_US.UTF-8" >> ~/.bashrc
echo "export LANG=en_US.UTF-8" >> ~/.bashrc
echo "export LANGUAGE=en_US.UTF-8" >> ~/.bashrc
echo "export TZ=UTC" >> ~/.bashrc

 


Timezone

sudo timedatectl set-timezone UTC
timedatectl

# timedatectl set-timezone Asia/Tokyo
# ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

Update NTP / systemd-timesyncd

Links:

sudo apt purge ntp
sudo apt install -y systemd-timesyncd
sudo systemctl start systemd-timesyncd
sudo systemctl status systemd-timesyncd
timedatectl

 


Swap partition

As we don’t have a separate physical partition this is simply a file on the root partition. Not the best way, but avoid some simple crashes

# Add swap file (not partition)
# https://askubuntu.com/a/796997

# Create an empty file (1K * 4M = 4 GiB).
sudo mkdir -v /var/cache/swap
cd /var/cache/swap
sudo dd if=/dev/zero of=swapfile bs=1K count=4M
sudo chmod 600 swapfile
# Convert newly created file into a swap space file.
sudo mkswap swapfile

# Enable file for paging and swapping.
# To disable, use sudo swapoff swapfile command.
sudo swapon swapfile

Verify by: swapon -s or top:

top -bn1 | grep -i swap
# Should display line like: 
# KiB Swap:  4194300 total,  4194300 free

Add to /etc/fstab to make it persistent on system boot.

cat /etc/fstab
sudo echo "/var/cache/swap/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab
cat /etc/fstab

Re-test swap file on startup. IMPORTANT: This commands re-checks the syntax of /etc/fstab. If /etc/fstab is configured incorrectly the system will not start.

sudo swapoff swapfile
sudo swapon -va

View the swap partition / file in htop

htop

 


Update Debian to latest

In this example we update from Debian Buster to Bullseye

Update the current system

# Update to Bullseye
# https://www.makeuseof.com/upgrade-debian-10-buster-to-11-bullseye-linux/
sudo apt update && sudo apt upgrade
sudo apt install gcc-8-base
cat /etc/os-release

Edit apt sources to the latest release

sudo sed -i 's/buster/bullseye/g' /etc/apt/sources.list{,.d/*.list}
sudo sed -i 's|bullseye/updates|bullseye-security|' /etc/apt/sources.list

# cat /etc/apt/sources.list
# deb http://deb.debian.org/debian bullseye main contrib non-free
# deb http://deb.debian.org/debian bullseye-updates main contrib non-free
# deb http://security.debian.org/debian-security bullseye-security main
# deb http://ftp.debian.org/debian bullseye-backports main contrib non-free

Fix the Radxa Apt key

export DISTRO=bullseye-stable
curl -LO apt.radxa.com/$DISTRO/public.key
sudo apt-key add public.key
rm public.key

# OR
# wget -O - apt.radxa.com/$DISTRO/public.key | sudo apt-key add –

Update the system

sudo apt update
sudo apt full-upgrade

Reboot the system

sudo reboot

Verify the update and clean up

cat /etc/os-release
sudo apt autoremove
sudo apt clean

 


Disable GUI

To disable the GUI:

sudo systemctl set-default multi-user.target

To re-enable the GUI:

sudo systemctl set-default graphical.target
sudo reboot

 


Remove GUI libraries

Remove the desktop libraries and auto-remove related dependencies

# https://unix.stackexchange.com/a/424973
sudo apt purge libx11-6 libwayland-client0 && sudo apt autoremove && sudo apt clean

 


Suspend and hibernation

Disable suspend and hibernation. See https://wiki.debian.org/Suspend

For systems which should never attempt any type of suspension, these targets can be disabled at the systemd level with the following:

sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

To re-enable hibernate and suspend use the following command:

sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target

A modern alternative approach for disabling suspend and hibernation is to create /etc/systemd/sleep.conf.d/nosuspend.conf as follows:

[Sleep]
AllowSuspend=no
AllowHibernation=no
AllowSuspendThenHibernate=no
AllowHybridSleep=no

 


Install ZSH

Optionally replace Bash with ZSH.

sudo apt update && sudo apt upgrade && sudo apt install zsh
chsh -s "$(which zsh)"

 


Install Locate

Install the locate command. Helpful as I always forget the syntax for find

sudo apt install -y man-db mlocate && sudo updatedb