The Bent Zone, AKA Sun Tzu Tech
Weblog
Archives
« April 2005 »
SunMonTueWedThuFriSat
     
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
30
       
Today
XML
Search

Links
Referrers

Today's Page Hits: 31

« Previous day (Apr 28, 2005) | Main | Next day (Apr 29, 2005) »
20050429 Friday April 29, 2005
Creating an Image file for Knoppix under QEMU, and Quickstarting an Image

At this point, we should have a working set of qemu binaries loaded in /tmp/qemu, a ISO image or CDROM copy of the Knoppix Live CD and a little experience starting up a Knoppix instances under QEMU in a Solaris 10 Host.

Next, we need to create a disk image file that we can use to load an OS image on. The command used to create these images file is called qemu-img. The qemu-img binary supports multiple formats including raw, cow, qcow and vdmk to name a few. Raw format appears to be the most platform neutral and independent, while the most versitile format appears to be qcow, which supports compression and encryption, as well as copy-on-write (COW). To create our image file to load Knoppix onto, run the commands:

     cd /export/src/images/Knoppix_3.8
     /tmp/qemu/bin/qemu create -f qcow knoppix.img 4G

You can verify that it built out the image the way you expected to by invoking the command:

     $ /tmp/qemu7/bin/qemu-img info knoppix.img                                                                   
     image: knoppix.img
     file format: qcow
     virtual size: 4.0G (4294967296 bytes)
     disk size: 17K

Starting Knoppix LiveCD to install on a QEMU Disk image

As it turns out, if you don't have your hard disk partitions setup and the /dev/hda1 partition doesn't have an ext2fs on it, running "tohd=/dev/hda1" at the Knoppix prompt doesn't work. So the first thing to do is to boot the Knoppix image off of CDROM or ISO image, yet add in the virtual disk image defined by "-hda knoppix.img". Because we're stil specifying "-boot d", QEMU will boot off the KNOPPIX CD or ISO image first.


     /tmp/qemu/bin/qemu -cdrom /vol/dev/rdsk/c1t0d0/knoppix -user-net \
              -enable-audio -pci -m 512 -k en-us -boot d -hda knoppix.img

Once Knoppix is booted, open a Konsole window from the KDE toolbar at the bottom of the Knoppix screen (It looks like a terminal), and type:


     $ su   # no password required for Knoppix
     # fdisk /dev/hda

From the fdisk partition menu, create a primary Linux partition on partition 1 of 3600MB and a Linux Swap partition on (0x82) on partition 2 of 500MB (remainder of the disk). Make partition 1 the active partition, but I'm not certain that because of how QEMU boots a system on whether or not this make any difference. But that's how you do it with a normal hard disk so let's do it that way here. Write out the changes to the disk and then do a mkfs /dev/hda1. Once that is complete, Halt the Knoppix image and restart it with the above command line. Once you see the Knoppix prompt again like this type:

     boot: knoppix screen=1152x864 dma tohd=/dev/hda1   # 1152x900 works under JDS/Linux Host, but 1152x864 is all Solaris can do

and then watch the disk spin for a bit, with the screen looking somewhat like this. When it's all done, Knoppix will boot normally. [On my 2Ghz Athlon system that I did this test on, the transfer rate racked up an impressive 30Mb/second for transferring the image from the ISO to the virtual disk on /dev/hda1.] What this actually does is just copy over the directory structure on the CDROM onto the Hard disk. (Gee, I thought you could install Knoppix to the Hard disk from the boot menu). Now, when you boot from your cdrom, you can add "fromhd=/dev/hda1" which will make it boot off the hard disk image. Given all things, this is probably not a big win, given that running from the CDROM or ISO image isn't going to be the limiting factor. However, it's a very quick test to make sure your virtual hard disk is writable, and you can boot from the image using the CDROM or ISO image. The start line for qemu doesn't change from the previous run, but how we invoke Knoppix is different. At the boot prompt, type:

     boot knoppix screen=1152x864 dma fromhd=/dev/hda1

