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

Image for post
Image for post

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.

Image for post
Image for post

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:

Launch Amazon Linux2 in AWS:

Image for post
Image for post
Image for post
Image for post

First, you proceed to install Docker

Image for post
Image for post

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

Image for post
Image for post

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
Image for post
Image for post

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
Image for post
Image for post

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.

Image for post
Image for post

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

$ ./register.sh
Image for post
Image for post

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

$ sudo reboot
Image for post
Image for post
Image for post
Image for post

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
Image for post
Image for post

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

Written by

DevOps SR | SRE @Miroculus.com San Francisco, CA www.itshellws.org

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store