个人工具

“UbuntuHelp:WindowsXPUnderQemuHowTo”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
(New page: {{From|https://help.ubuntu.com/community/WindowsXPUnderQemuHowTo}} {{Languages|php5}} === Running Windows Under Ubuntu 7.04 === [http://fabrice.bellard.free.fr/qemu/ QEmu] can run an OS i...)
 
第12行: 第12行:
 
<pre><nowiki>
 
<pre><nowiki>
 
grep -E '^flags.*(vmx|svm)' /proc/cpuinfo
 
grep -E '^flags.*(vmx|svm)' /proc/cpuinfo
</nowiki></code>
+
</nowiki></pre>
 
If there's any results, check out [[UbuntuHelp:KVM|Kernel Virtualization]], which is even faster than QEmu and KQEmu.  
 
If there's any results, check out [[UbuntuHelp:KVM|Kernel Virtualization]], which is even faster than QEmu and KQEmu.  
  
第22行: 第22行:
 
* Install the required packages  (see InstallingSoftware): <pre><nowiki>  
 
* Install the required packages  (see InstallingSoftware): <pre><nowiki>  
 
sudo apt-get install qemu kqemu-source module-assistant
 
sudo apt-get install qemu kqemu-source module-assistant
</nowiki></code>
+
</nowiki></pre>
  
 
* Build the kqemu module from Ubuntu's package: <pre><nowiki>
 
* Build the kqemu module from Ubuntu's package: <pre><nowiki>
第28行: 第28行:
 
sudo module-assistant build kqemu
 
sudo module-assistant build kqemu
 
sudo module-assistant install kqemu
 
sudo module-assistant install kqemu
</nowiki></code>
+
</nowiki></pre>
 
    
 
    
 
* Configure udev to create the /dev/kqemu device node upon loading the kqemu module:
 
* Configure udev to create the /dev/kqemu device node upon loading the kqemu module:
 
*** Create /etc/udev/rules.d/60-kqemu.rules with the following content: <pre><nowiki>
 
*** Create /etc/udev/rules.d/60-kqemu.rules with the following content: <pre><nowiki>
KERNEL=="kqemu", NAME="%k", MODE="0660", GROUP="kqemu"</nowiki></code>
+
KERNEL=="kqemu", NAME="%k", MODE="0660", GROUP="kqemu"</nowiki></pre>
 
*** Change the content of /etc/modprobe.d/kqemu to:<pre><nowiki>
 
*** Change the content of /etc/modprobe.d/kqemu to:<pre><nowiki>
options kqemu major=0</nowiki></code>
+
options kqemu major=0</nowiki></pre>
  
 
* Create a group "kqemu" and add all users who should be allowed to use QEMU with acceleration to this group:<pre><nowiki>
 
* Create a group "kqemu" and add all users who should be allowed to use QEMU with acceleration to this group:<pre><nowiki>
 
sudo addgroup --system kqemu
 
sudo addgroup --system kqemu
sudo adduser myUser kqemu</nowiki></code> Make sure to update your environment before proceeding to reflect the fact, that your user is now part of the kqemu group (for example by logging in and out).
+
sudo adduser myUser kqemu</nowiki></pre> Make sure to update your environment before proceeding to reflect the fact, that your user is now part of the kqemu group (for example by logging in and out).
  
 
* Load the kqemu module <pre><nowiki>
 
* Load the kqemu module <pre><nowiki>
sudo modprobe kqemu</nowiki></code>
+
sudo modprobe kqemu</nowiki></pre>
  
 
* If you want to load the kqemu module upon system start in the future, add "kqemu" to your /etc/modules file.
 
* If you want to load the kqemu module upon system start in the future, add "kqemu" to your /etc/modules file.
第47行: 第47行:
 
* Create a virtual drive for Windows <pre><nowiki>
 
* Create a virtual drive for Windows <pre><nowiki>
 
qemu-img create -f qcow windows.img 2G
 
qemu-img create -f qcow windows.img 2G
</nowiki></code>
+
</nowiki></pre>
  
 
This creates a two gigabyte virtual drive, stored as a single file called windows.img in the location where you ran the command. Any size above 1.5GB (the minimum to run Windows XP) is fine. The virtual drive will start out as a small file, and only fill its the size you specified when it reaches capacity due to the 'qcow' file format used.  
 
This creates a two gigabyte virtual drive, stored as a single file called windows.img in the location where you ran the command. Any size above 1.5GB (the minimum to run Windows XP) is fine. The virtual drive will start out as a small file, and only fill its the size you specified when it reaches capacity due to the 'qcow' file format used.  
第57行: 第57行:
 
* Install Windows XP. Put the CD in the drive and run: <pre><nowiki>
 
* Install Windows XP. Put the CD in the drive and run: <pre><nowiki>
 
qemu -localtime -cdrom /dev/cdrom -m 384 -boot d windows.img
 
qemu -localtime -cdrom /dev/cdrom -m 384 -boot d windows.img
</nowiki></code>
+
</nowiki></pre>
  
 
This starts QEmu using the time from Ubuntu, windows.img as the hard disk file, /dev/cdrom as the CD, 384 MB of memory (a good minimum for XP) and will boot from the CD.
 
This starts QEmu using the time from Ubuntu, windows.img as the hard disk file, /dev/cdrom as the CD, 384 MB of memory (a good minimum for XP) and will boot from the CD.
第63行: 第63行:
 
Alternatively, using a .iso image file: <pre><nowiki>
 
Alternatively, using a .iso image file: <pre><nowiki>
 
qemu -localtime -cdrom cdimagefile.iso -m 384 -boot d windows.img
 
qemu -localtime -cdrom cdimagefile.iso -m 384 -boot d windows.img
</nowiki></code>
+
</nowiki></pre>
  
 
'''Note to 64 bit users''': Use 'qemu-system-x86_64' instead of 'qemu'. Otherwise the "-kernel-kqemu" option will not work.
 
'''Note to 64 bit users''': Use 'qemu-system-x86_64' instead of 'qemu'. Otherwise the "-kernel-kqemu" option will not work.
第101行: 第101行:
  
  
</nowiki></code>
+
</nowiki></pre>
  
 
Pros
 
Pros
第145行: 第145行:
 
To set this up, start QEmu with the following command: <pre><nowiki>
 
To set this up, start QEmu with the following command: <pre><nowiki>
 
qemu -smb $HOME/qemu_share -m 384 -localtime windows.img
 
qemu -smb $HOME/qemu_share -m 384 -localtime windows.img
</nowiki></code>
+
</nowiki></pre>
  
 
Inside Windows, you can access the shared drive with the following command from a DOS prompt. For example, to map Windows drive 'e' to the share: <pre><nowiki>
 
Inside Windows, you can access the shared drive with the following command from a DOS prompt. For example, to map Windows drive 'e' to the share: <pre><nowiki>
 
net use e: \\10.0.2.2\qemu_share
 
net use e: \\10.0.2.2\qemu_share
</nowiki></code>
+
</nowiki></pre>
  
 
The IP address of Ubuntu will always be 10.0.2.2. If you have running servers on your Ubuntu box, they can also be accessed at this IP address (e.g. ftp:\\10.0.2.2)
 
The IP address of Ubuntu will always be 10.0.2.2. If you have running servers on your Ubuntu box, they can also be accessed at this IP address (e.g. ftp:\\10.0.2.2)
第161行: 第161行:
 
To mount the drive, create a directory '/media/qemu'. Then run: <pre><nowiki>
 
To mount the drive, create a directory '/media/qemu'. Then run: <pre><nowiki>
 
sudo mount -o loop,offset=32256 windows.img /media/qemu
 
sudo mount -o loop,offset=32256 windows.img /media/qemu
</nowiki></code>
+
</nowiki></pre>
  
 
==== Saving and Restoring the State of the VM ====
 
==== Saving and Restoring the State of the VM ====
第169行: 第169行:
 
To create an overlay image, use the qemu-image program. To create an image windows.ovl from windows.img, issue the following: <pre><nowiki>
 
To create an overlay image, use the qemu-image program. To create an image windows.ovl from windows.img, issue the following: <pre><nowiki>
 
qemu-img create -b windows.img -f qcow windows.ovl
 
qemu-img create -b windows.img -f qcow windows.ovl
</nowiki></code>
+
</nowiki></pre>
  
 
To run Windows, you would now use: <pre><nowiki>
 
To run Windows, you would now use: <pre><nowiki>
 
qemu windows.ovl -enable-audio -user-net -localtime -smb qemu_share
 
qemu windows.ovl -enable-audio -user-net -localtime -smb qemu_share
</nowiki></code>
+
</nowiki></pre>
  
 
If the winxp.ovl installation is ruined, you can delete it, and start QEmu using the winxp.img file. But you will lose changes made since the original install.
 
If the winxp.ovl installation is ruined, you can delete it, and start QEmu using the winxp.img file. But you will lose changes made since the original install.
第184行: 第184行:
 
To convert your raw 'windows.img' file to a qcow formatted 'windows.qcow', run: <pre><nowiki>
 
To convert your raw 'windows.img' file to a qcow formatted 'windows.qcow', run: <pre><nowiki>
 
qemu-img convert windows.img -O qcow windows.qcow
 
qemu-img convert windows.img -O qcow windows.qcow
</nowiki></code>
+
</nowiki></pre>
  
 
=== Troubleshooting ===
 
=== Troubleshooting ===
第190行: 第190行:
 
If you experience problems with mouse pointer hanging in bottom right corner, try before you start up qemu <pre><nowiki>
 
If you experience problems with mouse pointer hanging in bottom right corner, try before you start up qemu <pre><nowiki>
 
export SDL_VIDEO_X11_DGAMOUSE=0
 
export SDL_VIDEO_X11_DGAMOUSE=0
</nowiki></code>
+
</nowiki></pre>
  
 
=== External Links ===
 
=== External Links ===

2007年5月13日 (日) 12:41的版本

Running Windows Under Ubuntu 7.04

QEmu can run an OS inside another OS - for example, Windows under Linux. QEmu uses kqemu, an acceleration driver included in Ubuntu 7.04 Feisty Fawn to run Windows at usable speed.

Ubuntu 7.04 Feisty Fawn also includes a new version of rdesktop that can be used to start individual desktop apps from the VM on your normal desktop. See SeamlessVirtualization.

attachment:SeamlessVirtualizationWithThemingResized.png

Note: Most computers purchased since 2006 support VT or Pacifica, technologies that speed up virtualization considerably. To see if your system includes these technologies, run the following:

grep -E '^flags.*(vmx|svm)' /proc/cpuinfo

If there's any results, check out Kernel Virtualization, which is even faster than QEmu and KQEmu.

To install Ubuntu inside QEmu, please read UbuntuHelp:Installation/QemuEmulator.

Installing Windows in QEmu with Feisty 7.04

While the following guide uses Windows XP, older versions of Windows work fine, and may be preferred due to their increased speed.

  • Install the required packages (see InstallingSoftware):
     

sudo apt-get install qemu kqemu-source module-assistant

  • Build the kqemu module from Ubuntu's package:

sudo module-assistant prepare sudo module-assistant build kqemu sudo module-assistant install kqemu

  • Configure udev to create the /dev/kqemu device node upon loading the kqemu module:
      • Create /etc/udev/rules.d/60-kqemu.rules with the following content:
KERNEL=="kqemu", NAME="%k", MODE="0660", GROUP="kqemu"
      • Change the content of /etc/modprobe.d/kqemu to:
options kqemu major=0
  • Create a group "kqemu" and add all users who should be allowed to use QEMU with acceleration to this group:

sudo addgroup --system kqemu

sudo adduser myUser kqemu Make sure to update your environment before proceeding to reflect the fact, that your user is now part of the kqemu group (for example by logging in and out).
  • Load the kqemu module
sudo modprobe kqemu
  • If you want to load the kqemu module upon system start in the future, add "kqemu" to your /etc/modules file.
  • Create a virtual drive for Windows

qemu-img create -f qcow windows.img 2G

This creates a two gigabyte virtual drive, stored as a single file called windows.img in the location where you ran the command. Any size above 1.5GB (the minimum to run Windows XP) is fine. The virtual drive will start out as a small file, and only fill its the size you specified when it reaches capacity due to the 'qcow' file format used.

Note: If you want to install Windows XP Service Pack 2, 2 GB is not enough for the image size. Use at least 3 GB.

Note: If you use qcow images, you will not be able to mount the image within Ubuntu. You can omit '-f qcow' and create a mountable image, but this will mean that the size of the virtual drive will be fixed and larger. Instructions to convert a raw drive to a qcow drive appear at the end of this page.

  • Install Windows XP. Put the CD in the drive and run:

qemu -localtime -cdrom /dev/cdrom -m 384 -boot d windows.img

This starts QEmu using the time from Ubuntu, windows.img as the hard disk file, /dev/cdrom as the CD, 384 MB of memory (a good minimum for XP) and will boot from the CD.

Alternatively, using a .iso image file:
qemu -localtime -cdrom cdimagefile.iso -m 384 -boot d windows.img

Note to 64 bit users: Use 'qemu-system-x86_64' instead of 'qemu'. Otherwise the "-kernel-kqemu" option will not work.

Note for Windows 2000: Add the option '-win2k-hack'. Otherwise the install may fail with "Not enough disk space" even when that isn't the case.

QEmu will start, boot from the CD, and load the XP installer. The installer works like any other Windows install for the most part. However, on some systems the last part of the initial install, pictured, below, will stick around for a very long time. In this case, just reboot (restart QEmu), and the installer will proceed past this point.

attachment:windows+xp+in+qemu.png

After a few 'reboots' of QEmu you will be running Windows XP.

Clicking on the QEmu window will take control of the Windows cursor. To go back to Linux, press Ctrl + Alt.

You can also toggle fullscreen with Ctrl + Alt + F


Networking

QEmu provides two modes of networking. In both modes, a virtual network adapter is created inside Windows XP guest.

See QEmu network documentation

User mode networking

In user mode networking, QEmu manages network interface internally in the user mode emulator application. QEmu provides DHCP host which assigns a dynamic IP for the guest OS. TCP and UDP ports can be redirected from the host OS to the guest OS using QEmu command line parameters.

         QEMU VLAN      <------>  Firewall/DHCP server <-----> Host network
                           |          (10.0.2.2)
                           |
                           ---->  DNS server (10.0.2.3)
                           |     
                           ---->  SMB server (10.0.2.4)


Pros

  • Easy to set up

Cons

  • Only TCP and UDP connections are available by default. Ping command, for example, doesn't work inside the guest OS
  • Incoming connections must be configured beforehand

TAP network

In TAP networking, QEmu connects the guest OS ethernet to the host OS using TAP network bridge. Linux creates a virtual network interface (tap0) which appears in ifconfig listing as other network interfaces. Further, it is possible to bridge network traffic to the guest OS using normal Linux network bridging functionalities.

For examples, see following pages

Pros

  • Provides full emulated IP stack

Cons

  • Difficult to set up. The set-up is especially cumbersome if you try to run QEmu without root priviledges

Additional Options

Sharing Files With XP and Networking

It's not much use having an XP installation if you can't transfer files between Ubuntu and XP. Fortunately, QEMU sets up a virtual LAN and DHCP server for you. You can transfer files to and from XP just as if it was on a real LAN. You can also browse the net and download files and do all the network stuff you would do on a real networked XP box.

Sharing Files between the Host and VM

QEmu supports file sharing between the VM and host if you have Samba configured on the host system. The following assumes you have a share called 'qemu_share' in your home directory intended to transfer files between Ubuntu and Windows.

To set this up, start QEmu with the following command:
qemu -smb $HOME/qemu_share -m 384 -localtime windows.img
Inside Windows, you can access the shared drive with the following command from a DOS prompt. For example, to map Windows drive 'e' to the share:
net use e: \\10.0.2.2\qemu_share

The IP address of Ubuntu will always be 10.0.2.2. If you have running servers on your Ubuntu box, they can also be accessed at this IP address (e.g. ftp:\\10.0.2.2)

Mounting A Virtual Drive

You can also mount the QEmu virtual disk just like any other drive (if the drive was created in qcow format you'll need to convert it first, see below).

Make sure you are NOT running QEMU when you do this.

To mount the drive, create a directory '/media/qemu'. Then run:
sudo mount -o loop,offset=32256 windows.img /media/qemu

Saving and Restoring the State of the VM

You can quickly save and restore the state of your Windows System using QEmu's 'overlay images'. Once you have done your initial install, you can create an overlay image and run QEMU off this. The overlay image is very much smaller that the original image and will only contain changes made since the original install. If you trash your XP installation, you can simply delete the overlay image and create a new one from the original image.

To create an overlay image, use the qemu-image program. To create an image windows.ovl from windows.img, issue the following:
qemu-img create -b windows.img -f qcow windows.ovl
To run Windows, you would now use:
qemu windows.ovl -enable-audio -user-net -localtime -smb qemu_share

If the winxp.ovl installation is ruined, you can delete it, and start QEmu using the winxp.img file. But you will lose changes made since the original install.

QEmu also accepts commands from the shell while it is running. To do this, though, you need to press CTRL+ALT+2 with the QEmu window active. This brings up the QEmu Monitor. From here, you can swap CDs, send keypresses to the emulator, suspend to disk and so on. See the official documentation for full details. To exit the QEmu monitor press CTRL+ALT+1

Converting a raw drive to qcow format

To convert your raw 'windows.img' file to a qcow formatted 'windows.qcow', run:
qemu-img convert windows.img -O qcow windows.qcow

Troubleshooting

If you experience problems with mouse pointer hanging in bottom right corner, try before you start up qemu
export SDL_VIDEO_X11_DGAMOUSE=0

External Links

CategoryDocumentation CategoryCleanup