From Alpine Linux
Jump to: navigation, search

QEMU is a very flexible open source machine emulator and virtualizer. QEMU is able to virtualize x86, PowerPC, and S390 guests.

Install Alpine Linux in Qemu

Before You Start

Create the Virtual Machine

Create a disk image if you want to install Alpine Linux.

qemu-img create alpine.qcow 8G

The following command starts qemu with the alpine iso image as cdrom and boot device, the default network configuration, 256 MB memory, and the disk image that was created in the previous step.

qemu -cdrom alpine-2.3.6-x86_64.iso -hda alpine.qcow -boot d -net nic -net user -m 256 -localtime

Tip: Replace qemu with qemu-kvm if your hardware support this.
Log in as root (no password) and run:


At the question on how to use the disk select sys.

Booting the Virtual Machine

After the installation qemu can be started from disk image (-boot c) without cdrom.

qemu alpine.qcow -boot c -net nic -net user -m 256 -localtime

Live mode

If your just want to give Alpine Linux a try, qemu can be used without a disk image and further configuration.

qemu -m 512 -cdrom alpine-3.2.0-x86_64.iso

You need to issue

grsec nomodeset

at boot prompt to avoid being forced in graphical mode and loosing access.

Question: Is there a way to pass an apkovl as paramater at this stage?

Response to self: Yes. I do it like this and I mount /dev/vda1 as /media/config to store the apkovl and the apkcache:
mkdir -p /media/usb/images
qemu-img create -f raw /media/usb/images/mykvm.config 32M
qemu-system-x86_64 -enable-kvm -m 384 \
-name mykvm \
-cdrom /media/usb/images/alpine-3.2.0-x86_64.iso \
-drive file=/media/usb/images/mykvm.config,if=virtio \ 
-net lan \
-boot d &
And inside the KVM

fdisk /dev/vda mkdosfs /dev/vda1 mkdir -p /media/config echo "/dev/vda1 /media/config vfat rw 0 0" >> /etc/fstab mount /media/config setup-alpine lbu ci

At next reboot, it will use the newly generated apkovl and apkcache stored on /dev/vda1 running in run-from-ram from the latest official ISO.

Advanced network configuration

To get networking running correctly, you can use the tun/tap interface, which then becomes a real interface. The key is to define the virtual network interface on the correct virtual vlan, and the correct ifup script.

You need 2 net commands on the command line interface, one for the host:

-net tap,vlan=[somenumber],ifname=[host if],script=[some script]

one for the guest

-net nic,vlan=[samenumber]

So to have a single NIC on the qemu virtual system that is connected to tap0 on the physical host:

qemu -net tap,vlan=0,ifname=tap0,script=./qemu-ifup -net nic,vlan0 \
    -boot d -cdrom alpine*.iso}}

To create a qemu guest with more than one nic, just repeat the -net commands

qemu -net tap,vlan=0,ifname=tap0,script=./qemu-ifup -net nic,vlan0 \
      -net tap,vlan=0,ifname=tap1,script=./qemu-ifup -net nic,vlan0 \
      -net tap,vlan=0,ifname=tap2,script=./qemu-ifup -net nic,vlan0 \
      -boot d -cdrom alpine*.iso}}

Now your alpine guest will have 3 NICs, mapped to tap0, tap1, and tap2 respectively.

What's actually happening is you are effectively creating a point-to-point tunnel, with the phys tap0 device being one endpoint, and the virtual box's eth0 being on the other point of the tunnel.

So you need to assign ip addresses to BOTH sides of the tunnel. The qemu-ifup script is what does that for the host. Here's an example:

case $1 in
      tun0 | tap0 )
              sudo /sbin/ip addr add dev $1
              sudo /sbin/ip link set $1 up
      tap1 | tun1 )
              sudo /sbin/ip addr add dev $1
              sudo /sbin/ip link set $1 up
      tap2 | tun2 )
              sudo /sbin/ip addr add dev $1
              sudo /sbin/ip link set $1 up

In your alpinebox, create an interfaces file like this:

iface eth0 inet static

iface eth1 inet static

iface eth0 inet static

If on your host you now add a MASQUERADE rule for tap0 to your host's default nic, and you turn on ip_forward on your host, you can now do svn updates, surf, run tranmission, etc right from your qemu guest.

Using Xorg inside Qemu

The video driver needed for Xorg inside Qemu is xf86-video-modesetting.

Run a guest OS on Alpine Linux using Qemu

sudo apk add qemu-system-x86_64 qemu-gtk

sudo modprobe kvm-intel

sudo addgroup user kvm

Logout and login again so you become part of the kvm group

qemu-system-x86_64-gtk --enable-kvm -m 1024M -fda M6410220.IMG