Skip to content

About

Install Immich in LXC with optional CUDA support

Resources

Stars

5 stars

Watchers

2 watching

Forks

 
 

Repository files navigation

Immich with CUDA/ROCm Support in LXC (w/o Docker)

Build immich on new release

A complete guide for installing Immich in LXC, VM, or bare-metal without Docker, but with

  • CUDA/ROCm support for machine-learning (if one choose so),
  • hardware acceleration for transcoding,
  • HEIF, RAW, and JXL support,
  • Experimental Intel iGPU/dGPU/NPU support for machine-learning (if one choose so),
  • easy and fast upgrade, and
  • accessible proxy settings for PyPi and NPM registry.

Introduction

Immich is a

High performance self-hosted photo and video management solution

I really like Immich and its coherent experience across both mobile and web. However, the official Documents only provides Docker installation guide, which is less than ideal for a LXC user. But, in fairness to Immich, not providing a bare-metal installation guide can be justified, as it is more than a simple binary and does require some efforts to set up in current state.

This guide is heavily inspired by another guide Immich Native, and the install script & service files are modified from the ones in that repo. KUDO to its author, arter97!

Compared to Immich Native, this repo additionally offers the support for CUDA-accelerated machine learning and (out-of-box) support for processing HEIF, i.e. common smart phone image format, and RAW, i.e. common fancy big camera image format, images.

Why hardware acceleration?

I paid for the whole Speedometer, I'm gonna use the whole Speedometer.

-- Abraham Lincoln

Jokes aside, hardware acceleration really helps during importing library containing many videos, or live photos (essentially a photo and video bundle), or when one would like to switch to or test out a bigger and better machine learning model to improve smart search or face search functionality, which requires a redo of the entire indexing process. However, during current stage and foreseeable future, the heavy work of generating thumbnails will remain on using SIMD commands on CPU, and cannot be accelerated by GPU.

Lastly, by using this repo, one could reliably set up a hardware-accelerated Immich instance without much hassle. So why not.

Immich Components

Not so important
  • Immich
    • Web Server
    • Machine Learning Server
  • Database
    • Redis
    • Postgresql
      • VectorChord
  • System
    • Jellyfin-ffmpeg
    • Node.js
    • git
  • (Optional) Reverse Proxy
    • Nginx
  • (Optional) NVIDIA
    • Driver (i.e. CUDA Runtime)
    • CuDNN (Version 9)
  • (Optional) AMD
    • ROCm driver (6.4.1)

As one could tell, it is a lot of works, and a lot of things to get right. However, Immich is quite resilience and will fall-back to a baseline default when hardware acceleration does not work.

For the simplicity of the guide, all the components are installed in a single LXC container. However, it is always possible to run different components in different LXC containers. As it is always a design choice.


Host setup

Not so important

I am using Proxmox VE 8 as the LXC host, which is based on Debian 12, and I have a NVIDIA GPU, with a proprietary driver (550) installed. Some others are using a N100 mini PC box with Intel Quick Sync. And all of these do not matter.

However, if possible, use an LXC or VM with Ubuntu 24.04 LTS as it offers an easier set-up.


Prepare the LXC container, or whatever

First, create a LXC/VM normally. Make sure there is reasonable amount CPU and memory, because we are going to install and compile a lot of things, and it would not hurt to give it a bit more. For a CPU-only Immich server, there should be at least 8 GiB of storage, and one with nVidia GPU, at least 16 GiB storage needs to be available. However, once one starts using Immich, it will create a lot of cache (for thumbnails and low-res transcoded videos), so don't forget to resize the LXC volumes accordingly.

Also, there is no need for a privileged container (which is not recommended in almost all scenarios), if one does not plan to mount a file system, e.g., NFS, SMB, etc., directly inside the LXC container.

CI and prebuilt artifacts target Ubuntu 24.04 LTS, x86-64. Other distributions require a source build with compatible Python and system libraries.

Python requirements

Immich ML Python
<3.3 3.11
3.3+ >=3.12; defaults to Ubuntu 24.04's 3.12

Immich 3.3+ uses uv; earlier releases use Poetry. As root on Ubuntu 24.04:

apt update
apt install -y python3.12-venv python3.12-dev patchelf

For Immich <3.3, install Python 3.11 instead:

