Lima: A nice way to run Linux VMs on Mac
jvns.ca
jvns.ca
Their sample code includes a resizable display, shared drive, network access, etc. You can run x86 Linux on Apple Silicon (including running pre-built x86 binaries with Rosetta). On the latest release, you can save and restore the VM state to avoid boot initialization and application setup.
Run headless linux https://developer.apple.com/documentation/virtualization/run...
Run GUI linux https://developer.apple.com/documentation/virtualization/run...
Run intel binaries in linux vms on appleSilicon with rosetta https://developer.apple.com/documentation/virtualization/run...
Configuring Virtio shared directory https://developer.apple.com/documentation/virtualization/vzv...
And you can run MacOS VM's on Apple silicon:
https://developer.apple.com/documentation/virtualization/ins...
>The kernel and RAM disk image must support the CPU architecture of your Mac.
You _can_ run x86 via Rosetta inside the VM. But that's not the same thing as running an x86 VM.
To answer your question, Lima supports two VM types - QEMU and vz. QEMU is the default and is what's used by other projects to run x86. If you select a vz VM type then it uses MacOS' native APIs. I wouldn't expect a performance improvement in using a vz-typed VM with Lima and Apple's own instructions.
People say it a lot but I never really felt it until I tried it - python packaging is infuriating and is beyond a shadow of a doubt proof that python is a shit professional language. Not because professional languages need to have bulletproof packaging systems (see C/C++) but because the fact that python can't make it work after so long means python is fundamentally flawed. And don't tell me "well you're implicitly talking about C extensions". Yes I am but that's a language feature and if you design a language feature that your language fundamentally precludes you from being able to support, then again that's on you.
With the current state of Vbox on Arm it would be good to have a reliable free/cheap alternative to Parallels or VMWare for vagrant use.
In the latest releases hey are dropping support for native virtualization on mac and moving to QEMU only. I my experience the QEMU backend has not been as stable as the hyperkit one, but YMMV as usual.
"just".
Where "just" is:
- download and install XCode
- download sample project
- download a sample project
- download a Linux Kernel image
- load a RAM disk into memory
- write some Swift code to configure run parameters. Swift code is different if you want to run non-UI and UI versions
- you can only run one VM at a time or write your own code to manage that
- ....
Or, you know, use Docker Desktop, or lima, or...
I used it to run Ubuntu on an x86 on an M1 Mac because a vendor's alpha SDK could only run on x86 Ubuntu.
It's unfortunately not fully open source
I moved away from Docker Desktop to colima for a couple years and would not pay for Docker Desktop, but after a few weeks of swapping back to OrbStack now that it's public beta, I can definitely see myself paying. OrbStack just works and gets out of the way.
Just updated the docs with this info: https://docs.orbstack.dev/faq#free
I thought I'd elaborate on a few specific ways OrbStack improves on apps and issues mentioned elsewhere in this thread.
- Network hangs and connection issues: I wrote a new virtual network stack in userspace and made sure to address issues plaguing other virtual networking solutions (VPN compat, DNS failures, etc.).
- Inexplicable errors: Can't say it's perfect, but I do take every issue seriously. For example, sending OOM kill notifications on macOS instead of silently killing processes.
- Running x86 containers: Builtin fixes and workarounds for many Rosetta bugs. Since the bugs are on Apple's side, they affect all other apps (as of writing) and often cause issues when running linux/amd64 containers. If you're used to slow QEMU emulation, then well, it should be a major improvement.
- Multipass: OrbStack can run 15 different distros (https://docs.orbstack.dev/machines/distros#linux-distributio...). It's not limited to Ubuntu, and cloud-init support is also planned for most distros.
- UTM: OrbStack doesn't do graphics yet, so you'll have to stick to UTM for GUI, but the CLI and other integration is designed to be on WSL2 level. It also boots much faster: baseline in ~1 sec, each machine in ~250 ms, total ~1.2 sec.
- Bind mounts and file sharing: It uses VirtioFS which isn't affected by sshfs consistency issues, plus caching and optimizations to give it an edge.
- Colima: https://docs.orbstack.dev/compare/colima
Noticed you are using a very recent kernel, Linux ubuntu 6.3.12-orbstack, which is so great to test latest revisions of Linux system calls (eg. io_uring) locally, compared to Docker old 5.x kernels which I gave up figuring out how to upgrade.
Any way to select a specific kernel version for VM or container? That would be a killer feature for regression testing.
There's currently no support for changing the kernel version. I think it may not be feasible to support many versions because a lot of OrbStack's improvements are very closely tied to the kernel, and maintaining the patches for multiple versions wouldn't be worth the work. Outside of regression testing, it's rare that anything breaks and in the event that such changes occur upstream, I try to hold off on updating until they're fixed.
Are you mainly interested in 5.15/6.1 LTS or other specific versions? Having an alternate LTS kernel (for a total of two options) might be a possibility in the (long term) future.
or let me bind to other network interfaces not just the one :(
but i love orbstack. hard too go back after finding it. impossible actually. havent been at the computer in like two weeks so mabye its changed by now
Support for "isolated" machines that don't have bind mounts is planned (https://github.com/orbstack/orbstack/issues/169). This is actually mostly implemented internally, but I'm not exposing it until a few remaining security gaps are plugged or it would just give a false sense of security.
If you meant binding servers to specific interface IPs, it might be possible one day but it's very challenging to implement as all of the host's IPs need to be assigned to an interface in the guest and managed accordingly. If you meant connecting machines directly to your LAN, it'll be supported eventually but it's low priority due to unavoidable compatibility issues. https://github.com/orbstack/orbstack/issues/342
The only thing I'd like to have is some sort of background daemon, so my VM don't stop if I accidentally close the UTM window.
Parallels was a night and day difference in both stability and responsiveness of my desktop. And copy/paste Just Worked as well. Definitely worth the $100/year subscription in my opinion.
Having said that, yeah, Parallels performance still wins.
There's one issue I'm running into where it becomes unresponsive after a while and "docker ps" hangs forever though.
Some interesting caveats:
* By default, system packages don't persist, as the default alpine distribution runs on tmpfs and doesn't have a overlay. This is a reasonable default, as it keeps the default VM storage small.
* If you want to have additional system packages, you can turn on a ubuntu overlay that supports additional systemd services just fine. Of course, storage would balloon to a few GBs from a few hundred MBs.
Edit: typos.
BTW, the result of docker build is immediately available to the k8s (k3s) cluster without any insecure registry and/or side loading/caching steps, thanks to the seamless buildkit integration.
One of our tools runs in Docker just to ensure that it gets the right version of its dependencies, and that bug is a pretty huge bug for us, for that tool, as it basically broke things.
Still, we use colima; it is a decent workaround for the "Docker on macOS" problem otherwise.
… I had noticed that `--mount` in other contexts appears to work, but I have not had the time to investigate why or how that is.
(We've also had bugs with Docker proper in the past where they broke --mount but only for certain paths on the host.)
> Finch provides a simple client which is integrated with nerdctl. For the core build/run/push/pull commands, Finch depends upon nerdctl to handle the heavy lifting. It works with containerd for container management, and with BuildKit to handle Open Container Initiative (OCI) image builds. These components are all pulled together and run within a virtual machine managed by Lima.
Colima is a low-configuration command line tool to spin up a linux VM (using Lima) which includes docker support, so you can run docker commands in the Mac terminal but the containers actually run in the linux VM.
You still have to install the actual docker CLI tool separately via Homebrew etc. Colima just provides everything else.
This is also what happens generally when you install and run Docker Desktop on Mac or Windows, I just like Colima because it’s a much lighter installation and doesn’t come with the commercial paid license requirement of Docker Desktop.
If you want to draw some very coarse comparisons with big names, lima is like VMware Fusion, colima is like the Docker for Mac app.
colima kind of fills one of the use cases of docker-machine which kind of died as this use case was handled by DfM and the other use case (handling machines for swarm) was folded into docker swarm and docker compose.
Docker Desktop is a bad joke.
Recommended.
> why not use containers? [...]
> on Mac you need to run containers inside a Linux VM anyway, so I’d rather use a VM directly and not introduce another unnecessary layer
I was long confused at how Docker functioned on macOS, until I learned that it's "just" running a Linux VM within which it runs the container images. There is no other magic happening to run a (linux-assuming) container on macOS.
I have a bash script that uses multipass to setup a few VMs... but still it feels "primitive" compared to what I was using when I had an intel Mac (I was using Vagrant, but the Vagrant experience on M1 is awful: I have tried it with VMWare and it's not very stable in my experience).
Would you mind expanding some more on your use case and what is missing in Multipass? If it's static IPs, then as mentioned in https://news.ycombinator.com/item?id=36693413, there are ways to accomplish this.
Thanks for the feedback!
Have you seen https://multipass.run/docs/configure-static-ips for configuring static IP's? It's kind of Linux-centric as far as setting up the bridge on the host is concerned, but as long as you create a bridge as you see fit on any host, then the rest of the instructions should work.
Thanks for the feedback. We take it seriously!
I just wish multiarch containers weren't such a pain to deal with.
Yes, the dreaded Apple Firewall bug:( The cause is that somehow the firewall would block macOS's own bootpd process and that it the process responsible for handing out IP addresses to the virtual machine instances. We could never find out why macOS chose to block bootpd though.
Anecdotally, the number of users mentioning this issue have been much less lately, but I'm not sure if that is because the new Multipass release which has a newer QEMU made it better, a macOS update fixed it, or users have just given up.
The annoying thing was that multipass and UTM would initially work before the firewall killed it a few days later. Makes me think it was learning from heuristics or something rather than being a defined policy.
Lima constantly has i/o issues (usually network hangs, local connections within the VM). It's pretty rough to use when I need to do docker in Lima.
I really like being able to read some tech on my iPad, see something I want to try, and 5 seconds later I am SSHed/Mosh'ed into my remote dev VPS.
EDIT: that said, I do have Lima installed on my M1 MacBook Pro.
On the other hand, it has much much less CPU than an MBP, and usually no GPU at all.
On the third hand, the cloud allows one to quickly start more VMs, and to shut them down as quickly, something that's possible but a bit more limited on a laptop / desktop.
Pay for 3 years of AWS savings plans to make it cheap. Perhaps run a permanent instance for small things, make a setup that lets me spin up super power machines when i actually want to build.
Most of the time I'm at my ipad remoting in Im not actually compiling, just editing. I can just edit locally and pay for the few seconds/minutes it takes to build..
because honestly after about 3 years i always want to upgrade
and i can get windows that are completely functional for me on remote monitors with ipad now. just starting to wonder why im paying for physical compute power but 99% of the time browsing the web and editing code but not building it.
I do a ton of work on my iPad Pro: writing, research, using Google Colab for model development, and my beefy VPS remote dev box.
All that said, having good Linux and MacBook Pro laptops with a really large external monitor is sometimes very effective.
Depends on what I am working on.
When I want to make sure my software works on MacOS, it'd be nice if I could do that without having to have a whole other computer sitting in front of me.
You can also run macOS in docker, but it’s ultimately running through qemu/kvm as well[2]
Update: I edited the YAML file for the Lima VM and changed from qemu to vz, also made sure the mount was using virtiofs.
Observations - on the surface, no performance difference but I haven't really done much yet. I noticed that there is no longer a qemu process running (obviously), and I see that /System/Library/Frameworks/Virtualization.framework/Versions/A/XPCServices/com.apple.Virtualization.VirtualMachine.xpc/Contents/MacOS/com.apple.Virtualization.VirtualMachine is now running.
Having a look at https://developer.apple.com/documentation/virtualization?lan... for the documentation. It definitely looks like an interesting and well built framework.
In a cli, I want to start “vm”
It should check the current directly and go up each time similar to.asdf or .rbenv, looking for a .virtconfig dir
Depending on the config, I want:
1: it running a foreground instance, soo I don’t need ssh, and I know that it will shut down when I end the shell
2: I want to configure my shares/mounts, which by default don’t go up from the .virtconfig dir
3: I have to think about read only instances and multiple instances of the vm
The idea is that when you later cd into a project directory, .direnv (I think) can automatically turn into a Linux shell, or other OS which is also sandboxed.
I’d also want a single command that spans a Linux instance with the current director mounted (r or Re) to Linux. This way you get some sandboxing when trying someone else’s code
It's a wrapper that interfaces with QEMU in the background to make things nicer/easier in case anybody was wondering
lima now supports "macOS Virtualization.Framework"
https://zarinfam.medium.com/what-are-the-advantages-of-the-n...
https://news.ycombinator.com/item?id=36184400
I guess it's better/different and not just roughly the same thing wrapped in new packaging?
Apple has kicked errbody out of kernel space over security concerns, so even companies with 25 years of experience writing network virtualization kernel extensions must now instead use Apple's vastly inferior macOS facility that can reduce performance by as much as 80%.
OTOH, I don’t believe much of what I read on here because of such direct negative experiences like this (being downvoted on stuff I have first hand knowledge of) —and that truly is priceless.
I've gone through VMs, colinux, cygwin, and currently WSL2+VcXsrv for (b) and so far it's basically worked out fine.
(I'm aware that desktop linux wrangling is far, far easier than it used to be but this setup very rarely annoys me and if I'm going to do some recreational geekery on a "because I can" basis it's far more likely to be something like playing with a new programming language than reinstalling my laptop)
Anybody?
mounts:
- location: "~/sandbox"
writable: true
Lima cautions against this: # Setting `writable` to true is possible, but untested and dangerous.
But I never hit any problems when I played around with it. Here are my notes:
https://earthly.dev/blog/lima/[1]: https://ish.app/
They will tell you