All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] Building a disk image?
@ 2005-07-04  3:11 Matt Lawrence
  2005-07-04 15:34 ` [Qemu-devel] " Ronald
  0 siblings, 1 reply; 10+ messages in thread
From: Matt Lawrence @ 2005-07-04  3:11 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 538 bytes --]






I'm trying to figure out how to script the creation of disk images for
qemu.  I've already scripted file system creation with user-mode-linux, so
once I can get the partitions created correctly, the rest should be easy.
Right now, when I do a qemu-img create and run fdisk on the file, I get the
message "You must set cylinders".  So, how to I figure out what to set them
to?  And then, how do I convince mke2fs to create a filesystem in the
partition?  Or, am I attacking this problem from the wrong direction?

-- Matt

[-- Attachment #2: Type: text/html, Size: 572 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Qemu-devel] Re: Building a disk image?
  2005-07-04  3:11 [Qemu-devel] Building a disk image? Matt Lawrence
@ 2005-07-04 15:34 ` Ronald
  2005-07-05 17:55   ` Matt Lawrence
  0 siblings, 1 reply; 10+ messages in thread
From: Ronald @ 2005-07-04 15:34 UTC (permalink / raw)
  To: qemu-devel

Le Sun, 03 Jul 2005 22:11:53 -0500, Matt Lawrence a écrit :

> I'm trying to figure out how to script the creation of disk images for
> qemu.  I've already scripted file system creation with user-mode-linux, so
> once I can get the partitions created correctly, the rest should be easy.
> Right now, when I do a qemu-img create and run fdisk on the file, I get the
> message "You must set cylinders".  So, how to I figure out what to set them
> to?  And then, how do I convince mke2fs to create a filesystem in the
> partition?  Or, am I attacking this problem from the wrong direction?

It's easier to use losetup to associate the image with a loop device ,
then create the partitions with your favorite tool.
Once the image is partitionned pass the offset option to losetup then
create swap or filesystems on /dev/loop?. 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] Re: Building a disk image?
  2005-07-04 15:34 ` [Qemu-devel] " Ronald
@ 2005-07-05 17:55   ` Matt Lawrence
  2005-07-05 19:12     ` [Qemu-devel] " Ronald
  2005-07-05 20:42     ` [Qemu-devel] " Jim C. Brown
  0 siblings, 2 replies; 10+ messages in thread
From: Matt Lawrence @ 2005-07-05 17:55 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1209 bytes --]






qemu-devel-bounces+mattlaw=us.ibm.com@nongnu.org wrote on 07/04/2005
10:34:35 AM:

> Le Sun, 03 Jul 2005 22:11:53 -0500, Matt Lawrence a écrit :
>
> > I'm trying to figure out how to script the creation of disk images for
> > qemu.  I've already scripted file system creation with user-mode-linux,
so
> > once I can get the partitions created correctly, the rest should be
easy.
> > Right now, when I do a qemu-img create and run fdisk on the file, I get
the
> > message "You must set cylinders".  So, how to I figure out what to set
them
> > to?  And then, how do I convince mke2fs to create a filesystem in the
> > partition?  Or, am I attacking this problem from the wrong direction?
>
> It's easier to use losetup to associate the image with a loop device ,
> then create the partitions with your favorite tool.
> Once the image is partitionned pass the offset option to losetup then
> create swap or filesystems on /dev/loop?.

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

[-- Attachment #2: Type: text/html, Size: 1436 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Qemu-devel] Re: Re: Building a disk image?
  2005-07-05 17:55   ` Matt Lawrence
