# Kernel Based Virtualization (KVM)

## gertvs

Maybe this is not the right forum, but I imagine people here will know. I have searched the whole site but didn't find an answer.

I plan to start using Gentoo on new hardware I am currently buying (Intel Core 2 Duo Conroe E6300 based).

I want to install the system using a kernel with the KVM module. I didn't find any package though when I browsed through the package listing.

Is KVM currently available for Gentoo? Or should I wait until 2.6.20 is released?

Thanks

----------

## anello

It is not added as yet, though there is a request for an ebuild maintainer ... see here

----------

## gertvs

 *anello wrote:*   

> It is not added as yet, though there is a request for an ebuild maintainer ... see here

 

I could opt to build it outside the portage tree, right? Or would it be better to wait for it to be officially supported, either as a module or inside the 2.6.20 kernel?

Gert

----------

## anello

 *gertvs wrote:*   

> I could opt to build it outside the portage tree, right? 

 

Yes you can!

 *Quote:*   

> Or would it be better to wait for it to be officially supported, either as a module or inside the 2.6.20 kernel?

 

You should wait if you expect help from gentoo developers to troubleshoot the bugs that you'll encounter. So you're pretty much on your own, but you can still post here on the forums and hope that some of the users/devs here have experience in that regard that may help you.

----------

## JoeUser

You could still build it outside portage.  I'm running it.  I was too impatient to wait for the next kernel  :Smile: 

KVM-7 wouldn't build because I needed to use gcc4 but the QEmu part of KVM requires gcc3.  As of KVM-8 you can specifiy an alternate compiler for QEmu so now it's running here fine.

For me, i used the following for configure:

```
./configure --prefix=/usr/local/kvm --qemu-cc="/usr/bin/gcc-3.4.6"
```

then make, make install, added kvm-amd  (kvm-intel for you) to  /etc/modules.autoload.d/kernel-2.6 and modprobe'd it so I could use it right away.

----------

## stuorguk

How well does KVM work?  I have just installed 2.6.20-mm1, on a new Gentoo box that I am building and saw it as a kernel option.

Stuart.

----------

## JoeUser

 *stuorguk wrote:*   

> How well does KVM work?  I have just installed 2.6.20-mm1, on a new Gentoo box that I am building and saw it as a kernel option.

 

Currently not quite as smooth as VMWare but a little better then QEmu with KQemu.  It's still a young project but it's coming along very quickly.  I've been watching the kvm-devel mailing list on sourceforge and the new MMU Virtualization work for KVM appears to have some significant improvements but I've not tried that yet.  The MMU branch I read was for Intel VT only at the moment and I use AMD.  I'm looking forward to testing it though.  

Someone else that had tested the KVM MMU branch showed quite a good speed up over the current KVM release.  See the thread here:

http://sourceforge.net/mailarchive/forum.php?thread_id=31313271&forum_id=50582

Quote from the mailing list:

 *Quote:*   

> Here are some quick numbers. Context-switch overhead with lmbench
> 
> lat_ctx -s 0 [zero memory footprint]:
> 
> -------------------------------------------------
> ...

 

I run Windows XP with KVM and it runs just fine for what I need now.

----------

## drwook

 *JoeUser wrote:*   

>  *stuorguk wrote:*   How well does KVM work?  I have just installed 2.6.20-mm1, on a new Gentoo box that I am building and saw it as a kernel option. 
> 
> Currently not quite as smooth as VMWare but a little better then QEmu with KQemu. 

 

Noticably better or measurably better?  I run a windows server 2003 AD domain & some test VM's on one machine using gentoo/qemu, so if it's really noticable performance increase I might take a look.

----------

## JoeUser

 *drwook wrote:*   

> Noticably better or measurably better?  I run a windows server 2003 AD domain & some test VM's on one machine using gentoo/qemu, so if it's really noticable performance increase I might take a look.

 

Only slightly noticeably better than Qemu with KQemu after windows is booted but the boot up in KVM pauses a bit with a white screen.  I'm not sure what that's all about but after windows is booted it's fine.  

For running servers it might be better to wait for the official release of the 2.6.20 kernel if it includes the work from the optimized MMU virtualization branch.

----------

## stuorguk

