Giter VIP home page Giter VIP logo

Comments (12)

kdrag0n avatar kdrag0n commented on May 28, 2024 2

Thanks for those commands! I gave this a quick shot last month and it didn't work so I put it on the backburner (probably typo in the magic or mask), but your commands seem to work.

There are some kinks to work out for proper support, but this is a good start.

from orbstack.

imkiva avatar imkiva commented on May 28, 2024 1

It is possible to run mach-o via binfmt:

# for mach-o universal binary (all fields in universal header are big endian)
sudo /usr/sbin/update-binfmts --install mac-binfmt-universal /opt/orbstack-guest/bin/mac \
    --magic "\xca\xfe\xba\xbe\x00\x00\x00\x02\x01\x00\x00\x07" \
    --mask  "\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\x00" \
    --credentials yes --preserve no --fix-binary yes

# for mach-o single architecture binary (little endian)
sudo /usr/sbin/update-binfmts --install mac-binfmt-nonuniversal /opt/orbstack-guest/bin/mac \
    --magic "\xcf\xfa\xed\xfe\x0c\x00\x00\x01" \
    --mask  "\xff\xff\xff\xff\x00\xff\xff\xff" \
    --credentials yes --preserve no --fix-binary yes

reference: https://en.wikipedia.org/wiki/Mach-O

from orbstack.

kdrag0n avatar kdrag0n commented on May 28, 2024 1

Already implemented at /mnt/machines.

from orbstack.

kdrag0n avatar kdrag0n commented on May 28, 2024 1

Released in v0.7.0.

from orbstack.

imkiva avatar imkiva commented on May 28, 2024

Thanks for those commands! I gave this a quick shot last month and it didn't work so I put it on the backburner (probably typo in the magic or mask), but your commands seem to work.

There are some kinks to work out for proper support, but this is a good start.

Thank you for the explanation, I am really hoping to see official support for this.
I would say OrbStack is the best "macOS subsystem for Linux" I've ever seen. 👍

from orbstack.

kdrag0n avatar kdrag0n commented on May 28, 2024

@imkiva @SEmmmer @XingjianXie Can I get your opinion on how to handle argument/path translation for binfmt?

Currently, prefixing commands with mac and linking with mac link will conservatively translate some paths based on some heuristics to avoid mangling arguments, while specifying -p will translate all paths. Path translation works by resolving paths as viewed from the Linux perspective to the equivalent Mac path. So for example (Linux = macOS path):

  • /home/user = /Users/user/OrbStack/machine/home/user
  • /Users/user = /Users/user
  • /mnt/mac/Applications = /Applications

This makes running most commands much smoother, but it might be surprising behavior for arguments to be modified when running executables with binfmt. What do you think?

from orbstack.

XingjianXie avatar XingjianXie commented on May 28, 2024

from orbstack.

kdrag0n avatar kdrag0n commented on May 28, 2024

Yes, that's why I decided to only translate paths conservatively by default. Better to miss some paths than break others (e.g. remote ones) with no recourse.

I guess it probably makes sense to use the same logic for binfmt.

from orbstack.

imkiva avatar imkiva commented on May 28, 2024

This makes running most commands much smoother, but it might be surprising behavior for arguments to be modified when running executables with binfmt. What do you think?

It is good that an executable from macOS can directly access files within the orb. And I don't think translating the path argument will cause much confusion if it is documented. As we all know the orb Linux is located in a certain location in macOS, thus it is natural to have this mechanism.

A good question, as @XingjianXie mentioned, is how to tell a Linux path from macOS one, like, /usr/bin. This path exists both in macOS and Linux, and it is impossible to decide if it should be translated without the users' option.

Say, I have a program used as copy <a> <b> which copies all files in <a> to <b>. The problem arises when I type

# which argument should be translated?
copy /usr/bin /usr/local/bin

Maybe it is reasonable to have something like /mnt/linux: if a path is prefixed with /mnt/linux, we translate it to /Users/user/OrbStack/machine/. It's ugly but works well for edge cases. The above counterexample becomes:

copy /mnt/linux/usr/bin /usr/local/bin

from orbstack.

kdrag0n avatar kdrag0n commented on May 28, 2024

Good idea! /mnt/linux could be a symlink to / to make this explicit.

from orbstack.

imkiva avatar imkiva commented on May 28, 2024

And maybe another idea: symbolically link other distros in orb to /mnt/<distro>, but I don't know if it is useful (maybe no).

from orbstack.

kdrag0n avatar kdrag0n commented on May 28, 2024

Added for the next version.

from orbstack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.