lima-vm / lima

Linux virtual machines, with a focus on running containers
https://lima-vm.io/
Apache License 2.0
14.7k stars 575 forks source link

Unreliable permissions for lima with vz and writable virtiofs home directory mount #2437

Open 0xg0nz0 opened 1 month ago

0xg0nz0 commented 1 month ago

Description

An example -- note it's not just uv pip install that is non-deterministic, but here you can see the same command run twice fails initially and then succeeds the second time (under the hood what happens is chmod +x failed):

vscode ➜ /workspaces/diabolica (1-setup-monorepo) $ uv pip install -r requirements.txt
Resolved 120 packages in 91ms
error: Failed to install: jsonpointer-3.0.0-py2.py3-none-any.http.whl (jsonpointer==3.0.0)
  Caused by: failed to set permissions for file `/workspaces/diabolica/.venv/bin/jsonpointer`
  Caused by: Operation not permitted (os error 1)
vscode ➜ /workspaces/diabolica (1-setup-monorepo) $ uv pip install -r requirements.txt
Resolved 120 packages in 70ms
Installed 5 packages in 57ms
 + juliacall==0.9.20
 + seaborn==0.13.2
 + semver==3.0.2
 + six==1.16.0
 + soupsieve==2.5

This is with vz and virtiofs enabled & a writable home mount and limactl 0.22.0:

mountType: "virtiofs"
mounts:
  - location: "~"
    writable: true
  - location: "/tmp/lima"
    writable: true
vmType: vz

Otherwise it's a plain Docker template for the Lima VM.

The Lima VM is running in latest VSCode as an Ubuntu 24.04 guest on MacOS. Versions:

Before launching the devcontainer (SSH into Lima VM):

$ mount | grep gonzo
mount0 on /Users/gonzo type virtiofs (rw,relatime)

And inside the devcontainer:

mount0 on /workspaces/diabolica type virtiofs (rw,relatime)

I do not see this issue with Docker Desktop with the exact same configuration. I have a hunch that the write-through from the Docker container to the VM to the underlying MacOS filesystem is a bit unstable, leading to this non-deterministic behavior.

Lima VM is brilliant, and I'd love to switch fully over, but this is a blocker.

pythoninthegrass commented 2 weeks ago

Similar issue but user error on my end, @0xg0nz0's example helped me solve why my host mount wasn't working: I only had writable for the /tmp/lima mount on a macOS host. This is my known good config:

mountType: virtiofs
vmType: vz
mounts:
  - location: "~"
    writable: true
  - location: "/tmp/lima"
    writable: true

Just wanted to say thanks and hopefully help future googlers 🙏

Side note: when I ran

λ limactl edit ubuntu-2004 --mount-writable --mount-type=virtiofs
INFO[0000] Aborting, no changes made to the instance

it didn't catch the writable: true not being set for $HOME.