# help using KVM w/ kernel dev

## Wizumwalt

I'm trying to develop a linux kernel module and therefore, using KVM so that when it crashes, I won't crash my system.

I'm using gentoo and load a guest OS as follows ...

```

$ qemu-system-x86_64 -hda ./gentoo-i386.img -cdrom ./livecd-amd64-installer-2008.0.iso -boot d -m 512

```

I have a few questions.

1) How can I load the kernel that I have on my host system which is much quicker to load and doesn't load everything like the kernel on the live cd. That one takes too long. I also need the same version running on my host system because it's updated and that's what I've started developing towards.

2) Once I have a guest OS loaded, how do I go about loading the linux kernel module that I have been working on in my home directory on the host OS?

Any help much appreciated.

----------

## Hu

You can use -kernel to skip the normal bootloader process and have the guest start executing a kernel immediately.  For moving a kernel module into the guest, scp should work once you start sshd.  If you want to minimize time spent restoring the guest, consider booting it to a baseline point and taking a memory snapshot.  One way to do that would be to migrate to a file, exit the KVM instance, and start a new one with -snapshot -incoming.  The -snapshot will keep the new instance from modifying the permanent disk image, which is needed since any modifications to the disk image make it dangerous to resume the migrated copy.

----------

## Wizumwalt

I'm trying to be able to get networking going between the host OS and the guest OS so that I can scp a kernel module and load it from the guest OS kernel (so I don't crash my host OS). I'm loading the guest OS as such ...

```

 qemu-system-x86_64 -hda ./gentoo-i386.img -cdrom ./livecd-amd64-installer-2008.0.iso -boot d -m 512 -net nic -net user

```

And then I try to set it to the correct IP by doing ...

```

ifconfig eth0 192.168.0.5 netmask 255.255.255.0 broadcast 192.168.0.255 up

route add default gw 192.168.0.5      # (ip of host os)

```

Anyone see where I'm going wrong?

----------

## Hu

If I recall correctly, the user stack has its own DHCP server and routing settings.  You need to let the guest find an address via DHCP if you use that stack.  I usually configure a TUN/TAP device to connect host and guest.  You might find it more convenient to install a second virtual CD drive and provide the test modules to the guest by bundling them into an ISO, which is then inserted into the second drive.  You can automate that sequence if you place the monitor on a unix domain socket:

```
make module && mkisofs -o km.iso mymodule.ko && echo -e "eject ide1-cd1\nchange ide1-cd1 $(pwd)/km.iso" | socat - unix:/tmp/kvm.monitor
```

For high automation, you could even try driving a root shell in the guest via commands on the host so that the guest can rmmod and modprobe the new kernel module.  You could achieve this using the KVM sendkey interface or by configuring the guest with a serial console, which would then be connected to a unix domain socket on the host.

----------

