{"id":16606917,"url":"https://github.com/mrexodia/rosetta-multipass","last_synced_at":"2025-06-15T15:03:37.638Z","repository":{"id":187847627,"uuid":"620562122","full_name":"mrexodia/rosetta-multipass","owner":"mrexodia","description":"Use Rosetta to run amd64 binaries on your M1 with Multipass.","archived":false,"fork":false,"pushed_at":"2023-03-28T23:46:29.000Z","size":12,"stargazers_count":40,"open_issues_count":1,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-18T02:03:14.593Z","etag":null,"topics":["amd64","m1","m1-mac","macos","multipass","rosetta","virtualization","x86","x86-64"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrexodia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-28T23:43:44.000Z","updated_at":"2025-01-25T20:06:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"f7b0b037-7d95-4736-bedd-ffe3331cc2e3","html_url":"https://github.com/mrexodia/rosetta-multipass","commit_stats":null,"previous_names":["mrexodia/rosetta-multipass"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrexodia%2Frosetta-multipass","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrexodia%2Frosetta-multipass/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrexodia%2Frosetta-multipass/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrexodia%2Frosetta-multipass/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrexodia","download_url":"https://codeload.github.com/mrexodia/rosetta-multipass/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244815081,"owners_count":20514881,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amd64","m1","m1-mac","macos","multipass","rosetta","virtualization","x86","x86-64"],"created_at":"2024-10-12T01:10:43.275Z","updated_at":"2025-03-21T14:30:50.445Z","avatar_url":"https://github.com/mrexodia.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rosetta-multipass\n\nWould you also like to run `amd64` binaries in your [Multipass](https://multipass.run/) VMs on an M1 Mac? This is a guide/tool to enable [Rosetta](https://developer.apple.com/documentation/virtualization/running_intel_binaries_in_linux_vms_with_rosetta) without official support from Multipass. \n\n## Rosetta Installation (macOS host)\n\nFirst you need to [install Rosetta](https://osxdaily.com/2020/12/04/how-install-rosetta-2-apple-silicon-mac/) on your host system:\n\n```sh\nsoftwareupdate --install-rosetta --agree-to-license\n```\n\nYou should now have the `rosetta` translator binary:\n\n```sh\n% tree /Library/Apple/usr/libexec/oah\n/Library/Apple/usr/libexec/oah\n├── RosettaLinux\n│   └── rosetta # \u003c- this one\n├── debugserver -\u003e /usr/libexec/rosetta/debugserver\n├── libRosettaRuntime\n├── runtime -\u003e /usr/libexec/rosetta/runtime\n└── translate_tool -\u003e /usr/libexec/rosetta/translate_tool\n```\n\n**Note**: If you do not get the `RosettaLinux/rosetta` binary, try following the [UTM Rosetta Guide](https://docs.getutm.app/advanced/rosetta/) first, which should install Rosetta for you.\n\n## Rosetta Installation (Ubuntu guest)\n\nCopy the `RosettaLinux/rosetta` binary to your guest VM. In this example the binary has been copied to `/bin/rosetta`, but any path should work. Make sure that you can run the binary from inside the VM:\n\n```\n$ /bin/rosetta\nrosetta error: Rosetta is only intended to run on Apple Silicon with a macOS host using Virtualization.framework with Rosetta mode enabled\nTrace/breakpoint trap (core dumped)\n```\n\nThe error is expected, you can read more about it in a [Quick look at Rosetta on Linux](https://threedots.ovh/blog/2022/06/quick-look-at-rosetta-on-linux/). \n\n### Using `mount-rosetta.py`\n\nTo fix the error you can create a FUSE mount using `mount-rosetta.py`, which implements the `ioctl` required for the Rosetta handshake:\n\n```sh\nsudo apt install libfuse2\nsudo python -m pip install fusepy\n```\n\n**Note**: To mount without root, edit `/etc/fuse.conf` and uncomment `user_allow_other`. This shouldn't be necessary unless you are developing the script.\n\nNow you can run the script:\n\n```sh\nsudo python mount-rosetta.py /bin/rosetta\n```\n\nThis will shadow the `/bin/rosetta` binary and handle the necessary `ioctl` calls. To confirm you you can run:\n\n```sh\n$ /bin/rosetta\nUsage: rosetta \u003cx86_64 ELF to run\u003e\n\nOptional environment variables:\nROSETTA_DEBUGSERVER_PORT    wait for a debugger connection on given port\n\nversion: Rosetta-289.7\n```\n\n**Note**: You will have to run `mount-rosetta.py` in the background.\n\n### Installing the binfmt handler (guest)\n\nTo register `rosetta` for `amd64` binaries:\n\n```\nsudo apt install binfmt-support\nsudo update-binfmts --install rosetta /bin/rosetta \\\n    --magic \"\\x7fELF\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x3e\\x00\" \\\n    --mask \"\\xff\\xff\\xff\\xff\\xff\\xfe\\xfe\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff\\xff\" \\\n    --credentials yes --preserve no --fix-binary no\n```\n\n**Important**: If you want to use `--fix-binary yes` you will have to run `mount-rosetta.py` before the `update-binfmts` command.\n\n### Running an `amd64` executable\n\nYou should now be able to execute a statically linked executable:\n\n```sh\n$ ./tests/main-static\nHello from Rosetta!\n```\n\n### Creating a service\n\nYou can create `/etc/systemd/system/rosetta.service`:\n\n```\n[Unit]\nDescription=Rosetta Mount Service\n\n[Service]\nExecStart=/usr/bin/python3 /home/ubuntu/.local/bin/mount-rosetta.py /bin/rosetta\nEnvironment=PYTHONUNBUFFERED=1\nRestart=on-failure\n\n[Install]\nWantedBy=default.target\n```\n\nSee [here](https://github.com/torfsen/python-systemd-tutorial) for more information.\n\n```\nsudo systemctl list-unit-files | grep rosetta\nsudo systemctl enable rosetta.service\nsudo systemctl start rosetta.service\n```\n\n## Installing shared libraries (experimental)\n\n**Warning**: This section is super experimental and unlikely to yield great results. That being said, it is possible to run clang compiled for `amd64` and build something.\n\nRunning a dynamically linked binary will not work properly at this point:\n\n```\n$ ./tests/main-dynamic\n./tests/main-dynamic: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory\n```\n\nTo fix this (only tested on Ubuntu 22.04) you can run the following commands:\n\n```\nsudo apt install g++-multilib-x86-64-linux-gnu gcc-multilib-x86-64-linux-gnu\nsudo ln -s /usr/x86_64-linux-gnu/lib64 /lib64\nexport LD_LIBRARY_PATH=/usr/x86_64-linux-gnu/lib\n```\n\nAt this point things are working:\n\n```\n./tests/main-dynamic\nHello from Rosetta!\n```\n\n**Note**: For other distributions you can search for `multilib` or `multiarch` packages or look for guides on getting qemu usermode emulation to work.\n\n### Fixing some dynamic linker errors\n\nSince `/usr/x86_64-linux-gnu` is meant for compiling things and not running you might have to replace some `.so` files that are actually linker scripts with the binaries:\n\n```\n$ sudo -i\n$ cd /usr/x86_64-linux-gnu/lib\n$ rg GROUP # lists fake files\nlibc.so\n5:GROUP ( /usr/x86_64-linux-gnu/lib/libc.so.6 /usr/x86_64-linux-gnu/lib/libc_nonshared.a  AS_NEEDED ( /usr/x86_64-linux-gnu/lib64/ld-linux-x86-64.so.2 ) )\nlibm.so\n4:GROUP ( /usr/x86_64-linux-gnu/lib/libm.so.6  AS_NEEDED ( /usr/x86_64-linux-gnu/lib/libmvec.so.1 ) )\n\n$ mv libc.so libc.so.script\n$ cp libc.so.6 libc.so\n$ mv libm.so libm.so.script\n$ cp libm.so.6 libm.so\n```\n\n### Cross-compiling libraries\n\nIf you need to install something like [zlib](https://zlib.net) for `amd64` you can use [Zig](https://zig.news/kristoff/cross-compile-a-c-c-project-with-zig-3599) for easy cross compiling:\n\n```\nsudo snap install zig --classic --edge\ngit clone https://github.com/madler/zlib\ncd zlib\nCC=\"zig cc -target x86_64-linux-musl\" CXX=\"zig c++ -target x86_64-linux-musl\" AR=\"zig ar\" RANLIB=\"zig ranlib\" uname_S=\"Linux\" uname_M=\"x86_64\" C11_ATOMIC=yes USE_JEMALLOC=no USE_SYSTEMD=no ./configure --prefix /usr/x86_64-linux-gnu\nmake\nsudo make install\n```\n\nFor CMake project you can use [zig-cross](https://github.com/mrexodia/zig-cross) as a base.\n\n### Multithreading\n\nAccording to [Quick look at Rosetta on Linux](https://threedots.ovh/blog/2022/06/quick-look-at-rosetta-on-linux/) you might run into issues if the VM is not running in Total Store Ordering (TSO) mode. The solution should be to wrap `rosetta` in a `taskset` command during `update-binfmts`. This was not explored further.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrexodia%2Frosetta-multipass","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrexodia%2Frosetta-multipass","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrexodia%2Frosetta-multipass/lists"}