Making Knoppix boot very fast while using a HD install

This morning, we looked at how we can make QEMU boot a system much faster using the savevm/loadvm commands from the monitor. Once the above system has booted, and you've got all the applications setup the way you want them, then type CTRL-ALT-2 to go into the QEMU monitor. Once inside the QEMU monitor, type "savevm knoppix-save.vm" and then "quit". The file knoppix-save.vm should be in directory /export/src/images/Knoppix_3.8

Restarting a QEMU savevm'd image

Once again, we add another parameter to the startup line for the qemu instance. To get the very quick restart of a running image, we run:


     /tmp/qemu/bin/qemu -cdrom /vol/dev/rdsk/c1t0d0/knoppix -user-net -enable-audio \
           -pci -m 512 -k en-us -boot d -hda knoppix.img -loadvm knoppix-save.vm

and in about 10 seconds on my PIII/1Ghz with 1.5G of Ram, my Knoppix instance is back where it was when I ran the savevm command from the QEMU monitor.

After you restore an image like this, I found out that you should do a [CTRL-ALT-1] to reset the virtual machine's system state, which explains the weirdness I saw with the keyboard and restored image

I wish I had found this sooner. Waiting 10-15 minutes for something to bootup and enumerate all the devices is pretty hideous. Makes me really want to see a Solaris kqemu module for QEMU get written so we can have the near machine speed that the Linux folks have (I run JDS3/Build 32 on my Toshiba M2, and with kqemu it's really really nice, but this blarg is about making QEMU work on Solaris).


Apr 29 2005, 02:47:38 PM EDT Permalink Comments [0]

Running Knoppix under Solaris 10, A QEMU for Solaris Primer

Yesterday, I talked about QEMU and what it can do. As I've been working with it, there are a couple of reasons I want to run an OS under QEMU with Solaris 10 as my Host.
1) I need/want to run some Windows applications that I don't have under Solaris (say acrobat 7 or real player).
2) I want to test an OS out without having to frag my laptop again (as I've been doing since last year with Solaris 10 in beta, and now Solaris 10.1 [aka 11] in beta)

Getting started with QEMU

Assuming you can follow the download and patching of qemu-0.7.0 from yesterday, then running of

     ./configure --prefix=/tmp/qemu --with-oss=yes --oss-inc=/opt/oss/include; gmake install
the next thing you need to do is setup a working area. For the purposes of the demostration, I use /export/src/images as my top level directory where I keep the QEMU images. I also use /export/src/iso as the location for any CDROM image iso files I use to boot/install a guest OS under QEMU.

     $ mkdir -p /export/src/iso /export/src/images
     $ cd /export/src/images
     $ mkdir Knoppix_3.8
     $ cd Knoppix_3.8

The great thing about Knoppix is the ability to boot a complete OS on a PC without having to touch the hard disk, not to mention it's free and they have several yearly updates to the code base. These disks have become great recovery tools and have a lot of different uses. My favorite use of Knoppix is a test of how QEMU is running. Since it seems to take about 4 hours to install Solaris Express from a DVD image in a QEMU session, I'm really not interested in finding out it doesn't work after 4 hours. Plus, since it doesn't really require any disk space requirements at all, starting Knoppix under qemu is dead simple. Not everyone has Windows 98, 2000, XP, etc, and the time requirements to actually get comfortable with it are minimal compared to the amount of time it's taken me to get things like a 5 CD iso build of JD3 Linux/Build 32 installed, or Solaris Express on DVD. So I think is a pretty good example, plus I think any tech ought to be carrying a Knoppix disk, or something like it.

Getting Knoppix 3.8

Assuming you've gotten a Knoppix 3.8 iso image from your local bittorrent, and burned it to a CDROM, this is all you need. Blastwave has a version of bittorrent for Solaris, so getting a copy is just a matter of doing a "pkg-get -i bittorrent", assuming you loaded pkg-get from www.blastwave.org. (It seems that Knoppix V 3.7 was the last version available via FTP)

Booting Knoppix 3.8 from a CDROM under QEMU

So either you have an ISO image sitting in a directory like /export/src/iso/KNOPPIX_V3.8.1-2005-04-08-EN.iso or you actually burned the image onto media and it's in a CDROM drive in the Solaris system. If you are running vold (volume managment), we need make sure we can see the physical device.

$ eject -q cdrom       # to get the volume name of the knoppix disk
                       # it should be something like /vol/dev/dsk/c1t0d0/knoppix
                       # but we really need to give it the rdsk name so it can boot it.
#
#  To start Knoppix under QEMU if using a real CDROM under Solaris with vold enabled, try
#
$ /tmp/qemu/bin/qemu -cdrom /vol/dev/rdsk/c1t0d0/knoppix -user-net -enable-audio -pci -m 512 -k en-us
#
#  To start Knoppix under QEMU if using an ISO image file under Solaris, try
#
$ /tmp/qemu/bin/qemu -cdrom /export/src/iso/KNOPPIX_V3.8.1-2005-04-08-EN.iso -user-net -enable-audio -pci -m 512 -k en-us
#
#
# -user-net      : enables the slirp network stack that QEMU presents to the guest OS. This is default
#                  if you don't have tunnels (The tunnel code in QEMU for solaris is not quite there yet)
# -enable-audio  : have QEMU present a Soundblaster 16 to the virtual machine
# -pci           : have QEMU present a PCI bus.  The opposite is ISA, but at this point is only useful for
#                  things like DOS. Solaris Newboot as a guest chokes on "-isa"
# -m 512         : the ammount of physical memory to be given to QEMU for this guest OS.
#                  my system has 1536MB so giving it 512 is not too bad. This variable you
#                  will need to be careful with.
# -k en-us       : Sets up the keymapping for QEMU. Seems to be important if you're doing a savevm/loadvm,
#                  which I'll talk about later.
#

What you see immediately is a screen that looks like this. At this prompt type:

     boot knoppix screen=1152x864 dma # or screen=1024x768, something workable with your display window
                                         # 1152x900 works in JDS but for some reason doesn't work on Solaris. Go figure.

This takes about 15 minutes to boot on my PIII/1Ghz, and about 7 minutes to boot on my 2GHz Athlon XP. What this gives you is a working Knoppix instance running in QEMU under a Solaris host. Assuming you don't have any compile problems, and your Solaris host has a valid network/DNS mappings, your Knoppix guest OS should have an eth0 interface with an address of 10.0.2.15. Since QEMU provides a virtual DHCP server to the client (How else did it get that 10.0.2.15 address), and proxies DNS from a virtual host using 10.0.2.3 and having a defaultroute of 10.0.2.2, networking for the most part should just work. One big caveat - You cannot ping out of a guest OS to the host or any other address because SLIRP does not support ICMP. Telnet, FTP, SSH/SCP, X11, VNC and Samba all work without issue.

To verify, open a kconsole window (In your Knoppix QEMU Guest) , and run:


     $ ifconfig eth0

and see


     eth0      Link encap:Ethernet  HWaddr 52:54:00:12:34:56  
               inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
               inet6 addr: fe80::5054:ff:fe12:3456/64 Scope:Link
               UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
               RX packets:634 errors:0 dropped:0 overruns:0 frame:0
               TX packets:571 errors:0 dropped:0 overruns:0 carrier:0
               collisions:0 txqueuelen:1000 
               RX bytes:267069 (260.8 KiB)  TX bytes:53495 (52.2 KiB)
               Interrupt:11 Base address:0xc100 

(YES, your networking will look *exactly* like that, because the "virtual machine" presented by QEMU to the guest OS looks the same.)

One thing that occurs when you click your mouse into the QEMU guest OS window, is that QEMU grabs it, and doesn't let go of it. If you feel like you've lost your mouse, hit CTRL_ALT and see if it releases your mouse so you can go outside the QEMU window.

Start firefox and surf the web (though if your Solaris host uses a web proxy, so should the Guest OS's brower). You can ssh to your Solaris host (make sure to use the real network address of the host, not 127.0.0.1). FTP also works, but I find that often you may have to use passive mode ("quote pasv") in the ftp client to pass data back and forth. I've found ssh/scp much easier to work with when dealing with a QEMU guest OS and the user-net stack.

Booting Knoppix Really Fast

QEMU has the ability to save the state of the local VM, and restore back to it from the command line. How we do this is by going into the QEMU monitor using [CTRL-ALT-2]. The monitor is a command line tool which provides a set of of tools and features, as displayed by this help menu

     QEMU 0.7.0 monitor - type 'help' for more information
     (qemu) help
     help|? [cmd] -- show the help
     commit  -- commit changes to the disk images (if -snapshot is used)
     info subcommand -- show various information about the system state
     q|quit -- quit the emulator
     eject [-f] device -- eject a removable media (use -f to force it)
     change device filename -- change a removable media
     screendump filename -- save screen into PPM image 'filename'
     log item1[,...] -- activate logging of the specified items to '/tmp/qemu.log'
     savevm filename -- save the whole virtual machine state to 'filename'
     loadvm filename -- restore the whole virtual machine state from 'filename'
     stop  -- stop emulation
     c|cont  -- resume emulation
     gdbserver [port] -- start gdbserver session (default port=1234)
     x /fmt addr -- virtual memory dump starting at 'addr'
     xp /fmt addr -- physical memory dump starting at 'addr'
     p|print /fmt expr -- print expression value (use $reg for CPU register access)
     i /fmt addr -- I/O port read
     sendkey keys -- send keys to the VM (e.g. 'sendkey ctrl-alt-f1')
     system_reset  -- reset the system

Assuming you started your session as I described, you can hot-key between the QEMU guest, the QEMU monitor, and the QEMU serial port. CTRL-ALT-1 from the MONITOR or QEMU serial port will take you to the Guest OS. CTRL-ALT-2 from the Guest OS or the QEMU serial port will take you to the MONITOR. CTRL-ALT-3 from the GUEST or the MONITOR will take you to the QEMU serial port.

Saving a running QEMU Guest OS session

Use CTRL-ALT-2 to go to the MONITOR and type

     savevm knoppix-save.vm

then

     quit

You will find a file created in the local directory (still in /export/src/images/Knoppix_3.8, right?) called knoppix-save.vm which contains the memory contents of the virtual machine. Since we're running off of a CDROM iso image, it doesn't matter about what's in the "file system". We're not using one yet. As you can see, the more you do with QEMU, the more command line parameters you need, which is why I wrote the script to do this. There are some java GUI's, but I'm a command line kind of guy, so I write my own stuff. Restart the Knoppix session using the command from above plus a new parameter -loadvm knoppix-save.vm and make sure that the amount of memory you originally specified at the time you saved this instance is the same that you start the -loadvm knoppix-save.vm: like:


     /tmp/qemu/bin/qemu -cdrom /vol/dev/rdsk/c1t0d0/knoppix -user-net -enable-audio \
                        -pci -m 512 -k en-us -boot d -loadvm knoppix-save.vm

This will have the Knoppix system back up in about 10 seconds. Once the system is back up, switch to the QEMU console with [CTRL-ALT-2], then switch back to the VM using [CTRL-ALT-1]. This appears to prevent the weirdness I'm seeing with a Konsole window and the keyboard interaction, where the keyboard doesn't seem to work correctly. But still, it's much faster than the 15 minutes it took to actually start the virtual machine from a dead stop.

This is all fine and good in testing. However, the savevm/loadvm feature is more likely to be used on Operating Systems that have a read/write disk, and not a read-only disk such as a CDROM or ISO image. This is where it gets tricky. In order to prevent corruption of the Hard disk image file containing the Operating System, if you use the savevm/loadvm feature, it is imperative that you not boot the disk image without the -loadvm and it's statefile. Otherwise, some pretty serious corruption could take place.


Apr 29 2005, 10:30:29 AM EDT Permalink Comments [0]