* [Qemu-devel] Converting installed windows (or ?) partition to virtual machine image
@ 2008-10-10 2:41 orion
2008-10-10 12:26 ` Johannes Schindelin
0 siblings, 1 reply; 3+ messages in thread
From: orion @ 2008-10-10 2:41 UTC (permalink / raw)
To: qemu-devel
I'd like to try to convert the installed Windows partition of a dual boot
machine into a virtual machine image. It seems like qemu-img currently
only supports copying an entire disk (/dev/sda for example) to a disk
image. It would be nice if one could specify a single partition.
As a first hack/attempt to try this out, I'm trying the patch below
(against 0.9.1) to only copy a certain number of sectors. Since the
Windows partition is almost always the first partition on the disk,
hopefully this will work for most folks. I guess if you've already
installed grub you'll have issues unless you also include the /boot
partition.
It would be nice though to think about what it would take to do this
"right". Seems like you could source from a single partition and
generate the proper MBR and partition table in the virtual machine image
without too much trouble. A cursory glance seems to indicate that the
vvfat format does something like this.
Thoughts?
- Orion
--- qemu-0.9.1/qemu-img.c.part 2008-01-06 12:38:42.000000000 -0700
+++ qemu-0.9.1/qemu-img.c 2008-10-09 16:46:47.000000000 -0600
@@ -411,7 +411,7 @@
const char *fmt, *out_fmt, *out_filename;
BlockDriver *drv;
BlockDriverState **bs, *out_bs;
- int64_t total_sectors, nb_sectors, sector_num, bs_offset;
+ int64_t total_sectors, nb_sectors, sector_num, bs_offset,
requested_sectors = 0;
uint64_t bs_sectors;
uint8_t buf[IO_BUF_SIZE];
const uint8_t *buf1;
@@ -421,7 +421,7 @@
out_fmt = "raw";
flags = 0;
for(;;) {
- c = getopt(argc, argv, "f:O:hce6");
+ c = getopt(argc, argv, "f:O:s:hce6");
if (c == -1)
break;
switch(c) {
@@ -434,6 +434,9 @@
case 'O':
out_fmt = optarg;
break;
+ case 's':
+ requested_sectors = atoll(optarg);
+ break;
case 'c':
flags |= BLOCK_FLAG_COMPRESS;
break;
@@ -464,6 +467,9 @@
total_sectors += bs_sectors;
}
+ if (requested_sectors)
+ total_sectors = requested_sectors;
+
drv = bdrv_find_format(out_fmt);
if (!drv)
error("Unknown file format '%s'", out_fmt);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] Converting installed windows (or ?) partition to virtual machine image
2008-10-10 2:41 [Qemu-devel] Converting installed windows (or ?) partition to virtual machine image orion
@ 2008-10-10 12:26 ` Johannes Schindelin
2008-10-11 1:03 ` andrzej zaborowski
0 siblings, 1 reply; 3+ messages in thread
From: Johannes Schindelin @ 2008-10-10 12:26 UTC (permalink / raw)
To: orion; +Cc: qemu-devel
Hi,
On Thu, 9 Oct 2008, orion@cora.nwra.com wrote:
> I'd like to try to convert the installed Windows partition of a dual
> boot machine into a virtual machine image. It seems like qemu-img
> currently only supports copying an entire disk (/dev/sda for example) to
> a disk image. It would be nice if one could specify a single partition.
>
> As a first hack/attempt to try this out, I'm trying the patch below
> (against 0.9.1) to only copy a certain number of sectors. Since the
> Windows partition is almost always the first partition on the disk,
> hopefully this will work for most folks. I guess if you've already
> installed grub you'll have issues unless you also include the /boot
> partition.
I think a better method would be to do something like this:
(dd if=/dev/zero bs=32256 count=1 && dd if=/dev/sda1) > disk.img
and then adding one partition with "fdisk disk.img". The 32256 is what is
commonly reserved before the first partition (this is where the mbr and
boot sector viruses live).
> It would be nice though to think about what it would take to do this
> "right". Seems like you could source from a single partition and
> generate the proper MBR and partition table in the virtual machine image
> without too much trouble. A cursory glance seems to indicate that the
> vvfat format does something like this.
vvfat does something completely different. It takes an existing directory
structure and simulates a VFAT partition from that, no matter what the
original file system was.
Ciao,
Dscho
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] Converting installed windows (or ?) partition to virtual machine image
2008-10-10 12:26 ` Johannes Schindelin
@ 2008-10-11 1:03 ` andrzej zaborowski
0 siblings, 0 replies; 3+ messages in thread
From: andrzej zaborowski @ 2008-10-11 1:03 UTC (permalink / raw)
To: qemu-devel; +Cc: orion
2008/10/10 Johannes Schindelin <Johannes.Schindelin@gmx.de>:
> On Thu, 9 Oct 2008, orion@cora.nwra.com wrote:
>> It would be nice though to think about what it would take to do this
>> "right". Seems like you could source from a single partition and
>> generate the proper MBR and partition table in the virtual machine image
>> without too much trouble. A cursory glance seems to indicate that the
>> vvfat format does something like this.
>
> vvfat does something completely different. It takes an existing directory
> structure and simulates a VFAT partition from that, no matter what the
> original file system was.
It simulates a filesystem and it simulates a whole disk with a valid
partition table and one partition in it, so yes, it does what is
wanted and it shouldn't be hard to replace the part that simulates the
filesystem with an existing partition or file.
Cheers
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-10-11 1:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-10 2:41 [Qemu-devel] Converting installed windows (or ?) partition to virtual machine image orion
2008-10-10 12:26 ` Johannes Schindelin
2008-10-11 1:03 ` andrzej zaborowski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).