Difference between revisions of "Qemu on Linux"

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Jump to navigation Jump to search
(→‎Other stuff: moved notes from main qemu article, as they were Linux-specific)
(→‎Notes: moved "accessing the image" to its own page)
Line 8: Line 8:
 
* 2005-12-29 Current repository version of Qemu no longer says "warning: could not open /dev/net/tun: no virtual network emulation", but still can't see anyone on network except the local (virtual) machine. DHCP is not fetching an IP address.
 
* 2005-12-29 Current repository version of Qemu no longer says "warning: could not open /dev/net/tun: no virtual network emulation", but still can't see anyone on network except the local (virtual) machine. DHCP is not fetching an IP address.
 
* Need to figure out how to [[mount]] an .img file -- although it's probably not safe to write to an .img while it's in use by the emulator, so this actually wouldn't be all that useful; you'd have to shut down before writing files to the image. Networking is greatly preferable.
 
* Need to figure out how to [[mount]] an .img file -- although it's probably not safe to write to an .img while it's in use by the emulator, so this actually wouldn't be all that useful; you'd have to shut down before writing files to the image. Networking is greatly preferable.
 
 
===Problems/Solutions===
 
===Problems/Solutions===
 
* '''Problem''': "warning: could not open /dev/net/tun: no virtual network emulation"; '''Solution''':
 
* '''Problem''': "warning: could not open /dev/net/tun: no virtual network emulation"; '''Solution''':
Line 15: Line 14:
 
** Try qemu again. If the console asks for a password for "/etc/qemu-ifup", on [[Ubuntu]] the password it wants is your user password (not sure if this must be the user who installed qemu or the user who is running qemu; perhaps they have to be the same?); this may be different for other distros
 
** Try qemu again. If the console asks for a password for "/etc/qemu-ifup", on [[Ubuntu]] the password it wants is your user password (not sure if this must be the user who installed qemu or the user who is running qemu; perhaps they have to be the same?); this may be different for other distros
 
** However, the network card may still not work at this point; see Current Issues above.
 
** However, the network card may still not work at this point; see Current Issues above.
===Creating the disk image===
+
===The disk image===
 +
* '''To create the image''':
 
  [[qemu-img]] create <u>win98hd.img</u> 2G
 
  [[qemu-img]] create <u>win98hd.img</u> 2G
 
  [[qemu]] -hda <u>win98hd.img</u> -cdrom <u>win98.iso</u> -boot d
 
  [[qemu]] -hda <u>win98hd.img</u> -cdrom <u>win98.iso</u> -boot d
...where <u>win98hd.img</u> is the name of your disk-image file (it can be anything) and _win98.iso_ is the name of a CD ISO image (useful for installing an operating system from CD).
+
...where <u>win98hd.img</u> is the name of your disk-image file (it can be anything) and <u>win98.iso</u> is the name of a CD ISO image (useful for installing an operating system from CD).
===Accessing the disk image from Linux===
+
* '''To access the image''', i.e. to read and write files to it by [[mount]]ing it as a folder, see [[accessing a disk image in Linux]]
In general, assuming the image file was made with the default disk head/sector parameters:
 
[[sudo]] [[mount]] -o loop,offset=32256 <u>/path/to/image</u> <u>/path/to/directory/</u>
 
