danct12's boring log

Debian x86 chroot on ARM (w/o Exagear)

2019-12-22

Just in case if you’re not happy with the selection of arm64 programs, you’ll probably want to tap into the x86 part by running them!

How can you run x86 Linux processes on ARM?

By using QEMU, we can launch x86 Linux processes which then QEMU will translate the syscalls to your CPU on the fly. This also works on other architecture (e.g. PowerPC, RISC-V, MIPS,..) as long as QEMU is compiled for the platform.

Requirements

Target system

All of this will be done on PineTab by Pine64, the following specs are:

Prepare the system

Kernel

Nothing much needs to be changed, just make sure CONFIG_BINFMT_MISC is compiled to kernel.

On most kernels this should be enabled by default, but can be checked by zcat /proc/config.gz | grep BINFMT_MISC.

Dependencies

Those packages are required:

All those packages can be installed with one command:

For other distributions, please look for those packages by yourself.

Setup a x86 chroot

Create a folder where you want to store the Debian x86 chroot, in this case I’d like it to be in /srv/chroot/debian-x86, so you need to run mkdir -p /srv/chroot/debian-x86 (as root)

From now on /srv/chroot/debian-x86 will be our target directory for Debian.

Now you’ll have to look for a Debian mirror, I’ll be using http://debian.xtdv.net/debian because it’s the fastest mirror for me.

Next thing we’re gonna do is to install Debian 9 (Stretch):

# debootstrap --arch i386 --foreign stretch /srv/chroot/debian-x86 http://debian.xtdv.net/debian

A few moment later, you should be back to shell, now you need to copy qemu-i386-static to /srv/chroot/debian-x86/usr/bin

# cp /usr/bin/qemu-i386-static /srv/chroot/debian-x86/usr/bin

We’re now ready to run the second stage of debootstrap:

# chroot "/srv/chroot/debian-x86" /debootstrap/debootstrap --second-stage
I: Installing core packages...

Sit back and relax, and maybe take a silp of coffee, dunno, because this will take a while depends on your eMMC/SD Card speed.

Later you’ll get a message that the base system has successfully installed.

Finishing x86 chroot setup

If you made it to here, you’re almost done, keep going!

Create a new file /etc/schroot/chroot.d/debianx86.conf, this is where the schroot configuration will be.

[debian-x86]
description=Debian Stretch x86 chroot
aliases=debian-x86
type=directory
directory=/srv/chroot/debian-x86
profile=desktop
personality=linux
preserve-environment=true

Now you can chroot to the x86 system by using schroot, come on, it feels like home here.

[alarm@alarm ~]$ sudo schroot -c debian-x86
W: line 3 [debian-x86] aliases: Alias ‘debian-x86’ already associated with ‘unknown’ chroot
(debian-x86)root@alarm:/home/alarm# 

It’s safe to ignore that warning for now, but now you’re inside the Debian x86 chroot!

We need to run apt-get update to update and obtain the key signatures as it hasn’t setup yet and now you have finished setting up a Debian x86 chroot.

One thing to notice is that the /home directory is linked to the chroot, meaning that you can access your actual home directory from the chroot, this makes it easier to work with.

Keep in mind that users, groups and passwords configuration are copied every time you access schroot, this means that you can run executables under your current, non-root user without doing any additional setup, just su to the target user (in this case alarm).

X11 applications should work fine under the current user, too.

Additional setup

It is recommend to comment out some files (e.g. passwd, shadow) in the nssdatabases if you don’t want them to be overwritten: /etc/schroot/desktop/nssdatabases

If you have any questions, feel free to comment down below.