This means, we will have to boot Archlinux with special settings for the serialĬonsole.
This can be done with the -nographic flag of Qemu,īut then Qemu will expect the output to be written to the serial port. In a new window, but to behave like a standard application with stdin and In order to make Expect work with Qemu we first have to tell Qemu not to start the guest Questions and would usually require human interaction. the bootįor automation of interactive applications we can use Expect.Įxpect can control a program even if this program asks the user several Require automation of an interactive application, because e.g. Creating Qemu image inside a Qemu VM with a Live-CDĪnother approach is to use an Archlinux Live CD and boot the live CD insideĪ Qemu VM with an empty image attached as block device. The boot menu looks a bit broken, but afterwards the display is fine. Qemu-system-x86_64 -cpu host -enable-kvm -m 2048 -smp 2 -drive file =/tmp/image.qcow2 -nographic Thus, I had to read the latest installed modules from /lib/modules. Kernel version to load the modules, but my host kernel and the VM kernel ( chroot)ĭiffered. Additionally, mkinitcpio tries to autodetect the current Of the current host system, which might not work in the Qemu VM (in my case Initramfs without autodetect, because autodetect would detect the modules So far our setup steps are quite standard. Hwclock -systohc echo en_US.UTF-8 UTF-8 > /etc/locale.genĮcho LANG =en_US.UTF-8 > /etc/nfĮcho -e '127.0.0.1 localhost\n::1 localhost' > /etc/hosts # Standard Archlinux Setup ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime Pacman -S -noconfirm base linux linux-firmware mkinitcpio dhcpcd syslinux Pacman -Syu -noconfirm # dhcpcd will be required for standard networking in Qemu # syslinux will be our bootloader
# Select any server you want to have, or better multiple servers echo 'Server = $repo/os/$arch' \ > /etc/pacman.d/mirrorlist Sudo $mountpoint/bin/arch-chroot $mountpoint /bin/bash
This in the full script at the end of the article). Script as a bash command to arch-chroot for full automation (you can see Input instead of continuing script execution. arch-chroot will create an interactive shell and wait for user Standard shell commands again, but in the real automation script this won’t For the sake of readability I will display all commands as Now we can chroot into the bootstrap system and execute all requiredĬommands there. Sudo mkfs.ext4 $loopp # Extract archlinux-boostrap into the image's filesystem sudo mount $loopp $mountpoint sudo tar xf $archive -C $mountpoint -strip-components 1 Sudo parted -a optimal $loop mkpart primary 0% 100% dev/loop0p1) loop = $( sudo losetup -show -f -P $image ) # Create a partition and a file system on the device sudo parted $loop mklabel msdos # Mount the image to an available loopback device, exposing the inner # partition structure of the image (as e.g. We can conver the raw image to qcow2 after the installation.Īrchive =/tmp/archlinux-bootstrap-2020.05.01-x86_64.tar.gz (because raw images can be mounted easily) and setup a filesystem inside
But we’ll start with the simple steps.Īt first we will download the required archlinux iso, create an empty raw image Scheme, because without customization bootloaders often expect that you’re Installation of the bootloader is the toughest part in this installation We can chroot and then execute all required installation commands there. This approach uses a special Archlinux bootstrap image into which Let’s start with the chroot approach, because it is the one that is simpler Creating Qemu image in a chroot environment on the host Again, such a use case couldĪlso be a situation in which automation with Ansible/Puppet/Chef would be more For example you might have so manyĭifferent base configurations for your customers that creating a base imageįor each of them just would be too much effort. Might also have a use case for my approach.
Host system and the other one creates the Archlinux installation from aįor many applications it will probably make a lot more sense to createĪ base image once and then copy this base image for new VMs, but some people One uses a chroot environment from an existing linux In this tutorial I will show how we can automate the installation ofĪrchlinux into a newly created qcow2 image using Qemu.