lima icon indicating copy to clipboard operation
lima copied to clipboard

Add abstraction for the default `/tmp/lima` directory ?

Open afbjorklund opened this issue 1 year ago • 6 comments

Description

It doesn't work so great in a multi-user environment, and doesn't work on Windows (compared with e.g. C:\TEMP)

i.e. when several users are sharing a server, they will see the files from the other users in the shared /tmp/lima

Hosts based on Fedora put /tmp in RAM, so you need to use /var/tmp if you want to use a normal disk directory.

Should we have some placeholder value for the default.yaml, instead of the "/tmp/lima"? Similar to LIMA_HOME.

  • https://github.com/lima-vm/lima/pull/2337#issuecomment-2106195608

afbjorklund avatar May 12 '24 10:05 afbjorklund

One possible solution is that "/tmp/lima" is the placeholder, and replace it with $TMPDIR/lima.

i.e. something like filepath.Join(os.TempDir(), "lima"), so that it works also on Windows


systemd would try to use some complex scheme:

https://systemd.io/TEMPORARY_DIRECTORIES/

But it should be optional (opt-in), since it breaks things.

https://0pointer.de/blog/projects/tmp.html re: /tmp

afbjorklund avatar May 12 '24 11:05 afbjorklund

Using TMPDIR will break under macOS, with the default setup and the default mounts.

Since it is generated under /var/folders by default, but that location is not mounted...

Side note: /tmp is a symlink to /private/tmp

But /tmp/lima still works, because of symlink.

afbjorklund avatar Jul 16 '24 16:07 afbjorklund

It would to use something like $LIMA_TEMP.

https://lima-vm.io/docs/dev/internals/

Then you could set LIMA_TEMP=$TMPDIR/lima

i.e. similar to overriding LIMA_HOME=$HOME/.lima

afbjorklund avatar Jul 16 '24 16:07 afbjorklund

I'm not a fan of making /tmp/lima "magical" and replacing it with a different location at VM start. I would rather add support for templating, so you could write something like this:

- location: "{{.Temp}}/lima"
  mountPoint: /tmp/lima
  create: true
  writable: true

Where {{.Temp}} would be os.TempDir() evaluated at the start of the instance.

The create property would tell Lima to create the location if it doesn't exist. Maybe we don't need it, and we should always create non-existing locations, but having a separate setting feels safer. That way we can just drop mounts whose locations don't exist on the host. We should already be doing that, but I haven't checked.

I don't know what other template variables would make sense; we can add {{.Home}}, but it would be redundant with the special handling of ~ that already exists. Maybe {{.Cache}} and {{.Config}} for os.UserCacheDir() and os.UserConfigDir()?

We could add access to the host environment with something like {{.Env.LIMA_TEMP}}, but I would wait until we have an actual use-case.

I don't see a need for LIMA_TEMP; you can just set TMPDIR or TEMP before calling limactl and get the same effect.

jandubois avatar Jul 16 '24 18:07 jandubois

Using TMPDIR will break under macOS, with the default setup and the default mounts.

Since it is generated under /var/folders by default, but that location is not mounted...

I'm not sure what point you are trying to make. If you use it as the location for the /tmp/lima mount point, then it will be mounted for you...

Or are you saying that you can't mount paths under $TMPDIR into containers running inside an instance because the directory isn't mounted. That is true; the user would need to add that mount point themselves.

FWIW, Rancher Desktop mounts /private/var/folders into the instance for this reason.

Side note: /tmp is a symlink to /private/tmp

/var is also a symlink to /private/var...

jandubois avatar Jul 16 '24 18:07 jandubois

The mounts should be OK, it was a reflection on the TMPDIR (like that issue about it being not absolute in Windows)

Will leave /tmp/lima, and see if something can be templates instead.

afbjorklund avatar Jul 16 '24 20:07 afbjorklund