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:

systemctl disable unattended-upgrades
apt install python
update-alternatives --config editor
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 plays

ansible-playbook -l raspi.in.quay.net raspi_ubuntu.yml
ansible-playbook -l raspi.in.quay.net chrony.yml

Add the following to Ansible plays in the future:

  • dpkg-reconfigure tzdata
  • default editor
  • prune packages
  • sshd config
  • disable ubuntu account or remove
  • configre motd
  • apt install lm-sensors
  • update sshd keys

Hardware notes

Quick reference for Raspberry Pi hardware tools on Ubuntu.

Reference

ubuntu/pi.1611635773.txt.gz · Last modified: 2021-01-25 23:36 by gabriel