Sounds great.  I have a hard disk with a windows installation on it.  What I want to do is either get KVM to boot straight from the HD partition, or copy it into a virtual HD.  I assume thats possible.

Stuart.

----------

## gertvs

Thanks, everybody here for the excellent information.

I am currently resolving hardware problems with my new system, but I deduct from the performance comparisons provided here, eventhough they're not hard bench marks, that using either the proprietary VMware Player or Qemu with KQemu would be a good temporary option until kernel 2.6.20 is released.

When is 2.6.20 projected to be released?

Many thanks,

Gert

----------

## JoeUser

If you're going to use KVM eventually I'd recommend using QEmu while you wait rather then VMWare because KVM also uses QEmu as it's front and its disk images so you can reuse the same disk images you create now after you install KVM.  QEmu/KVM will also read VMWare 3 and 4 disk images but i'm not sure if it'll read newer VMWare 5 files.  Using QEmu now will save you from having to re-install everything in a new disk image later.

see here: qemu-img invocation

----------

## drwook

 *gertvs wrote:*   

> Thanks, everybody here for the excellent information.
> 
> I am currently resolving hardware problems with my new system, but I deduct from the performance comparisons provided here, eventhough they're not hard bench marks, that using either the proprietary VMware Player or Qemu with KQemu would be a good temporary option until kernel 2.6.20 is released.
> 
> When is 2.6.20 projected to be released?
> ...

 

qemu/kqemu has worked out quite nicely for me up to now  :Smile: 

----------

## JoeUser

 *gertvs wrote:*   

> ... I deduct from the performance comparisons provided here, even though they're not hard bench marks, that using either the proprietary VMware Player or Qemu with KQemu would be a good temporary option until kernel 2.6.20 is released...

 

There's some benchmarks here now.  

http://www.phoronix.com/scan.php?page=article&item=623&num=1

and

http://linux.inet.hr/finally-user-friendly-virtualization-for-linux.html

Personally I think the comparison was done too early because the MMU Optimized branch wasn't used but the numbers are still good.  Not quite as good as Xen but better than Qemu+KQemu.

----------

## Maf

Any hope for KVM available for amd64 s939 cpu or just physicly impossible?

----------

## JoeUser

 *Maf wrote:*   

> Any hope for KVM available for amd64 s939 cpu or just physicly impossible?

 

Does it have SVM support listed under 'flags' in '/proc/cpuinfo'?  I don't think it does but I'm not certain.

if it does you're in luck otherwise no.  sorry.

----------

## dpurcell

I've been trying to get kvm-11 to work on my amd64 X2 5200+ but am having trouble compiling it.  Perhaps any one of you may know what may be going on?  

The first problem I run into is with the ./configure.  It says I don't have sdl support, even though I emerged media-libs/libsdl and app-emulation/emul-linux-x86-sdl.  I also did a gcc-config and switched my computer to x86_64-pc-linux-gnu-3.4.6 and sourced /etc/profile.  When I type ./configure --prefix=/usr/local/kvm, this is what I get:

Install prefix    /usr/local/kvm

BIOS directory    /usr/local/kvm/share/qemu

binary directory  /usr/local/kvm/bin

Manual directory  /usr/local/kvm/share/man

ELF interp prefix /usr/gnemul/qemu-%M

Source path       /home/dpurcell/dev/kvm-11/qemu

C compiler        /usr/bin/gcc32

... cut out to not bore you with details....

SDL support       no

... cut out to not bore you with details....

kvm support       yes

Documentation     yes

ERROR: QEMU requires SDL or Cocoa for graphical output

To build QEMU without graphical output configure with --disable-gfx-check

Note that this will disable all output from the virtual graphics card.

However, when I cd into the qemu subdir and type './configure' from that subdirectory, I see "SDL support yes" and SDL static support   yes" in the output.  So I edited the qemu/configure script and forced 'sdl' to 'yes'.  After that, I see a 'yes' next to sdl when I run configure from the kvm-11 subdir.

The next issue happens a few moments after I type make (sorry for the tons of output):

/usr/bin/gcc32 -DQEMU_TOOL -I /home/dpurcell/dev/kvm-11/qemu/../user -Wall -O2 -g -fno-strict-aliasing -I. -g -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -o qemu-img qemu-img.c block.c block-cow.c block-qcow.c aes.c block-vmdk.c block-cloop.c block-dmg.c block-bochs.c block-vpc.c block-vvfat.c -lz -luuid

