Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements for the OPi image #19

Merged
merged 38 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d95044e
simplify matrix for testing
crschardt Jul 4, 2024
fe6c253
make bash default shell for user pi
crschardt Jul 4, 2024
0b3da4d
get rid of snaps
crschardt Jul 4, 2024
7eb5448
On 24.04, must specify all CPUs
crschardt Jul 4, 2024
714e6b2
quite apt-get to clean up the workflow log
crschardt Jul 4, 2024
e22b5c1
a few other lxd packages
crschardt Jul 4, 2024
53a6e1d
remove bluetooth
crschardt Jul 4, 2024
9e82ee7
improve startup time when using NetworkManager
crschardt Jul 4, 2024
a8510e0
turn off networkd waiting also
crschardt Jul 4, 2024
276ccc3
let it wait for the network (for now)
crschardt Jul 5, 2024
b63d532
look for the root partition
crschardt Jul 5, 2024
ca35d4a
check the files in /boot
crschardt Jul 5, 2024
9af48aa
set NetworkManager in coud-init
crschardt Jul 5, 2024
2cee482
not needed
crschardt Jul 5, 2024
02c47c0
typo
crschardt Jul 5, 2024
e6d78ab
another typo
crschardt Jul 5, 2024
8252161
not needed
crschardt Jul 5, 2024
83242b6
try setting the host name too
crschardt Jul 5, 2024
26e91ca
may be causing long boot delay
crschardt Jul 5, 2024
bfff396
enable photonvision network control
crschardt Jul 5, 2024
c337707
report how much space was freed up
crschardt Jul 5, 2024
f4a9321
disable cloud-init after first run
crschardt Jul 5, 2024
b6ff83c
fixed math expression
crschardt Jul 5, 2024
3c7468a
commenting the edits to files
crschardt Jul 5, 2024
f15db09
see if ignore carrier improves disconnected boot
crschardt Jul 5, 2024
e261a4b
file name helps
crschardt Jul 5, 2024
b3664fe
diagnostics
crschardt Jul 5, 2024
6133a12
Add CIDATA
crschardt Jul 5, 2024
35c690d
remove ls
crschardt Jul 5, 2024
dbbd5df
Add static IP config
crschardt Jul 5, 2024
14af023
copy network-config from repo
crschardt Jul 5, 2024
92aebe2
clean removes more than autoclean
crschardt Jul 5, 2024
b861857
restore main.yml
crschardt Jul 5, 2024
53a09d3
Create image for opi5pro
crschardt Jul 6, 2024
db8325c
update the networking configuration for OPi's
crschardt Jul 21, 2024
38e3836
Merge branch 'master' into opi-24-image-fixes
crschardt Jul 27, 2024
35b5587
revert a few changes that need more work
crschardt Jul 29, 2024
f1a3fe4
update actions to newest versions available
crschardt Jul 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
- name: opi5plus
script: ./install_opi5.sh
base_image: https://github.com/Joshua-Riek/ubuntu-rockchip/releases/download/v2.1.0/ubuntu-24.04-preinstalled-server-arm64-orangepi-5-plus.img.xz
- name: opi5pro
script: ./install_opi5.sh
base_image: https://github.com/Joshua-Riek/ubuntu-rockchip/releases/download/v2.1.0/ubuntu-24.04-preinstalled-server-arm64-orangepi-5-pro.img.xz

name: "Build for ${{ matrix.name }}"

Expand All @@ -58,7 +61,7 @@ jobs:
mv ${{ steps.install_deps.outputs.image }} photonvision_${{ matrix.name }}.img
sudo xz -T 0 -v photonvision_${{ matrix.name }}.img

- uses: actions/[email protected].3
- uses: actions/[email protected].4
with:
name: photonvision_${{ matrix.name }}.img.xz
path: photonvision_${{ matrix.name }}.img.xz
Expand All @@ -70,7 +73,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
# Download literally every single artifact
- uses: actions/[email protected].7
- uses: actions/[email protected].8
- run: find
# Push to dev release
- uses: pyTooling/Actions/[email protected]
Expand All @@ -82,7 +85,7 @@ jobs:
**/*.xz
if: github.event_name == 'push'
# Upload all xz archives to GH tag if tagged
- uses: softprops/[email protected].6
- uses: softprops/[email protected].8
with:
files: |
**/*.xz
Expand Down
18 changes: 18 additions & 0 deletions OPi5_CIDATA/meta-data
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This is the meta-data configuration file for cloud-init. Please refer to the
# cloud-init documentation for more information:
#
# https://cloudinit.readthedocs.io/

# Set the datasource mode to "local". This ensures that user-data is acted upon
# prior to bringing up the network (because everything about the datasource is
# assumed to be local). If you wish to use an HTTP datasource instead, you can
# change this to "net" or override it on the kernel cmdline (see README).
dsmode: local

