Qemu disk image conversion

I see that there is some confusion over how to convert disk images from various popular emulators, and I thought I’d try to clear some of this up. Without a doubt, the best free tool available for this is qemu-img. And it’s free! Currently as I write this, that makes Qemu 0.14.0 the current version. I’ll cover the common ones that I use.

For the most part for Qemu I used the qcow2 format. Naturally you can use any of these formats in Qemu… While others are limited.

Converting from..

Virtual PC source image..
To convert to a qcow2:

qemu-img convert source.vhd -O qcow2 destination.qcow2

To convert to VMDK for VMWare:

qemu-img convert source.vhd -O vmdk destination.vmdk

And to convert to a raw image, suitable for BOCHS.

qemu-img convert source.vhd -O raw destination.raw

And of couese you can mix and match from there… Say take your qcow2 and convert it for VPC like this:

qemu-img convert source.qcow2 -O vpc destination.vpc

Or convert a Virtual PC/Virtual Server/Hyper-V vhd (as long as the hyper-v image is consolodated) and convert it to VMWare like this:

qemu-img convert source.vhd -O vmdk destination.vmdk

Note that these VMWare VMDK’s are not for ESX/ESXi, they use more of a raw partition set… But of course you can always convert them to RAW then dd them into the target partition… But I’ll leave that exercise to you. Honestly that vmware converter thing is much easier as it’ll inject the needed drivers.

Speaking of which, this only converts image formats, don’t forget about pre-loading the needed drivers!

I hope this helps out anyone trying to move disk images around.

back to fun with pread.c

Well I know this topic keeps comming up over & over that the pread.c that I had used to build my Xenix on Qemu is long lost.

Anyways someone else was asking me for it, and I stumbled accross this Microsoft Memo:

http://support.microsoft.com/kb/100027

which means the device name I was listing was wrong… I’m unsure if it means in 2003 it change from what it was since 1991….

Anyways here is my new ‘pread’.

#include <stdio.h>
#include <stdlib.h>

define BUFFSIZE 1024*1024
void main(void)
{
FILE *disk;
FILE *ofile;
int disknumber;
char fname[255];
char oname[255];
char *buffer;
int rc;
int pass;
buffer=(char)malloc(BUFFSIZE); if(buffer==(char)NULL)
{printf("\nError allocating buffer!!\n");return;}
printf("please tell me the disk NUMBER that you want to read\n");
printf("for \\.\PhysicalDrive1 just answer 1\n\n:");
memset(fname,0x0,sizeof(fname));
scanf("%d",&disknumber);
sprintf(fname,"\\.\PhysicalDrive%d",disknumber);
printf("reading the device %s\n",fname);
disk=fopen(fname,"rb");
memset(oname,0x0,sizeof(oname));
printf("\nWhat is the output file name?\n\n:");
scanf("%s",oname);
ofile=fopen(oname,"wb");
if(ofile==NULL){printf("\n\nERROR with %s\n",oname);return;}
if(disk==NULL){printf("\n\nERROR with disk %s\n",fname);return;}
rc=5;
pass = 0;
while(rc!=0)
{
memset(buffer,0x0,sizeof(buffer));
rc=fread(buffer,1,BUFFSIZE,disk);
printf("\r%d\t%d:Megabytes processed",rc,pass);
fwrite(buffer,1,rc,ofile);
pass++;
}
fclose(disk);
fclose(ofile);
printf("\n\n\nDone!%c",7);
}

Running Xenix on qemu

Neither Bochs nor Qemu can boot the Xenix floppy diskettes all the way. Virtual PC & VMWare seemed to have no luck when the kernel transitions to protected mode. While on the way to work I had an idea. What if you had an old hard disk and a machine capapble of installing? Simply imaging the hard disk may be enough, since after that point you don’t need any floppy disks!

So this is what I have to show for the work today:

Freaking awesome, if I do say so myself.

OK, now how to do it? First you need an existing system running Xenix. If you have any plans on migrating an existing installation take note! This will preserve your install, just don’t format! On the Xenix boot screen take note of the geometry of the disk. We will need the geometry for later. Although I did a test boot without it, its a good thing to preserve it.

For virgin users, you will need a small disk to install on. I had a 2.5 GB disk that was too big, and 132MB disk that worked fine. I used a dell pc with 2 ide controllers for this. The longest task honestly was installing Xenix. I think that ran about 20 minutes. Once I was done, shutdown xenix, and put the disk in a machine running Windows (Linux fans can put it in their box, and just dd the Xenix disk into an image). Us poor Windows users don’t have dd. Anyways take not of what disk # it is, as Windows of course will not assign it a drive letter since it does not understand Xenix’s filesystem.

As you can see it’s disk #2 in this computer. Ok now we need to read the disk and write it into a disk image. I couldn’t find a util offhand to do it, so I wrote one real quick. Here is the source code, you’ll need a C compiler on your PC to compile it. I guess I could ‘neaten it up’ some, but for now here you go:

Source code

Executable

Yes I know its horrible, and blogger does a wonderfull job of formatting my program. Anyways compile it & run it. Now you’ll have a disk image of your hard disk!

Now for the fun part, running Xenix! We simply specifiy the hard disk geometry that we got earlier, and pass it the disk image that we created! I’m using an Quantum Pro drive ELS with the following geometry:

919 Cylinders
16 heads
17 bytes/sector

That translates into the following command:

qemu -M isapc -m 16 -hda xenix386-2.3.4.disk -hdachs 919,16,17 -L .

 

Let the good times roll!

–Update from 2011!

It is *NOW* possible to install Xenix in Qemu 0.14.0. You can read more about it here.