Skip to content

Instantly share code, notes, and snippets.

@faicker
Forked from oznu/README.md
Last active May 31, 2022 17:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faicker/52282441f90d3949b28a74d7fe73fa01 to your computer and use it in GitHub Desktop.
Save faicker/52282441f90d3949b28a74d7fe73fa01 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 latest 5.0.0

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:

MacOS,

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

Linux,

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(redir is deprecated):

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 \
  -device virtio-net-device,netdev=user0 \
  -netdev user,id=user0,hostfwd=tcp::2222-:22

Ssh:

ssh -p2222 oznu@localhost

Now you can access the internet in the arm VM! (ping not work)

Resources

@faicker
Copy link
Author

faicker commented Jul 20, 2020

Install OS from CDROM/iso image

qemu-img create -f qcow2 ubuntu1804-arm64.img 20G

qemu-system-aarch64 -m 1024 -smp 2 -cpu cortex-a57 -M virt -nographic \
  -pflash flash0.img \
  -pflash flash1.img \
  -device rtl8139,netdev=net0 \
  -device virtio-scsi-device \
  -device scsi-cd,drive=cdrom \
  -device virtio-blk-device,drive=hd0 \
  -drive "file=ubuntu-18.04.4-server-arm64.iso,id=cdrom,if=none,media=cdrom" \
  -drive "if=none,file=ubuntu1804-arm64.img,id=hd0" \
  -netdev user,id=net0

@faicker
Copy link
Author

faicker commented Jul 23, 2020

If you want to set the password by cloudinit,

#cloud-config
users:
  - name: oznu
    lock-passwd: false
  passwd: $6$rounds=4096$q8wfk.bn$36GhsXSNhWzhDzYD6sxZF0mHHWONtF.ZNjVR2ohKnvx8a6kJtweIkpzrp7/kFrmSZ0GNYFS9CPVrZenRPEpzi.
    ssh-authorized-keys:
      - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC...
    sudo: ['ALL=(ALL) NOPASSWD:ALL']
    groups: sudo
    shell: /bin/bash

passwd is generated with mkpasswd --method=SHA-512 --rounds=4096

this yaml pwd is 123456

@faicker
Copy link
Author

faicker commented Jul 23, 2020

ubuntu 20.04 install failed with ISO/cdrom. both images ubuntu-20.04-live-server-arm64.iso and focal-legacy-server-arm64.iso are tried.
missing drivers, need to attach removable usb or cdrom to load drivers.

but can boot with cloud image of focal-server-cloudimg-arm64.img.

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