[GH-ISSUE #2701] ollama.service cannot create folder defined by OLLAMA_MODELS or do not run when the folder is created manually #63652

Open
opened 2026-05-03 14:35:01 -05:00 by GiteaMirror · 14 comments
Owner

Originally created by @Crystal4276 on GitHub (Feb 23, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/2701

Hello
I'm facing an issue to locate the models into my home folder since my root partition is limited in size.
I followed the FAQ and information collected here and there to setup OLLAMA_MODELS in ollama.service.
When starting the service, the journal report that the server could not create the folder in my home directory.
Permission issue apparently.
This where i'm at, i couldn't find a way to fix it looking at various resources for systemd.
Can someone point me in the right direction ?

I'm using the package ollama-cuda on Arch.

[Unit]
Description=Ollama Service
Wants=network-online.target
After=network.target network-online.target

[Service]
ExecStart=/usr/bin/ollama serve
WorkingDirectory=/var/lib/ollama
Environment="HOME=/var/lib/ollama" "GIN_MODE=release" "OLLAMA_MODELS=/home/crystal/Applications/ollama_model"
User=ollama
Group=ollama
Restart=on-failure
RestartSec=3
Type=simple
PrivateTmp=yes
ProtectSystem=full
ProtectHome=yes

[Install]
WantedBy=multi-user.target
Feb 23 11:02:46 terrier systemd[1]: Started Ollama Service.
Feb 23 11:02:46 terrier ollama[37688]: Error: mkdir /home/crystal: permission denied
Feb 23 11:02:46 terrier systemd[1]: ollama.service: Main process exited, code=exited, status=1/FAILURE
Feb 23 11:02:46 terrier systemd[1]: ollama.service: Failed with result 'exit-code'.```
Originally created by @Crystal4276 on GitHub (Feb 23, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/2701 Hello I'm facing an issue to locate the models into my home folder since my root partition is limited in size. I followed the FAQ and information collected here and there to setup OLLAMA_MODELS in ollama.service. When starting the service, the journal report that the server could not create the folder in my home directory. Permission issue apparently. This where i'm at, i couldn't find a way to fix it looking at various resources for systemd. Can someone point me in the right direction ? I'm using the package ollama-cuda on Arch. ``` [Unit] Description=Ollama Service Wants=network-online.target After=network.target network-online.target [Service] ExecStart=/usr/bin/ollama serve WorkingDirectory=/var/lib/ollama Environment="HOME=/var/lib/ollama" "GIN_MODE=release" "OLLAMA_MODELS=/home/crystal/Applications/ollama_model" User=ollama Group=ollama Restart=on-failure RestartSec=3 Type=simple PrivateTmp=yes ProtectSystem=full ProtectHome=yes [Install] WantedBy=multi-user.target ``` ``` Feb 23 11:02:46 terrier systemd[1]: Started Ollama Service. Feb 23 11:02:46 terrier ollama[37688]: Error: mkdir /home/crystal: permission denied Feb 23 11:02:46 terrier systemd[1]: ollama.service: Main process exited, code=exited, status=1/FAILURE Feb 23 11:02:46 terrier systemd[1]: ollama.service: Failed with result 'exit-code'.```
Author
Owner

@Crystal4276 commented on GitHub (Feb 23, 2024):

I tried also other things.
Modify ollama.service with my user/group:

User=crystal
Group=crystal

I also tried to add my user name to ollama group and run with:

User=crystal
Group=ollama

None work (ie. no folder created), although the journal message is different now:

Feb 23 11:41:19 terrier systemd[1]: ollama.service: Main process exited, code=exited, status=1/FAILURE
Feb 23 11:41:19 terrier systemd[1]: ollama.service: Failed with result 'exit-code'.
<!-- gh-comment-id:1960935086 --> @Crystal4276 commented on GitHub (Feb 23, 2024): I tried also other things. Modify ollama.service with my user/group: ``` User=crystal Group=crystal ``` I also tried to add my user name to ollama group and run with: ``` User=crystal Group=ollama ``` None work (ie. no folder created), although the journal message is different now: ``` Feb 23 11:41:19 terrier systemd[1]: ollama.service: Main process exited, code=exited, status=1/FAILURE Feb 23 11:41:19 terrier systemd[1]: ollama.service: Failed with result 'exit-code'. ```
Author
Owner

@seanmavley commented on GitHub (Feb 23, 2024):

Try this out

Change OLLAMA_MODELS Path

Steps:

  • Create Directory: sudo mkdir /usr/local/share/ollama-models
  • Grant Ownership: sudo chown ollama:ollama /usr/local/share/ollama-models
  • Update Service File: Edit the /etc/systemd/system/ollama.service file and modify:
    -- Environment="OLLAMA_MODELS=/usr/local/share/ollama-models"
  • Restart Ollama: sudo systemctl restart ollama
<!-- gh-comment-id:1960942399 --> @seanmavley commented on GitHub (Feb 23, 2024): Try this out Change OLLAMA_MODELS Path Steps: - Create Directory: `sudo mkdir /usr/local/share/ollama-models` - Grant Ownership: `sudo chown ollama:ollama /usr/local/share/ollama-models` - Update Service File: Edit the /etc/systemd/system/ollama.service file and modify: -- `Environment="OLLAMA_MODELS=/usr/local/share/ollama-models"` - Restart Ollama: `sudo systemctl restart ollama`
Author
Owner

@Crystal4276 commented on GitHub (Feb 23, 2024):

@seanmavley
Thanks.
Since my goal is to have the models located in the home folder (no storage space left in / ) i have adapted what you proposed.
I created manually /home/crystal/Applications/ollama_model, subsequently added sudo chown ollama:ollama, and kept in ollama.service:

User=ollama
Group=ollama
Environment="HOME=/var/lib/ollama" "GIN_MODE=release" "OLLAMA_MODELS=/home/crystal/Applications/ollama_model"

Still same error the server doesn't start:

Feb 23 11:58:22 terrier systemd[1]: ollama.service: Main process exited, code=exited, status=1/FAILURE
Feb 23 11:58:22 terrier systemd[1]: ollama.service: Failed with result 'exit-code'.

This is the current permission set for the model folder in my home directory:
drwxr-xr-x 2 ollama ollama 4.0K Feb 23 11:54 ollama_model
Anything wrong ?

<!-- gh-comment-id:1960954360 --> @Crystal4276 commented on GitHub (Feb 23, 2024): @seanmavley Thanks. Since my goal is to have the models located in the home folder (no storage space left in / ) i have adapted what you proposed. I created manually /home/crystal/Applications/ollama_model, subsequently added `sudo chown ollama:ollama`, and kept in ollama.service: ``` User=ollama Group=ollama Environment="HOME=/var/lib/ollama" "GIN_MODE=release" "OLLAMA_MODELS=/home/crystal/Applications/ollama_model" ``` Still same error the server doesn't start: ``` Feb 23 11:58:22 terrier systemd[1]: ollama.service: Main process exited, code=exited, status=1/FAILURE Feb 23 11:58:22 terrier systemd[1]: ollama.service: Failed with result 'exit-code'. ``` This is the current permission set for the model folder in my home directory: ```drwxr-xr-x 2 ollama ollama 4.0K Feb 23 11:54 ollama_model``` Anything wrong ?
Author
Owner

@Crystal4276 commented on GitHub (Feb 23, 2024):

To note, when started from the shell with :

export OLLAMA_MODELS=/home/crystal/Applications/ollama_model
ollama serve

The server start without issue and models are correctly downloaded in /home/crystal/Applications/ollama_model.

It kooks like the issue is related to starting ollama server through systemd.

<!-- gh-comment-id:1961055805 --> @Crystal4276 commented on GitHub (Feb 23, 2024): To note, when started from the shell with : ``` export OLLAMA_MODELS=/home/crystal/Applications/ollama_model ollama serve ``` The server start without issue and models are correctly downloaded in `/home/crystal/Applications/ollama_model`. It kooks like the issue is related to starting ollama server through systemd.
Author
Owner

@fezzzza commented on GitHub (Mar 2, 2024):

Ditto this problem on Ubuntu. The workaround to export and serve works.

<!-- gh-comment-id:1974796731 --> @fezzzza commented on GitHub (Mar 2, 2024): Ditto this problem on Ubuntu. The workaround to export and serve works.
Author
Owner

@C0rn3j commented on GitHub (Apr 6, 2024):

The issue is ProtectHome=yes, systemctl edit ollama and create an override:

[Service]
ProtectHome=

This is a hack and you shouldn't do it, and you SHOULD NOT try to give it access to your own user, create a new home directory for it.

my goal is to have the models located in the home folder (no storage space left in / )

So you split / and /home and now you ran out of space?
Consider if you really need them split in the first place

<!-- gh-comment-id:2041165478 --> @C0rn3j commented on GitHub (Apr 6, 2024): The issue is `ProtectHome=yes`, systemctl edit ollama and create an override: ```ini [Service] ProtectHome= ``` This is a hack and you shouldn't do it, and you SHOULD NOT try to give it access to your own user, create a new home directory for it. > my goal is to have the models located in the home folder (no storage space left in / ) So you split / and /home and now you ran out of space? Consider if you really need them split in the first place
Author
Owner

@QuinnPiers commented on GitHub (May 4, 2024):

I will add that I'm so glad I finally found THIS issue with a working solve for ubuntu .
my models are in a zfs pool at /pool/models
so protect home wasn't my issue

edit: it does fix the permission issue but I still don't have any models detected. maybe its b/c my files are LMStudio/LocalAI compatible?

<!-- gh-comment-id:2094370604 --> @QuinnPiers commented on GitHub (May 4, 2024): I will add that I'm so glad I finally found THIS issue with a working solve for ubuntu . my models are in a zfs pool at /pool/models so protect home wasn't my issue edit: it does fix the permission issue but I still don't have any models detected. maybe its b/c my files are LMStudio/LocalAI compatible?
Author
Owner

@John-OK commented on GitHub (Sep 20, 2024):

@Crystal4276 It looks like you're trying to store the models in your user directory "/home/crystal/..."
I was trying to do the same thing and it just wouldn't work. I think it has something to do with ollama not having permission to access a user's directory.
What I did to get it working was create a directory in the /home directory: mkdir ollama_models
Give ollama ownership: sudo chown -R ollama:ollama ollama_models
And then edit the ollama.service file: sudo systemctl edit ollama.service
I added the following above the third line (the one that says "Lines below this comment will be discarde":

[Service]
Environment="OLLAMA_MODELS=/home/ollama_models"

Then I reloaded systemd and restarted ollama:

sudo systemctl daemon-reload
sudo systemctl restart ollama

This sometimes hangs the system for awhile (less than 30s for me), but be patient.
To check that it worked I gave the command to list models:
ollama list
If everything worked, it might hang for a while, but just be patient (could be > 1 min).
Then, you'll get output that looks like:
NAME ID SIZE MODIFIED
If you see that, everything worked! Now, just copy the contents of the old models directory to your new one.

Good luck!

<!-- gh-comment-id:2364630162 --> @John-OK commented on GitHub (Sep 20, 2024): @Crystal4276 It looks like you're trying to store the models in your user directory "/home/crystal/..." I was trying to do the same thing and it just wouldn't work. I think it has something to do with ollama not having permission to access a user's directory. What I did to get it working was create a directory in the /home directory: `mkdir ollama_models` Give ollama ownership: `sudo chown -R ollama:ollama ollama_models` And then edit the ollama.service file: `sudo systemctl edit ollama.service` I added the following above the third line (the one that says "Lines below this comment will be discarde": ```bash [Service] Environment="OLLAMA_MODELS=/home/ollama_models" ``` Then I reloaded systemd and restarted ollama: ```bash sudo systemctl daemon-reload sudo systemctl restart ollama ``` This sometimes hangs the system for awhile (less than 30s for me), but be patient. To check that it worked I gave the command to list models: `ollama list` If everything worked, it might hang for a while, but just be patient (could be > 1 min). Then, you'll get output that looks like: `NAME ID SIZE MODIFIED` If you see that, everything worked! Now, just copy the contents of the old models directory to your new one. Good luck!
Author
Owner

@MikeB2019x commented on GitHub (Oct 25, 2024):

@John-OK The critical part for was giving ollama ownership of the models directory. I did a create from GGUF from a completely different directory (for convenience) and that permission change was all that was needed to make things work as expected.

<!-- gh-comment-id:2438071759 --> @MikeB2019x commented on GitHub (Oct 25, 2024): @John-OK The critical part for was giving `ollama` ownership of the models directory. I did a create from GGUF from a completely different directory (for convenience) and that permission change was all that was needed to make things work as expected.
Author
Owner

@Mouradif commented on GitHub (Nov 22, 2024):

I am having the same issue trying to make ollama use my external hard drive. It automatically gets mounted to

/media/user/some-uuid-type-string

after creating folders and granting ownership:

sudo mkdir -p /media/user/some-uuid-type-string/ollama/models
sudo chown -R ollama:ollama /media/user/some-uuid-type-string/ollama

I still get the error:

ollama[41651]: Error: mkdir /media/user/some-uuid-type-string: permission denied

It seems it's trying to create the folder where my external drive is mounted.

Also, if I don't use systemctl and instead just run OLLAMA_MODELS=... ollama serve then it works as intended

<!-- gh-comment-id:2494456200 --> @Mouradif commented on GitHub (Nov 22, 2024): I am having the same issue trying to make ollama use my external hard drive. It automatically gets mounted to ``` /media/user/some-uuid-type-string ``` after creating folders and granting ownership: ``` sudo mkdir -p /media/user/some-uuid-type-string/ollama/models sudo chown -R ollama:ollama /media/user/some-uuid-type-string/ollama ``` I still get the error: ``` ollama[41651]: Error: mkdir /media/user/some-uuid-type-string: permission denied ``` It seems it's trying to create the folder where my external drive is mounted. Also, if I don't use `systemctl` and instead just run `OLLAMA_MODELS=... ollama serve` then it works as intended
Author
Owner

@vjeson commented on GitHub (May 5, 2025):

I also encountered the same issue. This problem occurs when you set the model directory on a newly mounted hard drive, and the root directory permissions of the new drive are incorrect.

For example, in the ollama.service file, there is:

Environment="OLLAMA_MODELS=/nvme2/ollama/models"

Check the permissions of the /nvme2 directory:

stat -c "%a %n" /nvme2

If the directory permissions are not 755, you'll get a "permission denied" error.
To fix it, change the directory permissions with:

sudo chmod -R 755 /nvme2

Then verify access by listing the directory as the ollama user:

sudo -u ollama ls /nvme2/ollama
<!-- gh-comment-id:2850828060 --> @vjeson commented on GitHub (May 5, 2025): I also encountered the same issue. This problem occurs when you set the model directory on a newly mounted hard drive, and the root directory permissions of the new drive are incorrect. For example, in the `ollama.service` file, there is: ``` Environment="OLLAMA_MODELS=/nvme2/ollama/models" ``` Check the permissions of the `/nvme2` directory: ``` stat -c "%a %n" /nvme2 ``` If the directory permissions are not `755`, you'll get a "permission denied" error. To fix it, change the directory permissions with: ``` sudo chmod -R 755 /nvme2 ``` Then verify access by listing the directory as the `ollama` user: ``` sudo -u ollama ls /nvme2/ollama ```
Author
Owner

@jasondunsmore commented on GitHub (Jun 11, 2025):

I just upgraded ollama and now the Environment="OLLAMA_MODELS=/home/user/.ollama/models line in /etc/systemd/system/ollama.service isn't working.

I see in the logs that Ollama tries to create files under /usr/share/ollama/.ollama/ and gets a permission denied error. The directory /usr/share/ollama does not exist on my system.

In order to start the ollama service, I have to change ownership of the /home/user/.ollama/models dir to my user, export OLLAMA_MODELS, and then run ollama serve from the shell.

<!-- gh-comment-id:2963135690 --> @jasondunsmore commented on GitHub (Jun 11, 2025): I just upgraded ollama and now the `Environment="OLLAMA_MODELS=/home/user/.ollama/models` line in `/etc/systemd/system/ollama.service` isn't working. I see in the logs that Ollama tries to create files under `/usr/share/ollama/.ollama/` and gets a permission denied error. The directory `/usr/share/ollama` does not exist on my system. In order to start the ollama service, I have to change ownership of the `/home/user/.ollama/models` dir to my user, export `OLLAMA_MODELS`, and then run `ollama serve` from the shell.
Author
Owner

@Kostis-S-Z commented on GitHub (Jul 16, 2025):

@Crystal4276 It looks like you're trying to store the models in your user directory "/home/crystal/..." I was trying to do the same thing and it just wouldn't work. I think it has something to do with ollama not having permission to access a user's directory. What I did to get it working was create a directory in the /home directory: mkdir ollama_models Give ollama ownership: sudo chown -R ollama:ollama ollama_models And then edit the ollama.service file: sudo systemctl edit ollama.service I added the following above the third line (the one that says "Lines below this comment will be discarde":

[Service]
Environment="OLLAMA_MODELS=/home/ollama_models"

Then I reloaded systemd and restarted ollama:

sudo systemctl daemon-reload
sudo systemctl restart ollama

This sometimes hangs the system for awhile (less than 30s for me), but be patient. To check that it worked I gave the command to list models: ollama list If everything worked, it might hang for a while, but just be patient (could be > 1 min). Then, you'll get output that looks like: NAME ID SIZE MODIFIED If you see that, everything worked! Now, just copy the contents of the old models directory to your new one.

Good luck!

@John-OK <--- this is the way
THANK YOU for this. This should be referenced here

<!-- gh-comment-id:3077753903 --> @Kostis-S-Z commented on GitHub (Jul 16, 2025): > [@Crystal4276](https://github.com/Crystal4276) It looks like you're trying to store the models in your user directory "/home/crystal/..." I was trying to do the same thing and it just wouldn't work. I think it has something to do with ollama not having permission to access a user's directory. What I did to get it working was create a directory in the /home directory: `mkdir ollama_models` Give ollama ownership: `sudo chown -R ollama:ollama ollama_models` And then edit the ollama.service file: `sudo systemctl edit ollama.service` I added the following above the third line (the one that says "Lines below this comment will be discarde": > > [Service] > Environment="OLLAMA_MODELS=/home/ollama_models" > > Then I reloaded systemd and restarted ollama: > > sudo systemctl daemon-reload > sudo systemctl restart ollama > > This sometimes hangs the system for awhile (less than 30s for me), but be patient. To check that it worked I gave the command to list models: `ollama list` If everything worked, it might hang for a while, but just be patient (could be > 1 min). Then, you'll get output that looks like: `NAME ID SIZE MODIFIED` If you see that, everything worked! Now, just copy the contents of the old models directory to your new one. > > Good luck! @John-OK <--- this is the way THANK YOU for this. This should be referenced [here](https://github.com/ollama/ollama/blob/main/docs/linux.md#customizing)
Author
Owner

@collinpeters commented on GitHub (Aug 2, 2025):

If the directory permissions are not 755, you'll get a "permission denied" error.

Comment from @vjeson is what finally solved it for me. Insane bug that it requires the PARENT directory to have certain permissions.

<!-- gh-comment-id:3146586483 --> @collinpeters commented on GitHub (Aug 2, 2025): > If the directory permissions are not 755, you'll get a "permission denied" error. Comment from @vjeson is what finally solved it for me. Insane bug that it requires the PARENT directory to have certain permissions.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#63652