个人工具

UbuntuHelp:Installation/QemuEmulator

来自Ubuntu中文

Wikibot讨论 | 贡献2007年11月30日 (五) 17:59的版本

跳转至: 导航, 搜索

This How To chronicles the steps taken to get any Ubuntu release up and running under this emulator, without repartitioning or fully installing on your system. See also UbuntuHelp:WindowsXPUnderQemuHowTo, https://wiki.ubuntu.com/ScreencastTeam/HowToSetupQEMU .

What is QEMU ?

(from the package description) QEMU is a FAST! processor emulator: currently the package supports arm, powerpc, sparc and x86 emulation. By using dynamic translation it achieves reasonable speed while being easy to port on new host CPUs. QEMU has two operating modes:

  • User mode emulation: QEMU can launch Linux processes compiled for one CPU on another CPU.
  • Full system emulation: QEMU emulates a full system, including a processor and various peripherals. It enables easier testing and debugging of system code. It can also be used to provide virtual hosting of several virtual PC on a single server.

As QEMU requires no host kernel patches to run, it is very safe and easy to use.

Why would you want to do this ?

QEMU emulates everything, including the CPU, so it is slower than the host system. You will not get much benefit of most of your hardware either. But it is a pretty good way of testing a distribution without having to repartition your drive or set up new hardware. It is also quite fun, in a geeky sort of way :)

Preparation of the QEMU virtual environment

  • First, of course, you need to get and install QEMU. Fortunately, this is quite easy. QEMU is a standard package available since the first version of Ubuntu in the Universe repository. If this is your first time doing this, there are on how to install a package in this guide.

Unlike some other virtualization systems, like VM Ware, there is no need for kernel modules or anything; it runs just fine in userland.

  • Download the Ubuntu ISO file you wish to install in a virtual QEMU environment - no need to actually burn it to a CD though.
  • Recent qemu versions seem to support networking out of the box. If networking doesn't work, you may need to set it up. There is a "linux-test" add-on on QEMU's site which is a one-line script to put among your network scripts; another, easier way is to run this command before starting the emulator:

sudo /sbin/ifconfig eth0 172.20.0.1

  • We also need a virtual disk for our system. You make a disk simply by creating a file of the size you like, something like this:

qemu-img create ubuntu-test 3G This creates a 3Gb large image named 'ubuntu-test'. qemu-img is another command that comes with the QEMU package, to create files needed for QEMU operation. qemu-img also supports other compressed and VMWare compatible disk-image formats. Another way of creating such images is using the stadnard dd utility: dd of=ubuntu-test bs=1024 seek=4194304 count=0 This will create a 10Gb 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 big. 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 run the install. You may want to download and test the latest development version of Ubuntu. Assuming your ISO image is named ubuntu-6.10-desktop-i386.iso for example, this is how to do it: qemu -hda ubuntu-test -cdrom ubuntu-6.10-desktop-i386.iso -m 192 -boot d

  • We set hda to be our empty disk file, set the CDROM device to actually be the Ubuntu ISO file, set the amount of memory our virtual machine has to 192Mb, and tell it to boot from the CDROM.

A word of caution: giving too much memory to the virtual system will make your real machine start swapping, 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. Moral: have a lot of memory on your host system. The installer should be booting at this point. You can go through the dialogues choosing the defaults at every turn. The installer should detect the virtual network properly and then install without a hitch.

  • Now, at the end, it tries to reboot the machine. 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 we have removed the boot parameter so it will boot ubuntu from the 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.

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`