add-apt-repository -y ppa:deadsnakes/ppa
apt update
apt install -y python3.11 python3.11-venv python3.11-dev

Do not change system or venv Python symlinks. Upgrading from 3.11 requires a fresh application/venv. If the old workaround changed /usr/bin/python3, restore it with apt install --reinstall python3-minimal.

Hardware-accelerated machine learning

Nvidia

Firstly, prepare a LXC with GPU available by following the guide at another repository of mine. This process is referred to as NVIDIA GPU pass-through in LXC.

After finishing all of the steps in that guide, the guest OS should execute command nvidia-smi without any error.

The major component that Immch requires is ONNX runtime, and here we are installing its dependency.

Ubuntu 24.04

For Immich machine learning support in Ubuntu, we need to install CuDNN and CUDA Toolkit. The default cuDNN version in apt is version 8, which is no longer supported by ONNX Runtime. Thus, we need to install the latest version 9.

The CuDNN install commands are from official website of NVIDIA, and should all be run as root. Also, one should check the NVIDIA website for updates.

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-keyring_1.1-1_all.deb
dpkg -i cuda-keyring_1.1-1_all.deb
apt-get update

apt-get -y install cudnn-cuda-12

In addition to the cuDNN, we also need libcublas12 things.

apt install -y libcublaslt12 libcublas12 libcurand10

Debian 12

For Immich machine learning support in Debian, we need to install CuDNN and CUDA Toolkit.

We install the entire CUDA Toolkit because install libcublas depends on CUDA Toolkit, and when install the toolkit, this right version of this component will be included.

The CuDNN install commands are from official website of NVIDIA, and should all be run as root. Also, one should check the NVIDIA website for updates.

# CuDNN part
wget https://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/cuda-keyring_1.1-1_all.deb
dpkg -i cuda-keyring_1.1-1_all.deb
add-apt-repository contrib
apt-get update
apt-get -y install cudnn
## Specified by NVIDIA, but does not seem to install anything
apt-get -y install cudnn-cuda-12

# CUDA Toolkit part
apt install -y cuda-toolkit

Zu easy, innit?


Intel/OpenVINO

This part is intended for users who would like to utilize Intel's OpenVINO execution provider. (System requirement, List of supported devices) The document listed the support for not only Intel iGPU and dGPU, but also its NPU, which seems very cool.

