<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rotu</id>
	<title>Alpine Linux - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rotu"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Rotu"/>
	<updated>2026-05-09T20:00:02Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=How_to_make_a_cross_architecture_chroot&amp;diff=29171</id>
		<title>How to make a cross architecture chroot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=How_to_make_a_cross_architecture_chroot&amp;diff=29171"/>
		<updated>2025-02-26T19:50:01Z</updated>

		<summary type="html">&lt;p&gt;Rotu: Add openrc package, which is needed to run `rc-service`&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;If you have an ARM computer, you will find that some software is only available for x86_64. One possible solution is to have a full x86_64 virtual machine, but that has quite a lot of overhead from having to emulate the entire system. Fortunately, there is [https://qemu-project.gitlab.io/qemu/user/main.html QEMU User space emulation] which still uses the host kernel, so there is less overhead. This guide will show you how to make a chroot and enable transparent x86_64 binary execution using qemu and binfmt_misc.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
&lt;br /&gt;
You should be familiar with the Linux command line.&lt;br /&gt;
&lt;br /&gt;
This guide is written assuming you have Alpine as the main install as well as putting Alpine in the chroot.&lt;br /&gt;
&lt;br /&gt;
Also, the commands shown assume you have &#039;&#039;&#039;root&#039;&#039;&#039; privileges. Either use &amp;lt;code&amp;gt;sudo/doas&amp;lt;/code&amp;gt; as needed (or &amp;lt;code&amp;gt;su&amp;lt;/code&amp;gt; first).&lt;br /&gt;
&lt;br /&gt;
== Installing necessary software ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;[[Repositories#Managing_repositories| Enable the Community Repository]]&#039;&#039;&#039; and install the &#039;&#039;&#039;qemu&#039;&#039;&#039; user mode binaries for the architectures you want to use, in this case x86_64 and i386:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# apk add {{Pkg|qemu-x86_64}} {{Pkg|qemu-i386}} {{Pkg|qemu-openrc}} {{Pkg|openrc}}}}&lt;br /&gt;
&lt;br /&gt;
Please note there are the &amp;lt;code&amp;gt;qemu-system-*&amp;lt;/code&amp;gt; packages, you don&#039;t want those since they are used for full virtual machine emulation.&lt;br /&gt;
&lt;br /&gt;
== Enable the &amp;lt;code&amp;gt;qemu-binfmt&amp;lt;/code&amp;gt; service and start it ==&lt;br /&gt;
&lt;br /&gt;
The qemu-binfmt script is an OpenRC init script that registers the binfmt_misc handlers when the service starts and unregisters them when the service stops. Add the service to the default runlevel and start it immediately:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# rc-update add qemu-binfmt default&lt;br /&gt;
&amp;amp;#35; rc-service qemu-binfmt start}}&lt;br /&gt;
&lt;br /&gt;
== Make the chroot folder ==&lt;br /&gt;
&lt;br /&gt;
To keep it simple, we&#039;re just going to use the apk repositories specified on the host system. This guide assumes the &amp;lt;code&amp;gt;$CHROOT&amp;lt;/code&amp;gt; environment variable holds the directory where you want to make the chroot. Make the chroot directory and the &amp;lt;code&amp;gt;etc/apk&amp;lt;/code&amp;gt; subdirectory (which we&#039;ll copy the apk repositories file to):&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# mkdir -p $CHROOT/etc/apk/}}&lt;br /&gt;
&lt;br /&gt;
Now copy the host&#039;s apk repositories into the chroot folder:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# cp /etc/apk/repositories $CHROOT/etc/apk/}}&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also need to copy the &amp;lt;code&amp;gt;resolv.conf&amp;lt;/code&amp;gt; file into the chroot so it can have internet access:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# cp /etc/resolv.conf $CHROOT/etc/}}&lt;br /&gt;
&lt;br /&gt;
== Install &amp;lt;code&amp;gt;alpine-base&amp;lt;/code&amp;gt; into the chroot folder ==&lt;br /&gt;
&lt;br /&gt;
The {{Pkg|alpine-base}} meta package is all that&#039;s needed to have a fully working alpine system. The apk invocation used here has a few more options than what you might be used to:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# apk add -p $CHROOT --initdb -U --arch x86_64 --allow-untrusted alpine-base}}&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what all the options do:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;-p $CHROOT&amp;lt;/code&amp;gt;: Sets the root of the install to &amp;lt;code&amp;gt;$CHROOT&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;&lt;br /&gt;
*&amp;lt;code&amp;gt;--initdb&amp;lt;/code&amp;gt;: Initialize a new package database.&lt;br /&gt;
*&amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt;: Alias for &amp;lt;code&amp;gt;--cache-max-age 1&amp;lt;/code&amp;gt;. Basically means don&#039;t install from cache.&lt;br /&gt;
*&amp;lt;code&amp;gt;--arch x86_64&amp;lt;/code&amp;gt;: Install x86_64 packages instead of native packages. Replace this with whichever architecture you want to emulate instead (e.g. &amp;lt;code&amp;gt;--arch x86&amp;lt;/code&amp;gt;).&lt;br /&gt;
*&amp;lt;code&amp;gt;--allow-untrusted&amp;lt;/code&amp;gt;: Install packages with untrusted signature or no signature. (This is needed since the keys for different architectures are different than what will be on your host. If you have the correct keys, you can copy them into the &amp;lt;code&amp;gt;$CHROOT/etc/apk/keys/&amp;lt;/code&amp;gt; directory and remove this flag).&lt;br /&gt;
&lt;br /&gt;
== Mount the virtual file systems into the chroot ==&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# mount -t proc proc $CHROOT/proc/&lt;br /&gt;
&amp;amp;#35; mount -t sysfs sys $CHROOT/sys/&lt;br /&gt;
&amp;amp;#35; mount -o bind /dev/ $CHROOT/dev/&lt;br /&gt;
&amp;amp;#35; mount -o bind /dev/pts/ $CHROOT/dev/pts/&lt;br /&gt;
&amp;amp;#35; mount -o bind /run $CHROOT/run/}}&lt;br /&gt;
&lt;br /&gt;
==The exciting part: Enter the chroot==&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve followed all the steps, this part should be uneventful. The &amp;lt;code&amp;gt;chroot&amp;lt;/code&amp;gt; invocation uses the special command of &amp;lt;code&amp;gt;sh -l&amp;lt;/code&amp;gt; to run as a login shell and source &amp;lt;code&amp;gt;/etc/profile&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# chroot $CHROOT/ sh -l}}&lt;br /&gt;
&lt;br /&gt;
==Troubleshooting==&lt;br /&gt;
&lt;br /&gt;
If you get a &amp;lt;code&amp;gt;ERROR: ${package_name}.post-install: script exited with error 127&amp;lt;/code&amp;gt; while trying to add the alpine-base, that normally means that qemu binfmt_misc hasn&#039;t been setup properly. Check if the &amp;lt;code&amp;gt;qemu-$arch&amp;lt;/code&amp;gt; package has been installed and see if the binfmt_misc service is running. Remember to restart the service after adding a new architecture.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# rc-service qemu-binfmt restart}}&lt;br /&gt;
&lt;br /&gt;
You can also see if there is a &amp;lt;code&amp;gt;qemu-$arch&amp;lt;/code&amp;gt; entry in &amp;lt;code&amp;gt;/proc/sys/fs/binfmt_misc/&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Programs that use [https://en.wikipedia.org/wiki/Netlink Netlink] (e.g. &amp;lt;code&amp;gt;ip addr&amp;lt;/code&amp;gt;) don&#039;t seem to work properly since qemu doesn&#039;t emulate the Netlink protocol properly.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [https://archive.is/ldO0C Transparently running binaries from any architecture in Linux with QEMU and binfmt_misc] (see the section titled &amp;lt;code&amp;gt;Emulating full ARM rootfs&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
[[Category:System Administration]]&lt;/div&gt;</summary>
		<author><name>Rotu</name></author>
	</entry>
</feed>