Wednesday, December 18, 2019

Qemu Guide

QEMU quick start guide

This page is intended as quick start guide for people who want to use QEMU to install
       Windows guest on Linux host
or
       Linux guest on Windows host
QEMU is a virtual machine program. So, that's a machine in the machine. There is a computer, called host, which runs an OS, called host OS, and QEMU (besides other programs). Inside QEMU, there runs an OS, called guest OS. QEMU is a simple program ("exe") from the host point of view.
While QEMU is able to handle different host and guest architectures like PPC, ARM or MIPS (not complete), this quick start guide only covers x86 where host and guest architectures are the same. To emulate a guest x86 machine on a host x86 we use QEMUs Full System Emulation mode.

Windows guest on Linux host

1. Download QEMU Binary distribution for linux-i386 and install it. Installation is simply done by extracting the contents of the tar archive in root directory ("/"). It will extract its contents to /usr/local/bin and /usr/local/share.
2. You need a blank disk image ("harddisk"). This is like adding a blank disk to the virtual computer that QEMU creates. Use qemu-img to create a 3Gb blank disk image:
qemu-img create -f qcow c.img 3G
The last argument is the size of the image (3G). This 3G will be the maximum end size of the image file. It will grow while adding contents (writing files to the harddisk). A fresh WinXP installation will use e.g. ~1.7Gb. For more information on creating a blank image see Disk Images.
3. When you install an OS on a real computer you normally boot an installation CD/DVD or an existing image. We'll do the same with the virtual computer. Here you have two options: Either you use a real installation CD/DVD or you have an install ISO image. Depending on this, the next steps are slightly different.
* If you have an installation CD, put the CD (e.g. Windows installation CD) into the real CD drive of your host computer. Then run
qemu -cdrom /dev/cdrom -hda c.img -m 256 -boot d
* Suppose you have an install ISO image , called my_os_install.iso. Then run
qemu -cdrom my_os_install.iso -hda c.img -m 256 -boot d
Both will run the virtual machine. It will have two drives, the primary master (/dev/hda) is the 3G image (-hda c.img). The secondary master is that cdrom or cdrom image. Note that (from the host point of view) those are still two plain files (in case of iso image). But from the guest OS (running in the VM), those are real drives. Boot is done from secondary master (-boot d) using 256MB of RAM (-m 256) using c.img as "hardisk" (image).
Note: If -m 256 or more fails (depends on your PC configuration) it will explain what to do.
So, the virtual machine is started. It shows a window in the monitor like on a real hardware. Now you can install the client OS just as you would in a real computer. First you probably need to create partitions, format them, run installer to copy files, and so on. If it needs to reboot the guest, feel free to do that, Qemu will not stop working.
If you don't like windowed mode, you can use special keys. Press ctrl-alt-f to go fullscreen. When you'd like to use your host OS, press ctrl-alt to release mouse grab or try seamless mouse. You can return to the VM any time.
When you stop guest OS, and the virtual machine halts, QEMU exits. But the image file (c.img) is modified (the guest OS remains on that), so, you don't have to reinstall it every time. So, if you have installed the client OS shutdown it as you will do with your real computer. You will then note that the image file (here c.img) will have increased dramatically. You can now start the system you just installed by booting from the "hardisk" (c.img):
qemu -hda c.img -m 256
If you want, you can compress c.img to backup, or do anything. Note that closing the VM window while guest OS is running is like unplugging the computer. It might complain next time
4. If you have basic system up and running, you may want to add sound and correct local time.
qemu -hda c.img -m 256 -soundhw sb16 -localtime
-soundhw sb16
just like putting a soundblaster card into the slot
-localtime
in case the host OS runs in local time (and not GMT)
-net nic -net user option is not necessary here because it is enabled by default if no -net option is specified. This is, by default, "user mode" (user-net) networking, which is the simplest way to reach internet from inside. It just works (getting IP address from DHCP automatically)
If you call QEMU without any parameters, it will show its possible parameter list.
At runtime QEMU itself can be controlled by QEMU Monitor.
5. To increase emulation speed, you would like to install QEMU Accelerator (KQEMU). Download latest QEMU Accelerator Module and follow KQEMU Compilation and kqemu installation.
If you start QEMU now, it will probably run significantly faster. Try -kernel-kqemu option as well.
To check if everything is okay, use QEMU Monitor command info kqemu:
(qemu) info kqemu
kqemu support: enabled for user and kernel mode
With this, your final command line to start QEMU with installed image (c.img) may now be
qemu -hda c.img -m 256 -kernel-kqemu
(plus additional options like above i.e. for sound or localtime)
6. This guide tries to give you some basic ideas how to start with QEMU and to explain some first steps to get you up with QEMU on Linux quickly. There are several areas for additional configuration (i.e. additional drives, further network, data exchange between host and guest, overlay images, VNC etc.) which are not covered here. For this, go on reading resources given in Documentation.
Acknowledgements
The text in this section was mainly taken from
       Daniel Carreras post to QEMU developer list.
       NyOS' post to QEMU developer list.
Links
       For a more detailed guide see QemuOnLinux

No comments:

Linux Software RAID

Introduction The main goals of using redundant arrays of inexpensive disks (RAID) are to improve disk data performance and provide data re...