qemu-devel
[Top][All Lists]
Advanced

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

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


From: Ronald
Subject: [Qemu-devel] Re: Re: Building a disk image?
Date: Tue, 05 Jul 2005 21:12:30 +0200
User-agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.)

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

> 
> 
> 
> 
> 
> address@hidden 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





reply via email to

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