Slipping addons into HassOS images for the Home Assistant Workshop

At Linux Conf 2019, I'll be running a home automation workshop, based on Home Assistant and my 1Wire home automation devices.

Part of this involves installing my OWFS to MQTT gateway, but since this is currently handled as a local repository, the Docker image for it is built on the local machine, which takes around 15 minutes on the Orange Pi Prime.

In order to expedite things for the workshop attendees, I decided to slipstream the addon into the install image. This is how I did it.

First, download and extract the HassOS image.

The image is too small to hold the docker images we will be adding (it is resized on first boot to fill the SD card), so we need to increase the size, I used 4GB.

truncate --size 4G hassos_opi-prime-2.6.img

Next, we need to repartition the device so the hassos-data partitition is big enough to fit our data. We will create a loopback device pointing at the file to allow us to treat it as a block device.

losetup -f ./hassos_opi-prime-2.6.img
losetup -a
sgdisk -e /dev/loop0
sgdisk -d 8 -n 8:0:0 -c 8:hassos-data -t 8:0FC63DAF-8483-4772-8E79-3D69D8477DE4 -u "8:a52a4597-fa3a-4851-aefd-2fbe9f849079" /dev/loop0
sgdisk -v /dev/loop0
losetup -D

Now we need to resize the filesys on the hassos-data partition

losetup -f -P /tmp/hassos_opi-prime-2.6-lca2019.img
e2fsck -y /dev/loop0p8
resize2fs -f /dev/loop0p8

We are now ready to mount the filesystem.

mount /dev/loop0p8 /mnt

Now it's simply a matter of copying across the docker and supervisor/addons directories from an established setup, and the addons will be available in the new instance after the image has been written to a card and booted. Note that this will also bring across the config.json files, so if there is sensitive information in the configs, such as usernames, passwords, or SSH keys, you should audit them first.

rm -rf /mnt/docker/
cp -Rpv docker/ /mnt
cd supervisor
vi addons.json
rm addons/data/a0d7b954_ssh/*
cp -Rpv addons* /mnt/supervisor/

Thats it! Unmount the image, recompress it and it's ready to hand out for distribution.

umount /mnt
losetup -D
gzip -9 hassos_opi-prime-2.6-lca2019.img