Specific example ({{Woozle}}'s system):
 
[[sudo]] [[mount]] -o loop,offset=32256 /home/woozle/win98/c.img /mnt/qemu
 
The reason for the offset is that the image represents an entire ''disk''; you can only mount a ''partition'', not the entire disk. The offset is where the main partition starts. You can find out where partitions are in a disk image by using fdisk:
 
[[fdisk]] /path/to/image
 
Woozle example:
 
[[fdisk]] /home/woozle/win98/c.img
 
This takes you to a menu, where you type "p" to get a partition table:
 
Command (m for help): p
 
 
Disk c.img: 0 MB, 0 bytes
 
64 heads, 63 sectors/track, 0 cylinders
 
Units = cylinders of 4032 * 512 = 2064384 bytes
 
 
Device Boot      Start        End      Blocks  Id  System
 
c.img1  *          1        520    1048288+  c  W95 FAT32 (LBA)
 
 
 
Based on what I worked out below (which you don't need to read unless that sort of thing interests you), you work this equation to find the correct offset:
 
[Start] x [bytes-per-sector] x [sectors/track]
 
...where [bytes-per-sector] is the number after the "*" in "cylinders of..."
 
 
 
(Working backwards from the knowledge that 32256 &ndash; which was a Magic Number found by Tenebram &ndash; is the correct number, and trying to figure out why it is correct: If we presume that "sectors/track" means the number of sectors per track for a ''single head'', then 4032 (which is 64 x 63) must be the number of sectors per track for ''all'' heads, and 512 is probably the sector size in bytes. The offset to a given sector, then (waving a magic wand at all this so that it matches reality somehow) is [start] x [bytes-per-sector] x [sectors-per-track] &ndash; which leads us to deduce that the units for the [start] number must be "tracks".)
 
 
===Accelerator===
 
===Accelerator===
 
For [[linux]] host systems, there is a loadable kernel module (called [[kqemu]]) that will allow qemu to run at near native speeds.  At the time of this writing, there aren't distributed packages available with the module built, so you'll need to download the source from the website and compile it locally.
 
For [[linux]] host systems, there is a loadable kernel module (called [[kqemu]]) that will allow qemu to run at near native speeds.  At the time of this writing, there aren't distributed packages available with the module built, so you'll need to download the source from the website and compile it locally.

Revision as of 02:11, 22 February 2006

Computing: Linux: Qemu: on Linux

This page is a seed article. You can help HTYP water it: make a request to expand a given page and/or donate to help give us more writing-hours!

This article is about setting up and running the Qemu emulator on Linux.

Reference

Notes

When Bochs mysteriously stopped being able to run Win98, I found that Qemu was able to use the exact same .img file Bochs had been using, and it did manage to load Win98 quite easily. It would appear, then, that the setup for Qemu on Linux is probably quite similar to that of Bochs.

Current issues

  • 2005-12-29 Current repository version of Qemu no longer says "warning: could not open /dev/net/tun: no virtual network emulation", but still can't see anyone on network except the local (virtual) machine. DHCP is not fetching an IP address.
  • Need to figure out how to mount an .img file -- although it's probably not safe to write to an .img while it's in use by the emulator, so this actually wouldn't be all that useful; you'd have to shut down before writing files to the image. Networking is greatly preferable.

Problems/Solutions

  • Problem: "warning: could not open /dev/net/tun: no virtual network emulation"; Solution:
    • as root, run "modprobe tun"; if no error, then the tun module has been installed successfully
    • "ls /dev/net/tun" to make sure the device has been created
    • Try qemu again. If the console asks for a password for "/etc/qemu-ifup", on Ubuntu the password it wants is your user password (not sure if this must be the user who installed qemu or the user who is running qemu; perhaps they have to be the same?); this may be different for other distros
    • However, the network card may still not work at this point; see Current Issues above.

The disk image

  • To create the image:
qemu-img create win98hd.img 2G
qemu -hda win98hd.img -cdrom win98.iso -boot d

...where win98hd.img is the name of your disk-image file (it can be anything) and win98.iso is the name of a CD ISO image (useful for installing an operating system from CD).

Accelerator

For linux host systems, there is a loadable kernel module (called kqemu) that will allow qemu to run at near native speeds. At the time of this writing, there aren't distributed packages available with the module built, so you'll need to download the source from the website and compile it locally.

I've been told that kqemu (or is that qemu-fast, or are they the same thing?) and Win98 don't get along, which seems borne out by my failed attempts so far to boot Win98 using either one of them – but that could be due to some configuration problem, as I haven't tried booting anything else with either of them either. --Woozle 12:10, 18 February 2006 (EST)

Other stuff

The sample /etc/qemu-ifup file which comes with linux-test-*.tar.gz:

#!/bin/sh
sudo /sbin/ifconfig $1 172.20.0.1