User Tools

Site Tools


ARMv8 Virtual Machine

General Information

Several ARM platforms are available Within the Mont-Blanc project. Even though all of them are available for the Mont-Blanc project partners, sometimes it is needed to have a local environment where to compile/test/develop our software. Basically, the scenarios are the following:

  • No availability of ARMv8 platforms where start compiling/testing applications while a new ARMv8 platform is deployed.
  • Security issues with your code (g.e., is not possible to have your application code on some “public” machine, but sending only the binary to the target platform is ok)

In both cases, one solution is to cross-compile your applications and then copy them to the target platform. But, cross-compiling is usually hard and error prone. Another option is to generate an ARMv8 Virtual Machine (ARMv8 VM) that can be executed on any other machine. The following guide will cover how to generate and use an ARMv8 VM through qemu.

Preparing the environment

Install dependencies

We need to install a set of packages before we start.

sudo apt-get install cloud-utils qemu-utils

Generating the QEMU image

First of all, we need to download the following:

Now a bit of information. Ubuntu cloud images have default users, but those users don't have a password setup. Therefore the only way to access the VM once is booted is via SSH by using SSH keys. It's also necessary that the Ubuntu image is a clean one, since the SSH keys are only added at the first boot.

Therefore, we need to specify the image, the user and the public keys we will be using to login to the cloud image. For this, create a text file called cloud.txt with the following content:

  - name: <your_username>
      - <your_SSH_public_key>
    sudo: ['ALL=(ALL) NOPASSWD:ALL']
    groups: sudo
    shell: /bin/bash

Now we only need to create the cloud-config disk image:

cloud-localds --disk-format qcow2 cloud-config.img cloud.txt

Running the QEMU image

At this point everything is prepared to run the VM. Just execute the following command.

sudo qemu-system-aarch64 \
    -smp 2 \
    -m 2048 \
    -M virt \
    -cpu cortex-a57 \
    -bios QEMU_EFI.fd \
    -nographic \
    -device virtio-blk-device,drive=image \
    -drive if=none,id=image,file=xenial-server-cloudimg-arm64-uefi1.img \
    -device virtio-blk-device,drive=cloud \
    -drive if=none,id=cloud,file=cloud-config.img \
    -device virtio-net-device,netdev=user0 \
    -netdev user,id=user0 \
    -redir tcp:2222::22

Here is a list of the options used by the script that can be changed to modify the virtualized hardware:

  • -smp 2 - 2 (virtual) cores.
  • -m 2048 - 1024MB of system memory.
  • -M virt - emulate a generic QEMU ARM machine.
  • -cpu cortex-a57 - the CPU model to emulate.
  • -bios QEMU_EFI.fd - the BIOS firmware file to use.
  • -nographic - output goes to the terminal (rather than opening a graphics capable window).
  • -device virtio-blk-device,drive=image - create a Virtio block device called “image”.
  • -drive if=none,id=image,file=xenial-server-cloudimg-arm64-uefi1.img - create a drive using the “image” device and our cloud server disk image.
  • -device virtio-blk-device,drive=cloud - create another Virtio block device called “cloud”.
  • -drive if=none,id=cloud,file=cloud-config.img - create a drive using the “cloud” device and our cloud-config disk image.
  • -device virtio-net-device,netdev=user0 - create a Virtio network device called “user0”
  • -netdev user,id=user0 - create a user mode network stack using device “user0”
  • -redir tcp:2222::22 - map port 2222 on the host to port 22 (the standard ssh port) on the guest.

Once it finishes the boot process, you should be able to SSH into the VM by executing:

ssh -p 2222 localhost

Basic configuration of the ARMv8 VM

At this point, your VM should be up and running, but little is configured. The following steps will guide you about some basic configuration that we use to perform here at BSC.

Increasing the size of the rootfs

If you followed this guide, your rootfs will have a size of ~2GB. This space could not be enough for your purposes.

We start by install one package at our VM. After that, shutdown the VM.

sudo apt-get update
sudo apt-get install -y cloud-initramfs-growroot
sudo shutdown -h now

Now it is time to increase the size of the QEMU image.

# To increase the image in 20G (total size = 2GB + 20GB)
sudo qemu-img resize xenial-server-cloudimg-arm64-uefi1.img +20G

Start the VM again, once the booting process finishes, login on it and the filesystem should be already resized.

Install basic packages

First of all, a set of packages that can come in handy. To install them, just execute the following:

# As root
apt-get update
apt-get install vim gcc gfortran g++ build-essential bash-completion make automake autoconf binutils binutils-dev libtcl8.6 tcl8.6-dev libtool bison flex libsqlite3-dev git htop screen gdb bc subversion mercurial mlocate patch m4 cmake cmake-curses-gui gnulib

Set a hostname

Another thing that can be done now is to set a proper hostname for our machine. For example, we will call our VM armv8vm on this example. For doing this, execute the following:

# As root
echo "armv8vm" > /etc/hostname
hostname armv8vm
cat > /etc/hosts <<EOF	localhost	armv8vm

Set a password for the user

Even though we already have SSH configured and a user to access it with SSH keys, it might be useful to put a password on the user so we can access the VM without the SSH keys. For this, once the VM is booted, execute the following:

druiz@armv8vm:~$ sudo passwd `whoami`
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

Now you can login as your user with the password you just set for it.

Deploy the Mont-Blanc software stack


As a final step, you can also download and copy to your VM the Mont-Blanc Software Stack. This will allow you to have a setup as close as possible to the one deployed in our ARMv8 platforms. You can download the software stack from the following link:

Once downloaded, send it to the VM and decompress it at / folder.

# At the host
scp -P 2222 /path/to/the/downloaded/tarball.tar.gz localhost:~/
# At the VM, as root
cd /
sudo tar xfps /path/to/the/downloaded/tarball.tar.gz
# Now execute some script that will configure the Environment Modules package
cd /apps/modules
# Install some missing dependencies and utilities
apt-get install -y gcc build-essential gfortran make cmake automake autoconf libtool binutils binutils-dev cmake-curses-gui flex bison gnulib screen aptitude vim bash-completion command-not-found git htop molly-guard mlocate memtester gdb zsh bc tree mercurial subversion binfmt-support dpkg-dev fakeroot fabric fontconfig-config git-man gperf libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libsqlite3-dev m4 patch ttf-dejavu-core ruby-dev tcl8.6-dev tclx8.4-dev libtcl8.6

Preconfigured VM Image

The following links provide a tarball with all the files you will obtained from everything that was explained in this wiki. So, after decompressing it, you should have everything setup. Some useful information:

To use the image, just download it and type the following:

# Decompress the tar file
tar xf MB_ARMv8_VM.tar.gz
# Enter the folder and start the VM
cd MB_ARMv8_VM

Once the kernel finishes booting, you will be able to login directly on the VM with the credentials supplied above. Anyhow, I strongly recommend to just leave that terminal alone and then use SSH to access the VM as showed below.

ssh arm64@localhost -p2222
wiki/arm64_vm.txt · Last modified: 2018/04/28 10:52 by kpeiro