ARM Emulation on x86 Amazon Linux 2/1/Centos — Ubuntu/Debian

Ezequiel Arielli
4 min readMay 29, 2020

--

Hello guys,

Today I’m going to write about to ARM Emulation on x86 Centos or Amazon Linux 1/2 . Setting Up ARM Emulation on x86 Ubuntu or Debian is easy because you have a support package called binfmt-support. In Centos this package doesn’t exist.

First, I will install ARM emulation on x86 Debian/Ubuntu — EASY WAY.

We’ll be using QEMU and Docker to set up our emulated environment. QEMU is an open source machine emulator and virtualizer. It allows users to to build ARM CUDA binaries on your x86 machine without needing a cross compiler.

Let’s see what happens before setting up the emulation when trying to execute a program compiled for a different architecture :ARM CUDA binaries on your x86 machine without needing a cross compiler.

$ uname -m # Display the host architecture 
x86_64
# Run aarch64 on x86_64
$ docker run --rm -t arm64v8/ubuntu uname -m
standard_init_linux.go:211: exec user process caused "exec format error"
standard_init_linux.go:211: exec user process caused "exec format error"

As expected, the instructions are not recognized since the packages are not installed yet. Installing the following packages should allow you to enable support for aarch64 containers on your x86 workstation:

# Install the qemu packages
$ sudo apt-get install qemu binfmt-support qemu-user-static
# This step will execute the registering scripts
$ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
# Testing the emulation environment
$ docker run --rm -t arm64v8/ubuntu uname -m
aarch64

The installation was successful, the emulation is working. At this point, we can now run aarch64 programs on the host x86_64 workstation.

Note: For advanced details on using QEMU and Docker, please refer to this repository on GitHub.

The first part of the article is not mine.

(This a original blog about running ARM on X86 in Debian/Ubuntu.
https://www.stereolabs.com/docs/docker/building-arm-container-on-x86/)

ARM Emulation on x86 Amazon Linux 2 / 1 / Centos

To start we can say that Running ARM emulation on x86 Debian/Ubuntu is easy, but in Amazon Linux this is a problem. This happend because we don’t have a package binfmt-support with the cpu instructions.

I read many articles about running ARM emulation on X86 Centos and I found the light at the end of the road.

Requirements:

  • Amazon Linux Instance or Centos
  • QEMU
  • Docker

Launch Amazon Linux2 in AWS:

First, you proceed to install Docker

Second, you start docker demon and I test running ARM Docker container in X86 Amazon Linux/Centos Host.

NOOO!!! Error again….

standard_init_linux.go:211: exec user process caused "exec format error"

The docker container doesn’t work, because the cpu doesn’t support the ARM instructions.

Now, you proceed to install qemu and libraries arm.

$ yum install qemu-user qemu-*-static qemu-kvm-tools qemu-kvm virt-install libvirt libvirt-python libguestfs-tools-c qemu-system-aarch64 glib2-devel pixman-devel -y

Later, you need download QEMU Multiarch scripts with CPU Instructions and set running permissons.

CPU Instructions:
https://github.com/qemu/qemu/blob/master/scripts/qemu-binfmt-conf.sh

$ wget https://raw.githubusercontent.com/qemu/qemu/master/scripts/qemu-binfmt-conf.sh$ wget https://raw.githubusercontent.com/multiarch/qemu-user-static/master/containers/latest/register.sh$ chmod 777 qemu-binfmt-conf.sh register.sh

In this step you need to edit in the register.sh the line 23 with the correct path for script register.sh

Don’t forget to modified the line 23 for ./ , and save.

Now, you are ready for running register.sh | If the result is corret you see the similar output.

$ ./register.sh

In this step you need reboot the instance to see the changes.

$ sudo reboot

Test running the arm docker, you’ll can see that works!!!

NOTE: In some cases you need running the script when Linux system init, So you can add the emulation script in /etc/rc.local for persistent forever :)

$ chmod 777 qemu-binfmt-conf.sh register.sh
$ mv qemu-binfmt-conf.sh qemu-binfmt-conf
$ mv register.sh register
$ mv * /etc/rc.d/init.d/
$ ls /etc/rc.d/init.d/
$ vi /etc/rc.local
$ cat /etc/rc.local

Test reboot instance and Enjoy multiarch ARM Running on Amazon Linux/Centos!

Kind Regards,

SRE|Sr. DevOps Ezequiel Arielli @ www.miroculus.com / CA, San Francisco.

About me — blog: www.itshellws.org

About Miroculus: www.miroculus.com

--

--