You are not logged in.

#1 2013-12-29 01:00:43

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,247

Can't dump qemu-kvm output to console or log

I've been playing around with qemu-kvm to see what is required to create a very minimal Linux system from scratch (not identical to LFS!)

I'm building it inside a raw image file using qemu-kvm. I'd like to be able to dump boot messages to a terminal and/or a log file.

I seem to recall getting this method (summarised below) to work previously but now when I start the vm nothing gets written to the log and qemu goes to the monitor prompt:

QEMU 1.7.0 monitor - type 'help' for more information
(qemu) 

I've also tried using "-chardev file,id=vm1,path=vm.log" (according to this) and "-serial file:vm.log" (according to this) - same result every time. NB: the vm does boot correctly; the failure I want help with is it won't dump boot messages to plain text accessible from a terminal on the host.

I will now describe the steps to replicate the problem exactly.

Create the raw image as image.img and put a filesystem on it:

#! /bin/bash
# Script for setting up a raw image with filesystem for a VM.
# Ref:
#   - http://web2.clarkson.edu/projects/itl/honeypot/ddtutorial.txt
#   - http://alexeytorkhov.blogspot.com.au/2009/09/mounting-raw-and-qcow2-vm-disk-images.html
#   - https://wiki.archlinux.org/index.php/Creating_Arch_Linux_disk_image
image="image.img"

# Create raw image.
sudo dd if=/dev/zero bs=1M count=4196 > $image

# Give it a filesystem
mkfs.ext4 -F $image

Mount the image (I will assume at ./mnt):

#! /bin/bash
# Script for setting up a raw image with filesystem for a VM.
# Ref:
#   - http://web2.clarkson.edu/projects/itl/honeypot/ddtutorial.txt
#   - http://alexeytorkhov.blogspot.com.au/2009/09/mounting-raw-and-qcow2-vm-disk-images.html
#   - https://wiki.archlinux.org/index.php/Creating_Arch_Linux_disk_image
image=image.img
mnt=mnt
[[ -d $mnt ]] || mkdir -pv $mnt
sudo mount $image $mnt

Give the image some directories:

mkdir -v mnt/{usr,proc,bin,etc,sbin,dev,lib,sys,var,boot}

Build a kernel using abs with this config and this PKGBUILD. Then copy vmlinuz-linux from pkg/linux/boot under the linux abs directory to mnt/boot.

Build a trivial init by putting the following in init.c and compiling it with "# gcc -static -o mnt/sbin/init init.c":

#include <stdio.h>

int main(int argc, char *argv) {
    printf("Hello world!\n");
    sleep(999999999);
}

Install syslinux from pacman, run "# extlinux --install mnt/boot" and put the following in mnt/boot/extlinux.conf:

DEFAULT archlinux
LABEL   archlinux
SAY     Booting Arch Linux
LINUX   /boot/vmlinuz-linux
APPEND  root=/dev/sda ro rootfstype=ext4 debug console=tty0 console=ttyS0,115200n8

Unmount the image:

# umount -R mnt

Start qemu-kvm:

#! /bin/bash
image="image.img"

logfile=vm.log
[[ -f $logfile ]] && rm -v $logfile
[[ -e $logfile ]] && exit 1

# Find an unused port.
port=9999
while [[ -n "$(lsof -i :$port)" ]]; do
    port=$(($port+1))
done
nc -l -p $port | tee vm.log &
sudo qemu-system-x86_64 -enable-kvm -drive file="$image" -monitor stdio -serial tcp:127.0.0.1:$port

Observe that the kernel boots and the init script prints out "Hello world" and "vm.log" is created but nothing is dumped to the console except the qemu monitor prompt and vm.log remains empty.

Can anyone spot what I should do differently to ensure boot messages dump to either the terminal or vm.log (or preferably both)?


Edit: replaced patch for PKGBUILD with full PKGBUILD on pastebin.

Last edited by /dev/zero (2013-12-29 01:04:46)

Offline

Board footer

Powered by FluxBB