Skip to content

Image Build Instructions

ChickenDevs edited this page Sep 25, 2021 · 10 revisions

If you want to be able to control everything that goes into the Pi, here are the instructions to build it from scratch.

We recommend choosing the smallest SD card possible. This will help to speed up image creation.

  1. Download the Raspberry Pi Imager.
  2. Click Choose OS, Ubuntu, then Ubuntu Server 20.10 (RPi 3/4/400)(Make sure you get the 64-bit).
  3. Plug in and choose the SD card. Click WRITE.
  4. Transfer the SD Card to the Raspberry Pi and power it on. Get the IP address for the pi. Then ssh to the pi using ssh ubuntu@ip-address with the password ubuntu.
  5. Change the hostname
    • Run sudo hostnamectl set-hostname webcast-pi
  6. Create the user
    • Run sudo useradd webcast -m -G sudo -s /bin/bash
    • Run sudo passwd webcast and enter the password. We will be using alma3738.
  7. Run sudo visudo and change
    • %sudo ALL=(ALL:ALL) ALL to %sudo ALL=(ALL) NOPASSWD: ALL
  8. Remove the ubuntu user and home directory
    • Close the ssh session, and login with the webcast username and password as set earlier. ssh webcast@ip-address with password alma3738.
    • Run sudo userdel ubuntu
    • Run sudo rm -r /home/ubuntu
  9. Update networking config
    • Run echo network: {config: disabled} | sudo tee /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg > /dev/null
    • Run sudo mv /etc/netplan/50-could-init.yaml /etc/netplan/50-webcast-pi.yaml
    • Run sudo vi /etc/netplan/50-webcast-pi.yaml and edit the file to look like the following:
    network:
        ethernets:
            eth0:
                dhcp4: true
                optional: true
        version: 2
        renderer: NetworkManager
    
    • Run sudo netplan generate
    • Run sudo netplan apply
  10. Pull the code and copy it to the right places
    • Run git clone https://github.com/ChickenDevs/webcast.git
    • Run cd webcast
    • Run sh setup.sh
  11. Clean up the image as needed, for example:
    • sudo apt --purge autoremove -y
    • sudo apt autoclean -y
    • sudo rm -rf /tmp/*
  12. Fill the empty space with zeros to maximize compression
    • Run dd if=/dev/zero of=/tmp/zero and wait for it to finish (might be a long time for large SD cards)
    • Run rm -f /tmp/zero
  13. Run history -c
  14. Shutdown the Pi and move the microSD card to another system for imaging.
    • We use a USB adapter to another Linux system
  15. Run sudo dd bs=4M if=/path/to/microSD of=/path/to/output.img
    • Replace the if= entry with the correct reference to the microSD card
    • Replace the of= entry with the desired destination
    • i.e. sudo dd bs=4M if=/dev/sde of=/data/backups/pi/webcast-pi4.img
  16. Shrink the resulting image and prepare it to for distribution
    • Install PiShrink on the Linux system being used to capture the image and use it to shrink and prepare the image
    • i.e. sudo pishrink.sh -za /data/backups/pi/webcast-pi4.img
    • The resulting file in the above example would be /data/backups/pi/webcast-pi4.img.gz which is ready for distribution
Clone this wiki locally