特殊:Badtitle/NS100:Installation/QemuEmulator:修订间差异
小无编辑摘要 |
小无编辑摘要 |
||
(未显示同一用户的9个中间版本) | |||
第1行: | 第1行: | ||
{{From|https://help.ubuntu.com/community/Installation/QemuEmulator}} | {{From|https://help.ubuntu.com/community/Installation/QemuEmulator}} | ||
{{Languages|UbuntuHelp:Installation/QemuEmulator}} | {{Languages|UbuntuHelp:Installation/QemuEmulator}} | ||
QEMU creates a virtual machine, similar to VMWare, Virtualbox, KVM, and Xen. It allows you to run one operating system from within another operating system. The operating systems can be the same ones, or different. You memory resources will be divided between your native (host) OS and your virtual machine (guest) OS. You will therefore notice a decrease in performance of activities in both the host OS and the guest OS. | |||
Therefore, if you plan to use QEMU only to create a Windows virtual environment in order to run Windows programs, consider using one of several free Linux [[UbuntuHelp:SoftwareEquivalents|SoftwareEquivalents]] instead. If you need to run only a single Windows program, also consider using [[UbuntuHelp:Wine|Wine]] instead of QEMU. Running a virtual machine environment such as QEMU will slow down your computer noticeably. | |||
Also see [[UbuntuHelp:WindowsXPUnderQemuHowTo|WindowsXPUnderQemuHowTo]], https://wiki.ubuntu.com/ScreencastTeam/HowToSetupQEMU . | |||
Also consider trying a QEMU interface, such as [http://qemulator.createweb.de/ Qemulator], or the package <code><nowiki>qemu-launcher</nowiki></code>. | |||
Another QEMU GUI is <code><nowiki>virt-manager</nowiki></code>. It manages virtual machines not only for QEMU, but also for kvm and xen, in a consistent fashion (through <code><nowiki>libvirt</nowiki></code>). | |||
=== What is QEMU ? === | === What is QEMU ? === | ||
[http://bellard.org/qemu/ QEMU] is a fast processor emulator. The package currently supports arm, powerpc, sparc and x86 emulation. By using dynamic translation it achieves reasonable speed, while being easy to port to new host CPUs. QEMU has two operating modes: | |||
[http:// | * User mode emulation: QEMU can launch individual Linux processes compiled for one CPU on another CPU. | ||
* User mode emulation: QEMU can launch Linux processes compiled for one CPU on another CPU. | * Full system emulation: QEMU can emulate a full system, including the processor and peripherals. This enables testing and debugging of system code in a contained (and quarantined) virtual system. It can even be used to host several virtual machines simultaneously on a single server (given enough host processor power and RAM). | ||
* Full system emulation: QEMU | As QEMU requires no host kernel patches to run, it is safe and easy to use. | ||
=== Why use an emulator? === | |||
As QEMU requires no host kernel patches to run, it is | QEMU emulates everything, including the CPU, so it is slower than the host system. Hardware acceleration will not be as effective for a software OS emulator. Nevertheless, it is a pretty good way of testing a distribution, without having to repartition your drive or set up new hardware. | ||
=== Why | |||
QEMU emulates everything, including the CPU, so it is slower than the host system. | |||
=== Preparation of the QEMU virtual environment === | === Preparation of the QEMU virtual environment === | ||
* QEMU is available as a standard package in the [[UbuntuHelp:Repositories/Ubuntu#head-5bbef89639d9a7d93fe38f6356dc17847d373096|Universe]]|repository. (There are [[UbuntuHelp:InstallingSoftware#head-82ee502162e81ddca57bfba9281ad97c39fd7fbeinstructions|on how to install packages elsewhere in this guide]]. Unlike some other virtualization systems (like VMWare), separate kernel modules are not needed. | |||
* | * Download the Ubuntu ISO file you wish to install into a virtual QEMU environment. | ||
* Recent QEMU versions support networking out of the box. There is a "linux-test" add-on at [http://www.nongnu.org/qemu/ QEMU's site], a one-line script. Alternatively, run this command before starting the emulator: | |||
Unlike some other virtualization systems | |||
* Download the Ubuntu ISO file you wish to install | |||
* Recent | |||
sudo /sbin/ifconfig eth0 172.20.0.1 | sudo /sbin/ifconfig eth0 172.20.0.1 | ||
* A virtual disk is needed for the virtual machine. A virtual disk is made by creating a file of a size appropriately large to contain the full guest OS: | |||
* | |||
<code><nowiki>qemu-img create ubuntu-test 3G</nowiki></code> | <code><nowiki>qemu-img create ubuntu-test 3G</nowiki></code> | ||
The 'qemu-img'' command (included in the QEMU package) creates a 3Gb image named 'ubuntu-test'. (''qemu-img'' also supports other compressed and VMWare compatible disk-image formats.) | |||
Another way of creating such images is using the standard ''dd'' utility: | |||
Another way of creating such images is using the | |||
<code><nowiki>dd of=ubuntu-test bs=1024 seek=4194304 count=0</nowiki></code> | <code><nowiki>dd of=ubuntu-test bs=1024 seek=4194304 count=0</nowiki></code> | ||
This will create a 4GB file named ''ubuntu-test'' to use as a disk. ''bs'' is the blocksize, ''seek'' is the number of bytes to skip from start of the file being created (a multiple of 1048576 (or 1024K) ). In this case the image would be 4GB. If you wish to get a number to create another size, multiply the number of GB desired by 1024^2 or 1048576. So , 10GB would be 10x1048576 = 10485760. | |||
This will create a | |||
=== Installation of an operating system from ISO to the QEMU environment === | === Installation of an operating system from ISO to the QEMU environment === | ||
We are ready to install the guest OS. Download, for example, [http://www.ubuntu.com/testing/ the latest development version of Ubuntu]. Assuming your ISO image is named ''ubuntu-6.10-desktop-i386.iso'' for example: | |||
We are ready to | |||
<code><nowiki>qemu -hda ubuntu-test -cdrom ubuntu-6.10-desktop-i386.iso -m 192 -boot d</nowiki></code> | <code><nowiki>qemu -hda ubuntu-test -cdrom ubuntu-6.10-desktop-i386.iso -m 192 -boot d</nowiki></code> | ||
* This command instructs QEMU to use hda as the empty disk file. It uses Ubuntu ISO file as if installing from the CDROM, and sets the amount of memory to use in the virtual machine to be 192Mb. It then instructs to boot from the CDROM. | |||
* | A word of caution: giving too much memory to the virtual system will make your native host machine start swapping to disk, which will slow things down a lot. On the other hand, giving it too little memory will make the virtual machine start swapping, which will slow things down as well. Clearly, the more RAM you have, the better. | ||
As the installer boots and goes through options, choose the defaults at each step. The installer should detect the virtual network properly and install without diificulties. | |||
A word of caution: giving too much memory to the virtual system will make your | * At the end, it will try to reboot the machine, but this will fail. | ||
* | |||
* Exit the emulator (type "quit" in the emulator console), then rerun: | * Exit the emulator (type "quit" in the emulator console), then rerun: | ||
<code><nowiki>qemu -hda ubuntu-test -cdrom ubuntu-6.10-desktop-i386.iso -m 192</nowiki></code> | <code><nowiki>qemu -hda ubuntu-test -cdrom ubuntu-6.10-desktop-i386.iso -m 192</nowiki></code> | ||
Note that the boot parameter is removed this time, so that it will boot ubuntu from the new virtual hard drive, not from the "cd". | |||
Note that | |||
* Follow the directions from the installer and create a user. The installer will then fetch updates and add additional packages. This may take between one and two hours, depending on your system configuration and options chosen. | * Follow the directions from the installer and create a user. The installer will then fetch updates and add additional packages. This may take between one and two hours, depending on your system configuration and options chosen. | ||
* At one point, it will register all documentation for the help system. | * At one point, it will register all documentation for the help system. | ||
* Graphics display and adapter setup is very easy; the only question is what video modes to support. Leave this at the defaults; the virtual video hardware may not support higher resolutions than those already set. | * Graphics display and adapter setup is very easy; the only question is what video modes to support. Leave this at the defaults; the virtual video hardware may not support higher resolutions than those already set. | ||
=== Installing QEMU in Windows === | |||
The reason to install QEMU in Windows is so that you can run an Ubuntu Server in a virtual machine. Such a virtual machine can be copied and moved. | |||
At this time, it is best to [http://www.qemu.org/download.html download the source] and then compile QEMU in Windows using [http://www.qemu.org/qemu-doc.html#SEC86 these instructions]. Once QEMU is running in Windows, usage is the same as in Linux. | |||
=== Usage === | === Usage === | ||
First of all, running an OS on emulated hardware is not screamingly, insanely fast. Don't expect to run anything demanding on this system, other than for testing purposes. That said, even on fairly underpowered hardware, it is certainly fast enough to test a distribution, perhaps install some packages, see how it all fits together. | First of all, running an OS on emulated hardware is not screamingly, insanely fast. Don't expect to run anything demanding on this system, other than for testing purposes. That said, even on fairly underpowered hardware, it is certainly fast enough to test a distribution, perhaps install some packages, see how it all fits together. | ||
This is also a good tool for increased security system management. QEMU can have a read-only disk image with a separate write-back file, so one use would be to test the installation of an intrusive packages (or test your own packages to make sure they don't break the system) without actually touching your real system. If it turns out it breaks the system, just remove the write-back file and it never happened. | This is also a good tool for increased security system management. QEMU can have a read-only disk image with a separate write-back file, so one use would be to test the installation of an intrusive packages (or test your own packages to make sure they don't break the system) without actually touching your real system. If it turns out it breaks the system, just remove the write-back file and it never happened. | ||
If you have a very fast network connection, you may want to remove the -cdrom parameter for future invocations of QEMU and comment out the line starting with ''deb cdrom:'' (insert a # sign at the beginning) from the command line: | If you have a very fast network connection, you may want to remove the -cdrom parameter for future invocations of QEMU and comment out the line starting with ''deb cdrom:'' (insert a # sign at the beginning) from the command line: | ||
`sudo nano /etc/apt/sources.list` | `sudo nano /etc/apt/sources.list` | ||
[[category:UbuntuHelp]] | [[category:UbuntuHelp]] |
2010年5月19日 (三) 22:51的最新版本
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/Installation/QemuEmulator }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/af | • {{#if: UbuntuHelp:Installation/QemuEmulator|Afrikaans| [[::Installation/QemuEmulator/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/ar | • {{#if: UbuntuHelp:Installation/QemuEmulator|العربية| [[::Installation/QemuEmulator/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/az | • {{#if: UbuntuHelp:Installation/QemuEmulator|azərbaycanca| [[::Installation/QemuEmulator/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/bcc | • {{#if: UbuntuHelp:Installation/QemuEmulator|جهلسری بلوچی| [[::Installation/QemuEmulator/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/bg | • {{#if: UbuntuHelp:Installation/QemuEmulator|български| [[::Installation/QemuEmulator/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/br | • {{#if: UbuntuHelp:Installation/QemuEmulator|brezhoneg| [[::Installation/QemuEmulator/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/ca | • {{#if: UbuntuHelp:Installation/QemuEmulator|català| [[::Installation/QemuEmulator/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/cs | • {{#if: UbuntuHelp:Installation/QemuEmulator|čeština| [[::Installation/QemuEmulator/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/de | • {{#if: UbuntuHelp:Installation/QemuEmulator|Deutsch| [[::Installation/QemuEmulator/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/el | • {{#if: UbuntuHelp:Installation/QemuEmulator|Ελληνικά| [[::Installation/QemuEmulator/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/es | • {{#if: UbuntuHelp:Installation/QemuEmulator|español| [[::Installation/QemuEmulator/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/fa | • {{#if: UbuntuHelp:Installation/QemuEmulator|فارسی| [[::Installation/QemuEmulator/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/fi | • {{#if: UbuntuHelp:Installation/QemuEmulator|suomi| [[::Installation/QemuEmulator/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/fr | • {{#if: UbuntuHelp:Installation/QemuEmulator|français| [[::Installation/QemuEmulator/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/gu | • {{#if: UbuntuHelp:Installation/QemuEmulator|ગુજરાતી| [[::Installation/QemuEmulator/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/he | • {{#if: UbuntuHelp:Installation/QemuEmulator|עברית| [[::Installation/QemuEmulator/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/hu | • {{#if: UbuntuHelp:Installation/QemuEmulator|magyar| [[::Installation/QemuEmulator/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/id | • {{#if: UbuntuHelp:Installation/QemuEmulator|Bahasa Indonesia| [[::Installation/QemuEmulator/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/it | • {{#if: UbuntuHelp:Installation/QemuEmulator|italiano| [[::Installation/QemuEmulator/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/ja | • {{#if: UbuntuHelp:Installation/QemuEmulator|日本語| [[::Installation/QemuEmulator/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/ko | • {{#if: UbuntuHelp:Installation/QemuEmulator|한국어| [[::Installation/QemuEmulator/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/ksh | • {{#if: UbuntuHelp:Installation/QemuEmulator|Ripoarisch| [[::Installation/QemuEmulator/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/mr | • {{#if: UbuntuHelp:Installation/QemuEmulator|मराठी| [[::Installation/QemuEmulator/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/ms | • {{#if: UbuntuHelp:Installation/QemuEmulator|Bahasa Melayu| [[::Installation/QemuEmulator/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/nl | • {{#if: UbuntuHelp:Installation/QemuEmulator|Nederlands| [[::Installation/QemuEmulator/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/no | • {{#if: UbuntuHelp:Installation/QemuEmulator|norsk| [[::Installation/QemuEmulator/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/oc | • {{#if: UbuntuHelp:Installation/QemuEmulator|occitan| [[::Installation/QemuEmulator/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/pl | • {{#if: UbuntuHelp:Installation/QemuEmulator|polski| [[::Installation/QemuEmulator/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/pt | • {{#if: UbuntuHelp:Installation/QemuEmulator|português| [[::Installation/QemuEmulator/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/ro | • {{#if: UbuntuHelp:Installation/QemuEmulator|română| [[::Installation/QemuEmulator/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/ru | • {{#if: UbuntuHelp:Installation/QemuEmulator|русский| [[::Installation/QemuEmulator/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/si | • {{#if: UbuntuHelp:Installation/QemuEmulator|සිංහල| [[::Installation/QemuEmulator/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/sq | • {{#if: UbuntuHelp:Installation/QemuEmulator|shqip| [[::Installation/QemuEmulator/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/sr | • {{#if: UbuntuHelp:Installation/QemuEmulator|српски / srpski| [[::Installation/QemuEmulator/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/sv | • {{#if: UbuntuHelp:Installation/QemuEmulator|svenska| [[::Installation/QemuEmulator/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/th | • {{#if: UbuntuHelp:Installation/QemuEmulator|ไทย| [[::Installation/QemuEmulator/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/tr | • {{#if: UbuntuHelp:Installation/QemuEmulator|Türkçe| [[::Installation/QemuEmulator/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/vi | • {{#if: UbuntuHelp:Installation/QemuEmulator|Tiếng Việt| [[::Installation/QemuEmulator/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/yue | • {{#if: UbuntuHelp:Installation/QemuEmulator|粵語| [[::Installation/QemuEmulator/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/zh | • {{#if: UbuntuHelp:Installation/QemuEmulator|中文| [[::Installation/QemuEmulator/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/zh-hans | • {{#if: UbuntuHelp:Installation/QemuEmulator|中文(简体)| [[::Installation/QemuEmulator/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Installation/QemuEmulator | UbuntuHelp:Installation/QemuEmulator | {{#if: | :}}Installation/QemuEmulator}}/zh-hant | • {{#if: UbuntuHelp:Installation/QemuEmulator|中文(繁體)| [[::Installation/QemuEmulator/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:Installation/QemuEmulator|:Installation/QemuEmulator|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :Installation/QemuEmulator/zh | | {{#ifexist: Installation/QemuEmulator/zh | | {{#ifeq: {{#titleparts:Installation/QemuEmulator|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:Installation/QemuEmulator|1|-1|}} | zh | | }}
QEMU creates a virtual machine, similar to VMWare, Virtualbox, KVM, and Xen. It allows you to run one operating system from within another operating system. The operating systems can be the same ones, or different. You memory resources will be divided between your native (host) OS and your virtual machine (guest) OS. You will therefore notice a decrease in performance of activities in both the host OS and the guest OS.
Therefore, if you plan to use QEMU only to create a Windows virtual environment in order to run Windows programs, consider using one of several free Linux SoftwareEquivalents instead. If you need to run only a single Windows program, also consider using Wine instead of QEMU. Running a virtual machine environment such as QEMU will slow down your computer noticeably.
Also see WindowsXPUnderQemuHowTo, https://wiki.ubuntu.com/ScreencastTeam/HowToSetupQEMU .
Also consider trying a QEMU interface, such as Qemulator, or the package qemu-launcher
.
Another QEMU GUI is virt-manager
. It manages virtual machines not only for QEMU, but also for kvm and xen, in a consistent fashion (through libvirt
).
What is QEMU ?
QEMU is a fast processor emulator. The package currently supports arm, powerpc, sparc and x86 emulation. By using dynamic translation it achieves reasonable speed, while being easy to port to new host CPUs. QEMU has two operating modes:
- User mode emulation: QEMU can launch individual Linux processes compiled for one CPU on another CPU.
- Full system emulation: QEMU can emulate a full system, including the processor and peripherals. This enables testing and debugging of system code in a contained (and quarantined) virtual system. It can even be used to host several virtual machines simultaneously on a single server (given enough host processor power and RAM).
As QEMU requires no host kernel patches to run, it is safe and easy to use.
Why use an emulator?
QEMU emulates everything, including the CPU, so it is slower than the host system. Hardware acceleration will not be as effective for a software OS emulator. Nevertheless, it is a pretty good way of testing a distribution, without having to repartition your drive or set up new hardware.
Preparation of the QEMU virtual environment
- QEMU is available as a standard package in the Universe|repository. (There are on how to install packages elsewhere in this guide. Unlike some other virtualization systems (like VMWare), separate kernel modules are not needed.
- Download the Ubuntu ISO file you wish to install into a virtual QEMU environment.
- Recent QEMU versions support networking out of the box. There is a "linux-test" add-on at QEMU's site, a one-line script. Alternatively, run this command before starting the emulator:
sudo /sbin/ifconfig eth0 172.20.0.1
- A virtual disk is needed for the virtual machine. A virtual disk is made by creating a file of a size appropriately large to contain the full guest OS:
qemu-img create ubuntu-test 3G
The 'qemu-img command (included in the QEMU package) creates a 3Gb image named 'ubuntu-test'. (qemu-img also supports other compressed and VMWare compatible disk-image formats.)
Another way of creating such images is using the standard dd utility:
dd of=ubuntu-test bs=1024 seek=4194304 count=0
This will create a 4GB file named ubuntu-test to use as a disk. bs is the blocksize, seek is the number of bytes to skip from start of the file being created (a multiple of 1048576 (or 1024K) ). In this case the image would be 4GB. If you wish to get a number to create another size, multiply the number of GB desired by 1024^2 or 1048576. So , 10GB would be 10x1048576 = 10485760.
Installation of an operating system from ISO to the QEMU environment
We are ready to install the guest OS. Download, for example, the latest development version of Ubuntu. Assuming your ISO image is named ubuntu-6.10-desktop-i386.iso for example:
qemu -hda ubuntu-test -cdrom ubuntu-6.10-desktop-i386.iso -m 192 -boot d
- This command instructs QEMU to use hda as the empty disk file. It uses Ubuntu ISO file as if installing from the CDROM, and sets the amount of memory to use in the virtual machine to be 192Mb. It then instructs to boot from the CDROM.
A word of caution: giving too much memory to the virtual system will make your native host machine start swapping to disk, which will slow things down a lot. On the other hand, giving it too little memory will make the virtual machine start swapping, which will slow things down as well. Clearly, the more RAM you have, the better. As the installer boots and goes through options, choose the defaults at each step. The installer should detect the virtual network properly and install without diificulties.
- At the end, it will try to reboot the machine, but this will fail.
- Exit the emulator (type "quit" in the emulator console), then rerun:
qemu -hda ubuntu-test -cdrom ubuntu-6.10-desktop-i386.iso -m 192
Note that the boot parameter is removed this time, so that it will boot ubuntu from the new virtual hard drive, not from the "cd".
- Follow the directions from the installer and create a user. The installer will then fetch updates and add additional packages. This may take between one and two hours, depending on your system configuration and options chosen.
- At one point, it will register all documentation for the help system.
- Graphics display and adapter setup is very easy; the only question is what video modes to support. Leave this at the defaults; the virtual video hardware may not support higher resolutions than those already set.
Installing QEMU in Windows
The reason to install QEMU in Windows is so that you can run an Ubuntu Server in a virtual machine. Such a virtual machine can be copied and moved. At this time, it is best to download the source and then compile QEMU in Windows using these instructions. Once QEMU is running in Windows, usage is the same as in Linux.
Usage
First of all, running an OS on emulated hardware is not screamingly, insanely fast. Don't expect to run anything demanding on this system, other than for testing purposes. That said, even on fairly underpowered hardware, it is certainly fast enough to test a distribution, perhaps install some packages, see how it all fits together. This is also a good tool for increased security system management. QEMU can have a read-only disk image with a separate write-back file, so one use would be to test the installation of an intrusive packages (or test your own packages to make sure they don't break the system) without actually touching your real system. If it turns out it breaks the system, just remove the write-back file and it never happened. If you have a very fast network connection, you may want to remove the -cdrom parameter for future invocations of QEMU and comment out the line starting with deb cdrom: (insert a # sign at the beginning) from the command line: `sudo nano /etc/apt/sources.list`