特殊:Badtitle/NS100:WindowsXPUnderQemuHowTo:修订间差异

来自Ubuntu中文
跳到导航跳到搜索
Oneleaf留言 | 贡献
无编辑摘要
Oneleaf留言 | 贡献
无编辑摘要
第20行: 第20行:
While the following guide uses Windows XP, older versions of Windows work fine, and may be preferred due to their increased speed.
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): <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></pre>
</nowiki></pre>


* Build the kqemu module from Ubuntu's package: <pre><nowiki>
* Build the kqemu module from Ubuntu's package:  
<pre><nowiki>
sudo module-assistant prepare
sudo module-assistant prepare
sudo module-assistant build kqemu
sudo module-assistant build kqemu
sudo module-assistant install kqemu
sudo module-assistant install kqemu
</nowiki></pre>
</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  
<pre><nowiki>
gksu gedit /etc/udev/rules.d/60-kqemu.rules </nowiki></pre> with the following content:  
<pre><nowiki>
KERNEL=="kqemu", NAME="%k", MODE="0660", GROUP="kqemu"</nowiki></pre>
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></pre>
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></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).
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></pre>
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:
<pre><nowiki>
gksu gedit /etc/modules </nowiki></pre>


* 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></pre>
</nowiki></pre>
第55行: 第66行:
'''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.
'''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: <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></pre>
</nowiki></pre>
第61行: 第73行:
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.


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></pre>
</nowiki></pre>
第93行: 第106行:


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




第143行: 第156行:
QEmu supports file sharing between the VM and host if you have [[UbuntuHelp:SettingUpSamba|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.
QEmu supports file sharing between the VM and host if you have [[UbuntuHelp:SettingUpSamba|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: <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></pre>
</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></pre>
</nowiki></pre>
第155行: 第170行:
==== Mounting A Virtual Drive ====
==== 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).
You can also mount the QEmu virtual disk just like any other drive. QCOW images cannot be mounted. 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.
Make sure you are '''NOT''' running QEMU when you do this.


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></pre>
</nowiki></pre>
第167行: 第183行:
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.  
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: <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></pre>
</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></pre>
</nowiki></pre>
第182行: 第200行:
==== Converting a raw drive to qcow format ====
==== Converting a raw drive to qcow format ====


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></pre>
</nowiki></pre>
第188行: 第207行:
=== Troubleshooting ===
=== Troubleshooting ===


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></pre>
</nowiki></pre>

2007年5月24日 (四) 14:14的版本

{{#ifexist: :WindowsXPUnderQemuHowTo/zh | | {{#ifexist: WindowsXPUnderQemuHowTo/zh | | {{#ifeq: {{#titleparts:WindowsXPUnderQemuHowTo|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:WindowsXPUnderQemuHowTo|1|-1|}} | zh | | }}

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.

WindowsXPUnderQemuHowTo?action=AttachFile&do=get&target=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
gksu gedit /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:
gksu gedit /etc/modules 
  • 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.

WindowsXPUnderQemuHowTo?action=AttachFile&do=get&target=windows%2Bxp%2Bin%2Bqemu.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. QCOW images cannot be mounted. 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