Quick test Linux system on QEMU

24年 9月 29日 Sunday
299 words
2 minutes

TL;DR This article just demonstrate how to live boot alpine linux with QEMU and doesn't guide you how to install it with QEMU.

Why I'm doing this?

Sometimes I want to mess around with Linux to test something, and QEMU will definitely come in handy for this purpose.

It depends on what you need on the linux system, just playing with kernel? maybe busybox+kernel or OneFileLinux is sufficient, need a package manager? maybe minimalist distribution like arch linux or alpine linux will fulfill the needs.

Alpine linux

In this article, we will use alpine linux as an example to live boot linux system.

text
qemu-system-x86_64 -cdrom ./alpine-standard-3.20.2-x86_64.iso -m 128 -nographic -enable-kvm

setup network:

text
echo "auto eth0
iface eth0 inet dhcp" > /etc/network/interfaces
rc-service networking start

or you can just setup the whole thing by exec: setup-alpine.

after setup some stuff, you might want to install bash, bash-completion and curl, since the live boot environment only provide busybox utility as default program (which use ash shell by default).

Bonus

alpine linux installer program is pretty convenient, it's like Windows installer where you can press next button multiple times until you've finished :P

you just need to prepare a virtual disk:

text
qemu-img -f qcow2 alpine_linux.qcow2 10G

and after installation, you can boot it:

text
qemu-system-x86_64 \
-drive file=./alpine.qcow2,media=disk,if=virtio \
-m 1024 \
-cpu host \
-enable-kvm \
-nographic

Alternative

I've heard about docker and it gives me a weird impression with an idea of one process per container.

TODO: discuss how to build simplest and naive linux system from scratch

What next?

I will leave what to do with the rest of system up to you, happy hacking! ^^

unrelated note:

if you trying to setup live boot linux system on virt-manager and libvirt, good luck dealing with dns resolve problem ^^

also see:

Title:Quick test Linux system on QEMU

Author:ReYuki

Link:https://www.reyuki.site/posts/quick-test-linux-on-qemu [copy]

Last updated:


This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. You are free to share and adapt it, as long as you give appropriate credit, don’t use it for commercial purposes, and distribute your contributions under the same license. Provided under license CC BY-NC-SA 4.0