Skip to contentSkip to conversation

installing a boot loader into the disk images

Qemu-devel Diego Iastrubni 6 participants 8 messages Sep 11, 2004 – Sep 12, 2004

lore
Share & tools
lore
#0 lore raw

Hi all

I am sorry if this if offtopic here, if it is, please point me to the correct location. (did not find a qemu-users list or something).

I am writing a new installation for linux distro, and I would like to test it on qemu before I do it on real HW.

I found some nice utilities to make a HD image from a a dir, and another one for mounting the image on the host, however they are not enough. I need a way to partition the HD image, and decide which partition will be (ext3 or swap for example), and most importat: I need to install from the host a boot loader on the HD image.

The last one is really tricky since last time I tried, lilo did not want to use a file, but it insisted on a real device. I did not try grub yet.

As anyone tried such things? how can I do this?

Signature · 6 lines
diego, kde-il translation team

Please avoid sending me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
Free MS-Office replacement for most platforms
http://www.openoffice.org/
#1 lore raw
Quoted 2 lines

I am sorry if this if offtopic here, if it is, please point me to the correct location. (did not find a qemu-users list or something).

I think the consensus is that the users list has some problems at the moment.

Quoted 8 lines

I found some nice utilities to make a HD image from a a dir, and another one for mounting the image on the host, however they are not enough. I need a way to partition the HD image, and decide which partition will be (ext3 or swap for example), and most importat: I need to install from the host a boot loader on the HD image.

The last one is really tricky since last time I tried, lilo did not want to use a file, but it insisted on a real device. I did not try grub yet.

I assume you're on a linux host: if it's just a raw HD image, use the losetup command to bind the image file to a loop block device (e.g. /dev/loop0), then install grub / lilo on that.

The loop block device is handy becuase it allows you to make a file appear as a block device to the rest of the OS. Unfortunately, it does not support partitions within the "file" device. There are patches available on the internet which if applied to your host kernel may enable this...

An alternative approach would be to get a working Linux install in QEmu, with two virtual hard drives - one containing the stock Linux distro, one containing your own. Then use the stock distro in QEmu to prepare the other disk...

HTH,
Mark

#2 lore raw

בשבת, 11 בספטמבר 2004, 16:18, נכתב על ידי Mark A. Williamson:

Quoted 8 lines

I assume you're on a linux host: if it's just a raw HD image, use the losetup command to bind the image file to a loop block device (e.g. /dev/loop0), then install grub / lilo on that.

The loop block device is handy becuase it allows you to make a file appear as a block device to the rest of the OS. Unfortunately, it does not support partitions within the "file" device. There are patches available on the internet which if applied to your host kernel may enable this...

Lets take this approach.

Now my problem is:
I use a disk with one partition. I put the kernel on thr proper location and install lilo/grub on it. Will this work? I think the boot loader will be looking for a normal setup, not this hack.

Another option is still is making a boot floppy, that will mount /dev/hda (the raw disk image) as /. (Thanks Tim).
http://rescuecd.sourceforge.net/288.html#grub

Anyway, you been more then helpfull. Thanks!

Signature · 6 lines
diego, kde-il translation team

Please avoid sending me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
Free MS-Office replacement for most platforms
http://www.openoffice.org/
#3 lore raw
Quoted 6 lines
Quoted 5 lines

The loop block device is handy becuase it allows you to make a file appear as a block device to the rest of the OS. Unfortunately, it does not support partitions within the "file" device. There are patches available on the internet which if applied to your host kernel may enable this...

Quoted 6 lines

Lets take this approach.

Now my problem is:
I use a disk with one partition. I put the kernel on thr proper location and install lilo/grub on it. Will this work? I think the boot loader will be looking for a normal setup, not this hack.

I skirted round this issue a bit ;-)

The loop device would make the file appear like a disk, so you could install a bootloader. You've still, unfortunately, got to get partitions onto it somehow.

A brief test suggests that fdisk will manipulate disk files directly, so you could probably partition your image using that. You will be able to losetup it then but the kernel won't see the partitions since loop block devices don't support partitions.

Depending on whether Lilo / Grub actually use the Linux partition support this may still be enough to allow an install to the loop device.

