I ran out of space on my system drive because of Ollama’s AI models. To fix this, I decided to move the Ollama models folder to a secondary drive.
By default ollama uses this place to store the models /usr/share/ollama/.ollama/models
|
1 2 3 4 |
$ du -sh /usr/share/ollama/.ollama 13G /usr/share/ollama/.ollama |
I stopped the ollama
|
1 2 3 |
$ sudo systemctl stop ollama |
And created a new folder on the new disk
|
1 2 3 |
mkdir -p /work/ai/ollama/usr/share/ollama/.ollama |
then I synced the files via rsync
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$ sudo rsync -av /usr/share/ollama/.ollama/ /work/ai/ollama/usr/share/ollama/.ollama [sudo: authenticate] Password: sending incremental file list ./ id_ed25519 id_ed25519.pub models/ ... models/manifests/ models/manifests/registry.ollama.ai/library/nomic-embed-text/latest models/manifests/registry.ollama.ai/library/qwen2.5-coder/ models/manifests/registry.ollama.ai/library/qwen2.5-coder/1.5b models/manifests/registry.ollama.ai/library/qwen2.5-coder/3b sent 13,034,956,989 bytes received 614 bytes 253,105,972.87 bytes/sec total size is 13,031,771,822 speedup is 1.00 |
After that I added new place to the ollama service config
|
1 2 3 4 |
$ sudo mkdir -p /etc/systemd/system/ollama.service.d/ $ sudo nano cat /etc/systemd/system/ollama.service.d/override.conf |
you need to change or in my case append the next
|
1 2 3 4 |
[Service] Environment="OLLAMA_MODELS=/work/ai/ollama/usr/share/ollama/.ollama" |
Rename your old models folder to something like models-tmp
|
1 2 3 |
$ sudo mv /usr/share/ollama/.ollama/models /usr/share/ollama/.ollama/models-tmp |
Then restart the daemon and ollama
|
1 2 3 4 |
$ sudo systemctl daemon-reload $ sudo systemctl start ollama |
You can validate that the new folder is configured properly by executing the next. Scroll to the right of the output to see the new folder
|
1 2 3 4 5 |
$ systemctl show ollama.service --property=Environment systemctl show ollama.service --property=Environment Environment=PATH=/home/ ... OLLAMA_MODELS=/work/ai/ollama/usr/share/ollama/.ollama/models |
if everything ok validate your models
|
1 2 3 4 5 6 7 8 9 |
$ ollama list NAME ID SIZE MODIFIED qwen2.5-coder:3b f72c60cabf62 1.9 GB 2 weeks ago nomic-embed-text:latest 0a109f422b47 274 MB 4 months ago qwen2.5-coder:1.5b d7372fd82851 986 MB 4 months ago llama3.1:8b 46e0c10c039e 4.9 GB 4 months ago deepseek-r1:8b 28f8fd6cdc67 4.9 GB 11 months ago |
if your models om place remove the old folder
|
1 2 3 |
$ sudo rm -rf .ollama/models-tmp |
and check the disk space
|
1 2 3 4 |
$ du -sh /usr/share/ollama/.ollama 12K /usr/share/ollama/.ollama |