@ 2005-07-05 19:12     ` Ronald
  2005-07-05 20:21       ` Matt Lawrence
  2005-07-05 20:42     ` [Qemu-devel] " Jim C. Brown
  1 sibling, 1 reply; 10+ messages in thread
From: Ronald @ 2005-07-05 19:12 UTC (permalink / raw)
  To: qemu-devel

Le Tue, 05 Jul 2005 12:55:49 -0500, Matt Lawrence a écrit :

> 
> 
> 
> 
> 
> qemu-devel-bounces+mattlaw=us.ibm.com@nongnu.org wrote on 07/04/2005
> 10:34:35 AM:
> 
>> Le Sun, 03 Jul 2005 22:11:53 -0500, Matt Lawrence a écrit :
>>
>> > I'm trying to figure out how to script the creation of disk images for
>> > qemu.  I've already scripted file system creation with user-mode-linux,
> so
>> > once I can get the partitions created correctly, the rest should be
> easy.
>> > Right now, when I do a qemu-img create and run fdisk on the file, I get
> the
>> > message "You must set cylinders".  So, how to I figure out what to set
> them
>> > to?  And then, how do I convince mke2fs to create a filesystem in the
>> > partition?  Or, am I attacking this problem from the wrong direction?
>>
>> It's easier to use losetup to associate the image with a loop device ,
>> then create the partitions with your favorite tool.
>> Once the image is partitionned pass the offset option to losetup then
>> create swap or filesystems on /dev/loop?.
> 
> 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.

ok, I'll try to write a step by step method :

( create a 512 MB disk image )

$ qemu-img create /mnt/emu/test.img 512M

( use losetup to bind the created file to a block device )

# losetup /dev/loop0 /mnt/emu/test.img

( fdisk /dev/loop0 )

# fdisk /dev/loop0

( here I create an extended partition and within it 2 logical one , first
will be swap (82) and second linux (83 this is default) )

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4): 1
First cylinder (1-65, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-65, default 65): 
Using default value 65

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (1-65, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-65, default 65): +64M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (10-65, default 10): 
Using default value 10
Last cylinder or +size or +sizeM or +sizeK (10-65, default 65): 
Using default value 65

Command (m for help): u
Changing display/entry units to sectors

Command (m for help): t
Partition number (1-6): 5
Hex code (type L to list codes): 82
Changed system type of partition 5 to 82 (Linux swap / Solaris)

Command (m for help): p

Disk /dev/loop0: 536 MB, 536870912 bytes
255 heads, 63 sectors/track, 65 cylinders, total 1048576 sectors
Units = sectors of 1 * 512 = 512 bytes

      Device Boot      Start         End      Blocks   Id  System
/dev/loop0p1              63     1044224      522081    5  Extended
/dev/loop0p5             126      144584       72229+  82  Linux swap / Solaris
/dev/loop0p6          144648     1044224      449788+  83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 22: Argument invalide.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

( notice the typed 'u' this change unit from cylinders to sectors )

( free the loop device )

# losetup -d /dev/loop0

( make swap on partition 5 ) 
# losetup -o $((512*126)) /dev/loop0 /mnt/emu/test.img 
# mkswap -L That_s_the_swap /dev/loop0
Setting up swapspace version 1, size = 536801 kB
LABEL=That_s_the_swap, UUID=619ada0f-53ed-4941-b72c-04243181d654

# losetup -d /dev/loop0 
# losetup -o $((512*144648)) /dev/loop0 /mnt/emu/test.img
#  mke2fs -b 1024 -L that_s_the_root /dev/loop0
mke2fs 1.37 (21-Mar-2005)
Étiquette de système de fichiers=that_s_the_root
Type de système d'exploitation: Linux
Taille de bloc=1024 (log=0)
Taille de fragment=1024 (log=0)
113344 inodes, 451964 blocs
22598 blocs (5.00%) réservé pour le super usager
Premier bloc de données=1
56 bloc de groupes
8192 blocs par groupe, 8192 fragments par groupe
2024 inodes par groupe
Archive du superbloc stockée sur les blocs: 
	8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Écriture des tables d'inodes: complété                        
Écriture des superblocs et de l'information de comptabilité du système de fichiers: complété

Le système de fichiers sera automatiquement vérifié tous les 28 montages ou après
180 jours, selon la première éventualité.  Utiliser tune2fs -c ou -i
pour écraser la valeur.

# losetup -d /dev/loop0
# mount -o loop,offset=$((512*144648)) /mnt/emu/test.img /mnt/loop
# pushd /mnt/loop/
# tar -xzf /mnt/config/Images/fullroot.libc5.tgz
# umount /mnt/loop
# popd

to install a boot loader (grub for me on x86) , I use a standard floppy
to boot and install ( using an image is possible too ) , maybe there is a
better way to do.

I hope I don't forget anything nor made a mistake in copy/paste somewhere.

> -- 
> Matt

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] Re: Re: Building a disk image?
  2005-07-05 19:12     ` [Qemu-devel] " Ronald
@ 2005-07-05 20:21       ` Matt Lawrence
  0 siblings, 0 replies; 10+ messages in thread
From: Matt Lawrence @ 2005-07-05 20:21 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 686 bytes --]





qemu-devel-bounces+mattlaw=us.ibm.com@nongnu.org wrote on 07/05/2005
02:12:30 PM:

> > 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.
>
> ok, I'll try to write a step by step method :
>
> ( create a 512 MB disk image )
>
> $ qemu-img create /mnt/emu/test.img 512M
>
> ( use losetup to bind the created file to a block device )
>
> # losetup /dev/loop0 /mnt/emu/test.img

That's what I was doing wrong!  I was trying to use fdisk on test.img.
Thank you, thank you, thank you!!!!

-- Matt

[-- Attachment #2: Type: text/html, Size: 900 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] Re: Building a disk image?
  2005-07-05 17:55   ` Matt Lawrence
  2005-07-05 19:12     ` [Qemu-devel] " Ronald
@ 2005-07-05 20:42     ` Jim C. Brown
  2005-07-06  1:09       ` Magnus Damm
  1 sibling, 1 reply; 10+ messages in thread
From: Jim C. Brown @ 2005-07-05 20:42 UTC (permalink / raw)
  To: qemu-devel

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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] Re: Building a disk image?
  2005-07-05 20:42     ` [Qemu-devel] " Jim C. Brown
@ 2005-07-06  1:09       ` Magnus Damm
  2005-07-06 23:57         ` Jim C. Brown
  0 siblings, 1 reply; 10+ messages in thread
