Skip to content

Instantly share code, notes, and snippets.

@yiidtw
Created March 31, 2024 18:21
Show Gist options
  • Save yiidtw/401b5b178d225468b7d4bb0315ec5b71 to your computer and use it in GitHub Desktop.
Save yiidtw/401b5b178d225468b7d4bb0315ec5b71 to your computer and use it in GitHub Desktop.
This is a simple script to run qemu arm64 system simulation on x86 host with prebuilt image. Tested on QEMU emulator version 6.2.0 on Ubuntu22.04 LTS host.
#!/bin/sh
# Disclaimer:
# This is a simple script to run qemu arm64 system simulation on x86 host with
# prebuilt image. Tested on QEMU emulator version 6.2.0 on Ubuntu22.04 LTS host.
#
# Directory layout:
# qemu_ubuntu2204_arm64;
# ├── cloud-config.img
# ├── cloud-config.txt
# ├── QEMU_EFI.fd
# ├── run_qemu_ubuntu2204_arm64.sh
# └── ubuntu-22.04-server-cloudimg-arm64.img
# Step 1: sudo apt install qemu-system-aarch64 guestfs-tools cloud-image-utils
# Step 2: mkdir -p qemu_ubuntu2204_arm64; cd qemu_ubuntu2204_arm64
# Step 3: wget https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-arm64.img
# Step 4: wget https://releases.linaro.org/components/kernel/uefi-linaro/latest/release/qemu64/QEMU_EFI.fd
# Step 5:
# cat <<EOF > cloud-config.txt
# #cloud-config
# users:
# - default
# - name: <your login user name>
# ssh-authorized-keys:
# - ssh-rsa <your login public key>
# sudo: ['ALL=(ALL) NOPASSWD:ALL']
# groups: sudo
# shell: /bin/bash
# EOF
# Step 6: cloud-localds --disk-format qcow2 cloud-config.img cloud-config.txt
# Step 7: sudo virt-customize -a ubuntu-22.04-server-cloudimg-arm64.img --root-password password:<root password for tty login>
# Step 8: (execute the following script)
qemu-system-aarch64 -m 1024 -smp 2 -cpu cortex-a57 -M virt -nographic \
-bios QEMU_EFI.fd \
-drive if=none,file=ubuntu-22.04-server-cloudimg-arm64.img,id=hd0 \
-device virtio-blk-device,drive=hd0 \
-drive if=none,id=cloud-config,file=cloud-config.img \
-device virtio-blk-device,drive=cloud-config \
-netdev user,id=user0,hostfwd=tcp::2222-:22 \
-device virtio-net-device,netdev=user0
# --loadvm mysnapshot
# Step 9: Create snapshot while QEMU executing (use Ctrl-A + c)
# (qemu) savevm mysnapshot
# (qemu) info snapshots
# List of snapshots present on all disks:
# ID TAG VM SIZE DATE VM CLOCK ICOUNT
# -- mysnapshot 783 MiB 2024-03-31 22:48:54 00:10:10.584
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment