Post

Home Assistant 2024.12 upgrade in FreeBSD jail

About this page

This is a memo that I use when upgrading my Home-Assistant jail, and it’s based on this Brendan’s bits blog post

Credits and thanks go to:

When upgrading different services which run in dedicated jails, I prefer to rebuild the jail from scratch, it’s just a personnal motto that I use since many years and which basically says

“Backup data only and know how to rebuild the rest.”

1. Create a new jail for Home-Assistant 2024.12

All my root pools on FreeBSD are named “rpool”, a small relic that I kept from OpenSolaris :), and I keep a templated jail for latest FreeBSD version with preinstalled packages such as bash and joe (my prefered editor), the templated jail is kept is ZFS stream and is built from standard poudriere’s jail snapshot.

1
zfs receive -v rpool/jail/hass202412 < /poudriere/data/packages/zfs/jail142-release.zfs

Add it in /etc/jail.conf

1
hass202412  { ip4.addr = vlan2|192.168.X.X; allow.raw_sockets = 1; allow.sysvipc = 1; }

Start the jail, enter it

1
2
service jail start hass202412
jexec hass202412 bash

2. Prepare jail packages

1
2
# These are dependecies required to build Home-Assistant
pkg install tmux git-lite ca_root_nss cmake ffmpeg gcc gmake libjpeg-turbo nasm openblas openjpeg pkgconf sqlite3 pyenv rust

3. Prepare Home-Assistant account and Python 3.12

Create service account, install Python 3.12

1
2
3
4
5
NAME=homeassistant ID=998 && pw groupadd -n $NAME -g $ID && pw useradd -n $NAME -g $NAME -u $ID -s /usr/local/bin/bash -w no -d /home/$NAME -m -M 750 -G wheel
su - homeassistant
pyenv install 3.12.7
pyenv global 3.12.7
pyenv init

edit .profile and add this

1
2
3
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

restart su session, then check python 3.12 is setup correctly

1
2
3
exit
su - homeassistant
python --version

4. Install HomeAssistant in python virtual environment

Below are the final steps condensed into the script below, which will say “DONE” at the end in case of success. If it fails at some step, it will say “mort..” and will stop, se investigate what went wrong, fix it, then manually complete missing steps.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash

mort() {
  echo "mort.." && exit
}

mkdir -p ~/HA-2024.12 || mort
cd ~/HA-2024.12 || mort
python -m venv . || mort
source bin/activate || mort
pip install --upgrade pip || mort
pip install wheel || mort
pip install mutagen || mort

mkdir -p ~/src || mort
cd ~/src || mort
if [ ! -d python-isal ]; then git clone https://github.com/pycompression/python-isal.git; fi
cd python-isal || mort
sed -i '' "s@1.7.0-dev@1.6.1@" setup.py || mort
git submodule update --init --recursive || mort
pip install . || mort

cd ~/src || mort
pip install git+https://github.com/rhasspy/webrtc-noise-gain.git@a5ea46ffa29e76d5bde2b0bafaa28bee21cb7415 || mort

cd ~/src || mort
if [ ! -d numpy ]; then git clone https://github.com/numpy/numpy.git; fi
cd numpy || mort
git checkout v1.26.0 || mort
git cherry-pick 040ed2d || mort
git submodule update --init || mort
pip install . || mort

cd ~/ || mort
pip install homeassistant~=2024.12.1 || mort
echo DONE

5. Copy data folder and switch the jails, first start

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Control-D to leave the jail, then as root
# stop both jails, new one and prod
service jail stop hass202412 hass
# copy prod data folder to the new jail
cd /jail/hass/home/homeassistant
pax -rw -pe .homeassistant /jail/hass202412/home/homeassistant/
cd
# rename
zfs rename rpool/jail/hass rpool/jail/hass202411
# sometimes this fails, zfs umount -f rpool/jail/hass && zfs mount rpool/jail/hass
zfs rename rpool/jail/hass202412 rpool/jail/hass
# start the new jail
service jail start hass
jexec hass bash
su - homeassistant
cd ~/HA-2024.12
source bin/activate
hass --ignore-os-check -v -c /home/homeassistant/.homeassistant
# wait until until all additional deps are installed and first start complete, then Control-C to stop it

6. Add service script, enable auto start

Install service script from Brendan’s bits repo at https://brew.bsd.cafe/brendans_bits/freebsd-home-assistant-rc-script/src/branch/main/usr/local/etc/rc.d/homeassistant

1
2
3
4
5
6
7
8
9
# back into the new jail, then as root
jexec hass bash
fetch -q -o /usr/local/etc/rc.d/homeassistant https://brew.bsd.cafe/brendans_bits/freebsd-home-assistant-rc-script/raw/branch/main/usr/local/etc/rc.d/homeassistant
chmod 755 /usr/local/etc/rc.d/homeassistant
sysrc homeassistant_environment="/home/homeassistant/HA-2024.12"
sysrc homeassistant_enable="YES"
service homeassistant start
# Inspect log to see everything runs ok
tail /var/log/homeassistant/homeassistant-daemon.log