block-vmdk.c: In function `vmdk_open':

block-vmdk.c:420: warning: passing arg 1 of `dirname' discards qualifiers from pointer target type

/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.6/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-linux-gnu/3.4.6/../../../libz.so when searching for -lz

/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.6/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-linux-gnu/3.4.6/../../../libz.a when searching for -lz

/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.6/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible /lib/libz.so when searching for -lz

/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.6/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible /usr/lib/libz.so when searching for -lz

/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.6/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible /usr/lib/libz.a when searching for -lz

/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.6/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lz

collect2: ld returned 1 exit status

make[1]: *** [qemu-img] Error 1

make[1]: Leaving directory `/home/dpurcell/dev/kvm-11/qemu'

make: *** [qemu] Error 2

Why would qemu have trouble finding a compatible libz?  I have made sure I have zlib installed.

-Confused

----------

## dpurcell

Ha! Figured it out.  All I needed to do was this:

```
/configure --prefix=/usr/local/kvm --qemu-cc="/usr/bin/gcc-3.4.6"
```

and all my sdl and zlib problems went away!

----------

## Maf

 *JoeUser wrote:*   

> 
> 
> Does it have SVM support listed under 'flags' in '/proc/cpuinfo'?  I don't think it does but I'm not certain.
> 
> if it does you're in luck otherwise no.  sorry.

 

Ok, then I have small OT question: Which other VM do you all suggest to use? Qemu, Xen? Or something else?

I'd like it to be fast and use free/libre license.

----------

## whig

If you want an X gui in a VM then KVM uses Qemu's. Xen is faster, but console only I understand.

----------

## JoeUser

It depends on your needs.  Do you plan on running Windows on it?   Xen has the same limitation as KVM.  It can't run Windows without an SVM or VT capable processor.  Xen's paravirtualization can get near native performance using modifed Xen aware guests but MS isn't going to let anyone release modified Windows source.  Windows will only run unmodified in Xen and KVM with hardware assisted full virtualization.  You also need to VNC, TSClient, XDMCP or SSH with X forwarding to get a windowed interface to a Xen guest.  The kvm-devel mailing list has some work being done to give KVM paravirtualization support but then like Xen it'll require modified guests to make them 'aware'.  I might be wrong here but that's how I understand it all.  

Also, I couldn't get Xen to work reliably.  I don't think it likes my Acer because when I booted the Xen kernel built from the Xen modified kernel source in Portage everything just went BAD. I think Xen is overkill for most peoples needs unless you're consolidating a server farm into fewer machines.  The average Linux user probably just wants it to run windows for their last few programs they don't have replacements for yet.  That's my situation and KVM is fine for me. 

Qemu with KQemu accelerator isn't bad if you don't have an SVM/VT processor.  It'll run Windows for you unmodified but KQemu isn't open.  There was an open source project to create a Qemu accelerator called QVM86 but I haven't tried it.Last edited by JoeUser on Sat Jan 13, 2007 1:13 pm; edited 1 time in total

----------

## Maf

I have Athlon 64 @ s939 cpu, so I probably have to stay with Qemu + KQemu, which works quiet ok.

----------

## kraix

there has been one thing I have been wanting to know but haven't really put any time into figuring it out, with virtualization hardware, AMD Turion Tl-50,  is it possible to get good 3d rendering for games under Xen or KVM? pretty  much for games...

----------

## whig

Socket 754 here: Qemu gives me a Cirrus "card" so no hardware opengl. The programs do run, at about 4 fps  :Sad: 

----------

## kraix

But I don't believe the 754 has virtualization support at all. The turion tl-50 does have virtualization support, which might increase opengl performance for some very strange reason.

----------

## whig

The 754 can do virtualization,  kqemu, and I do it often, knowing all along it won't be as fast as KVM or Xen. For desktop guests the performance is not 100% but definitely usable. I installed Ubuntu in a VM - that took a while - Ubuntu takes a while anyway. Doesn't matter, the install was done within a window on my Gentoo desktop. I think I was web browsing and listening to .oggs while Ubuntu did its thing. Then I copied Ubuntu from the VM to a partition on my real hdd.

If you run opengl apps in guests prepare to take a hit, even if you have an AM3 board.

----------

## JoeUser

 *kraix wrote:*   

> there has been one thing I have been wanting to know but haven't really put any time into figuring it out, with virtualization hardware, AMD Turion Tl-50,  is it possible to get good 3d rendering for games under Xen or KVM? pretty  much for games...

 

You wont get any 3d rendering with this for a while.  KVM virtualizes the processor but it uses Qemu to emulate the rest of the hardware in the VM.

http://fabrice.bellard.free.fr/qemu/qemu-doc.html#SEC7

 *From the Qemu docs wrote:*   

> 
> 
> The QEMU PC System emulator simulates the following peripherals:
> 
>     * i440FX host PCI bridge and PIIX3 PCI to ISA bridge
> ...

 

I'm not 100% positive about Xen but I believe for Xen you have to remote desktop or vnc into the guest so you probably wont be getting any 3d rendering there either.

There's a good explaination of why 3d rendering doesn't work in the guest VM here:

http://wiki.xensource.com/xenwiki/XenFaq#head-d5a7a247a5168517291228a6f02fd74b419badeb

----------

## kraix

Oh well, that stinks. hopefully someday full 3d will be available. Well thanks for the link, it was rather informative.

To Whig,

Yes I already know ALL processors CAN do emulation. What I specified about, which you may have just glossed over, was whether or not virtualization equipped hardware was capable of providing full 3d rendering. I knew 3d rendering sucked on a normal platform already.

----------

## JoeUser

AMD is doing quite a lot to further develop virtualization technologies.  We have the processor virtualization now.  The next step is the IO virtualization then we should be able to run 3d rendering with unmodified graphics drivers.  There's an interesting article here about their IOMMU:

http://www.devx.com/amd/Article/32146

It means another hardware upgrade so I think I better start saving my pennies...probably my nickles and dimes too.   :Smile: 

----------

## kraix

That article looks very interesting. Hopefully they don't make it cost an arm and a leg though. I would assume it wouldn't be anything more than a motherboard upgrade potentially. I would assume this because they would just plug it into the hyper-transport bus, just like any other hypertransport device, i.e. gpus on a socket. Doesn't seem like it would require a total system change.

----------

## Maf

 *kraix wrote:*   

> But I don't believe the 754 has virtualization support at all. The turion tl-50 does have virtualization support, which might increase opengl performance for some very strange reason.

 

AFAIK, only AMDs with AM2 socket have this feature

----------

## JoeUser

This link should help clear up the confusion over which processors support it 

HVM Compatible Processors: http://wiki.xensource.com/xenwiki/HVM_Compatible_Processors

----------

## vinboy

KVM is quite good.

It's lighter and smoother than VMware, the only downside is you don't have nice GUI to set the settings.

----------

## JoeUser

GUI like these?

GTK:

http://emeitner.f2o.org/qemu_launcher

KDE:

http://kqemu.sourceforge.net/

the KDE KQemu name is misleading because it's the same name as the Qemu accelerator module.

Neither of them are specifically KVM but since KVM uses Qemu they should still work.

----------

## drescherjm

How is the disk performance with kvm? Is it any good with a windows guest?

I ask this because at work I have installed VMWare Server on my main windows development box (as well as several gentoo boxes) which is an Opteron 248 with 2GB of memory and a fast SATA drive but running 32 bit gentoo under XP the disk performance is very poor even with preallocating drive images turning off memory trimming. It seems like gentoo takes 4 to 8 times longer to build than it should with this hardware and I have the vmware tools installed and running. One example of this was kde. On this box with vmware installed KDE took several days to build. The same box and native it takes a few hours. I have done cpu performance tests and I know it is not that as prime95 almost runs at native speed so I know this must be disk related.

I have done a lot of other testing with different vms and different hardware but the only place I got good disk performance was with xen with linux host and linux guest.

----------

## EricHsu

guys,

a kvm n0ob's question - where could I get the "slightly modified qemu" which is kvm-awared (?) ?

I've been searching through the forums and internet, seems no answer...

I'm now installing winxp even without the kvm-intel module (I just rmmod'd it...), when will I need kvm/kvm-intel? and how to let qemu (which is emerge'd from portage) know that I have kvm module and use it?

TIA!

----------

## EricHsu

 *EricHsu wrote:*   

> guys,
> 
> a kvm n0ob's question - where could I get the "slightly modified qemu" which is kvm-awared (?) ?
> 
> I've been searching through the forums and internet, seems no answer...

 

by downloaded the kvm-13 release from sourceforge, I guess I have the answer now   :Embarassed: 

----------

## drescherjm

There is an ebuild here:

https://bugs.gentoo.org/show_bug.cgi?id=157987

----------

## sirtalon42

Just so everyone knows, the latest version of the KQemu Accelerator is now GPL (1.3.0pre10, see http://lwn.net/Articles/220807/ ).

----------

## whig

 *sirtalon42 wrote:*   

> Just so everyone knows, the latest version of the KQemu Accelerator is now GPL (1.3.0pre10, see http://lwn.net/Articles/220807/ ).

 

I have installed kqemu-1.3.0_pre11 from portage, today I think.

----------

## EricHsu

Guys, I've got my winxp up and running on my gentoo! KVM + Qemu is awesome!

So here's another question, the default resolution to my winxp is only 800x600, my gentoo host is 1680x1050, so the winxp is now a really small box in my screen, how could I possibly set it to higher resolution like 1024x768 or 1280x1024?

TIA!

----------

## rcb1974

So I got Windows XP installed in KVM/Qemu.  Everything works great, except networking.  So far I've tried to correct this by:

USER MODE NETWORKING:

```
qemu-system-x86_64 -hda /home/disks/vm/hd_qemu_winxp.qcow -boot c -m 512 -localtime -soundhw sb16 -usb -net nic -net user
```

...and configured the Windows XP guest to use DHCP to configure the NIC.  However, that didn't work.  So I tried using a network tap instead:

NETWORK TAP:

Relevant output of ifconfig BEFORE starting qemu (configured this in /etc/conf.d/net):

```

tap0      Link encap:Ethernet  HWaddr 52:54:27:C0:4F:C0

          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0

          inet6 addr: fe80::5054:27ff:fec0:4fc0/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:8 overruns:0 carrier:0

          collisions:0 txqueuelen:100

          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

```

Output of route:

```

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

user-10mt5h0.ca *               255.255.255.224 U     0      0        0 eth1

192.168.1.0     *               255.255.255.0   U     0      0        0 tap0

192.168.0.0     *               255.255.255.0   U     0      0        0 eth4

loopback        *               255.0.0.0       U     0      0        0 lo

default         user-10mt5h1.ca 0.0.0.0         UG    0      0        0 eth1

```

...and when I execute Qemu using:

```

qemu-system-x86_64 -hda /home/disks/vm/hd_qemu_winxp.qcow -boot c -m 512 -localtime -soundhw sb16 -usb -net nic -net tap,fd=h,ifname=tap0

```

...and configured the Windows XP guest NIC with this TCP/IP info:

```

IP: 192.168.1.2

GATEWAY: 192.168.1.1

MASK: 255.255.255.0

DNS: (the same as what is in /etc/resolve.conf on the Gentoo host OS)

```

That didn't work either.  I still cannot get Windows XP guest to connect to anything.   What do I need to do differently?

Thanks,

Richard

----------

## JoeUser

 *EricHsu wrote:*   

> Guys, I've got my winxp up and running on my gentoo! KVM + Qemu is awesome!
> 
> So here's another question, the default resolution to my winxp is only 800x600, my gentoo host is 1680x1050, so the winxp is now a really small box in my screen, how could I possibly set it to higher resolution like 1024x768 or 1280x1024?
> 
> TIA!

 

You should be able to change the resolution from the windows display settings and Qemu will just resize itself to fit.  I'm running KVM/Qemu at 1024x768 and that's all I did.  I right clicked on the windows desktop, click properties, then the settings tab.  The video emulated by Qemu will allow you to choose up to 1280x1024x16. I'm running 1024x768x16 but 24 bit is also possible at 1024x768.

 *rcb1974 wrote:*   

> So I got Windows XP installed in KVM/Qemu. Everything works great, except networking.

 

Have you tried not specifying any network options so it just uses default user mode?  Networking works fine for me that way.  Here's the command I use to start WinXP:

```
qemu-system-x86_64 -hda ~/kvm/windowsxp/windowsxp.img -boot c -m 256 -localtime -no-acpi -soundhw sb16
```

Window's uses DHCP and receives the following settings (retrieved from windows ipconfig) automatically from Qemu's built in VLAN DHCP server.

```
IP Address: 10.0.2.15

Default gateway: 10.0.2.2

DHCP server: 10.0.2.2

DNS server: 10.0.2.3
```

----------

## rcb1974

JoeUser,

I got networking working in Windows XP on KVM/Qemu.  I was using an XP installation on an old Qemu disk image.  I reinstalled XP from scratch in the VM and networking started working.

Thanks,

Richard

----------

## EricHsu

 *JoeUser wrote:*   

> 
> 
> You should be able to change the resolution from the windows display settings and Qemu will just resize itself to fit.  I'm running KVM/Qemu at 1024x768 and that's all I did.  I right clicked on the windows desktop, click properties, then the settings tab.  The video emulated by Qemu will allow you to choose up to 1280x1024x16. I'm running 1024x768x16 but 24 bit is also possible at 1024x768.

 

Hi JoeUser,

Thank you very much for your reply! With your hint, I just notice that I made a stupid mistake that I didn't realize the resolution slider could be simply dragged to the right to set to 1280x1024! (I thought the left side of the slider 800x600 is the max value! - I'm a stupid windows user :p ) now I can set it up to 1280x1024x24! awesome!

Thanks a lot  :Wink: 

Edit:

Yet another question: I've already set my rtc to:

```

$ cat /proc/sys/dev/rtc/max-user-freq 

1024

