User Tools

Site Tools


ubuntu:pi

This is an old revision of the document!


Ubuntu on Raspberry Pi

Notes for configuring Ubuntu 20.04.1 LTS on Raspberry Pi.

Custom Ubuntu image

I currently use a customized Ubuntu image that includes the following modifications:

  • Disabled resizing of partitions and filesystems to use entire SD card on first boot in cloud-init
  • Disabled automatic patching of Ubuntu on first boot via cloud-init
  • Add users, SSH keys, and sudo configuration for Ansible

First boot

On first boot you can find the Pi on the network from a DHCP server (or any other host that has an ARP cache for the subnet including this host) using the following:

#!/bin/bash
echo "The following Raspberry Pi 4 devices have been found:"
arp -a | grep dc:a6
# add MAC for other models...

Grow filesystem and disable cloud-init

After logging in you should reconfigure the filesystem and disable cloud-init to ensure that it does not automatically modify the filesytem or partitions in future updates.

# disable
touch /etc/cloud/cloud-init.disabled

# manually modify the partition table and grow the filesystem
parted /dev/mmcblk0
resizepart # configure partition 2 as desired
quit
resize2fs /dev/mmcblk0p2

# optional: remove cloud-init completely
apt-get purge cloud-init
# if you do not remove cloud-init be sure not to allow your
# configuration to be overwritten in future updates to the package

Another option is to create a small 1Mb partition after your root partition to ensure that it can never be grown into the empty space on your SD card.

Next do the following:

# disable the unattended upgrades service (you can re-enable later if you prefer)
systemctl disable unattended-upgrades

# install python for Ansible
apt install python

# set editor to Vim (optional)
update-alternatives --config editor

# set a hostname
echo "$MYHOSTNAME" > /etc/hostname

# don't forget to update /etc/hosts

Configure network interface for static use:

# /etc/netplan/99-static.yaml
network:
    version: 2
    renderer: networkd
    ethernets:
        eth0:
            addresses:
                - 10.1.2.1/24
            gateway4: 10.1.2.1
            link-local: [ ]
            nameservers:
                search: [subnet.quay.net, quay.net]
                addresses:
                    - 10.1.2.3

To test this:

netplan try
# if that works, remove any other config files and run:
netplay apply

Ansible playbooks

# standard configuration for all Raspberry Pi systems
# this playbook does the following:
#  - base configurations (raspi_ubuntu)
#  - time service config (chrony)
#  - firewall config (nftables)
ansible-playbook -l raspi.in.quay.net raspi_ubuntu.yml

# regenerate SSHD keys on host after build
# NOTE: Ubuntu ships with a default set of SSHD keys
ansible-playbook -l raspi.in.quay.net regen_sshd_keys.yml

Add the following to Ansible plays in the future:

  • default editor
  • prune packages
  • configre motd
  • apt install lm-sensors

Hardware notes

Quick reference for Raspberry Pi hardware tools on Ubuntu.

Reference

ubuntu/pi.1612220017.txt.gz · Last modified: 2021-02-01 17:53 by gabriel