个人工具

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

来自Ubuntu中文

跳转至: 导航, 搜索
第2行: 第2行:
 
{{Languages|UbuntuHelp:WindowsXPUnderQemuHowTo}}
 
{{Languages|UbuntuHelp:WindowsXPUnderQemuHowTo}}
 
Consider if you really need to run the Windows program: in most cases, its functionality is provided by a free Linux program, see SoftwareEquivalents.
 
Consider if you really need to run the Windows program: in most cases, its functionality is provided by a free Linux program, see SoftwareEquivalents.
 
 
Consider also to use [[UbuntuHelp:Wine]] instead of Qemu, if you need to run a single Windows programs.
 
Consider also to use [[UbuntuHelp:Wine]] instead of Qemu, if you need to run a single Windows programs.
 
 
Most of the stuff in this page is not specific to install Windows XP under Qemu, but can be used to install also free operating systems.
 
Most of the stuff in this page is not specific to install Windows XP under Qemu, but can be used to install also free operating systems.
 
 
See also [[UbuntuHelp:Installation/QemuEmulator]].
 
See also [[UbuntuHelp:Installation/QemuEmulator]].
 
 
 
=== Running Windows Under Ubuntu 7.04/7.10 ===
 
=== Running Windows Under Ubuntu 7.04/7.10 ===
 
 
[http://fabrice.bellard.free.fr/qemu/ 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.
 
[http://fabrice.bellard.free.fr/qemu/ 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. This also works in Ubuntu 7.10 Gusty Gibbon.
 
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. This also works in Ubuntu 7.10 Gusty Gibbon.
 
 
https://help.ubuntu.com/community/WindowsXPUnderQemuHowTo?action=AttachFile&do=get&target=SeamlessVirtualizationWithThemingResized.png
 
https://help.ubuntu.com/community/WindowsXPUnderQemuHowTo?action=AttachFile&do=get&target=SeamlessVirtualizationWithThemingResized.png
 
 
<u>Note</u>: Most computers purchased since 2006 support VT or Pacifica, technologies that provide hardware support for virtualization. To see if your system includes these technologies, run the following:
 
<u>Note</u>: Most computers purchased since 2006 support VT or Pacifica, technologies that provide hardware support for virtualization. To see if your system includes these technologies, run the following:
 
<pre><nowiki>
 
<pre><nowiki>
第23行: 第14行:
 
</nowiki></pre>
 
</nowiki></pre>
 
If there are any results, then [[UbuntuHelp:KVM|Kernel Virtualization]] is another possibility for virtualizing other operating systems.
 
If there are any results, then [[UbuntuHelp:KVM|Kernel Virtualization]] is another possibility for virtualizing other operating systems.
 
 
<u>Note</u>: Even if you get no output from the above command, your computer may actually support virtualization in hardware. Some machines are delivered with a BIOS option switching off hardware virtualization. Other machines require updating to the latest BIOS for it to work correctly.
 
<u>Note</u>: Even if you get no output from the above command, your computer may actually support virtualization in hardware. Some machines are delivered with a BIOS option switching off hardware virtualization. Other machines require updating to the latest BIOS for it to work correctly.
 
 
To install ''Ubuntu'' inside QEmu, please read [[UbuntuHelp:Installation/QemuEmulator]].  
 
To install ''Ubuntu'' inside QEmu, please read [[UbuntuHelp:Installation/QemuEmulator]].  
 
 
=== Installing Windows in QEmu with Feisty 7.04 and Gutsy 7.10 ===
 
=== Installing Windows in QEmu with Feisty 7.04 and Gutsy 7.10 ===
 
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.
 
+
# First you need to  install qemu kqemu-source and module assistant from the Universe Repository. (In Gutsy(7.10),Use the synaptic package manager, search for kqemu and install kqemu-source. Module Assistant is not needed.)
* First you need to  install qemu kqemu-source and module assistant from the Universe Repository. (In Gutsy(7.10),Use the synaptic package manager, search for kqemu and install kqemu-source. Module Assistant is not needed.)
+
2. Next you need to build the kqemu module from Ubuntu's package
* Next you need to build the kqemu module from Ubuntu's package
+
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo module-assistant prepare
 
sudo module-assistant prepare
 
sudo module-assistant auto-install kqemu
 
sudo module-assistant auto-install kqemu
 
</nowiki></pre>
 
</nowiki></pre>
 
+
3. Next you need to configure udev to create the /dev/kqemu device node upon loading the kqemu module
* Next you need to configure udev to create the /dev/kqemu device node upon loading the kqemu module
+
* Create /etc/udev/rules.d/60-kqemu.rules  
 
+
**** Create /etc/udev/rules.d/60-kqemu.rules  
+
 
<pre><nowiki>
 
<pre><nowiki>
 
gksu gedit /etc/udev/rules.d/60-kqemu.rules   
 
gksu gedit /etc/udev/rules.d/60-kqemu.rules   
第48行: 第33行:
 
KERNEL=="kqemu", NAME="%k", GROUP="kqemu", MODE="0660"   
 
KERNEL=="kqemu", NAME="%k", GROUP="kqemu", MODE="0660"   
 
</nowiki></pre>
 
</nowiki></pre>
* Change the content of /etc/modprobe.d/kqemu to
+
4. Change the content of /etc/modprobe.d/kqemu to
 
<pre><nowiki>
 
<pre><nowiki>
 
options kqemu major=0
 
options kqemu major=0
 
</nowiki></pre>
 
</nowiki></pre>
 
+
5. Create a group "kqemu" and add all users who should be allowed to use QEMU with acceleration to this group
* Create a group "kqemu" and add all users who should be allowed to use QEMU with acceleration to this group
+
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo addgroup --system kqemu
 
sudo addgroup --system kqemu
 
sudo adduser $USER kqemu  
 
sudo adduser $USER kqemu  
 
</nowiki></pre>  
 
</nowiki></pre>  
**** Make sure to update your environment before proceeding to reflect the fact, that your user is now part of the      
+
* 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).
 
kqemu group (for example by logging in and out).
 
+
6. Force udev to reload its config files
* Force udev to reload its config files
+
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo /etc/init.d/udev reload
 
sudo /etc/init.d/udev reload
 
</nowiki></pre>
 
</nowiki></pre>
 
+
7. Load the kqemu module  
* Load the kqemu module  
+
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo update-modules
 
sudo update-modules
 
sudo modprobe kqemu
 
sudo modprobe kqemu
 
</nowiki></pre>
 
</nowiki></pre>
 
+
8. Check that the permissions are right  
* Check that the permissions are right  
+
 
<pre><nowiki>
 
<pre><nowiki>
 
$ ls -l /dev/kqemu
 
$ ls -l /dev/kqemu
 
crw-rw---- 1 root kqemu 10, 62 2007-07-22 15:36 /dev/kqemu
 
crw-rw---- 1 root kqemu 10, 62 2007-07-22 15:36 /dev/kqemu
 
</nowiki></pre>  
 
</nowiki></pre>  
**** If the permissions are wrong, it is probably because your udev rule wasn't read properly. Try re-loading the          
+
* If the permissions are wrong, it is probably because your udev rule wasn't read properly. Try re-loading the    
 
module
 
module
 
<pre><nowiki>
 
<pre><nowiki>
第85行: 第66行:
 
and see if that clears the problem. If not, add <code><nowiki>OWNER="youruser"</nowiki></code> to the end of the udev rule and try   
 
and see if that clears the problem. If not, add <code><nowiki>OWNER="youruser"</nowiki></code> to the end of the udev rule and try   
 
again
 
again
 
+
9. 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>
 
<pre><nowiki>
 
gksu gedit /etc/modules  
 
gksu gedit /etc/modules  
 
</nowiki></pre>
 
</nowiki></pre>
 
+
10. Create a virtual drive for Windows  
* Create a virtual drive for Windows  
+
 
<pre><nowiki>
 
<pre><nowiki>
 
qemu-img create -f qcow windows.img 2G
 
qemu-img create -f qcow windows.img 2G
 
</nowiki></pre>
 
</nowiki></pre>
 
+
* This creates a two gigabyte virtual drive, stored as a single file called windows.img in the location where   
**** 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
 
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   
 
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.  
 
qcow file format used.  
 
+
* '''Note''': If you want to install Windows XP Service Pack 2 + Updates, 2 GB is not enough for the image   
**** '''Note''': If you want to install Windows XP Service Pack 2 + Updates, 2 GB is not enough for the image   
+
 
size. Use at least 3-4 GB.
 
size. Use at least 3-4 GB.
 
+
* '''Note''': Consider using as much disk space as you can afford. Resizing NTFS partitions is a pain in the   
**** '''Note''': Consider using as much disk space as you can afford. Resizing NTFS partitions is a pain in the   
+
 
ass, but hard disk space is cheap.
 
ass, but hard disk space is cheap.
 
+
* '''Note''': If you use qcow images, you will not be able to mount the image within Ubuntu. You can omit '-f   
**** '''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   
 
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.
 
larger. Instructions to convert a raw drive to a qcow drive appear at the end of this page.
 
+
11. Install Windows XP. Put the CD in the drive and run:  
* Install Windows XP. Put the CD in the drive and run:  
+
 
<pre><nowiki>
 
<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>
 
+
12. 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.
+
13. Alternatively, you can use a .iso image file  
 
+
* Alternatively, you can use a .iso image file  
+
 
<pre><nowiki>
 
<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>
 
+
14. If you're having trouble creating the Windows partition during Windows installation, check that you have read and write access to the disk image. Use this command to set the file permissions for the windows.img file so that all users in the kqemu group can access the virtual disk  
* If you're having trouble creating the Windows partition during Windows installation, check that you have read and write access to the disk image. Use this command to set the file permissions for the windows.img file so that all users in the kqemu group can access the virtual disk  
+
 
<pre><nowiki>
 
<pre><nowiki>
 
chmod 660 windows.img
 
chmod 660 windows.img
 
sudo chown $USER:kqemu windows.img
 
sudo chown $USER:kqemu windows.img
 
</nowiki></pre>
 
</nowiki></pre>
 
+
* '''Note to 64 bit users''': Use 'qemu-system-x86_64' instead of 'qemu'. Otherwise the "-kernel-kqemu" option
**** '''Note to 64 bit users''': Use 'qemu-system-x86_64' instead of 'qemu'. Otherwise the "-kernel-kqemu" option    
+
 
will not work.
 
will not work.
 
+
* '''Note for Windows 2000''':  Add the option '-win2k-hack'. Otherwise the install may fail with "Not enough
**** '''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.
 
disk space" even when that isn't the case.
 
+
15. 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.
* 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.
+
 
+
 
https://help.ubuntu.com/community/WindowsXPUnderQemuHowTo?action=AttachFile&do=get&target=windows%2Bxp%2Bin%2Bqemu.png
 
https://help.ubuntu.com/community/WindowsXPUnderQemuHowTo?action=AttachFile&do=get&target=windows%2Bxp%2Bin%2Bqemu.png
 
+
16. After a few 'reboots' of QEmu you will be running Windows XP.
* After a few 'reboots' of QEmu you will be running Windows XP.
+
17. Clicking on the QEmu window will take control of the Windows cursor. To go back to Linux, press Ctrl + Alt and to toggle fullscreen press Ctrl + Alt + F
 
+
* Clicking on the QEmu window will take control of the Windows cursor. To go back to Linux, press Ctrl + Alt and to toggle fullscreen press Ctrl + Alt + F
+
 
+
 
+
 
=== Networking ===
 
=== Networking ===
 
 
QEmu provides two modes of networking. In both modes, a virtual network adapter is created inside Windows XP guest.  
 
QEmu provides two modes of networking. In both modes, a virtual network adapter is created inside Windows XP guest.  
 
 
==== User mode networking ====
 
==== 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.
 
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.
 
 
<pre><nowiki>
 
<pre><nowiki>
 
QEMU VLAN      <------>  Firewall/DHCP server <-----> Host network
 
QEMU VLAN      <------>  Firewall/DHCP server <-----> Host network
第159行: 第118行:
 
|     
 
|     
 
---->  SMB server (10.0.2.4)
 
---->  SMB server (10.0.2.4)
 
 
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Pros
 
Pros
 
 
* Easy to set up
 
* Easy to set up
 
 
Cons
 
Cons
 
 
* Only TCP and UDP connections are available by default. Ping command, for example, doesn't work inside the guest OS
 
* 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
 
* Incoming connections must be configured beforehand
 
 
==== TAP network ====
 
==== 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.
 
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
 
For examples, see following pages
 
 
* http://www.ubuntuforums.org/showthread.php?t=179472
 
* http://www.ubuntuforums.org/showthread.php?t=179472
 
 
* http://compsoc.dur.ac.uk/~djw/qemu.html
 
* http://compsoc.dur.ac.uk/~djw/qemu.html
 
 
* http://bbs.archlinux.org/viewtopic.php?id=27298
 
* http://bbs.archlinux.org/viewtopic.php?id=27298
 
 
Pros
 
Pros
 
 
* Provides full emulated IP stack
 
* Provides full emulated IP stack
 
 
Cons  
 
Cons  
 
 
* Difficult to set up. The set-up is especially cumbersome if you try to run QEmu without root priviledges
 
* Difficult to set up. The set-up is especially cumbersome if you try to run QEmu without root priviledges
 
 
==== VDE and Dnsmasq ====
 
==== VDE and Dnsmasq ====
 
 
This is an alternative to TAP networking. Most of this is from the page [https://help.ubuntu.com/community/KVM#head-db5235851cc1b9c712f99a074f02c91e8590c880-2 KVM - Advanced Networking]  and http://compsoc.dur.ac.uk/~djw/qemu.html.
 
This is an alternative to TAP networking. Most of this is from the page [https://help.ubuntu.com/community/KVM#head-db5235851cc1b9c712f99a074f02c91e8590c880-2 KVM - Advanced Networking]  and http://compsoc.dur.ac.uk/~djw/qemu.html.
 
 
Caution: The following package, "dnsmasq" provides dns, tftp and dhcpd services.  An LTSP standalone server would be affected because dnsmasq would interfere with the dhcpd and tftp services.  
 
Caution: The following package, "dnsmasq" provides dns, tftp and dhcpd services.  An LTSP standalone server would be affected because dnsmasq would interfere with the dhcpd and tftp services.  
 
 
* Install the packages vde dnsmasq:
 
* Install the packages vde dnsmasq:
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo apt-get install vde dnsmasq
 
sudo apt-get install vde dnsmasq
 
</nowiki></pre>
 
</nowiki></pre>
 
 
* In the file /etc/sysctl uncomment the following line to allow IP forwarding:
 
* In the file /etc/sysctl uncomment the following line to allow IP forwarding:
 
<pre><nowiki>
 
<pre><nowiki>
第209行: 第146行:
 
</nowiki></pre>
 
</nowiki></pre>
 
* In the file /etc/modules, add a new line with "tun", to make that module load on boot.
 
* In the file /etc/modules, add a new line with "tun", to make that module load on boot.
 
 
* Add the new network interface. Edit the file /etc/network/interfaces and paste this:
 
* Add the new network interface. Edit the file /etc/network/interfaces and paste this:
 
<pre><nowiki>
 
<pre><nowiki>
第224行: 第160行:
 
</nowiki></pre>
 
</nowiki></pre>
 
Temporary vdeq control sockets are created in /tmp and the vde_switch socket in /var/run/vde.ctl/
 
Temporary vdeq control sockets are created in /tmp and the vde_switch socket in /var/run/vde.ctl/
 
 
* Configure DNSmasq. Edit the file /etc/dnsmasq.conf and change the following options:
 
* Configure DNSmasq. Edit the file /etc/dnsmasq.conf and change the following options:
 
<pre><nowiki>
 
<pre><nowiki>
第232行: 第167行:
 
dhcp-range=10.111.111.1,10.111.111.253,255.255.255.0,10.111.111.255,8h
 
dhcp-range=10.111.111.1,10.111.111.253,255.255.255.0,10.111.111.255,8h
 
</nowiki></pre>
 
</nowiki></pre>
 
 
'''To avoid the need for root privileges''' add the group "vde2-net" to all users that will use VDE (log-out and log-in for this to take effect)
 
'''To avoid the need for root privileges''' add the group "vde2-net" to all users that will use VDE (log-out and log-in for this to take effect)
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo usermod -aG vde2-net $USER
 
sudo usermod -aG vde2-net $USER
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Either restart the PC or simply do:
 
Either restart the PC or simply do:
 
<pre><nowiki>
 
<pre><nowiki>
第245行: 第178行:
 
</nowiki></pre>
 
</nowiki></pre>
 
Then you will have a virtual network on qtap0 interface. All the VM will be able to connect to the Internet (because of the iptable line on /etc/network/interfaces), but will not be accessible from it.
 
Then you will have a virtual network on qtap0 interface. All the VM will be able to connect to the Internet (because of the iptable line on /etc/network/interfaces), but will not be accessible from it.
 
 
To run a VM with the virtual network use vdeqemu instead of qemu:
 
To run a VM with the virtual network use vdeqemu instead of qemu:
 
<pre><nowiki>
 
<pre><nowiki>
 
vdeqemu -net vde,vlan=0 -net nic,vlan=0 -m 384 -boot c windows.img
 
vdeqemu -net vde,vlan=0 -net nic,vlan=0 -m 384 -boot c windows.img
 
</nowiki></pre>
 
</nowiki></pre>
 
 
See [https://help.ubuntu.com/community/KVM#head-db5235851cc1b9c712f99a074f02c91e8590c880-2 KVM Advanced Networking - Permanent Setup-] for more details on using qemu-launcher and qemuctl with VDE and KVM hardware virtualisation
 
See [https://help.ubuntu.com/community/KVM#head-db5235851cc1b9c712f99a074f02c91e8590c880-2 KVM Advanced Networking - Permanent Setup-] for more details on using qemu-launcher and qemuctl with VDE and KVM hardware virtualisation
 
 
=== Additional Options ===
 
=== Additional Options ===
 
 
==== Sharing Files With XP and Networking ====
 
==== 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.
 
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 =====
 
===== Sharing Files between the Host and VM =====
 
 
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:  
 
To set this up, start QEmu with the following command:  
 
<pre><nowiki>
 
<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
 
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>
 
<pre><nowiki>
 
net use e: \\10.0.2.2\qemu_share
 
net use e: \\10.0.2.2\qemu_share
 
</nowiki></pre>
 
</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)
 
 
==== USB Tablet Emulation ====
 
==== USB Tablet Emulation ====
 
 
QEmu can emulate a USB tablet input device instead of an ordinary mouse. Since a tablet reports the pointer
 
QEmu can emulate a USB tablet input device instead of an ordinary mouse. Since a tablet reports the pointer
 
position in absolute coordinates, it is possible to have the guest pointer track the host pointer position
 
position in absolute coordinates, it is possible to have the guest pointer track the host pointer position
第285行: 第206行:
 
</nowiki></pre>
 
</nowiki></pre>
 
Windows XP automatically uses the tablet without having to install any additional drivers.
 
Windows XP automatically uses the tablet without having to install any additional drivers.
 
 
(TODO: Maybe these options should simply be added to the default ones at the top of the page. Not everyone
 
(TODO: Maybe these options should simply be added to the default ones at the top of the page. Not everyone
 
will find this paragraph, and the feature is so useful that it should probably be recommended for general
 
will find this paragraph, and the feature is so useful that it should probably be recommended for general
 
use. --DanielElstner)
 
use. --DanielElstner)
 
 
==== Mounting A Virtual Drive ====
 
==== 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 [[convertimg2raw 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 [[convertimg2raw 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
 
To mount the drive, create a directory '/media/qemu'. Then run
 
<pre><nowiki>
 
<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>
 
 
==== Saving and Restoring the State of the VM ====
 
==== 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.  
 
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  
 
To create an overlay image, use the qemu-image program. To create an image windows.ovl from windows.img, issue the following  
 
<pre><nowiki>
 
<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
 
To run Windows, you would now use
 
<pre><nowiki>
 
<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>
 
 
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.
 
 
===== Snapshot mode =====
 
===== Snapshot mode =====
 
With the option <code><nowiki>-snapshot</nowiki></code>, QEmu writes to temporary files instead of disk image files. In this case, the raw disk image you use is not written back. You can however force the write back by pressing C-a s. The snapshot mode if useful to try a program that you don't trust (you should never trust a closed source program).
 
With the option <code><nowiki>-snapshot</nowiki></code>, QEmu writes to temporary files instead of disk image files. In this case, the raw disk image you use is not written back. You can however force the write back by pressing C-a s. The snapshot mode if useful to try a program that you don't trust (you should never trust a closed source program).
 
 
==== QEmu Monitor ====
 
==== QEmu Monitor ====
 
 
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 [http://fabrice.bellard.free.fr/qemu/qemu-doc.html official documentation] for full details.
 
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 [http://fabrice.bellard.free.fr/qemu/qemu-doc.html official documentation] for full details.
 
To exit the QEmu monitor press CTRL+ALT+1
 
To exit the QEmu monitor press CTRL+ALT+1
 
 
 
==== Converting a qcow image to a raw file ====
 
==== Converting a qcow image to a raw file ====
 
 
To convert a qcow image, 'windows.img', to a raw 'windows.raw' file , run
 
To convert a qcow image, 'windows.img', to a raw 'windows.raw' file , run
 
<pre><nowiki>
 
<pre><nowiki>
 
qemu-img convert windows.img -O raw windows.raw
 
qemu-img convert windows.img -O raw windows.raw
 
</nowiki></pre>
 
</nowiki></pre>
 
 
==== Converting a raw drive to qcow format ====
 
==== Converting a raw drive to qcow format ====
 
 
To convert a raw 'windows.img' file to a qcow formatted 'windows.qcow', run
 
To convert a raw 'windows.img' file to a qcow formatted 'windows.qcow', run
 
<pre><nowiki>
 
<pre><nowiki>
 
qemu-img convert windows.img -O qcow windows.qcow
 
qemu-img convert windows.img -O qcow windows.qcow
 
</nowiki></pre>
 
</nowiki></pre>
 
 
=== Troubleshooting ===
 
=== Troubleshooting ===
 
 
If you experience problems with mouse pointer hanging in bottom right corner, try before you start up qemu  
 
If you experience problems with mouse pointer hanging in bottom right corner, try before you start up qemu  
 
<pre><nowiki>
 
<pre><nowiki>
 
export SDL_VIDEO_X11_DGAMOUSE=0
 
export SDL_VIDEO_X11_DGAMOUSE=0
 
</nowiki></pre>
 
</nowiki></pre>
 
 
=== External Links ===
 
=== External Links ===
 
* [http://qemu.org/ QEmu Homepage]
 
* [http://qemu.org/ QEmu Homepage]
 
* [http://homepage.sunrise.ch/mysunrise/ekeller00/EricKellerUbuntuPage.html Ubuntu emulated in Windows with QEmu]
 
* [http://homepage.sunrise.ch/mysunrise/ekeller00/EricKellerUbuntuPage.html Ubuntu emulated in Windows with QEmu]
 
 
This has been tested by me and works in Ubuntu 7.10 Gutsy Gibbon. Ubuntu:Vaderdarth211
 
This has been tested by me and works in Ubuntu 7.10 Gutsy Gibbon. Ubuntu:Vaderdarth211
 
[[category:CategoryDocumentation]]  
 
[[category:CategoryDocumentation]]  
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2007年11月30日 (五) 22:31的版本

Consider if you really need to run the Windows program: in most cases, its functionality is provided by a free Linux program, see SoftwareEquivalents. Consider also to use UbuntuHelp:Wine instead of Qemu, if you need to run a single Windows programs. Most of the stuff in this page is not specific to install Windows XP under Qemu, but can be used to install also free operating systems. See also UbuntuHelp:Installation/QemuEmulator.

Running Windows Under Ubuntu 7.04/7.10

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. This also works in Ubuntu 7.10 Gusty Gibbon. WindowsXPUnderQemuHowTo?action=AttachFile&do=get&target=SeamlessVirtualizationWithThemingResized.png Note: Most computers purchased since 2006 support VT or Pacifica, technologies that provide hardware support for virtualization. To see if your system includes these technologies, run the following:

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

If there are any results, then Kernel Virtualization is another possibility for virtualizing other operating systems. Note: Even if you get no output from the above command, your computer may actually support virtualization in hardware. Some machines are delivered with a BIOS option switching off hardware virtualization. Other machines require updating to the latest BIOS for it to work correctly. To install Ubuntu inside QEmu, please read UbuntuHelp:Installation/QemuEmulator.

Installing Windows in QEmu with Feisty 7.04 and Gutsy 7.10

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

  1. First you need to install qemu kqemu-source and module assistant from the Universe Repository. (In Gutsy(7.10),Use the synaptic package manager, search for kqemu and install kqemu-source. Module Assistant is not needed.)

2. Next you need to build the kqemu module from Ubuntu's package

sudo module-assistant prepare
sudo module-assistant auto-install kqemu

3. Next you need to 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: (the order between GROUP and MODE seems to matter, be sure to add a newline at the end of the file)

KERNEL=="kqemu", NAME="%k", GROUP="kqemu", MODE="0660"  

4. Change the content of /etc/modprobe.d/kqemu to

options kqemu major=0

5. 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 $USER 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). 6. Force udev to reload its config files

sudo /etc/init.d/udev reload

7. Load the kqemu module

sudo update-modules
sudo modprobe kqemu

8. Check that the permissions are right

$ ls -l /dev/kqemu
crw-rw---- 1 root kqemu 10, 62 2007-07-22 15:36 /dev/kqemu
  • If the permissions are wrong, it is probably because your udev rule wasn't read properly. Try re-loading the

module

sudo modprobe -r kqemu
sudo modprobe kqemu

and see if that clears the problem. If not, add OWNER="youruser" to the end of the udev rule and try again 9. 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 

10. 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 + Updates, 2 GB is not enough for the image

size. Use at least 3-4 GB.

  • Note: Consider using as much disk space as you can afford. Resizing NTFS partitions is a pain in the

ass, but hard disk space is cheap.

  • 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. 11. Install Windows XP. Put the CD in the drive and run:

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

12. 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. 13. Alternatively, you can use a .iso image file

qemu -localtime -cdrom cdimagefile.iso -m 384 -boot d windows.img

14. If you're having trouble creating the Windows partition during Windows installation, check that you have read and write access to the disk image. Use this command to set the file permissions for the windows.img file so that all users in the kqemu group can access the virtual disk

chmod 660 windows.img
sudo chown $USER:kqemu 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. 15. 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 16. After a few 'reboots' of QEmu you will be running Windows XP. 17. Clicking on the QEmu window will take control of the Windows cursor. To go back to Linux, press Ctrl + Alt and to toggle fullscreen press Ctrl + Alt + F

Networking

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

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

VDE and Dnsmasq

This is an alternative to TAP networking. Most of this is from the page KVM - Advanced Networking and http://compsoc.dur.ac.uk/~djw/qemu.html. Caution: The following package, "dnsmasq" provides dns, tftp and dhcpd services. An LTSP standalone server would be affected because dnsmasq would interfere with the dhcpd and tftp services.

  • Install the packages vde dnsmasq:
sudo apt-get install vde dnsmasq
  • In the file /etc/sysctl uncomment the following line to allow IP forwarding:
net.ipv4.conf.default.forwarding=1
  • In the file /etc/modules, add a new line with "tun", to make that module load on boot.
  • Add the new network interface. Edit the file /etc/network/interfaces and paste this:
auto qtap0
iface qtap0 inet static
address 10.111.111.254
netmask 255.255.255.0
pre-up /sbin/modprobe ipt_MASQUERADE
pre-up /usr/bin/vde_switch --tap qtap0 --daemon --group vde2-net --mod 775 --mgmtmode 770 --pidfile /var/run/vde_switch.pid
pre-up /etc/init.d/dnsmasq restart
up iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
down iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
post-down kill -s HUP `cat /var/run/vde_switch.pid`

Temporary vdeq control sockets are created in /tmp and the vde_switch socket in /var/run/vde.ctl/

  • Configure DNSmasq. Edit the file /etc/dnsmasq.conf and change the following options:
user=nobody
domain=qemu.lan
interface=qtap0
dhcp-range=10.111.111.1,10.111.111.253,255.255.255.0,10.111.111.255,8h

To avoid the need for root privileges add the group "vde2-net" to all users that will use VDE (log-out and log-in for this to take effect)

sudo usermod -aG vde2-net $USER

Either restart the PC or simply do:

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
sudo modprobe tun
sudo ifup qtap0

Then you will have a virtual network on qtap0 interface. All the VM will be able to connect to the Internet (because of the iptable line on /etc/network/interfaces), but will not be accessible from it. To run a VM with the virtual network use vdeqemu instead of qemu:

vdeqemu -net vde,vlan=0 -net nic,vlan=0 -m 384 -boot c windows.img

See KVM Advanced Networking - Permanent Setup- for more details on using qemu-launcher and qemuctl with VDE and KVM hardware virtualisation

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)

USB Tablet Emulation

QEmu can emulate a USB tablet input device instead of an ordinary mouse. Since a tablet reports the pointer position in absolute coordinates, it is possible to have the guest pointer track the host pointer position directly without a mouse grab. Running QEmu with the command line options "-usb -usbdevice tablet" enables USB emulation and the tablet input device:

qemu -m 384 -localtime -usb -usbdevice tablet windows.img

Windows XP automatically uses the tablet without having to install any additional drivers. (TODO: Maybe these options should simply be added to the default ones at the top of the page. Not everyone will find this paragraph, and the feature is so useful that it should probably be recommended for general use. --DanielElstner)

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 convertimg2raw 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.

Snapshot mode

With the option -snapshot, QEmu writes to temporary files instead of disk image files. In this case, the raw disk image you use is not written back. You can however force the write back by pressing C-a s. The snapshot mode if useful to try a program that you don't trust (you should never trust a closed source program).

QEmu Monitor

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 qcow image to a raw file

To convert a qcow image, 'windows.img', to a raw 'windows.raw' file , run

qemu-img convert windows.img -O raw windows.raw

Converting a raw drive to qcow format

To convert a 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

This has been tested by me and works in Ubuntu 7.10 Gutsy Gibbon. Ubuntu:Vaderdarth211