From: Magnus Damm @ 2005-07-06  1:09 UTC (permalink / raw)
  To: qemu-devel

On 7/6/05, Jim C. Brown <jma5@umd.edu> wrote:
> 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.

One solution for that problem would be to access the images through
qemu. My little tool fsimage does that for you, but no bootloader is
included for now. If there is enough interest then I would be happy to
add new features such as bootloaders.

http://lists.gnu.org/archive/html/qemu-devel/2005-03/msg00106.html

/ magnus

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] Re: Building a disk image?
  2005-07-06  1:09       ` Magnus Damm
@ 2005-07-06 23:57         ` Jim C. Brown
  2005-07-07  1:53           ` Magnus Damm
  0 siblings, 1 reply; 10+ messages in thread
From: Jim C. Brown @ 2005-07-06 23:57 UTC (permalink / raw)
  To: Magnus Damm, qemu-devel

On Wed, Jul 06, 2005 at 10:09:50AM +0900, Magnus Damm wrote:
> One solution for that problem would be to access the images through
> qemu. My little tool fsimage does that for you, but no bootloader is
> included for now. If there is enough interest then I would be happy to
> add new features such as bootloaders.
> 
> http://lists.gnu.org/archive/html/qemu-devel/2005-03/msg00106.html
> 
> / magnus
> 

This is quite clever. I don't see the sources for fsimage (the host program)
anywhere though - it would be a lot more useful if one could tinker with both
the host and the guest sides. This can be made to cover everything except
resizing qcow images (and there is already work on that particular front
elsewhere).

Could be especially useful for manipulating disk images on Windows hosts.

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] Re: Building a disk image?
  2005-07-06 23:57         ` Jim C. Brown
@ 2005-07-07  1:53           ` Magnus Damm
  2005-07-10  5:11             ` Henrik Nordstrom
  0 siblings, 1 reply; 10+ messages in thread
From: Magnus Damm @ 2005-07-07  1:53 UTC (permalink / raw)
  To: Jim C. Brown; +Cc: qemu-devel

On 7/7/05, Jim C. Brown <jma5@umd.edu> wrote:
> This is quite clever. I don't see the sources for fsimage (the host program)
> anywhere though - it would be a lot more useful if one could tinker with both
> the host and the guest sides. This can be made to cover everything except
> resizing qcow images (and there is already work on that particular front
> elsewhere).

The goal was to build a small distribution that could be used to
modify filesystems in a host-independent way, without root
permissions. But now I find myself using fsimage for all kinds of
tasks, kernel programming, booting laptops without cdroms etc. So
yeah, thanks, I actually think it is pretty clever too.  =)

But the source for the host program _is_ included, or rather, the host
program is a shell script.

And, another cool thing is that it comes with full source code. So
people that want to tinker with it could download
fsimage-0.1.2-guest-src.tar.gz and type configure, make and make
install. Download from:

http://www.smallworks.com/~jim/fsimage/

> Could be especially useful for manipulating disk images on Windows hosts.

Yep, as long as the tftp server path prefix thing gets sorted out then
I think everything will be ok. But it depends on a bourne shell right
now, maybe it is better to replace the shell script with c code that
can be compiled for both *nix and windows.

/ magnus

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] Re: Building a disk image?
  2005-07-07  1:53           ` Magnus Damm
@ 2005-07-10  5:11             ` Henrik Nordstrom
  0 siblings, 0 replies; 10+ messages in thread
From: Henrik Nordstrom @ 2005-07-10  5:11 UTC (permalink / raw)
  To: Magnus Damm, qemu-devel; +Cc: Jim C. Brown

On Thu, 7 Jul 2005, Magnus Damm wrote:

> And, another cool thing is that it comes with full source code. So
> people that want to tinker with it could download
> fsimage-0.1.2-guest-src.tar.gz and type configure, make and make
> install. Download from:
>
> http://www.smallworks.com/~jim/fsimage/

Personally I use e2fsimage for building ext2 images, and then dump the 
filesystem image at the desired offset in the drive image with dd.

But this is with raw images.

> Yep, as long as the tftp server path prefix thing gets sorted out then
> I think everything will be ok. But it depends on a bourne shell right
> now, maybe it is better to replace the shell script with c code that
> can be compiled for both *nix and windows.

cygwin or mingw both have good shells for windows users..

Regards
Henrik

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2005-07-10  5:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-04  3:11 [Qemu-devel] Building a disk image? Matt Lawrence
2005-07-04 15:34 ` [Qemu-devel] " Ronald
2005-07-05 17:55   ` Matt Lawrence
2005-07-05 19:12     ` [Qemu-devel] " Ronald
2005-07-05 20:21       ` Matt Lawrence
2005-07-05 20:42     ` [Qemu-devel] " Jim C. Brown
2005-07-06  1:09       ` Magnus Damm
2005-07-06 23:57         ` Jim C. Brown
2005-07-07  1:53           ` Magnus Damm
2005-07-10  5:11             ` Henrik Nordstrom

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.