Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to mount Rosetta on Linux guests #313

Merged
merged 2 commits into from
Mar 15, 2024

Conversation

jamestut
Copy link
Contributor

This PR add an option to enable Rosetta for Linux guests. This feature is introduced in macOS 13. Full information about this feature here.

This PR only add the Share Rosetta for Linux option under the Sharing section in Linux VM settings, which when checked will allow the guest VM to mount -t virtiofs Rosetta (mountpoint) to mount the Rosetta binary.

This PR does not include:

  • The script required to setup Rosetta so that it can be directly used to execute x86_64 binaries.
  • Prompting user to download and install Rosetta. Instead, user will be asked to install Rosetta will be shown in the warning section and the help section of the Sharing VM settings section.

@insidegui
Copy link
Owner

Thanks, @jamestut! I'll take some time to review this as soon as I can.

Any suggestion of a distro I could use to test Rosetta functionality?

@jamestut
Copy link
Contributor Author

Hi @insidegui, any glibc-based distro will work for this purpose (which is basically all the "main" distros like Enterprise Linux family (CentOS, Fedora, Rocky, Alma, etc.), Debian, Ubuntu, etc.). Even a live ISO will do. All we need is to do on the Linux guest is as follows (reference from Apple's documentation):

mount -t virtiofs Rosetta /mnt/rosetta
/usr/sbin/update-binfmts --install rosetta /mnt/rosetta \
    --magic "\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00" \
    --mask "\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff" \
    --credentials yes --preserve yes --fix-binary yes

Then x86_64 binary should run straight away!

Oh and also a tips for reference, in Linux we can easily check if a binary is arm or x86 using the file command.

@jamestut
Copy link
Contributor Author

jamestut commented Mar 14, 2024

This is my first time doing serious work on Swift programming language, so please let me know for anything that is amiss in this PR! I'll have more things in the future that I want to make PR off this repository, especially related to Linux guests.

Additionally, when you're okay with this, I can add the guide on how to use Rosetta in the README of this project on this PR.

And on another note, if this one is approved, I'll make a separate PR to enable AOT caching on macOS Sonoma host (I actually haven't tried yet on how that works).

Also it might be nice to have a Linux guest addition that can do the following:

  • Mount VirtualBuddyShare (and Rosetta if configured).
  • Perform the above update-binfmts.
  • Sync Linux guest' time with host via RTC device (I already have this rtcd project).

@insidegui
Copy link
Owner

Thanks!

I like that there's someone who cares about Linux and is willing to contribute, since I'm not much of a Linux person 😅

I'll be reviewing this soon 🙌🏻

@jamestut
Copy link
Contributor Author

I like that there's someone who cares about Linux and is willing to contribute

Don't underestimate VirtualBuddy! With a few polishes, this might be one of the best way to run Linux on aarch64 (yes, not just Linux on Apple Silicon)! VirtualBuddy just fits perfectly with my use case! Now tell me any other virtualisation product that have all these:

  • Allows using custom Linux kernel, initramfs, rootfs = count Docker Desktop out.
  • Minimal performance and energy overhead (runs Linux like it is an app!).
  • Automatic disk shrinking (delete a file in Linux guest and the macOS disk space usage is freed straight away) = count all commercial virtualisation products out!
  • Lightweight and not confined to macOS' sandbox = count the other popular open source project out!
  • Easily configurable (we have GUI and .plist if the GUI is not suffice!) = same as above!
  • Disk image not tied to VM configuration.
  • Open source, written in a modern programming language, and fully leverages what the latest macOS has to offer.

I'm so grateful that you made this app. This also forces me to learn Swift. 😅

@insidegui insidegui merged commit 7d0744e into insidegui:main Mar 15, 2024
@insidegui
Copy link
Owner

This is my first time doing serious work on Swift programming language

I wouldn't have noticed, because the code looks great 😊

The only thing I'm not 100% happy with is not code related, but I can fix it in a follow-up PR.

Additionally, when you're okay with this, I can add the guide on how to use Rosetta in the README of this project on this PR.

Feel free to open a new PR for that.

@jamestut jamestut deleted the linux-rosetta branch March 29, 2024 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants