commit 1929f21b1a83446fd46870093aeb74cf335a271e Author: Antonio de la Rosa Date: Tue Apr 1 18:13:54 2025 +0200 Added incus_ollama diff --git a/install_incus_ollama.sh b/install_incus_ollama.sh new file mode 100644 index 0000000..9c33baa --- /dev/null +++ b/install_incus_ollama.sh @@ -0,0 +1,153 @@ +#!/bin/bash + +# Script for create a simple ai system with LXC and Incus. + +## Install updated repos for debian 12 + +echo "Install new repos for debian..." + +sudo bash -c 'echo "deb http://deb.debian.org/debian bookworm-backports main contrib non-free non-free-firmware" >> /etc/apt/sources.list.d/backports.list' + +sudo curl -fsSL https://pkgs.zabbly.com/key.asc | gpg --show-keys --fingerprint + +sudo mkdir -p /etc/apt/keyrings/ + +sudo curl -fsSL https://pkgs.zabbly.com/key.asc -o /etc/apt/keyrings/zabbly.asc + +sudo sh -c 'cat < /etc/apt/sources.list.d/zabbly-incus-stable.sources +Enabled: yes +Types: deb +URIs: https://pkgs.zabbly.com/incus/stable +Suites: $(. /etc/os-release && echo ${VERSION_CODENAME}) +Components: main +Architectures: $(dpkg --print-architecture) +Signed-By: /etc/apt/keyrings/zabbly.asc + +EOF' + +sudo apt install -y software-properties-common + +sudo apt-add-repository -y contrib + +sudo apt-add-repository -y non-free + +sudo apt-add-repository -y non-free-firmware + +sudo apt-get update && sudo apt-get upgrade + +# Install new kernel. + +sudo apt-get -y install linux-image-6.11.10+bpo-amd64 linux-headers-6.11.10+bpo-amd64 + +# Install cuda nvidia drivers + +echo "Install nvidia drivers" + +sudo apt -y purge "*nvidia*" + +wget https://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/cuda-keyring_1.1-1_all.deb +sudo dpkg -i cuda-keyring_1.1-1_all.deb +sudo apt-get -y -f install +sudo apt -y update + +sudo bash -c 'echo "deb [signed-by=/usr/share/keyrings/cuda-archive-keyring.gpg] https://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/ /" \ + | tee /etc/apt/sources.list.d/cuda-debian12-x86_64.list' + +sudo apt -y update + +sudo apt -y install cuda-drivers + +sudo apt -y install curl +sudo curl -fsSL https://ollama.com/install.sh | sh + +sudo systemctl stop ollama && sudo systemctl disable ollama + +# Installing incus + +echo "Installing Incus" + +sudo apt -y install qemu-system-x86/bookworm-backports qemu-system-common/bookworm-backports qemu-system-data/bookworm-backports seabios/bookworm-backports + +sudo apt -y install incus + +sudo usermod -a -G incus,incus-admin $USER + +incus admin init + +# Install ollama container + +echo "Create ollama container" + +incus launch images:debian/12 ollama-container + +incus restart ollama-container + +incus config device add ollama-container gpu gpu + +# Install nvidia + +incus exec ollama-container -- bash -c 'echo "deb http://deb.debian.org/debian bookworm-backports main contrib non-free non-free-firmware" >> /etc/apt/sources.list.d/backports.list' + +incus exec ollama-container -- curl -fsSL https://pkgs.zabbly.com/key.asc | gpg --show-keys --fingerprint + +incus exec ollama-container -- mkdir -p /etc/apt/keyrings/ + +incus exec ollama-container -- curl -fsSL https://pkgs.zabbly.com/key.asc -o /etc/apt/keyrings/zabbly.asc + +incus exec ollama-container -- sh -c 'cat < /etc/apt/sources.list.d/zabbly-incus-stable.sources +Enabled: yes +Types: deb +URIs: https://pkgs.zabbly.com/incus/stable +Suites: $(. /etc/os-release && echo ${VERSION_CODENAME}) +Components: main +Architectures: $(dpkg --print-architecture) +Signed-By: /etc/apt/keyrings/zabbly.asc + +EOF' + +incus exec ollama-container -- apt install -y software-properties-common + +incus exec ollama-container -- apt-add-repository -y contrib + +incus exec ollama-container -- apt-add-repository -y non-free + +incus exec ollama-container -- apt-add-repository -y non-free-firmware + +incus exec ollama-container -- apt-get update && sudo apt-get upgrade + +# Install new kernel. + +incus exec ollama-container -- apt-get -y install linux-image-6.11.10+bpo-amd64 linux-headers-6.11.10+bpo-amd64 + +# Install cuda nvidia drivers + +echo "Install nvidia drivers in container" + +incus exec ollama-container -- apt -y purge "*nvidia*" + +incus exec ollama-container -- wget https://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/cuda-keyring_1.1-1_all.deb +incus exec ollama-container -- dpkg -i cuda-keyring_1.1-1_all.deb +incus exec ollama-container -- apt-get -y -f install +incus exec ollama-container -- apt update + +incus exec ollama-container -- bash -c 'echo "deb [signed-by=/usr/share/keyrings/cuda-archive-keyring.gpg] https://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/ /" \ + | tee /etc/apt/sources.list.d/cuda-debian12-x86_64.list' + +incus exec ollama-container -- apt -y update + +incus exec ollama-container -- apt -y install cuda-drivers + +echo "Install Ollama in container ollama-container" + +incus exec ollama-container -- apt -y install curl +incus exec ollama-container -- curl -fsSL https://ollama.com/install.sh | sh + +incus exec ollama-container -- ollama run gemma3:4b + + +echo "Done!!!" + +sleep 3 + +echo "Please, you can enter to ollama container with incus exec ollama-container -- /bin/bash" +echo "Use journalctl -u ollama.service command for check if ollama is working"