The problem...
Home Assistant cannot really build anymore on a raspbian Raspberry Pi 3: you need to install pyenv to get Python 3.13 and all build dependencies, it takes easilly 1-2 GB and even, the build process requires so much RAM that it simply fails.
An alternative would be to use podman/docker to run Home Assistant, but these containerization solutions do use so much disk, there is no way to start a Home Assistant container on a 8GB SD-card.
Hence I came up with some hacking to overcome this problem, fasten your seat belts, it will be a few steps.
First pull the HA image on your PC:
podman pull --platform=linux/arm/v7 ghcr.io/home-assistant/home-assistant:stable
Create a Containerfile
to squash the layers in this home-assistant container image:
cat > Containerfile <<EOF
FROM --platform=linux/arm/v7 ghcr.io/home-assistant/home-assistant:stable
EOF
Run podman build to create the squashed image:
podman build -t ha-custom --platform linux/arm/v7 --squash-all .
Export the image to a tar archive:
podman save -o /tmp/ha.tar ha-custom:latest
Untar the archive:
mkdir /tmp/layers
tar xf /tmp/ha.tar -C /tmp/layers
You will see one layer similar to this:
❯ cd /tmp/layers
❯ ls -la
total 1530852
drwxrwxr-x 3 kris kris 140 Jan 2 18:22 .
drwxrwxrwt 31 root root 1040 Jan 2 18:21 ..
drwxrwxr-x 2 kris kris 100 Jan 2 18:22 5ad0840b525f38812d396803799c16271d2d6d2072c817cce74edd61ed59d0cb
-r--r--r-- 1 kris kris 1567576576 Jan 1 1970 9f0f354b3f4302e527049940c640172969298fbb7c03429a614ffd09b91dd882.tar
-r--r--r-- 1 kris kris 1650 Jan 1 1970 a21e0feafae2ee21ce32e3d0eac01a288adf7781628f0acefa30b1f47c332ecf.json
-r--r--r-- 1 kris kris 208 Jan 1 1970 manifest.json
-r--r--r-- 1 kris kris 101 Jan 1 1970 repositories
Untar the layer:
mkdir /tmp/ha-root
tar xf 9f0f354b3f4302e527049940c640172969298fbb7c03429a614ffd09b91dd882.tar -C /tmp/ha-root
Now, compress the Home Assistant files to a SquashFS archive:
cd /tmp/ha-root
mksquashfs . ../ha.sqfs
And copy this file to your RPi into, let's say, /opt/homeassistant
.
Now all we need to do is to mount it (at boot):
sudo -i
cat > /usr/local/bin/homeassistant_fs.sh <<EOF
#!/bin/bash
mkdir -p /opt/homeassistant/{readonly,upper,work,image}
cd /opt/homeassistant
mount -o loop ha.sqfs readonly
mount -t overlay -o lowerdir=readonly,upperdir=upper,workdir=work overlay image
cd image
mount -B /dev dev
mount -B /proc proc
mount -B /sys sys
cp /etc/resolv.conf /opt/homeassistant/image/etc/resolv.conf
mkdir -p run/dbus
mount -B /run/dbus run/dbus
mount -o remount,bind,ro /opt/homeassistant/image/run/dbus
EOF
chmod +x /usr/local/bin/homeassistant_fs.sh
cat > /etc/systemd/system/homeassistant-fs.service <<EOF
[Unit]
Description=Home Assistant Filesystem prepare Script
After=network.target local-fs.target
Requires=local-fs.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/homeassistant_fs.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable homeassistant-fs
systemctl start homeassistant-fs
Now we can start Home Assistant
sudo chroot /opt/homeassistant/image /usr/local/bin/hass
We could create a systemd unit for this, but my first attempt failed, as a workaround I run it from tmux
.
The upper
directory contains all modified files on our Home Assistant, so backing up the instance shouldn't be more than backing up the upper
directory.
Upgrading the instance shouldn't be complicated either, simply re-generate and replace the sqfs file.