# Specifies the "unique" identifier of the instance. Typically in cloud-init
# this is generated by the owning cloud and is actually unique (to some
# degree). Here our data-source is local, so this is just a fixed string.
# Warning: changing this will cause cloud-init to assume it is running on a
# "new" instance, and to go through first time setup again (the value is
# compared to a cached copy).
instance-id: cloud-image
35 changes: 35 additions & 0 deletions OPi5_CIDATA/network-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This file contains a netplan-compatible configuration which cloud-init will
# apply on first-boot (note: it will *not* update the config after the first
# boot). Please refer to the cloud-init documentation and the netplan reference
# for full details:
#
# https://netplan.io/reference
# https://cloudinit.readthedocs.io/en/latest/topics/network-config.html
# https://cloudinit.readthedocs.io/en/latest/topics/network-config-format-v2.html
#
# Please note that the YAML format employed by this file is sensitive to
# differences in whitespace; if you are editing this file in an editor (like
# Notepad) which uses literal tabs, take care to only use spaces for
# indentation. See the following link for more details:
#
# https://en.wikipedia.org/wiki/YAML

# Some additional examples are commented out below

network:
version: 2
renderer: NetworkManager
ethernets:
zz-all-en:
renderer: NetworkManager
match:
name: "en*"
dhcp4: true
optional: true
zz-all-eth:
renderer: NetworkManager
match:
name: "eth*"
dhcp4: true
optional: true

118 changes: 118 additions & 0 deletions OPi5_CIDATA/user-data
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#cloud-config

# This is the user-data configuration file for cloud-init. By default this sets
# up an initial user called "ubuntu" with password "ubuntu", which must be
# changed at first login. However, many additional actions can be initiated on
# first boot from this file. The cloud-init documentation has more details:
#
# https://cloudinit.readthedocs.io/
#
# Please note that the YAML format employed by this file is sensitive to
# differences in whitespace; if you are editing this file in an editor (like
# Notepad) which uses literal tabs, take care to only use spaces for
# indentation. See the following link for more details:
#
# https://en.wikipedia.org/wiki/YAML
#
# Some additional examples are provided in comments below the default
# configuration.

# The (default) ubuntu user must be in the video group for hardware acceleration
users:
- default
- name: ubuntu
groups: video

# On first boot, set the (default) ubuntu user's password to "ubuntu" and
# expire user passwords
chpasswd:
expire: true
users:
- name: ubuntu
password: ubuntu
type: text

## Set the system's hostname. Please note that, unless you have a local DNS
## setup where the hostname is derived from DHCP requests (as with dnsmasq),
## setting the hostname here will not make the machine reachable by this name.
## You may also wish to install avahi-daemon (see the "packages:" key below)
## to make your machine reachable by the .local domain
hostname: photonvision

## Set up the keyboard layout. See localectl(1), in particular the various
## list-x11-* sub-commands, to determine the available models, layouts,
## variants, and options
#keyboard:
# model: pc105
# layout: gb
# variant:
# options: ctrl:nocaps

# Enable password authentication with the SSH daemon
ssh_pwauth: true

## On first boot, use ssh-import-id to give the specific users SSH access to
## the default user
#ssh_import_id:
#- lp:my_launchpad_username
#- gh:my_github_username

## Add users and groups to the system, and import keys with the ssh-import-id
## utility
#groups:
#- robot: [robot]
#- robotics: [robot]
#- pi
#
#users:
#- default
#- name: robot
# gecos: Mr. Robot
# primary_group: robot
# groups: users
# ssh_import_id: foobar
# lock_passwd: false
# passwd: $5$hkui88$nvZgIle31cNpryjRfO9uArF7DYiBcWEnjqq7L1AQNN3

## Update apt database and upgrade packages on first boot
#package_update: true
#package_upgrade: true

## Install additional packages on first boot
#packages:
#- avahi-daemon
#- rng-tools
#- python3-gpiozero
#- [python3-serial, 3.5-1]

## Write arbitrary files to the file-system (including binaries!)
#write_files:
#- path: /etc/default/console-setup
# content: |
# # Consult the console-setup(5) manual page.
# ACTIVE_CONSOLES="/dev/tty[1-6]"
# CHARMAP="UTF-8"
# VIDEOMODE=
# FONT="Lat15-Terminus18x10.psf.gz"
# FONTFACE=
# FONTSIZE=
# CODESET="Lat15"
# permissions: '0644'
# owner: root:root
#- encoding: gzip
# path: /root/Makefile
# content: !!binary |
# H4sICF2DTWIAA01ha2VmaWxlAFNWCM8syVBILMjPyU/PTC1WKMlXiPB2dlFQNjSx5MpNteLi
# dLDiSoRQxYl5KeWZyRkgXrSCkoqKRmaKgm6pppKCbmqhgoFCrIKamkK1QmpyRr6Ckn92YqWS
# NdC80uQMBZhOa4VahZoaqIrwjMQSewXfxOxUhcwShcr80qLi1Jw0RSUuAIYfEJmVAAAA
# owner: root:root
# permissions: '0644'

## Run arbitrary commands at rc.local like time
#runcmd:
#- [ ls, -l, / ]
#- [ sh, -xc, "echo $(date) ': hello world!'" ]
#- [ wget, "http://ubuntu.com", -O, /run/mydir/index.html ]

