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 support for macOS #615

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Add support for macOS #615

wants to merge 4 commits into from

Conversation

kevindurb
Copy link

@kevindurb kevindurb commented Feb 7, 2023

This gets the installer working on macos systems, you still need to brew install coreutils so we might want to add that to the README.md

This also changes mounting of volumes for macos only to skip /, /dev, /tmp, /sys and changes the user home mount to be a "regular" shared mount rather than rslave

@kevindurb kevindurb changed the title install: update installer to use ginstall if on macos Add support for macOS Feb 7, 2023
@drewmoseley
Copy link

Trying this branch on my M1 MacBook Air using colima results in:

$ distrobox create
Image registry.fedoraproject.org/fedora-toolbox:36 not found.
Do you want to pull the image now? [Y/n]: y
36: Pulling from fedora-toolbox
79ccb8138384: Pull complete
b58c382a31cf: Pull complete
Digest: sha256:48aab1f04aa02b0a7a1f1aabfde1ba9908686e08a43123bd34fe966f15c47dab
Status: Downloaded newer image for registry.fedoraproject.org/fedora-toolbox:36
registry.fedoraproject.org/fedora-toolbox:36
Creating 'my-distrobox' using image registry.fedoraproject.org/fedora-toolbox:36	 [ OK ]
Distrobox 'my-distrobox' successfully created.
To enter, run:

distrobox enter my-distrobox

Error response from daemon: mount /etc/localtime:/var/lib/docker/overlay2/b376c5aa8df3a346fa74220efc29dda6d881c9a80de9b83e432fc26a9dabed33/merged/usr/share/zoneinfo/Etc/UTC, flags: 0x5001: not a directory

Using it with docker-desktop, it seems that the distrobox is not created when distrobox-create exits. I view the logs of the container and it continues installing packages and such for some time. I'm not sure if that is normal. But if I let that run to what appears to be completion (ie I see "container_setup_done" in the container logs), then I get the following:

$ distrobox enter my-distrobox
OCI runtime exec failed: exec failed: unable to start container process: chdir to cwd ("/run/host/work/dmoseley/distrobox") set in config.json failed: no such file or directory: unknown

@kevindurb
Copy link
Author

Are you running with the experimental virtio and rosetta 2 support? I think those are gonna be key in getting io and cpu performant enough to make this viable, without them my enter errors out as well

@kevindurb
Copy link
Author

