Skip to content

Instantly share code, notes, and snippets.

@oznu
Last active November 22, 2023 19:49
Show Gist options
  • Star 59 You must be signed in to star a gist
  • Fork 18 You must be signed in to fork a gist
  • Save oznu/ac9efae7c24fd1f37f1d933254587aa4 to your computer and use it in GitHub Desktop.
Save oznu/ac9efae7c24fd1f37f1d933254587aa4 to your computer and use it in GitHub Desktop.
QEMU + Ubuntu ARM aarch64

QEMU + Ubuntu ARM aarch64

These are the steps I used to get Ubuntu ARM aarch64 running with QEMU on OSX.

Get Ubuntu Image and QEMU EFI:

wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-arm64-uefi1.img
wget https://releases.linaro.org/components/kernel/uefi-linaro/latest/release/qemu64/QEMU_EFI.fd

Create EFI volumes:

dd if=/dev/zero of=flash0.img bs=1m count=64
dd if=QEMU_EFI.fd of=flash0.img conv=notrunc
dd if=/dev/zero of=flash1.img bs=1m count=64

Create a cloud.txt file replacing the username, here shown as oznu, and the ssh-rsa value with the values appropriate for you:

#cloud-config
users:
  - name: oznu
    ssh-authorized-keys:
      - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC...
    sudo: ['ALL=(ALL) NOPASSWD:ALL']
    groups: sudo
    shell: /bin/bash

Create a cloud-config disk image:

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

cloud-localds is part of the cloud-utils package which is not is not available on OSX. I used an Ubuntu docker image to run the command.

docker run --rm -it -v $(pwd):$(pwd) -w $(pwd) ubuntu
apt-get update && apt-get -y install cloud-utils
cloud-localds --disk-format qcow2 cloud.img cloud.txt

Backup your image:

cp ubuntu-16.04-server-cloudimg-arm64-uefi1.img ubuntu-16.04-server-cloudimg-arm64-uefi1.img.original

Launch QEMU Guest:

qemu-system-aarch64 -m 1024 -smp 2 -cpu cortex-a57 -M virt -nographic \
  -pflash flash0.img \
  -pflash flash1.img \
  -drive if=none,file=ubuntu-16.04-server-cloudimg-arm64-uefi1.img,id=hd0 \
  -device virtio-blk-device,drive=hd0 \
  -drive if=none,id=cloud,file=cloud.img \
  -device virtio-blk-device,drive=cloud \
  -netdev user,id=user0 -device virtio-net-device,netdev=user0 \
  -redir tcp:2222::22

Resources

@miladmalekzadeh
Copy link

Hi, Thanks for the useful set of commands.
I want to have a emulator for my Jetson Xavier on my Ubuntu 16.04 or 18.04 system. Is this guide that you wrote for such a case?
Could you please refer me to a page in this regard?
Thanks

@actaeon
Copy link

actaeon commented May 9, 2020

Thanks for this!

I stumbled over the '#cloud-config' line in the cloud.txt file.. I had omitted it thinking it was a comment. This line is necessary apparently.

@iulia-yuy
Copy link

iulia-yuy commented Jul 29, 2020

Hi, Thanks for this.
Unfortunately I was not able to complete all the steps. My qemu-system-aarch64 doesn't have "-redir" option and I used instead the following option:
'-device virtio-net-device,netdev=user0
-netdev user,id=user0,hostfwd=tcp::2222-:22'
When I run "$ ssh -p 2222 username@localhost" command for ssh authentication I always get "Permission denied (publickey)." and I can't do the authentication.
Do you know which might be the reason for this?

@iulia-yuy
Copy link

Hi, Thanks for this.
Unfortunately I was not able to complete all the steps. My qemu-system-aarch64 doesn't have "-redir" option and I used instead the following option:
"-device virtio-net-device,netdev=user0
-netdev user,id=user0,hostfwd=tcp::2222-:22"
When I run "$ ssh -p 2222 username@localhost" command for ssh authentication I always get "Permission denied (publickey)." and I can't do the authentication.
Do you know which might be the reason for this?

I have succeeded to resolve the issue. The problem for me was that the home directory path is different than the default one. To change the home directory path you must add in cloud-config file the following option:
homedir: /your/home/directory/path

@cuj
Copy link

cuj commented Mar 23, 2021

I have a question, can I also use https://cdimage.ubuntu.com/focal/daily-live/current/focal-desktop-arm64.iso instead of cloudimg?

@recolic
Copy link

recolic commented Dec 8, 2022

Some of the commands need to be updated.

Replace bs=1m with bs=1M
Replace -redir tcp:2222::22 with -nic user,hostfwd=tcp::2222-:22

Ref: https://stackoverflow.com/questions/55043135/qemu-system-arm-redir-invalid-option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment