# KVM fails to boot Windows 7

## jcalvinowens

I'm trying to get Windows 7 (64-bit) to run under KVM. The installation was successful, and it even booted successfully off the hard drive to finish the installation, but when I attempt to boot now, I get the following error:

```

KVM: entry failed, hardware error 0x80000021

If you're running a guest on an Intel machine without unrestricted mode

support, the failure can be most likely due to the guest entering an invalid

state for Intel VT. For example, the guest maybe running in big real mode

which is not supported on less recent Intel processors.

EAX=00000010 EBX=00000080 ECX=00000000 EDX=00000080

ESI=0025da4a EDI=0007da4a EBP=00001f20 ESP=00000200

EIP=0000009b EFL=00000002 [-------] CPL=3 II=0 A20=1 SMM=0 HLT=0

ES =0020 00000200 0000ffff 00009300

CS =b000 002b0000 0000ffff 0000f300

SS =0020 00000200 0000ffff 0000f300

DS =0020 00000200 0000ffff 00009300

FS =0020 00000200 0000ffff 00009300

GS =0020 00000200 0000ffff 00009300

LDT=0000 00000000 0000ffff 00008200

TR =0000 00000000 0000ffff 00008b00

GDT=     002b0000 00000027

IDT=     00000000 000003ff

CR0=00000010 CR2=00000000 CR3=00000000 CR4=00000000

DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 

DR6=00000000ffff0ff0 DR7=0000000000000400

EFER=0000000000000000

Code=02 00 00 ea 91 00 00 00 18 00 0f 20 c0 66 83 e0 fe 0f 22 c0 <66> 31 c0 8e d8 8e c0 8e d0 66 bc 00 04 00 00 8e e0 8e e8 ea 00 00 00 20 00 00 00 20 4a da

```

The dissassembly of the code is:

```

calvinow@Mozart ~ $ ndisasm -b 32 dump.bin

00000000  0200              add al,[eax]

00000002  00EA              add dl,ch

00000004  91                xchg eax,ecx

00000005  0000              add [eax],al

00000007  0018              add [eax],bl

00000009  000F              add [edi],cl

0000000B  20C0              and al,al

0000000D  6683E0FE          and ax,byte 0xfe

00000011  0F22C0            mov cr0,eax

00000014  <6631C0>          xor ax,ax

00000017  8ED8              mov ds,eax

00000019  8EC0              mov es,eax

0000001B  8ED0              mov ss,eax

0000001D  66BC0004          mov sp,0x400

00000021  0000              add [eax],al

00000023  8EE0              mov fs,eax

00000025  8EE8              mov gs,eax

00000027  EA000000200000    jmp dword 0x0:0x20000000

0000002E  0020              add [eax],ah

00000030  4A                dec edx

00000031  DA                db 0xda

```

So it would seem that Windows is trying to enable protected mode (apparently we're 32-bit at this point), and for some reason KVM doesn't like it? That doesn't make a great deal of sense.

Is it the case that qemu-kvm doesn't support 64-bit guests? That would be ridiculous, so I'm assuming that isn't true... I've tried passing several different -machine and -cpu options to qemu-kvm, and none seem to make it happy.

Anybody see what I'm missing?

----------

## Hu

KVM supports 64-bit guests, at least for some hardware.  What is the output of emerge --info ; cat /proc/cpuinfo?

----------

## cach0rr0

I'd also be curious to see what parameters you're using to start this machine 

I have a Win7Ultimate x64 guest that, while I rarely use it, it does work - a bit sluggish, but it works, so I can confirm that at least. The only real hiccup I hit was having to initially boot with IDE HDD emulation, install the virtio drivers for the HDD, add a disk, etc etc - PITA but it eventually worked.

----------

## jcalvinowens

 *Quote:*   

> KVM supports 64-bit guests, at least for some hardware. What is the output of emerge --info ; cat /proc/cpuinfo?

 

```

calvinow@Mozart ~ $ emerge --info

Portage 2.1.10.49 (default/linux/amd64/10.0, gcc-4.5.3, glibc-2.14.1-r3, 3.4.0-rc7-intel x86_64)

=================================================================

System uname: Linux-3.4.0-rc7-intel-x86_64-Genuine_Intel-R-_CPU_U7300_@_1.30GHz-with-gentoo-2.0.3

Timestamp of tree: Thu, 10 May 2012 02:15:01 +0000

distcc 3.1 x86_64-pc-linux-gnu [disabled]

app-shells/bash:          4.2_p20

dev-java/java-config:     2.1.11-r3

dev-lang/python:          2.7.2-r3, 3.2.2

dev-util/cmake:           2.8.7-r5

dev-util/pkgconfig:       0.26

sys-apps/baselayout:      2.0.3

sys-apps/openrc:          0.9.8.4

sys-apps/sandbox:         2.5

sys-devel/autoconf:       2.13, 2.68

sys-devel/automake:       1.11.1

sys-devel/binutils:       2.21.1-r1

sys-devel/gcc:            4.5.3-r2

sys-devel/gcc-config:     1.5-r2

sys-devel/libtool:        2.4-r1

sys-devel/make:           3.82-r1

sys-kernel/linux-headers: 3.1 (virtual/os-headers)

sys-libs/glibc:           2.14.1-r3

Repositories: gentoo

ACCEPT_KEYWORDS="amd64"

ACCEPT_LICENSE="* -@EULA"

CBUILD="x86_64-pc-linux-gnu"

CFLAGS="-O2 -march=core2 -fomit-frame-pointer -pipe"

CHOST="x86_64-pc-linux-gnu"

CONFIG_PROTECT="/etc /usr/share/config /usr/share/gnupg/qualified.txt"

CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"

CXXFLAGS="-O2 -march=core2 -fomit-frame-pointer -pipe"

DISTDIR="/usr/portage/distfiles"

FEATURES="assume-digests binpkg-logs distlocks ebuild-locks fixlafiles news parallel-fetch protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch"

FFLAGS=""

GENTOO_MIRRORS="ftp://ftp.ussg.iu.edu/pub/linux/gentoo"

LDFLAGS="-Wl,-O1 -Wl,--as-needed"

LINGUAS="en_us"

MAKEOPTS="-j2"

PKGDIR="/usr/portage/packages"

PORTAGE_CONFIGROOT="/"

PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"

PORTAGE_TMPDIR="/var/tmp"

PORTDIR="/usr/portage"

PORTDIR_OVERLAY=""

SYNC="rsync://rsync25.us.gentoo.org/gentoo-portage"

USE="X acl alsa amd64 berkdb bzip2 cdr cli consolekit cracklib crypt cups cxx dbus declarative dri dvd fortran gdbm gpm gtk gudev iconv icu ipv6 java kde libkms mmx mng modules mudflap multilib ncurses nls nptl ogg opengl openmp pam pcre png policykit pppd python qt3support qt4 readline semantic-desktop session sql sse sse2 ssl svg tcpd unicode vorbis webkit xorg zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LINGUAS="en_us" PHP_TARGETS="php5-3" RUBY_TARGETS="ruby18" USERLAND="GNU" VIDEO_CARDS="intel" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"

Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LANG, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, USE_PYTHON

calvinow@Mozart ~ $ cat /proc/cpuinfo

processor       : 0

vendor_id       : GenuineIntel

cpu family      : 6

model           : 23

model name      : Genuine Intel(R) CPU           U7300  @ 1.30GHz

stepping        : 10

microcode       : 0xa07

cpu MHz         : 1299.996

cache size      : 3072 KB

physical id     : 0

siblings        : 2

core id         : 0

cpu cores       : 2

apicid          : 0

initial apicid  : 0

fpu             : yes

fpu_exception   : yes

cpuid level     : 13

wp              : yes

flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good nopl aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 xsave lahf_lm dts tpr_shadow vnmi flexpriority

bogomips        : 2599.99

clflush size    : 64

cache_alignment : 64

address sizes   : 36 bits physical, 48 bits virtual

power management:

processor       : 1

<snip>

calvinow@Mozart ~ $ cat /proc/version

Linux version 3.4.0-rc7-intel (calvinow@Mozart) (gcc version 4.5.3 (Gentoo 4.5.3-r2 p1.2, pie-0.4.7) ) #11 SMP PREEMPT Sat May 12 22:17:33 CDT 2012

```

 *Quote:*   

> I'd also be curious to see what parameters you're using to start this machine

 

I've just been running "qemu-kvm -hda win7.img -m 2048". I've tried different "-cpu" and "-machine" options to no avail. 

I found a suggestion on linux-kvm.org to do a "system recovery" with the windows installation CD. I'm trying that right now.

----------

## jcalvinowens

Well, no luck.

I've tried reinstalling a couple times with different "-cpu" options, but it seems to make no difference. The recovery mode on the Windows installation CD says "The version of Windows installed is unsupported", and refuses to do anything. I used ms-sys to write new bootsectors, but that also made no difference. 

I'm starting to think this is a problem with the way my hardware interacts with KVM. I used to run WIn7-64bit in VirtualBox on this same machine, so I know its capable of doing it. I just wanted to use the in-tree solution instead, plus I don't want to use modules in my kernels.

I'm going to try this on another machine and see if it works. Maybe it's a bug in KVM?

----------

## d2_racing

Hi, can you post your actual command(qemu-kvm) plz  :Razz: 

----------

## jcalvinowens

I tried it on the desktop, and it works: Windows 7 64-bit using the same installation CD. (My desktop is an AMD 8-core Bulldozer, also running Gentoo; the laptop I'm having the issues on is a Core2 duo).

The command I'm running is:

```

qemu-kvm -cpu phenom -smp 4 -m 4096 -hda Win7.img -cdrom /dev/sr0 -boot d

```

(substituting "-cpu core2duo" on the laptop. The image is "raw", created with qemu-img.)

I would believe the error message's suggestion about the CPU being too old to support VT-d for some weird mode Windows is going into, but from the assembly it looks like it's just entering 32-bit protected mode without paging (0xfe in cr0), which seems completely normal for an OS during its boot process... Plus, I used to run Windows 7 64-bit in virtualbox on this same machine.

----------

## johndoe31415

Hi jcalvinowens,

I've run exactly into the same problem as you have also while trying to run Windows7. I'm using qemu-kvm-1.0.1 and my CPU is a Intel Code Quad Q9550:

```

processor   : 3

vendor_id   : GenuineIntel

cpu family   : 6

model      : 23

model name   : Intel(R) Core(TM)2 Quad CPU    Q9550  @ 2.83GHz

stepping   : 10

cpu MHz      : 2003.000

cache size   : 6144 KB

physical id   : 0

siblings   : 4

core id      : 3

cpu cores   : 4

apicid      : 3

initial apicid   : 3

fpu      : yes

fpu_exception   : yes

cpuid level   : 13

wp      : yes

flags      : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good nopl aperfmperf pni dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm sse4_1 xsave lahf_lm dts tpr_shadow vnmi flexpriority

bogomips   : 5680.71

clflush size   : 64

cache_alignment   : 64

address sizes   : 36 bits physical, 48 bits virtual

power management:

```

The error message I'm getting is:

```

KVM: entry failed, hardware error 0x80000021

If you're running a guest on an Intel machine without unrestricted mode

support, the failure can be most likely due to the guest entering an invalid

state for Intel VT. For example, the guest maybe running in big real mode

which is not supported on less recent Intel processors.

EAX=00000010 EBX=00000080 ECX=00000000 EDX=00000080

ESI=0025da4a EDI=0007da4a EBP=00001f20 ESP=00000200

EIP=0000009b EFL=00000002 [-------] CPL=3 II=0 A20=1 SMM=0 HLT=0

ES =0020 00000200 0000ffff 00009300

CS =b000 002b0000 0000ffff 0000f300

SS =0020 00000200 0000ffff 0000f300

DS =0020 00000200 0000ffff 00009300

FS =0020 00000200 0000ffff 00009300

GS =0020 00000200 0000ffff 00009300

LDT=0000 00000000 0000ffff 00008200

TR =0000 00000000 0000ffff 00008b00

GDT=     002b0000 00000027

IDT=     00000000 000003ff

CR0=00000010 CR2=00000000 CR3=00000000 CR4=00000000

DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 

DR6=00000000ffff0ff0 DR7=0000000000000400

EFER=0000000000000000

Code=02 00 00 ea 91 00 00 00 18 00 0f 20 c0 66 83 e0 fe 0f 22 c0 <66> 31 c0 8e d8 8e c0 8e d0 66 bc 00 04 00 00 8e e0 8e e8 ea 00 00 00 20 00 00 00 20 4a da

```

which leads to

```

   0:   02 00                   add    (%eax),%al

   2:   00 ea                   add    %ch,%dl

   4:   91                      xchg   %eax,%ecx

   5:   00 00                   add    %al,(%eax)

   7:   00 18                   add    %bl,(%eax)

   9:   00 0f                   add    %cl,(%edi)

   b:   20 c0                   and    %al,%al

   d:   66 83 e0 fe             and    $0xfffffffe,%ax

  11:   0f 22 c0                mov    %eax,%cr0

  14:   66 31 c0                xor    %eax,%eax

  17:   8e d8                   mov    %ax,%ds

  19:   8e c0                   mov    %ax,%es

  1b:   8e d0                   mov    %ax,%ss

  1d:   66 bc 00 04 00 00       mov    $0x400,%esp

  23:   8e e0                   mov    %ax,%fs

  25:   8e e8                   mov    %ax,%gs

  27:   ea 00 00 00 20          ljmp   $0x2000,$0x0

```

It bails at 0x14, and that really looks like we're screwed. What the instruction before does is setting the bit 0 (value 1) of %cr0 to 0. This is the PE bit (protection enable) and it tells you if the system is running in real or protected mode. From the registers (ESI=0025da4a) it looks like the system was in protected more (PE=1) before execution of the mov %eax, %cr0 (because %esi > 0xffff). The move then tries to switch back to real mode (possibly in an attempt to enter big real mode briefly before firing up the operating system properly in protected mode).

So it really may be that our CPUs are too old and Intel-VT at that time did not support switching back to real mode yet :-( I'll try on my laptop later today (Intel I5), which should definitely support it and see if it works there. If so, we're screwed and need to buy new PCs. Damnit.

HTH, Best regards,

Joe

----------

## johndoe31415

OK, I'm now pretty certain that we're screwed and cannot use kvm to emulate Windows 7. Here's the timelime of what I've done to come to this conclusion:

1. First I was looking at my BIOS and found it curious that there was no mention of VT. Looked at the net, found an update. Updated the BIOS -- aha -- now there's a VT option. Enabled by default. Tried it again, same error.

2. Then I copied the VM image onto my laptop:

```

processor   : 0

vendor_id   : GenuineIntel

cpu family   : 6

model      : 42

model name   : Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz

stepping   : 7

microcode   : 0x23

cpu MHz      : 800.000

cache size   : 3072 KB

physical id   : 0

siblings   : 4

core id      : 0

cpu cores   : 2

apicid      : 0

initial apicid   : 0

fpu      : yes

fpu_exception   : yes

cpuid level   : 13

wp      : yes

flags      : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid

bogomips   : 4989.03

clflush size   : 64

cache_alignment   : 64

address sizes   : 36 bits physical, 48 bits virtual

power management:

```

It's running xubuntu which comes with qemu-kvm 0.14.1. Image worked like a charm on there.

3. Recompiled a new kernel on my desktop (3.3.7, was 3.1.5 before). Same issue.

4. To confirm it wasn't qemu, I downloaded the qemu-kvm-0.14.1 package myself and compiled on my desktop machine. Same error :-(

5. At this point I'm VERY certain that my desktop processor misses the "Unrestricted Guest" feature that is apparently needed to boot Windows 7 (PS: fuck you, Microsoft). To clarify, I have posted http://software.intel.com/en-us/forums/showthread.php?t=105687 for clarification.

Summing it up:

Error: Intel Core 2 Q9550, Yorkfield 45nm

Works: Intel Core i5 2520-M, Sandy Bridge 32nm

----------

## johndoe31415

Since the qemu-kvm people probably are most knowledgeable about this issue, I've also posted at the kvm-devel mailing list: http://thread.gmane.org/gmane.comp.emulators.kvm.devel/91786 Maybe there's a way out (I really hope so).

----------

## Mad Merlin

 *jcalvinowens wrote:*   

> I tried it on the desktop, and it works: Windows 7 64-bit using the same installation CD. (My desktop is an AMD 8-core Bulldozer, also running Gentoo; the laptop I'm having the issues on is a Core2 duo).

 

Core 2 Duo, or Core Duo? There's a BIG difference, as Core Duo is 32-bit only, Core 2 Duo is 64-bit.

----------

## ryao

Have any of you tried `-cpu host`?

----------

## johndoe31415

Yup, that's in my cmdline:

```

bin/qemu-system-x86_64 -cpu host -enable-kvm -net nic -net

user,smb=Share,restrict=on -drive

media=disk,file=Windows7_x32.qcow2,if=virtio -m 2048 -smp 1 -nographic

```

And from the /proc/cpuinfo of jcalvinowens it's clear that he's running a Core 2 Duo (SU7300).

----------

## johndoe31415

The problem was solved by Avi Kivity on the qemu-kvm mailing list. There were some kernel bugfixes that he did and the resulting kernel commit cf3d9372065470403e0780599ca612553211a10b on

```

git://git.kernel.org/pub/scm/virt/kvm/kvm.git big-real-mode

```

Works for me perfectly! Awesome :-)

----------

## VictorLazlo61

I am using kvm-qemu 1.0 with a core i5; I got windows 7 to work almost straight away, with some messing with drivers for the 'hard disks'; it required the latest from redhat virtio.

Glad you got some help from Avi and the guys, they just seem to have no time for most problems.

I am using 7 x64 embedded actually, but I would be grateful for any experience you have of using audio on a virtual 7 x64 through your i5 setup.

We actually have DQ67OW boards from intel, and I am not at all sure that the hda support works with 64 bit; messages range from hardware not detected to drivers missing or corrupted(Error code 39 in microsoft money). Incidentally, for what it's worth, we use a 2.38.8 host kernel. Host sound works perfectly.

----------

## ronstudio

 *johndoe31415 wrote:*   

> The problem was solved by Avi Kivity on the qemu-kvm mailing list. There were some kernel bugfixes that he did and the resulting kernel commit cf3d9372065470403e0780599ca612553211a10b on
> 
> ```
> 
> git://git.kernel.org/pub/scm/virt/kvm/kvm.git big-real-mode
> ...

 

Hi~ I have recently running into the same problem with my C2D Q6600 with exactly the same error message during the system boot up. I have read the post which Avi mentioned there would be a patch on this. May I ask if this means a newer version of kvm in Gentoo? As the stable version which I used still having this problem.

Could anyone share with me the instruction that I can get my Q6600 to boot successfully into Win7?

Sorry if the qemu-kvm mailing list mentioned it already, as I am very new to this kvm and may not able to pick it up even it had been mentioned.    :Embarassed: 

----------