```

but qemu still complains every  time I run it:

```

$ kvm . -hda winxp.img -boot c -m 384 -soundhw all -smp 2 -no-acpi -localtime

Could not configure '/dev/rtc' to have a 1024 Hz timer. This is not a fatal

error, but for better emulation accuracy either use a 2.6 host Linux kernel or

type 'echo 1024 > /proc/sys/dev/rtc/max-user-freq' as root.

```

I'm running it as a normal user, how could I "fix" this? TIA  :Smile: 

----------

## JoeUser

I had that problem too until one day I upgraded my kernel and forgot about it because I wasn't getting the error anymore.  Grep of .config shows only these two RTC related items enabled:

```
CONFIG_HPET_EMULATE_RTC=y

CONFIG_RTC=y
```

Maybe that will help?

----------

## EricHsu

 *JoeUser wrote:*   

> I had that problem too until one day I upgraded my kernel and forgot about it because I wasn't getting the error anymore.  Grep of .config shows only these two RTC related items enabled:
> 
> ```
> CONFIG_HPET_EMULATE_RTC=y
> 
> ...

 

hey JoeUser, it works! BiG thanks!  :Wink: 

----------

## Gilbo

Does anyone know if it's possible to give Windows XP control or access to USB devices when it's run under KVM?

----------

## JoeUser

 *Gilbo wrote:*   

> Does anyone know if it's possible to give Windows XP control or access to USB devices when it's run under KVM?

 

You can specify the USB device on the command line with the -usbdevice option or from the QEmu monitor while it's running using the command add_usb.  For example, my laptop has a few built in USB devices such as a camera.  While KVM/QEmu is running I hit ctrl-alt-2 to switch to the QEmu monitor and enter the command "info usbhost".  This lists the USB devices that are available to be added to the guest OS. 

```
(qemu) info usbhost

   Device 2.2, speed 1.5 Mb/s

      Class 00: USB device 046d:c518, USB Receiver

   Device 1.3, speed 480 Mb/s

      Class 00: USB device 0402:5602, USB2.0 Camera

   Device 1.4, speed 480 Mb/s

      Class 00: USB device 058f:6331, Mass Storage Device

(qemu) usb_add host:0402:5602
```

or from command line:

```
 /usr/local/kvm/bin/qemu-system-x86_64 -hda ~/kvm/windowsxp/windowsxp.img -boot c -m 256 -localtime -no-acpi -smb ~/mnt/qemu -usb -usbdevice host:0402:5601
```

Windows does it's little "found new hardware" thing and then it appears in Device Manager as a functional USB device.

----------

## Gilbo

Thanks a lot JoeUser.

----------

## saintpa