You'll have to figure out a way of getting files onto this disk image at some stage :-) Some possibilities:
* Use a distro running in QEmu to copy the files across (which it could in turn get from NFS, SAMBA, etc.)
* Patch your host kernel so that it understands partitions in loop devices
* Use losetup to individually map the partitions to loop devices, using the -o (offset) switch, then mount those. (I saw a script for doing this on a mailing list somewhere - Google knows)

Remember while doing all this to avoid having two "views" of the disk at once (e.g. avoid setups where the same part of the file appears at multiple mountpoints / devices simultaneously, since this may corrupt the image).

Cheers,
Mark

#4 lore raw

Hello,

Quoted 8 lines

You'll have to figure out a way of getting files onto this disk image at some stage :-) Some possibilities:
* Use a distro running in QEmu to copy the files across (which it could in turn get from NFS, SAMBA, etc.)
* Patch your host kernel so that it understands partitions in loop devices
* Use losetup to individually map the partitions to loop devices, using the -o (offset) switch, then mount those. (I saw a script for doing this on a mailing list somewhere - Google knows)

I've created a tool that makes it possible to create and populate filesystems (ext2/ext3/reiserfs right now) on a disk image. Scriptable without root permissions.

This tool is actually a small custom linux distribution (< 3 Mbytes) desigend to be executed in the QEMU environment. It is possible to pass a set of commands or a script to the QEMU environment for easy scripting. Files are transfered from the host to the guest with TFTP. Busybox fdisk is included (if I remember correctly that is), but no lilo/grub yet. You need a recent CVS snapshot of QEMU or 0.6.0 with a patch to get the tftp support.

I really would like to get this project out of my closet, one big problem right now is that the entire source code is so damn large (> 100 Mbytes) and I need a way to distribute that amount of data. I was thinking bittorrent, does anyone know a good tracker for FOSS?

Thanks!

/ magnus

#5 lore raw
In reply to Mark A. Williamson
Quoted 2 lines

An alternative approach would be to get a working Linux install in
QEmu, with two virtual hard drives - one containing the stock Linux distro, one containing your own. Then use the stock distro in QEmu to prepare the other disk...

Floppydistros may fit. I personally partition my disk images via a bootable Linux floppy containing the GNU PartEd. Never tried LILO or GRUB stuff, because I usually let the real distro to do the right job.
If you just need a bootloader (ANY bootloader), I use GAG (http://gag.sourceforge.net/) for real machines, and find it to be very practical. Its approach implies that there's nothing else than GAG itself in the MBR; so you'll have to tell your OS'es of choice to place their LILO/GRUB/whatever in the boot sector of their own partition, and nowhere else, while installing. This might seem odd, but I never encountered yet an OS that GAG can't start; and it's quite easy and quick to get back if corrupted or overwritten, say, by a Windows reinstallation.

	yo,
	RDO
#6 lore raw
In reply to Diego Iastrubni
Quoted 8 lines

I found some nice utilities to make a HD image from a a dir, and another one for mounting the image on the host, however they are not enough. I need a way to partition the HD image, and decide which partition will be (ext3 or swap for example), and most importat: I need to install from the host a boot loader on the HD image.

The last one is really tricky since last time I tried, lilo did not want to use a file, but it insisted on a real device. I did not try grub yet.

Well, you can always boot the blank image in conjunction with a boot floppy/cd and just do a normal install.

On the other hand, if you are really really wanting to do it from the host OS, I have found this link handy:

http://rescuecd.sourceforge.net/288.html#grub

hth,
tim

#7 lore raw
Quoted 5 lines · Tim
Quoted 3 lines

I found some nice utilities to make a HD image from a a dir, and another one for mounting the image on the host, however they are not enough. I need a way to partition the HD image, and decide which partition will be (ext3 or swap for example), and most importat: I need to install from the host a boot loader on the HD image.

The last one is really tricky since last time I tried, lilo did not want to use a file, but it insisted on a real device. I did not try grub yet.

Quoted 7 lines

Well, you can always boot the blank image in conjunction with a boot floppy/cd and just do a normal install.

On the other hand, if you are really really wanting to do it from the host OS, I have found this link handy:

http://rescuecd.sourceforge.net/288.html#grub

You can also use EVMS to partition the loop device. This is a complete replacement of lomount. But it's like (as Russians say) shooting sparrows from a big cannon.

Signature · 1 line
Alexander E. Patrakov