qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] Re: Building a disk image?


From: Jim C. Brown
Subject: Re: [Qemu-devel] Re: Building a disk image?
Date: Tue, 5 Jul 2005 16:42:09 -0400
User-agent: Mutt/1.4i

On Tue, Jul 05, 2005 at 12:55:49PM -0500, Matt Lawrence wrote:
> I guess I don't don't quite understand how to get the partition table set
> up correctly with losetup.  It looks like another issue.  Also, how do I
> get the bootloader configured correctly in a disk image?  I'm still a bit
> confused.
> 
> -- Matt

First of all, losetup will not work with qcow images. You will need to use
raw images if you want to be able to use losetup. fdisk (and cfdisk and sfdisk)
have the same restriction.

The number of heads should be 16 and the number of sectors should be 63, unless
you know what you are doing. (It is ok to use different values for these
sometimes, but thats a topic for another thread.) The number of cylinders is
then (desired size)/(heads*sectors*512) rounded to the highest integer. (The
512 represents the number of bytes in a single sector - do not use a different
value unless you really know what you are doing.) The size you want to pass to
qemu-img is then cylinders*head*sectors*/2 (the reason that you divide the size
by 2 is because cylinders*head*sectors is in 512, or in half kilobytes, but
qemu-img wants full kilobytes).

qemu-img create -f raw image.img cylinders*head*sectors*/2

Now that you have the image, you need to create the partition table and
the file systems.

sfdisk -C cylinders -H heads -S sectors image.img

At this point, things will get tricky. To create the filesystem on any 
particular
partion, you need to know its offset in the hard disk image. Calculating this
by reading the image.img as a file is not trivial.

losetup -o NN /dev/loop0 image.img (where NN is the offset for that partition)
mkfs -t ext2 /dev/loop0
losetup -d /dev/loop0

This must be done for each partition you want to place a filesystem on. It
is possible to calculate the offset from the output of sfdisk, but it is a
good exercise of shell script programming.

Finally, you will need to install the bootloader. This is bootloader
dependent - I am only familiar on how to install lilo. If you want to use
a different bootloader then you will have to read its documentation.

Create a lilo config file, call it qlilo.conf, set it up normally as you would
in all other ways except set the install device to /dev/loop0 
("boot=/dev/loop0")
and then install lilo.

losetup /dev/loop0 image.img
/sbin/lilo -C qlilo.conf
losetup -d /dev/loop0

Then you are finished. (Note - you may want to fiddle with qlilo.conf some more,
such as using a different map file or something. That's up to you.)

-- 
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]