Has anyone tried running existing Windows XP Installations? I (unfortunately) has a dell with OEM windows installation disk, which won't install under qemu. I have tried with qemu/kqemu to boot from that partition, but the guest OS blue-screened shortly after boot.

----------

## whig

The XP install cd BSoD'd me using kqemu, so I tried qemu without the -kernel-kqemu option and it worked. Now the image runs okay with the option for a bit more speed. Socket 754 here.

----------

## user

i tried kvm-18 too, 

but i have the problem that kvm/qemu failed[stopped] short after running.

if i start with an invalid boot option i can see kvm/qemu vgabios error message of wrong boot device

My workaround is to start two instances of kvm/qemu.

First instance failed [stopped] and take 100% cpu load of one core.

Now starting second instance, i can enjoy kvm/qemu.

I using vanilla kernel 2.6.20 with kvm-18 modules on x86_64 VT system.

Any clue?

----------

## user

hi,

after getting more information with strace i found out that using no-tdf or no-rtc option solving my problem.

----------

## kimczuba

 *EricHsu wrote:*   

> Guys, I've got my winxp up and running on my gentoo! KVM + Qemu is awesome!

 

When installing windows xp you sometimes need to reboot. When doing so, kvm/qemu on my system stops with some dump to the console. In other words, it does not automatically reboot. I can start the os again and there seems to be no problems what so ever, but it would be nice if it could automatically reboot.

So my question is, can you (that is, any of you with succesfull installations) reboot your windows xp in kvm/qemu without problems?

I use kvm-18 on amd 64 and use the -no-acpi switch.

----------

## bk0

Qemu keeps crashing when using KVM on my machine. I have amd64 (Athlon X2 4200+), multilib Gentoo. With kernel 2.6.21 (included KVM modules) and KVM-17 version of qemu, whenever I try and run my VM (windows XP install CD) it keeps crashing shortly after startup.

```

~/apps/bin/qemu-system-x86_64 -hda ./xp-qcow2.img -cdrom ~/xpinstall.iso -boot d -m 256        

unhandled vm exit:  0x0

rax 0000000000000023 rbx 000000008086c777 rcx 000000000000d801 rdx 0000000040000000

rsi 00000000c0000000 rdi 000000008080d938 rsp 000000008080400d rbp 000000008080d8c5

r8  0000000000000000 r9  0000000000000000 r10 0000000000000000 r11 0000000000000000

r12 0000000000000000 r13 0000000000000000 r14 0000000000000000 r15 0000000000000000

rip 000000008080d877 rflags 00000086

cs 0008 (00000000/ffffffff p 1 dpl 0 db 1 s 1 type b l 0 g 0 avl 0)

ds 0023 (00000000/ffffffff p 1 dpl 3 db 1 s 1 type 3 l 0 g 1 avl 0)

es 0023 (00000000/ffffffff p 1 dpl 3 db 1 s 1 type 3 l 0 g 1 avl 0)

ss 0010 (00000000/ffffffff p 1 dpl 0 db 1 s 1 type 3 l 0 g 1 avl 0)

fs 0030 (ffdff000/00001fff p 1 dpl 0 db 1 s 1 type 3 l 0 g 1 avl 0)

gs 0000 (00000000/0000ffff p 1 dpl 0 db 0 s 1 type 3 l 0 g 0 avl 0)

tr 0028 (80042000/000020ab p 1 dpl 0 db 0 s 0 type 9 l 0 g 0 avl 0)

ldt 0000 (00000000/0000ffff p 0 dpl 0 db 0 s 0 type 0 l 0 g 0 avl 0)

gdt 8003f000/3ff

idt 8003f400/7ff

cr0 8001003d cr2 23 cr3 39000 cr4 0 cr8 e efer 0

Aborted

```

The same VM runs normally (though slow) in standard software-emulation QEmu as installed by portage. Any ideas on how to diagnose the problem?

EDIT: Upgrading to KVM-21 and using the external modules instead of the ones included in kernel 2.6.21 solved the crashing issue.

----------

## lex82

On the kvm wiki i found this: http://kvm.qumranet.com/kvmwiki/Status

It seems like that only 32 bit version of Windows can be run inside KVM/qemu... did you tried to emulate a 32 bit system insted of a 64 bit one?

----------