Not sure about lima :(

@drewmoseley
Copy link

I just enabled virtio and rosetta2 support but the behavior was the same for me.

@kevindurb
Copy link
Author

hmm weird, just reset my settings and tried creating the fedora toolbox image and it works great for me. it does take a couple minutes to start up so i had to run distrobox enter... a couple times before it finally dropped me in

--volume \"${distrobox_export_path}\":/usr/bin/distrobox-export:ro
--volume \"${distrobox_hostexec_path}\":/usr/bin/distrobox-host-exec:ro
--volume \"${container_user_home}\":\"${container_user_home}\":rslave"
fi

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

			--volume \"${distrobox_entrypoint_path}\":/usr/bin/entrypoint:ro
			--volume \"${distrobox_export_path}\":/usr/bin/distrobox-export:ro
			--volume \"${distrobox_hostexec_path}\":/usr/bin/distrobox-host-exec:ro

is the same for both cases, so maybe you can move them to line 468?

else
install $@
fi
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

POSIX install should work why specifically use gnu install?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is the -D flag isn’t present in macOS’s install.

https://apple.stackexchange.com/questions/201029/install-illegal-option-d

I’m not familiar with which flags are required by POSIX.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@89luca89 Actually, it looks like install is not part of POSIX unfortunately.

The command is not defined in POSIX. It has mostly split into two camps in terms of compatibility, a GNU type and a BSD type. The main incompatibility lies in the definition of options -D and -d.

https://en.wikipedia.org/wiki/Install_(Unix)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Luckily, we can just add coreutils as a build dependency. It would easier to make brew install distrobox the main way to install distrobox on macOS. There's already a forumla at distrobox.rb.

It only needs slight modifications (removing depends_on :linux and adding coreutils as a dependency for macOS). I have the installer working on my Intel-based macOS just via brew install coreutils and then adding the GNU commands earlier in my PATH. Here is why:

~ $ install -D
install: illegal option -- D
usage: install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
               [-o owner] file1 file2
       install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
               [-o owner] file1 ... fileN directory
       install -d [-v] [-g group] [-m mode] [-o owner] directory ...
~ $ /usr/local/opt/coreutils/libexec/gnubin/install -D
ginstall: missing file operand
Try 'ginstall --help' for more information.

It is easier to implement to use ginstall directly, though:

~ $ ginstall -D
ginstall: missing file operand
Try 'ginstall --help' for more information.
~ $

I'm currently working on getting brew install distrobox to fully work out of the box on Linux (Homebrew/homebrew-core#135178). This should hopefully aid in porting basic features to macOS (Homebrew/discussions#4603).

The way I currently simulate distrobox enter on macOS is very bare-bones and depends on manually creating and renaming the containers. I can learn from the way distrobox create does it and write my own scripts, but porting distrobox to macOS would benefit more people.

#!/usr/bin/env bash

# Usage: my-distrobox-enter <name>
#
# Note: You kinda have to create the container first
#   1. podman run -it homebrew/brew
#   2. open -a "Podman Desktop" # Find the name
#   3. podman rename suspicious_wozniak brew

# Debugging
set -ex

# Start the podman machine (VM) if needed
podman machine start || true

# Start the container if needed
podman start "$1"

# Profit
podman exec -it "$1" bash

Copy link
Contributor

@osalbahr osalbahr Jun 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure why my replies are marked “Pending” and they seem not visible

Edit: I figured it out thx to https://github.com/orgs/community/discussions/10369

@@ -82,6 +82,14 @@
icon_dest_path="${prefix}/share/icons"
completion_dest_path="${prefix}/share/bash-completion/completions/"

install_command() {
if [ "$(uname)" == "Darwin" ]; then
ginstall $@

Check failure

Code scanning / shellcheck

Double quote array expansions to avoid re-splitting elements.

Double quote array expansions to avoid re-splitting elements.
if [ "$(uname)" == "Darwin" ]; then
ginstall $@
else
install $@

Check failure

Code scanning / shellcheck

Double quote array expansions to avoid re-splitting elements.

Double quote array expansions to avoid re-splitting elements.
--volume \"${distrobox_export_path}\":/usr/bin/distrobox-export:ro
--volume \"${distrobox_hostexec_path}\":/usr/bin/distrobox-host-exec:ro
--volume \"${container_user_home}\":\"${container_user_home}\":rslave"
if [ "$(uname)" == "Darwin" ]; then

Check warning

Code scanning / shellcheck

In POSIX sh, == in place of = is undefined.

In POSIX sh, == in place of = is undefined.
@@ -82,6 +82,14 @@
icon_dest_path="${prefix}/share/icons"
completion_dest_path="${prefix}/share/bash-completion/completions/"

install_command() {
if [ "$(uname)" == "Darwin" ]; then

Check warning

Code scanning / shellcheck

In POSIX sh, == in place of = is undefined.

In POSIX sh, == in place of = is undefined.
@89luca89
Copy link
Owner

Hi @kevindurb glad to see work is being done on this! 😄

Hopefully I can find some mac where to test this stuff 👀

I've left a couple of comments, and some linting stuff to do, will try to also create a macos VM where to test all of this

@pythoninthegrass
Copy link

Hi @kevindurb glad to see work is being done on this! 😄

Hopefully I can find some mac where to test this stuff 👀

I've left a couple of comments, and some linting stuff to do, will try to also create a macos VM where to test all of this

@89luca89 Would you be able to work off of an x86 2017 MacBook Air? I might be able to acquire one from work and ship it to you. If not, I'd be happy to test on any of my Macs; I have access to x86 and arm64 Apple laptops and one x86 mini.

I'd even be willing to setup a GitHub Actions runner to do the same if it's possible to test in CI.

Would love to see this get spearheaded for testing ephemeral Mac instances the same way I do with Linux 🙌

@89luca89
Copy link
Owner

89luca89 commented Mar 9, 2023

@89luca89 Would you be able to work off of an x86 2017 MacBook Air? I might be able to acquire one from work and ship it to you. If not, I'd be happy to test on any of my Macs; I have access to x86 and arm64 Apple laptops and one x86 mini.

Thanks for the offer but I'd prefer not to accept, that would be too much :)

But if anyone knows If there are any services online that can (legally) give you access to a remote Macos VM (where I can also run lima and docker-desktop) that can help

@pythoninthegrass
Copy link

No worries!

Looks like you've got HostMyApple (HMA), MacInCloud (MIC), and MacStadium. Latter is the most spendy for bare metal at $119/mo; they don't advertise the virtualized instance prices.

Former two are both $25/mo. HMA is a VM, MIC is bare metal.

If you setup a GitHub Sponsorship, can chip in for any of the above.

@89luca89
Copy link
Owner

89luca89 commented Mar 9, 2023

No worries!

Looks like you've got HostMyApple (HMA), MacInCloud (MIC), and MacStadium. Latter is the most spendy for bare metal at $119/mo; they don't advertise the virtualized instance prices.

Former two are both $25/mo. HMA is a VM, MIC is bare metal.

If you setup a GitHub Sponsorship, can chip in for any of the above.

Will take a look at them thanks a lot! :)

@89luca89 89luca89 force-pushed the main branch 3 times, most recently from 85306b9 to 8b31dc4 Compare March 26, 2023 14:14
@FedX-sudo
Copy link
Contributor

Hi, I see that this was built with Docker Desktop in mind. However, Podman is supported on MacOS as well, and I was wondering if you have been able to test this with Podman. I am trying to spin up a MacOS VM to test this but I don't exactly have convenient access to a Mac either!

@FedX-sudo
Copy link
Contributor

I don't see a reference to ginstall in Brew. What's that package?

@kevindurb
Copy link
Author

@FedX-sudo brew install coreutils and i couldnt get podman working, mounting all of home inside the vm ends up crashing podman. I assume podman would need macos virtio fs support like docker desktop has

@ericcurtin
Copy link
Contributor

Highly recommend podman desktop backend for this on macOS, just saying... https://podman-desktop.io/downloads

@89luca89 89luca89 force-pushed the main branch 5 times, most recently from a1c5095 to 2061ce7 Compare June 13, 2023 19:08
@89luca89 89luca89 force-pushed the main branch 4 times, most recently from 615a4b5 to c8ed679 Compare June 15, 2023 07:30
@osalbahr
Copy link
Contributor

Just stumbled across this PR. I have an Intel-based MacBook Pro. Is there anything I can help with?

@almereyda
Copy link

Running ./install on this branch with colima on a Mac Book Air M1 currently yields this error:

% distrobox create --image registry.fedoraproject.org/fedora-toolbox:37 --name fedorabox
Image registry.fedoraproject.org/fedora-toolbox:37 not found.
Do you want to pull the image now? [Y/n]:
37: Pulling from fedora-toolbox
dcee36d2eab5: Pull complete
fef687da97fd: Pull complete
Digest: sha256:5145e00e875a45d7b468bb2eb662c30c7b7d408096fd4a76924119f8bfbb3712
Status: Downloaded newer image for registry.fedoraproject.org/fedora-toolbox:37
registry.fedoraproject.org/fedora-toolbox:37
Creating 'fedorabox' using image registry.fedoraproject.org/fedora-toolbox:37    [ OK ]
Distrobox 'fedorabox' successfully created.
To enter, run:

distrobox enter fedorabox

Error response from daemon: mount /etc/localtime:/var/lib/docker/overlay2/6ee806a0e2392482c10e731dda1ded6e715393805d79e95b50ffdf8daecb8677/merged/usr/share/zoneinfo/Etc/UTC, flags: 0x5001: not a directory

Trying to enter that distrobox then yields:

% distrobox enter fedorabox
Container fedorabox is not running.
Starting container fedorabox
run this command to follow along:

 docker logs -f fedorabox

Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/etc/localtime" to rootfs at "/etc/localtime": mount /etc/localtime:/etc/localtime (via /proc/self/fd/6), flags: 0x5001: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
Error: failed to start containers: fedorabox

Should this branch be rebased against main, and we test again to create a working and documented Distrobox environment for (ARM) Macs?

@89luca89 89luca89 marked this pull request as draft June 23, 2023 17:44
@osalbahr
Copy link
Contributor

Is there a reason this PR was drafted? I'd love to help port distrobox to macOS

@almereyda
Copy link

almereyda commented Jun 28, 2023

Could you check out this branch and try it out locally, in so we can improve on the remaining issues together? I would be interested in seeing how far you get in trying to get it to work.

There's this /etc/localtime mount error, where it stopped for me, and I suspect there would be other mounts failing, if that one passed.

@osalbahr
Copy link
Contributor

osalbahr commented Jun 28, 2023

Could you check out this branch and try it out locally, in so we can improve on the remaining issues together? I would be interested in seeing how far you get in trying to get it to work.

There's this /etc/localtime mount error, where it stopped for me, and I suspect there would be other mounts failing, if that one passed.

I’d be interested in collaborating on a PR, if there’s interest in officially maintaining it! It’s up to @89luca89 (and other maintainers) if it’s worth the effort.

Feel free to @ me if this PR re-opens or there’s another open PR. Also, I think small bite-sized incremental support is better than one big PR. Like, one only for the install (and maybe some clarifying documentation that it’s in beta, we can also add a caveat to the brew formula).

@89luca89 89luca89 force-pushed the main branch 3 times, most recently from 6c315c5 to 88e2b5a Compare August 6, 2023 12:27
@redthing1
Copy link

I would be interested in helping as well.

@redthing1
Copy link

Having this issue:

❯ distrobox create --image fedora
Image fedora not found.
Do you want to pull the image now? [Y/n]:
Resolved "fedora" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
Trying to pull registry.fedoraproject.org/fedora:latest...
Getting image source signatures
Copying blob sha256:b515bb6817bb5717be9fa1a4e838bcc307d1278ead65a4a80f268661fcb77b44
Copying config sha256:a831f8cb3d2be39ecc55228b3a6a29a23d83f35ec18143d6441a22df67ede8cc
Writing manifest to image destination
a831f8cb3d2be39ecc55228b3a6a29a23d83f35ec18143d6441a22df67ede8cc
Creating 'fedora' using image fedora Error: statfs /usr/local/bin/distrobox-export: no such file or directory

@ericcurtin
Copy link
Contributor

@redthing1 looks like you got pretty far to be honest, it would be interesting to see:

uname -a
cat /etc/*release

output there.

If you manually copy in a distrobox-export to /usr/local/bin/distrobox-export ... You might get further?

@ericcurtin
Copy link
Contributor

ericcurtin commented Aug 16, 2023

By the way Fedora Asahi Remix aka Asahi Linux:

https://asahilinux.org/2023/08/fedora-asahi-remix/

works out the box for distrobox, if you want to install Linux on your Apple Silicon system and run distrobox that way.

@89luca89
Copy link
Owner

I think the problem relies on how distrobox mounts some of its own stuff into the container, so probably one needs to
copy distrobox also in the container for it to be able to mount itself

I'm not sure after that how much integration would work having a VM as middleman
I doubt that sound, graphics and devices integration will work

And at that point, you may as well use a regular podman/docker container

@redthing1
Copy link

I think the problem relies on how distrobox mounts some of its own stuff into the container, so probably one needs to copy distrobox also in the container for it to be able to mount itself

I'm not sure after that how much integration would work having a VM as middleman I doubt that sound, graphics and devices integration will work

And at that point, you may as well use a regular podman/docker container

Yeah, I'm currently working on a minimalist implementation of this that provides a more abstracted/automated CLI for macOS. If anyone else is interested, let me know and I'll share it

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.

None yet

9 participants