Can't activate ollama after changing model folder

Ubuntu 24.04 new install
Gnome, X11, dash to panel plugin
I’ve installed Ollama on my pc, after install, I checked and it’s working, after few times changing the model’s folder to my separate HD, I can’t activate ollama any longer, what’s the correct procedure? The steps I took: open terminal

  1. sudo systemctl status ollama
  2. sudo systemctl stop ollama
  3. sudo geany /etc/systemd/system/ollama.service
  4. add Environment=“OLLAMA_MODELS=/media/data/backup/user/AI/Ollama_models/” at the end of [Service] entry, then save and exit
  5. sudo systemctl daemon-reload
  6. sudo systemctl restart ollama.service
    I remembered doing the same procedure in my previous MX Linux, it was working fine, but this time I got the error Process: 8334 ExecStart=/usr/local/bin/ollama serve (code=exited, status=1/FAILURE) What I’m missing?

Does the user Ollama is running as have permission to

  • read, write, and navigate your custom Ollama models directory (rwx permissions);
  • navigate (at least x permission) all parent/ancestor directories of your custom Ollama models directory, so that it can reach your custom Ollama models directory:
    • /media/data/backup/user/AI
    • /media/data/backup/user
    • /media/data/backup
    • /media/data
    • /media
    • /

After Ollama fails to start, does

systemctl status ollama

show any related messages?

@halogen2 yes, this is the message
Loaded: loaded (/etc/systemd/system/ollama.service; enabled; preset: enabled) Active: activating (auto-restart) (Result: exit-code) since Sun 2025-03-23 14:29:46 > Process: 24698 ExecStart=/usr/local/bin/ollama serve (code=exited, status=1/FAILURE) Main PID: 24698 (code=exited, status=1/FAILURE)
and the log shows permission error
Mar 23 14:29:49 UbuntuMini systemd[1]: Started ollama.service - Ollama Service. Mar 23 14:29:49 UbuntuMini ollama[24712]: 2025/03/23 14:29:49 routes.go:1230: INFO server> Mar 23 14:29:49 UbuntuMini ollama[24712]: Error: mkdir /media/data: permission denied Mar 23 14:29:49 UbuntuMini systemd[1]: ollama.service: Main process exited, code=exited, > Mar 23 14:29:49 UbuntuMini systemd[1]: ollama.service: Failed with result 'exit-code'. Mar 23 14:29:52 UbuntuMini systemd[1]: ollama.service: Scheduled restart job, restart cou>
and my Ollama_models folder is wide open
drwxrwxrwx 1 root root 0 Mar 23 08:53 Ollama_models
do I need to change the owner?

Does the /media/data directory exist?
Are you running Ollama with some kind of sandboxing (e.g. AppArmor, bubblewrap, or systemd-based sandboxing)?
Could you please post the full contents of your /etc/systemd/system/ollama.service file?

@halogen2 yes, /media/data directory exist
no, I’m not running in sandboxing, which one do you use/recommend?
here’s the output:
`[Unit]
Description=Ollama Service
After=network-online.target

[Service]
ExecStart=/usr/local/bin/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
Environment=“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin”
Environment=“OLLAMA_MODELS=/media/data/backup/user/AI/Ollama_models/”

[Install]
WantedBy=default.target`

Please post the output from running this in Terminal -

d=/media/data/backup/user/AI/Ollama_models; while [[ -n "$d" ]];do ls -ld "$d";d="${d%/*}";done

@halogen2 sorry, made a mistake, it’s missing michael in the path, this is the output:
drwxrwxrwx 1 root root 0 Mar 23 08:53 /media/michael/data/backup/user/AI/Ollama_models drwxrwxrwx 1 root root 4096 Mar 23 17:27 /media/michael/data/backup/user/AI drwxrwxrwx 1 root root 4096 Mar 17 09:06 /media/michael/data/backup/user drwxrwxrwx 1 root root 4096 Mar 17 09:12 /media/michael/data/backup drwxrwxrwx 1 root root 8192 Mar 22 10:48 /media/michael/data drwxr-x---+ 3 root root 4096 Mar 19 21:33 /media/michael drwxr-xr-x 3 root root 4096 Mar 18 06:16 /media

This is likely the problem. Are you able to mount this partition somewhere else?

@halogen2 thanks for you time and effort, I opened that folder to rwx, now it works. This partition is mounted when pc boots up.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.