runcmd:
- [ touch, /etc/cloud/cloud-init.disabled ]
77 changes: 55 additions & 22 deletions install_opi5.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,91 @@ if id "$1" >/dev/null 2>&1; then
echo 'user found'
else
echo "creating pi user"
useradd pi -b /home
useradd pi -m -b /home -s /bin/bash
usermod -a -G sudo pi
mkdir /home/pi
chown -R pi /home/pi

echo 'pi ALL=(ALL) NOPASSWD: ALL' | tee -a /etc/sudoers.d/010_pi-nopasswd >/dev/null
chmod 0440 /etc/sudoers.d/010_pi-nopasswd
fi
echo "pi:raspberry" | chpasswd

apt-get update
apt-get update --quiet

before=$(df --output=used / | tail -n1)
# clean up stuff
echo 'Purging snaps'
# get rid of snaps
rm -rf /var/lib/snapd/seed/snaps/*
rm -f /var/lib/snapd/seed/seed.yaml
apt-get purge --yes --quiet lxd-installer lxd-agent-loader
apt-get purge --yes --quiet snapd

# remove bluetooth daemon
apt-get purge --yes --quiet bluez

apt-get --yes --quiet autoremove

after=$(df --output=used / | tail -n1)
freed=$(( before - after ))

echo "Freed up $freed KiB"

# run Photonvision install script
wget https://git.io/JJrEP -O install.sh
chmod +x install.sh

sed -i 's/# AllowedCPUs=4-7/AllowedCPUs=4-7/g' install.sh
sed -i 's/# AllowedCPUs=4-7/AllowedCPUs=0-7/g' install.sh

./install.sh -n -q
./install.sh -m -q
rm install.sh

echo "Installing additional things"

# Remove extra packages
echo "Purging extra things"
# apt-get remove -y gdb gcc g++ linux-headers* libgcc*-dev
# apt-get remove -y snapd
apt-get autoremove -y
apt-get install --yes --quiet network-manager net-tools libatomic1

# let netplan create the config during cloud-init
rm -f /etc/netplan/00-default-nm-renderer.yaml

echo "Installing additional things"
sudo apt-get update
apt-get install -y network-manager net-tools libatomic1
# set NetworkManager as the renderer in cloud-init
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got some reservations about the approach using cloud-init.

The upstream image exposes these on a separate device partition for editing on Windows. That's all fine, but it would be confusing for these files to be present yet not honored after first boot. IMO either keep cloud-init and always execute it (with a boot performance penalty) or just remove it entirely.

Copy link
Contributor Author

@crschardt crschardt Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding of cloud-init is that it doesn't regenerate the network configuration on every boot, but I'll admit that it isn't entirely clear to me from the documentation. In addition, when photonvision changes the IP to static, NetworkManager adds it's own configuration file to /etc/netplan which will override any changes made in the cloud-init setup files.

cp -f ./OPi5_CIDATA/network-config /boot/network-config

apt-get install -y libc6 libstdc++6
# add customized user-data file for cloud-init
cp -f ./OPi5_CIDATA/user-data /boot/user-data

# cat > /etc/netplan/00-default-nm-renderer.yaml <<EOF
# network:
# renderer: NetworkManager
# tell NetworkManager not to wait for the carrier on ethernet, which can delay boot
# when the coprocessor isn't connected to the ethernet
# cat > /etc/NetworkManager/conf.d/50-ignore-carrier.conf <<EOF
# [main]
# ignore-carrier=*
Comment on lines -40 to +61
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why's this still commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignoring the carrier may change current behavior on the robot. I'm not sure that it's a problem, but I'd like to leave it commented out until I have a chance to test on a robot network to make sure that nothing unexpected happens.

# EOF

# modify photonvision.service to wait for the network before starting
# this helps ensure that photonvision detects the network the first time it starts
# but it may cause a startup delay if the coprocessor isn't connected to a network
sed -i '/Description/aAfter=network-online.target' /etc/systemd/system/photonvision.service
cat /etc/systemd/system/photonvision.service

# networkd isn't being used, this causes an unnecessary delay
systemctl disable systemd-networkd-wait-online.service

# the bluetooth service isn't needed and causes a delay at boot
systemctl disable ap6275p-bluetooth.service

apt-get install --yes --quiet libc6 libstdc++6

if [ $(cat /etc/lsb-release | grep -c "24.04") -gt 0 ]; then
# add jammy to apt sources
echo "Adding jammy to list of apt sources"
add-apt-repository -y -S 'deb http://ports.ubuntu.com/ubuntu-ports jammy main universe'
fi

apt-get update
apt-get --quiet update

# mrcal stuff
apt-get install -y libcholmod3 liblapack3 libsuitesparseconfig5
apt-get install --yes --quiet libcholmod3 liblapack3 libsuitesparseconfig5


rm -rf /var/lib/apt/lists/*
apt-get clean
apt-get --yes --quiet clean

rm -rf /usr/share/doc
rm -rf /usr/share/locale/