Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Setup armv7h chroot under x86_64 host (Archlinux/Archlinuxarm biased)

Setup armv7h chroot under x86_64 host (Archlinux/Archlinuxarm biased)

Simple way to setup an arm chroot for building packages for your arm devices. This is an alternative to cross-compiling where you are limited to only linking against the libs in your toolchain.

Setup chroot-fs

You can store the chroot wherever you like. I choose to store it in a disk-image which I mount to my filesystem.

First create a raw disk.

$ dd of=archlinuxarm.img bs=1 seek=4G count=0

Make a ext4 filesystem of the whole disk-image

$ mkfs.ext4 -F archlinuxarm.img

Mount the disk-image somewhere

$ mkdir arm-chroot
# mount archlinuxarm.img arm-chroot

Get the arm root-fs you want to use and copy it to the chroot folder. I use the sun7i archlinuxarm root-fs (same as I have on my Cubietruck).

$ wget
# tar -xf ArchLinuxArm-sun7i-latest.tar.gz -C arm-chroot

chroot with QEMU

You can use qemu-user-static to interpret the ARM instructions in the chroot [1]. Get it from AUR if you are on Archlinux.

Copy the qemu-arm-static binary to the chroot.

# cp /usr/bin/qemu-arm-static arm-chroot/usr/bin

Register the qemu-arm-static as an ARM interpreter in the kernel (using binfmt_misc kernel module) [1].

# echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:' > /proc/sys/fs/binfmt_misc/register

I have made a tool to make this easier, available here.

Finally bind {/proc,/dev,/dev/pts,/sys} and chroot into the chroot.

# mount -t proc /proc arm-chroot/proc
# mount -o bind /dev arm-chroot/dev
# mount -o bind /dev/pts arm-chroot/dev/pts
# mount -o bind /sys arm-chroot/sys
# chroot arm-chroot /bin/bash

When in the chroot check that it is working

[chroot]# uname -a
Linux saturn 3.14.6-1-ARCH #1 SMP PREEMPT Sun Jun 8 10:08:38 CEST 2014 armv7l GNU/Linux

Depending on the rootfs you used you might want to set the nameserver to something like in /ect/resolv.conf in order to lookup services by domainname (or copy the /etc/resolv.conf from your host system).

When you are done, exit the chroot and unmount everything

[chroot]# exit
# umount arm-chroot/{sys,proc,dev/pts,dev}
# umount arm-chroot



This comment has been minimized.

Copy link

jeremyd commented Dec 19, 2017

Great howto! Thanks for writing this. In addition, the steps I used to enable the binfmt for qemu-arm was as follows:

packer -S binfmt-support # or install from AUR via another method
sudo update-binfmts --enable qemu-arm
sudo systemctl enable binfmt-support.service # for load on reboot

After this I'm able to arch-chroot (from the arch-install-scripts package) into the arm filesystem. (no need for the bind mounting by hand.)


This comment has been minimized.

Copy link

faddat commented Apr 21, 2018

Yes, many thanks! I'm using this for an image-builder and this guide was immensely helpful.


This comment has been minimized.

Copy link

initrider commented May 29, 2018

Why I can't ping from alarm user?
[root@mypc /]# ping
PING ( 56(84) bytes of data.
Unsupported ancillary data: 1/29
Warning: time of day goes back (-98945us), taking countermeasures.
64 bytes from icmp_seq=1 ttl=57 time=6.69 ms
Unsupported ancillary data: 1/29
64 bytes from icmp_seq=2 ttl=57 time=4.03 ms
--- ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 4.036/5.364/6.693/1.330 ms
[root@mypc /]# su alarm
[alarm@mypc /]$ ping
ping: socket: Operation not permitted


This comment has been minimized.

Copy link

Danct12 commented Jul 20, 2018

For the first step (creating raw disk), you can use truncate instead of dd.
truncate archlinuxarm.img -s 8G (creates 8GB raw disk)


This comment has been minimized.

Copy link

WarheadsSE commented Apr 1, 2019

You can make this simpler, once you have qemu-arm-static AUR package.

systemd-binfmt.service is a built-in that will activate once the qemu-arm-static is installed.

With qemu in play, arch-chroot from arch-install-scripts doesn't care and does all the special mounts you need.

pacman -U 
systemctl start systemd-binfmt.service
arch-chroot arm-chroot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.