Disclaimer: This part is not yet tested by the repo owner, and it is composed based on documentation. However, success have been reported (Issue #58), even though one could not see the background tasks (Issue #62).

Moe Firstly, prepare a LXC with proper hardware available. For iGPU user, one could use `intel_gpu_top` to see its availability.

Then, install the dependency specified by Immich for Intel.

./dep-intel.sh

Before running install.sh, set the following in the installation .env file described below. Run dep-intel.sh as root; hardware access and driver setup are separate from Python dependency installation.

isCUDA=openvino

I know, this is ugly as hell, but whatever, it works.

Now, when installing Immich, it will be using OpenVINO as its ML backend.



Others

Since Immich depends on ONNX runtime, it is possible that other hardware that is not officially supported by Immich can be used to do machine learning tasks. The idea here is that installing the dependency for the hardware following ONNX's instruction.

Some users have also reported successful results using GPU Transcoding in Immich by following the Proxmox configurations from this video: iGPU Transcoding In Proxmox with Jellyfin Media Center - Just avoid all the Jellyfin stuff and do the configurations on the Immich container instead. At the end, you should be able to use your iGPU Transcoding in Immich by going to needs to go to Administration > Settings > Video Transcoding Settings > Hardware Acceleration > Acceleration API and select Quick Sync to explicitly use the GPU to do the transcoding.

Good luck and have fun!


Immich Installation

User creation

First of all, create a Immich user, if you already done so in the above optional section, you may safely skip the following code block. The user created here will run Immich server.

adduser --shell /bin/bash --disabled-password immich --comment "Immich Mich"
# --shell changes the default shell the immich user is using. In this case it will use /bin/bash, instead of the default /bin/sh, which lacks many eye-candy
# --disabled-password skips creating password, and (sort of) only allows using su to access the user. If you need to change the password of the user, use the command: passwd immich
# --comment adds user contact info, not super useful but mandatory, probably thanks to Unix legacy.
apt install -y git
usermod -aG video,render immich

Clone the repo

I have make some helper script in this repo, so all one needs to do is clone the repo. We change to the user immich so that the files we cloned will have proper permission. And, just in case one does not know, the commands are as follow.

su - immich
cd ~
git clone https://github.com/tautomer/immich-in-lxc.git

Additionally, it is recommend to have our working directory set to the repo's directory.

cd immich-in-lxc

Install custom photo-processing library

Likely because of license issue, many libraries included by distribution package managers do not support all the image format we want, e.g., HEIF, RAW, etc. Thus, we need compile these libraries from source. It can be painful to figure out how to do this, but luckily, I have already sorted out for you.

Install compile tools and compile 始める

Now exit the immich user, as the upcoming commands should be run as root user.

# As root, from the cloned repository
cd /home/immich/immich-in-lxc
./pre-install.sh

It is just so satisfying to see the compiling log rolling down the terminal, ain't it? Look carefully at the log, though. There should not be any error. However, some warning about relink will pop up, which is normal.

Config PostgreSQL like a champ

The following steps apply to both Debian 12 and Ubuntu 24.04 instances.

Enter PostgreSQL control interface

# As root
su postgres
# Now you are user:postgres
psql

In the psql interface, run:

CREATE DATABASE immich;
CREATE USER immich WITH ENCRYPTED PASSWORD 'A_SEHR_SAFE_PASSWORD';
GRANT ALL PRIVILEGES ON DATABASE immich to immich;
ALTER USER immich WITH SUPERUSER;
\q

Note: change password, seriously.

Note: To change back to the pre-su user, exit should do the trick.

Database Migration for Existing Users (v1.133.0+)

Note: Starting with Immich v1.133.0, the project has migrated from pgvecto.rs to VectorChord for better performance and stability.

If you're upgrading from a version prior to v1.133.0 and have an existing Immich installation, you may need to perform a database migration. The migration from pgvecto.rs to VectorChord is automatic, but you should:

  1. Backup your database before upgrading
  2. Ensure you're upgrading from at least v1.107.2 or later

Note: If you have an existing $INSTALL_DIR/runtime.env (e.g. /home/immich/runtime.env) file with DB_VECTOR_EXTENSION=pgvector, you should update it to DB_VECTOR_EXTENSION=vectorchord for the new VectorChord extension.

For more details on the VectorChord migration, see the official Immich v1.133.0 release notes.

Install Immich Server

The star of the show is the install script, i.e. install.sh in this repo. It installs or updates the current Immich instance. The Immich instance itself is stateless, thanks to its design. Thus, it is safe to delete the app folder that will resides inside INSTALL_DIR folder that we are about to config.

Note: DO NOT DELETE THE UPLOAD FOLDER SPECIFIED BY UPLOAD_DIR IN .env. It stores all the user-uploaded content.

Also note: One should always do a snapshot of the media folder during the updating or installation process, just in case something goes horribly wrong.

The installation environment

As immich, create and edit .env in the checkout:

su - immich
cd /home/immich/immich-in-lxc
cp -n install.env .env
nano .env
Variable Purpose
REPO_TAG Exact Immich release tag to build.
INSTALL_DIR Installation directory; defaults to /home/immich. Use paths without spaces.
UPLOAD_DIR Persistent media directory, outside app.
isCUDA false (CPU), true (CUDA), openvino, or rocm.
ML_PYTHON Optional source-build interpreter override; defaults follow the Python table above.
PROXY_NPM Optional npm/pnpm registry mirror.
PROXY_NPM_DIST Optional Node distribution mirror.
PROXY_POETRY Optional Python package index for uv/Poetry.

The immich user needs read/write access to INSTALL_DIR and UPLOAD_DIR. .env controls installation; $INSTALL_DIR/runtime.env controls the services.

Run the script

After the .env is properly configured, we are now ready to do the actual installation.

./install.sh

Note, install.sh should be executed as user immich, or the user who is going to run immich.

It should go without errors, just like ever dev says.

After several minutes, ideally, it would say,

Done. Please install the systemd services to start using Immich.

Lastly, we need to review and modify the runtime.env that is inside your specified INSTALL_DIR (not the runtime.env inside this repo). The default values could also work, unless you changed the DB_PASSWORD when installing Postgres.

Note: If your DB_PASSWORD contains special characters (such as $, !, etc.), you must wrap the value in single quotes, e.g., DB_PASSWORD='your$pec!alP@ss'. This prevents shell expansion issues when the environment file is sourced. (See issue #95 for details.)

For Timezones TZ, you can consult them in the TZ Database Wiki.

Post install script

Run post-install.sh as root from the repository. It creates the log directory and copies service files only if they do not already exist; it does not overwrite existing units. Review installed units on upgrades, especially their paths and ExecStart.

# As root
cd /home/immich/immich-in-lxc
./post-install.sh

Then, modify the service files to make sure every path name is spelled correctly. You might need to modify the variables WorkingDirectory, EnvironmentFile, ExecStart with the INSTALL_DIR specified in the .env file (in case you didn't leave the default INSTALL_DIR).

nano /etc/systemd/system/immich-ml.service # Modify WorkingDirectory, EnvironmentFile, and ExecStart with your INSTALL_DIR, in case you changed it.
nano /etc/systemd/system/immich-web.service # Modify ExecStart with your INSTALL_DIR, in case you changed it.

After reviewing runtime.env and both units, start the services:

systemctl daemon-reload && \
systemctl start immich-ml && \
systemctl start immich-web

The default setting exposes the Immich web server on port 2283 on all available address. For security reason, one should put a reverse proxy, e.g. Nginx, HAProxy, in front of the immich instance and add SSL to it.

To make the service persistent and start after reboot,

systemctl enable immich-ml && \
systemctl enable immich-web

Immich config

Because we are install Immich instance in a none docker environment, some DNS lookup will not work. For instance, we need to change the URL inside Administration > Settings > Machine Learning Settings > URL to http://localhost:3003, otherwise the web server cannot communicate with the ML backend.

Additionally, for LXC with CUDA or other GPU Transcoding support enabled, one needs to go to Administration > Settings > Video Transcoding Settings > Hardware Acceleration > Acceleration API and select your GPU Transcoding (e.g., NVENC - for CUDA) to explicitly use the GPU to do the transcoding.

Update a source-built instance

Back up your database, media, application, and configuration. Review upstream upgrade requirements. As root, install the required Python above and stop the services:

systemctl stop immich-ml immich-web

As immich, update this fork's checkout, set REPO_TAG in .env, and rebuild:

cd /home/immich/immich-in-lxc
git pull --ff-only
nano .env
./install.sh

The installer replaces app, including the ML venv, but preserves UPLOAD_DIR and an existing runtime.env. Remove any obsolete Python 3.11 override for 3.3+. After a successful install, restart and check both services as root:

systemctl restart immich-ml immich-web
systemctl status immich-ml immich-web

Install or update prebuilt artifacts

For Ubuntu 24.04 x86-64, installed at /home/immich, with OpenVINO ML. The database, Redis, FFmpeg, GPU drivers, and runtime configuration must already be set up. Install the matching Python from the table above and stow.

  1. Back up your database, media, and configuration. Stop both services as root.

  2. Download both archives from the same release in this fork's releases.

  3. As root, unstow/uninstall old dependency libraries first. Back up any existing /opt/stow/deps, then install the new libraries:

    apt install -y stow
    mkdir -p /opt/stow
    if [ -d /opt/stow/deps ]; then mv /opt/stow/deps "/opt/stow/deps.old-$(date +%s)"; fi
    tar -xzf /root/dependencies.tar.gz --no-same-owner -C /opt/stow
    cd /opt/stow/deps/stow
    for package in */; do stow -v -t /usr/local "${package%/}"; done
    ldconfig
  4. As immich, with server.tar.gz in /home/immich, replace the application:

    cd /home/immich
    stamp=$(date +%Y%m%d-%H%M%S)
    if [ -d app ]; then mv app "app.old-$stamp"; fi
    if [ -d geodata ]; then mv geodata "geodata.old-$stamp"; fi
    tar -xzf server.tar.gz
    UPLOAD_DIR=/your/existing/upload/path
    ln -sfnT "$UPLOAD_DIR" app/upload
    ln -sfnT "$UPLOAD_DIR" app/machine-learning/upload
  5. Keep your existing runtime.env and review the installed service paths. As root, restart and check immich-ml and immich-web. Keep backups until both work. Do not change the packaged venv's Python interpreter.

About

Install Immich in LXC with optional CUDA support

Resources

Stars

5 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages