I hope you have some hands on experience on linux and have some knowledge of the processor architectures. If not let me explain you in layman terms.
There are so many computers out there and they all run on different processors with different architectures. For example our normal windows PC has a x86 architecture of processors, most of the Single Board Computer (eg:- Raspberry Pi) run on ARM architecture. With different architectures of processors their applications also differ and hence if an application is running on and ARM processor it will not run on x86 processor architectures (excluding java applications which are platform independent).
In this blog i will explain you how to run ARM application on and x86 machine using virtualisation and emulation. This means that we are going to make an ARM architecture machine inside a x86 machine using QEMU software to run our ARM based application on and x86 machine, for example running Raspberry Pi application on your linux PC.
Now the question is why we want to do such things when there have plethora of application already running on x86 machines ? There may be many use cases such as
- For testing application on your machine before installing it on the original hardware.
- For running specific application which are only available for different architecture, if you physically do not have the hardware.
- For my purpose, i wanted to cross compile the application on PC as considering the weak hardware present on Raspberry Pi it was taking centuries to compile. Therefore i wanted to compile on PC and then would take the Debian package onto my original machine and just install it over there. This would save a lot of time and debugging will also become very easy.
I think i have discussed enough about the topic, now let us jump in for the creation of cross platform architecture on out PC (or on our x86 machine).
Multi platform virtualisation using chroot, QEMU, debootstrap
Install Required Packages
To accomplish the above task we need install the following packages.
Note :- We have logged in as a root user. To do that type “su”, press enter and enter the root password.
apt-get install binfmt-support qemu qemu-user-static debootstrap
Make Directory for ARM OS installation
We have to make a directory where the guest OS for ARM architecture needs to be installed by debootstrap.
Install guest OS
Install the guest OS by deebootstrap. By default, debootstrap creates a very minimal system.
qemu-debootstrap --arch armel stretch arm_dir http://deb.debian.org/debian/
Copy emulation file
Now we have to copy the QEMU emulation file onto our guest OS from the host OS to start the virtualisation of the ARM machine onto our x86 machine.
cp /usr/bin/qemu-arm-static arm_dir/usr/bin
Starting the virtual environment
Now environment is ready to be used. Start the environment by using the chroot command. This will take you into a sandbox and give you the root access in the virtual environment for ARM machine. This is really beneficial as any changes made in this environment will not affect the host system in any way, therefor this is also the best environment for testing purposes.
Reference – Official Debian Documentation
Hope you have enjoyed learning something new in the linux world. I to love to learn and share new thing with you all. Therefore please like, share and subscribe to our youtube channel and for continuous learning you can bookmark our blog URL. This will give us motivation to bring more such learning to you all 🙂 .