---
title: "Immich Migration"
date: 2026-04-07
tags:
  - freebsd
  - cli
  - immich
  - cuda
---

# 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:

```text
/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:

```sh
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:

```text
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:

```sh
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:

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

The important files are:

```text
/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`:

```sh
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:

```text
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:

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

The key paths are:

```text
/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:

```sh
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:

```sh
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:

```sh
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:

```sh
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:

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

Expected results:

```text
{"res":"pong"}
pong
```

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

```sh
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:

```text
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:

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

Dry-run the import first:

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

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

```sh
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:

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

That path is mounted into `immich-server` as:

```text
/external-library
```

## 9. Rollback notes

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

```sh
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
