Try   HackMD

Run Alpine on QEMU aarch64 Virtual Machine

tags: Virtual Machine, QEMU, Alpine

Prepare

Get Alpine NET Installer's Kernel and Initial RAM Disk

The vmlinuz-lts and initramfs-lts of Alpine's net installer https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/aarch64/netboot/

The Virtual Disk Going to be Installed

Prepare the virtual disk qemu-img create -f qcow2 disk.qcow2 8G

Installation Steps

Use the net installer to install Alpine into the virtual disk

$ qemu-system-aarch64 -smp 2 \ -M virt -cpu cortex-a57 -m 1G \ -initrd initramfs-lts \ -kernel vmlinuz-lts \ --append "console=ttyAMA0 ip=dhcp alpine_repo=http://dl-cdn.alpinelinux.org/alpine/latest-stable/main/ modloop=http://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/aarch64/netboot/modloop-lts" \ -hda disk.qcow2 \ -netdev user,id=unet -device virtio-net-device,netdev=unet -net user \ -nographic
  • setup-alpine
  • us and us-intl
  • set hostname
  • eth0
  • dhcp, not manual network
  • root password
  • Timezone
  • proxy no
  • NTP client: busybox
  • mirror site
  • ssh server: openssh
  • use disk: vda
  • poweroff

PS. Get the alpine_repo and modloop with HTTP, instead of HTTPs. Because, the crypto of secured HTTPs is not supported during boot time.

Boot the New System

Extract the Kernel and Initial RAM Disk from the Virtual Disk

$ sudo modprobe nbd max_part=8 $ sudo qemu-nbd --connect=/dev/nbd0 disk.qcow2 $ sudo mount /dev/nbd0p1 /mnt/ $ cp /mnt/vmlinuz-lts ./vmlinuz-lts.img $ cp /mnt/initramfs-lts ./initramfs-lts.img $ sudo umount /dev/nbd0p1 $ sudo nbd-client -d /dev/nbd0 $ sudo modprobe -r nbd

Boot

$ qemu-system-aarch64 -smp 2 \ -M virt -cpu cortex-a57 -m 1G \ -initrd initramfs-lts.img \ -kernel vmlinuz-lts.img \ --append "console=ttyAMA0 root=/dev/vda3 rw rootfstype=ext4" \ -hda disk.qcow2 \ -device e1000,netdev=net0 \ -net nic -netdev user,hostfwd=tcp:127.0.0.1:2222-:22,id=net0 \ -nographic

Note:

  • Append the rootfstype=ext4 to kernel's boot command. Otherwise, kernel does not know how to mount the loop.
  • The usable ethernet interface is the e1000. It might be eth1, not eth0. So, check the ethernet interface before use internet.

Reference