/var/log

A blog about UNIX and programming.

ho.stna.me : ~ ❯ ls

blog foo.txt

ho.stna.me : ~ ❯ cd blog

ho.stna.me : ~/blog ❯ cat immich-migrate.md

Immich Migration

Migrating the AppJail Immich CUDA ML Stack

This document describes how to migrate the current AppJail Director Immich deployment to another FreeBSD host, including the local CUDA-enabled immich-machine-learning image.

The active source layout on this host is:

/root/appjail
/var/appjail-volumes/immich
localhost/local/immich-machine-learning:freebsd-cuda

Do not copy this document as a blind script. Review IP addresses, interface names, pool/dataset layout, and secrets on the destination host.

1. Destination host prerequisites

Install and enable the same runtime pieces before importing data:

pkg install -y appjail py311-director podman buildah nvidia-driver linux-nvidia-libs
sysrc linux_enable=YES
sysrc kld_list+=nvidia
service linux start
kldload nvidia
nvidia-smi

The CUDA ML path depends on:

  • FreeBSD NVIDIA driver working on the host.
  • Linuxulator enabled.
  • linux-nvidia-libs matching the host NVIDIA driver.
  • AppJail and AppJail Director available.
  • The same LAN IP plan, or updated .env values on the destination.

The current AppJail Director service IPs are:

immich-server: 192.168.3.110
immich-ml:     192.168.3.111
redis:         192.168.3.112
postgres:      192.168.3.113

If those IPs are not valid on the destination, update .env before running appjail-director up.

2. Stop the source stack

Stop the source stack before taking the final database and asset copy:

cd /root/appjail
appjail-director down

If you need minimal downtime, take an initial copy while the stack is live, then stop the stack and run a final incremental copy.

3. Copy AppJail Director config

Copy the AppJail project directory to the destination:

rsync -aHAX /root/appjail/ new-host:/root/appjail/

The important files are:

/root/appjail/appjail-director.yml
/root/appjail/Makejail
/root/appjail/Makejail.ml
/root/appjail/immich-postgres-template.conf
/root/appjail/scripts/ml-poststart.sh
/root/appjail/.env

Before starting on the destination, review /root/appjail/.env:

sed -n '1,120p' /root/appjail/.env

Do not reuse a placeholder password accidentally. Either copy the real DB_PASSWORD intentionally or rotate it as part of a planned database migration.

The ML service uses:

localhost/local/immich-machine-learning:freebsd-cuda

The remote services still use args:--pull; the ML service intentionally does not, because it consumes a local image.

4. Copy persistent data

Copy the AppJail volumes:

rsync -aHAX /var/appjail-volumes/immich/ new-host:/var/appjail-volumes/immich/

The key paths are:

/var/appjail-volumes/immich/library
/var/appjail-volumes/immich/external-library
/var/appjail-volumes/immich/postgres
/var/appjail-volumes/immich/redis
/var/appjail-volumes/immich/cache

cache is optional from a correctness standpoint, but copying it avoids model and thumbnail/cache re-download or regeneration work.

5. Transfer the local CUDA ML image

The local ML image is host-specific because it includes Linux NVIDIA userspace libraries copied from the FreeBSD host. If the destination host uses the same NVIDIA driver version, transfer the image:

podman save \
  -o /root/immich-machine-learning-freebsd-cuda.tar \
  localhost/local/immich-machine-learning:freebsd-cuda

rsync -aHAX \
  /root/immich-machine-learning-freebsd-cuda.tar \
  new-host:/root/

On the destination:

podman load -i /root/immich-machine-learning-freebsd-cuda.tar
podman image inspect localhost/local/immich-machine-learning:freebsd-cuda

If the destination NVIDIA driver version differs, rebuild the image on the destination instead of reusing the source image:

rsync -aHAX \
  /root/immich/custom-images/immich-machine-learning/ \
  new-host:/root/immich/custom-images/immich-machine-learning/

/root/immich/custom-images/immich-machine-learning/build.sh

Rebuilding is safer when driver versions differ because the derived image bakes in host-matched Linux NVIDIA libraries.

6. Start on the destination

Start the AppJail Director stack:

cd /root/appjail
appjail-director up

The remote images should pull from GHCR. The ML image should resolve from the local image store.

7. Validate runtime health

Check the server and ML endpoints:

fetch -qo- http://192.168.3.110:2283/api/server/ping
fetch -qo- http://192.168.3.111:3003/ping

Expected results:

{"res":"pong"}
pong

Validate Linux runtime mounts and GPU device exposure in the ML jail:

appjail cmd jexec immich_machine_learning sh -lc 'cat /proc/cpuinfo >/dev/null && echo proc-ok'
appjail cmd jexec immich_machine_learning sh -lc 'test -d /sys && echo sys-ok'
appjail cmd jexec immich_machine_learning sh -lc 'ls -l /dev/nvidia0 /dev/nvidiactl'

Then trigger a real ML operation from Immich, such as smart search or a CLIP prediction, and inspect the ML logs for:

CUDAExecutionProvider

The CUDA provider log is the meaningful GPU validation. /ping only proves the service is alive.

8. Optional: import a large media folder with the Immich CLI

If you are not copying the existing Immich upload library and instead want to import a large folder as normal uploaded assets, use the Immich CLI.

Install and log in:

npm i -g @immich/cli
immich login http://192.168.3.110:2283/api '<api-key>'

Dry-run the import first:

immich upload --dry-run --recursive /path/to/photos

For a large mostly-unique first import, skip the CLI-side pre-upload hash pass:

immich upload --skip-hash --recursive /path/to/photos

--skip-hash avoids local pre-hashing in the CLI. Immich still performs server-side hashing and deduplication, but re-running imports with many already-uploaded files is usually better without --skip-hash so the CLI can avoid unnecessary upload attempts.

If the folder should remain referenced in place rather than copied into Immich's upload library, use the external library path instead:

/var/appjail-volumes/immich/external-library

That path is mounted into immich-server as:

/external-library

9. Rollback notes

If the destination ML jail starts but does not use the GPU, check these first:

nvidia-smi
podman image inspect localhost/local/immich-machine-learning:freebsd-cuda
sed -n '1,120p' /root/appjail/Makejail.ml
sed -n '1,120p' /root/appjail/scripts/ml-poststart.sh

Common causes are:

  • the local ML image was not loaded
  • the image was transferred across mismatched NVIDIA driver versions
  • linprocfs or linsysfs did not mount
  • AppJail devfs rules did not expose /dev/nvidia*
  • the ML log is only showing service startup, not a real inference request yet

EOF

ho.stna.me : ~/blog ❯ ls -lta

drwxr-xr-x 4 user staff 13 16:23 .
drwxr-xr-x 3 user staff 2 16:23 ..
drwxr-xr-x 3 user staff 3 16:23 archives
drwxr-xr-x 10 user staff 10 16:23 tags
-rw-r--r-- 1 user staff 5967 16:23 collaboration.md
-rw-r--r-- 1 user staff 7349 16:23 fossil-agent-dev.md
-rw-r--r-- 1 user staff 9680 16:23 codex-freebsd.md
-rw-r--r-- 1 user staff 6873 16:23 immich-migrate.md
-rw-r--r-- 1 user staff 2139 16:23 mkblog-source.md
-rw-r--r-- 1 user staff 4195 16:23 mkblog-intro.md
-rw-r--r-- 1 user staff 3975 16:23 authoring-posts.md
-rw-r--r-- 1 user staff 328 16:23 terminal-demo.md
-rw-r--r-- 1 user staff 118 16:23 hello-world.md

ho.stna.me : ~/blog ❯