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.
qemu-system-x86_64 \
-cdrom ./alpine-standard-3.20.2-x86_64.iso \
-m 128 -nographic -enable-kvm
setup network:
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).
Exec
alpine linux installer program is pretty convenient, it's like Windows installer where you can tap next button multiple times until you've finished :P
you just need to prepare a virtual disk:
qemu-img -f qcow2 alpine_linux.qcow2 10G
and after installation, you can boot it:
qemu-system-x86_64 \
-drive file=./alpine.qcow2,media=disk,if=virtio \
-m 1024 \
-cpu host \
-enable-kvm \
-nographic
Arch linux
I used arch linux distro on vm to test my dotfiles, and to install and run it on qemu, the procedure is not much different from Alpine Linux, except you might want to visit installation page on arch wiki site.
the qemu command I use to after installation to run it:
qemu-system-x86_64 \
-drive file=arch-btw.qcow2,media=disk,if=virtio \
-m 4069 -enable-kvm -net nic,model=virtio-net-pci -net user,hostfwd=tcp::4444-:22 \
-vga qxl -device virtio-serial-pci \
-spice unix=on,addr=/tmp/vm_spice.socket,disable-ticketing=on \
-device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
-chardev spicevmc,id=spicechannel0,name=vdagent
and use remmina to access the system, set the server field to unix:///tmp/vm_spice.socket
and connect!
to add share clipboard feature, just start the systemd spice-vdagentd
unit service on the host and spice-vdagent
client program on the client, however currently it somehow stopped working, see this issue.
you also can adjust the display resolution with xrandr if you want:
xrandr --output Virtual-1 --mode 1920x1080
Alternative
I've heard about docker and it gives me a weird impression with an idea of one process per container, I will tried to explore this one someday.
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:
- minimum requirement for alpine linux - wiki.alpinelinux.org
- OpenRC - wiki.alpinelinux.org
- Configure Networking - wiki.alpinelinux.org
- What is the difference between
ash
andsh
shell on Linux? - unix.stackexchange.com - build simplest and naive linux system from scratch - github.com