This is a quick protocol of the kvmtool hacking session with @richard @dxld @goliath @littlelion and @Lambda
Preliminary discussion
Kvmtool currently has the problem that off-the-shelf OS images will not boot because it doesn’t really have BIOS/firmware support (at least on x86) yet.
We want to investigate what needs to be done to make that happen or make kvmtool usable with common linux distros some other way.
Get it booting with firmware
Richard found the Gerd’s patch series1 for seabios which seems to enable using seabios as a firmware image with kvmtool.
We found that we need to apply patches [1/3]
and [2/3]
to seabios master to
get things working. To apply them we used patch -p1 < mbox...
[2]. We
didn’t look at [3/3]
for now.
[2]: git-am is too picky and won’t allow the necessary fuzz
Konfig need some tweaking though to get things working. We need to first do
make defconfig
and then set CONFIG_KVMTOOL=y
and CONFIG_ROM_SIZE=128
in make menuconfig
. The defconfig seems to default to ROM_SIZE=0
even
though patch [1/3]
adds a default 128 if KVMTOOL
. We’re unsure if/how
that’s supposed to work.
With this we can get seabios and grub/syslinux booting. However the kernel/initrd will be unable to find any virtio block devices.
This is because kvmtool uses nasty kernel cmdline hacks to elide having to
write various tables, see kvm__arch_set_cmdline()
in
kvmtool/x86/kvm.c
. To get PCI working in the guest we found that enabling
--sdl
on the kvmtool commandline works.
Note that to enable --sdl
support in kvmtool, libsdl1.2-dev
(Debian)
needs to be installed before running make
.
While this might seem bizzare we can see how the kernel will try to find
either a HOST_BRIDGE
or DISPLAY_VGA
device in pci_sanity_check()
and
while kvmtool does not seem to provide a HOST_BRIDGE
, with --sdl
we get
a DISPLAY_VGA
device at least. This will subsequently allow
pci_check_type1()
to succeed.
Note: Kvmtool would usually pass pci=type1
on the kernel cmdline as
discussed before to skip this check entirely.
So together with --sdl
we can successfully boot both Debian and OpenSUSE
images.
Full working command line:
$ ./lkvm --firmware ../seabios/out/bios.bin --disk my-distro-disk.img --sdl
Get SMP working
When we set --cpus
to something greater than one we don’t get see any
extra cpus in the guest. After much investigating we found that when a
kernel is booted by plain kvmtool --kernel
an MP table is passed in which
contains ncpus info.
Seabios however overwrites the memory where kvmtool put the mptable in
malloc_init()
specifically the f-segment in the BIOS memory.