Live data from Hacker News

Running GUI Linux in a virtual machine on a Mac

developer.apple.com

181–190 of 206 posts

Re: Running GUI Linux in a virtual machine on a Mac

#181
post #170
post #81

Earlier quoted context omitted.

It takes some work, but you can pass in an XQuartz display to a Docker container and have it render to that.

Doesn't Monterey still run X - so you could forward x11 over ssh from host into docker?

I don't think MacOS has shipped with an X11 server for a while (https://www.macrumors.com/2012/02/17/apple-removes-x11-in-os...).

Re: Running GUI Linux in a virtual machine on a Mac

#182
Does this differ from previously posted solutions that needed to pre-allocate a chunk of RAM to the Linux VM?

This is indeed cool, but RAM on Apple Silicon is relatively low (with only 8Gb in some models) if I allocate more than 2Gb to a VM, the base desktop will struggle.

Re: Running GUI Linux in a virtual machine on a Mac

#183
post #134

Earlier quoted context omitted.

I'm not sure what you think Docker on a Mac does. Docker is a Linux-specific piece of software, and the only way to use it within macOS is to run a Linux virtual machine, with Docker running inside the Linux VM. If the containers you want to run with Docker are x86 software, that Linux VM either needs to be an x86 Linux distro running in qemu emulation of a full x86 machine, or an ARM Linux distro using the new (not…

Sure, there is a VM in Docker as well. I'm sorry if it wasn't clear, I'm looking for the most straightforward way. With Docker it's a single command, it helps with documenting the steps for other coworkers. It feels slow though. I'm wondering if the new way with Rosetta is going to be better in performance.

The most straightforward way is to use a product. This article documents the APIs for those building those products.

Re: Running GUI Linux in a virtual machine on a Mac

#184
post #181
post #170

Earlier quoted context omitted.

Doesn't Monterey still run X - so you could forward x11 over ssh from host into docker?

I don't think MacOS has shipped with an X11 server for a while ( https://www.macrumors.com/2012/02/17/apple-removes-x11-in-os... ).

Ah, apparently it's possible to install, though:

https://www.xquartz.org/

Re: Running GUI Linux in a virtual machine on a Mac

#185
post #184
post #181

Earlier quoted context omitted.

I don't think MacOS has shipped with an X11 server for a while ( https://www.macrumors.com/2012/02/17/apple-removes-x11-in-os... ).

Ah, apparently it's possible to install, though: https://www.xquartz.org/

Yes, in case it wasn't clear, that's what I was referring to. You can install XQuartz, configure it a little bit, and pass the display into a Docker container.

Re: Running GUI Linux in a virtual machine on a Mac

#187
post #128
post #121

Earlier quoted context omitted.

Docker is equally complicated under the hood.

Yes, but it's a single command to run, without the need to learn the internals, if the use case is just to run the binary.

This is developer documentation, it's for people who want the internals.

For example, docker-desktop on arm-mac can run x86_64 images by leveraging binfmt-qemu within docker's VM. Changing that to use binfmt-rosetta should have huge gains (as there's specific hardware support to enable rosetta).

Yes it's easier to use docker. Hopefully this trickles down so that you get the benefits of this while not changing your usage at all.

Re: Running GUI Linux in a virtual machine on a Mac

#188
post #5

UTM works great. Emulate X86, AMD64, or run on Apple Silicon. It's essentially a GUI on top of QEMU. https://mac.getutm.app/

I didn't realize UTM was open source, so I followed a few guides for setting up VMs directly with libvirt: https://n8henrie.com/2022/09/linux-vms-on-my-m1-mac/

Having since learned that they are open source I think I'll look into UTM again, but even as a novice I didn't find it too difficult to use libvirt.

Re: Running GUI Linux in a virtual machine on a Mac

#189

Wow, you can use Rosetta to run x86 Linux binaries inside the VM on ARM? That seems pretty awesome. https://developer.apple.com/documentation/virtualization/run...

I've tried using this a while back, soon after Apple released Ventura beta to developers. I can say that documentation (and examples) are quite nice and easy to follow, I managed to start Linux VM with Rosetta support, and SSH, in 1-2 hours. Geekbench numbers were quite close when running in VM (via Rosetta) and natively, they were only a few percentages slower in VM, so it stands to reason that computation heavy wor…

I found that the Rosetta/Linux support worked best to run x86_64 containerized workloads, and I never experienced crashes working this way. In my experience, this is far more reliable than using something like debian/ubuntu multiarch support to install both aarch64 and x86_64 into the base system.

I ran x86_64 geekbench in a Linux/aarch64 VM using both Rosetta and QEMU binfmt_misc support and found that Rosetta outperformed QEMU by about 3x. The extra speed is welcome, but I do hope that all the dirty tricks Rosetta uses are eventually able to be used by both non-apple implementations of x86_64 emulation and on non-apple ARM CPUs.

Re: Running GUI Linux in a virtual machine on a Mac

#190
post #112

Earlier quoted context omitted.

It seems overly complicated. Is there any benefit over using Docker?

Docker can benefit from it by running 1000x faster if they would be able to leverage Rosetta.

In my benchmarks running Geekbench via docker, Rosetta performed about 3x faster than QEMU's binfmt_misc translation. On certain microbenchmarks it was 10x-50x faster.
Post reply on HN