The Bent Zone, AKA Sun Tzu Tech
Weblog
Archives
« November 2009
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
28
29
30
     
       
Today
XML
Search

Links
Referrers

Today's Page Hits: 9

« Running Knoppix... | Main | Using Knoppix under... »
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]

Trackback URL: http://blogs.sun.com/thebentzone/entry/creating_an_image_file_for
Comments:

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed