QEMU with Alpinelinux
#1
Information 
Alpinelinux in QEMU

I have used the introduction from astr0baby and a few other internet sources and came up with a working solution to boot Alpinelinux in QEMU on the Pinebook Pro. The settings are relatively simple and should work with other target ISOs in a similar way. There is no graphics support, yet. The host distro used here is Manjaro. There might be some differences with other distros. Mind you, this describes how to run an arch64 ISO on an arch64 system.

Install Qemu and create a folder to keep all files together:

Code:
pacman -S qemu-base
pacman -S qemu-img
mkdir qemu

Copy the ISO of Alpinelinux to your qemu folder.  I have used the Standard ISO for the aarch64 architecture.

Then you need to download a BIOS

Code:
wget https://releases.linaro.org/components/kernel/uefi-linaro/latest/release/qemu64/QEMU_EFI.fd

Last thing to prepare is a virtual harddrive to install Alpinelinux

Code:
qemu-img create -f qcow2 alpine.qcow2 8G

This makes a 8G virtual hard disk in a file named alpine.qcow2, the qcow2 format being a format which appears to be 8G to the guest (VM), but only actually writes to the host any sectors which were written to by the guest in practice.

Install Alpinelinux

With all in place you can now start qemu from the .iso file and then install Alpinelinux to your virtual harddrive

Code:
qemu-system-aarch64 \
-machine virt -cpu cortex-a57 \
-m 1024M -nographic \
-bios QEMU_EFI.fd \
-drive format=raw,readonly=on,file=alpine-standard-3.17.3-aarch64.iso \
-drive file=alpine.qcow2,media=disk,if=virtio

A small explanation. The first line is qemu for the aarch64 architecture. The second line describes the cpu. Then memory of 1024M is assigned. 512M is also fine. No graphics is supported. Next is the bios and then the two drives. The ISO file and the virtual harddrive.

Later I show how to use kvm and smp. They could also be used here, but this keeps is simple.

Once Alpinelinux has booted login like this:

user: root

passwd: <leave empty>

Once logged in you can straight away start the install process.

Code:
setup-alpine

Please see the Alpine Docu  and Alpine Wiki for details of the installation process.

You will be asked a bunch of questions, most of them will be default. Things to notice:
  • maybe set your timezone
  • you will be asked which drive you want to use: vda
  • what kind of installation you want: sys

Run Alpinelinux

After the system is installed successfully, you can poweroff. To restart the system you don't need the ISO file anymore. The command after installation is:

Code:
qemu-system-aarch64 \
-machine virt -cpu cortex-a57 \
-m 1024M -nographic \
-bios QEMU_EFI.fd \
-drive file=alpine.qcow2,media=disk,if=virtio

SMP

If you want qemu to use more than one cpu add the [backcolor=#f6f8fa]-smp 2[/backcolor] switch. This gives two cpus, more is possible.

KVM

For Kvm to work you either have to add your user in Manjaro to the kvm group, or run qemu with sudo.

Also:
  • add -accel kvm
  • you can switch [backcolor=#f6f8fa]-cpu[/backcolor] to host

If you use KVM there appears to be a bug that sometimes creates this error message:

Quote:qemu-system-aarch64: kvm_init_vcpu: kvm_arch_init_vcpu failed (0): Invalid argument

Just repeat the start command until it works.

Code:
qemu-system-aarch64 \
-accel kvm -machine virt -cpu host -smp 2 \
-m 1024M -nographic \
-bios QEMU_EFI.fd \
-drive file=alpine.qcow2,media=disk,if=virtio

Edit See comment from jpalus below for a better way to call qemu with kvm.

That's it. I am sure there is still much to improve, but it works.

References

https://drewdevault.com/2018/09/10/Getti...-qemu.html
  Reply


Messages In This Thread
QEMU with Alpinelinux - by Surehand53 - 05-03-2023, 01:41 PM
RE: QEMU with Alpinelinux - by jpalus - 05-05-2023, 04:13 PM
RE: QEMU with Alpinelinux - by korreckj328 - 05-06-2023, 04:21 AM
RE: QEMU with Alpinelinux - by jpalus - 05-06-2023, 10:43 AM
RE: QEMU with Alpinelinux - by slyecho - 05-09-2023, 01:23 PM
RE: QEMU with Alpinelinux - by jpalus - 05-09-2023, 02:41 PM
RE: QEMU with Alpinelinux - by slyecho - 05-16-2023, 01:19 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)