QEMU not booting my image

hello all,
I have been trying to boot an image (.IMG) using qemu, for quite some time now and i can't seem to get it to work. I've been able to boot from the Windows XP CD, the Debian iso image, etc, so I know qemu is configured properly and is working. But when it come to booting an image that I created, it just doesn't work. I have tried creating an image with only the grub files, and qemu does not seem to even recognize the image as a bootable image. The result I get when trying to boot from the latter, is the same result I get if I just type the command "qemu" without any options. The image in question is attached below.

Please tell us exactly how you're running qemu, word for word, letter for letter, keystroke for keystroke.

There's more to using grub than just putting the files on it. How did you install grub? again: word for word, letter for letter, keystroke for keystroke.

You might also be putting the files one dir in too deep, boot/grub/ instead of just grub/. I often see people make a symlink boot -> . so they can put them directly in grub, letting either option work.

For that matter, I can't remember ever seeing grub used in a situation without partitions, and I'm not sure where to proceed on that. You might do better to get an image for a working grub floppy, or perhaps a USB booting thing, then modify it to your needs.

I looked at your test.img using

xxd test.img | less

It is not a bootable image. That would appear to be the reason that QEMU will not boot the image.

ok I found these step on how to make a bootable image:

$ cd /usr/lib/grub/i386-pc
$ dd if=stage1 of=image.img bs=512 count=1
1+0 records in
1+0 records out
$ dd if=stage2 of=image.img bs=512 seek=1
153+1 records in
153+1 records out
$

But is this correct and if it is will I be able to freely add files afterwards?

Sort of. You didn't need to create image.img in the current directory, and probably shouldn't, and didn't need to run any of that as root. It also only creates a 105KB file, not a 1440KB file, so I'd modify it a little:

cd /usr/lib/grub/i386-pc
# make a completely blank disk image
dd if=/dev/zero of=~/image.img bs=512 count=2880
# copy the boot sector onto it.  "conv=notrunc" tells it not to shrink the file.
dd if=stage1 of=~/image.img conv=notrunc bs=512
# copy stage2 onto it
dd if=stage2 of=~/image.img conv=notrunc seek=1 bs=512

My system has them in /lib/grub/, not /usr/lib/grub incidentally, but systems do differ. "bs=512" is redundant since dd defaults to that but it doesn't hurt anything.

It contains no filesystem, there's nothing to add files to. It would only boot to a grub prompt.

But it should almost certainly be a valid boot disk image, with which you can test qemu.

---------- Post updated at 12:13 PM ---------- Previous update was at 12:05 PM ----------

[edit] the below instructions didn't work because the grub utility can't install on a floppy that way. argh.

But the reason I want to get this working is so that I can load some modules, therefore I need to add files to the image.

How about you tell us what your ultimate goal is, not just what your problem of the millisecond is, so we can guide you in the right direction now instead of when we finally find out where you're trying to go. You spent a long time making an ext2 disk image when that turned out not to be what you needed...

ok, basically I am compiling a kernel and some modules, then I intend to boot it. The instructions here are what I'm trying to follow but they don't work. I've only gotten as far as compiling the kernel.

Exactly what instructions do not work for you?

Are you on a 32-bit or 64-bit OS?

I'm on a 32-bit system and basically all the instructions work, except for the fact that the image does not boot. qemu just seems to not even recognize the image as being bootable.

How are you checking to ensure that you have a bootable image? What is the output of

dd if=<your image> bs=512 count=1 | xxd

I used the instructions given by corona688 an obtained an image that produced this when executing the command:

#dd if=the_image.img bs=512 count=1 | xxd
0000000: eb48 9000 0000 0000 0000 0000 0000 0000  .H..............
0000010: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000020: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000030: 0000 0000 0000 0000 0000 0000 0000 0302  ................
0000040: ff00 0080 0100 0000 0008 faeb 07f6 c280  ................
0000050: 7502 b280 ea59 7c00 0031 c08e d88e d0bc  u....Y|..1......
0000060: 0020 fba0 407c 3cff 7402 88c2 52be 7f7d  . ..@|<.t...R..}
0000070: e834 01f6 c280 7454 b441 bbaa 55cd 135a  .4....tT.A..U..Z
0000080: 5272 4981 fb55 aa75 43a0 417c 84c0 7505  RrI..U.uC.A|..u.
0000090: 83e1 0174 3766 8b4c 10be 057c c644 ff01  ...t7f.L...|.D..
00000a0: 668b 1e44 7cc7 0410 00c7 4402 0100 6689  f..D|.....D...f.
00000b0: 5c08 c744 0600 7066 31c0 8944 0466 8944  \..D..pf1..D.f.D
00000c0: 0cb4 42cd 1372 05bb 0070 eb7d b408 cd13  ..B..r...p.}....
00000d0: 730a f6c2 800f 84ea 00e9 8d00 be05 7cc6  s.............|.
00000e0: 44ff 0066 31c0 88f0 4066 8944 0431 d288  D..f1...@f.D.1..
00000f0: cac1 e202 88e8 88f4 4089 4408 31c0 88d0  ........@.D.1...
0000100: c0e8 0266 8904 66a1 447c 6631 d266 f734  ...f..f.D|f1.f.4
0000110: 8854 0a66 31d2 66f7 7404 8854 0b89 440c  .T.f1.f.t..T..D.
0000120: 3b44 087d 3c8a 540d c0e2 068a 4c0a fec1  ;D.}<.T.....L...
0000130: 08d1 8a6c 0c5a 8a74 0bbb 0070 8ec3 31db  ...l.Z.t...p..1.
0000140: b801 02cd 1372 2a8c c38e 0648 7c60 1eb9  .....r*....H|`..
0000150: 0001 8edb 31f6 31ff fcf3 a51f 61ff 2642  ....1.1.....a.&B
0000160: 7cbe 857d e840 00eb 0ebe 8a7d e838 00eb  |..}.@.....}.8..
0000170: 06be 947d e830 00be 997d e82a 00eb fe47  ...}.0...}.*...G
0000180: 5255 4220 0047 656f 6d00 4861 7264 2044  RUB .Geom.Hard D
0000190: 6973 6b00 5265 6164 0020 4572 726f 7200  isk.Read. Error.
00001a0: bb01 00b4 0ecd 10ac 3c00 75f4 c300 0000  ........<.u.....
00001b0: 0000 0000 0000 0000 0000 0000 0000 2412  ..............$.
00001c0: 0f09 00be bd7d 31c0 cd13 468a 0c80 f900  .....}1...F.....
00001d0: 750f beda 7de8 cfff eb9d 466c 6f70 7079  u...}.....Floppy
00001e0: 00bb 0070 b801 02b5 00b6 00cd 1372 d7b6  ...p.........r..
00001f0: 01b5 4fe9 e6fe 0000 0000 0000 0000 55aa  ..O...........U.

But like I said I need to add files to the image, because I want to boot a kernel. However, this method does not allow me to do so.

What I usually do, instead of building bootable things from scratch, is adapt existing ones. I usually use boot ISO's, not floppies, since they can actually hold an entire kernel. Give me a bit and I'll craft an example for you.

That's a good option, but I'll still like you to tell me how to make one. But if you can make one for me just for me to get my project going I'd appreciate it. Here are the files to be included:

There's so many fiddly things in any boot process that it's best to start from a working example than build your own from scratch, I think. When your own goes wrong, it can't tell you why. When modifying an existing one, you can keep making changes until you do something that breaks it, then undo what you did and learn.

I'm making a script that builds one out of files I borrowed from a gentoo disk, with some basic files to boot into. when it works I'll tar it up and upload somewhere.

Here is a basic script which builds a small image with just GRUB Legacy on it and uses QEMU to test if the image boots. It is for Fedora 14 X64. All you need to do is change GRUBFILEDIR to point to the directory containing your GRUB stage{1,2} files.

#!/bin/bash
#
#  Create a bootable image containing just Legacy Grub
#  and use QEMU to test boot it if requested
#

if (( $(id -u) != 0 ))
then
    echo "ERROR: This script must be run as root" 1>&2
    exit 1
fi

GRUBFILEDIR=/usr/share/grub/x86_64-redhat
IMAGE=myimage
LOOPDEV=$(/sbin/losetup -f)

dd if=/dev/zero of=${IMAGE}.img bs=512 count=2880

if [[ -d ${IMAGE} ]]
then
    rm -rf ${IMAGE}
fi
mkdir -p ${IMAGE}/boot/grub

cp ${GRUBFILEDIR}/stage1 ${IMAGE}/boot/grub
cp ${GRUBFILEDIR}/stage2 ${IMAGE}/boot/grub

/sbin/losetup ${LOOPDEV} ${IMAGE}.img
/sbin/mke2fs ${LOOPDEV}
mount ${LOOPDEV} -o loop /mnt
chmod 777 /mnt
cp -aR ${IMAGE}/* /mnt
umount /mnt
cat <<EOF | /sbin/grub --batch --device-map=/dev/null
device (fd0) ${LOOPDEV}
root (fd0)
setup (fd0)
quit
EOF

/sbin/losetup -d ${LOOPDEV}

read -n1 -p "Use QEMU to boot the image (Y/N) "
echo
if [[ $REPLY = [yY] ]]
then
    qemu  -fda ${IMAGE}.img
fi

exit 0

You can easily extend it to include a kernel and other binaries.

He could have done that with my disk image too but refused to try it... Not like a modern, 4-meg linux kernel will fit on a 1.44 floppy either.

Hey I never refused I said I'd appreciate it, I even uploaded the files to be included in the image. I said I wanted to know because, it's always good to know how to fish, if you know what I mean.

I meant the basic grub image that couldn't contain files. Right now we don't even know if you're running qemu correctly :stuck_out_tongue:

I'm uploading an image maker thing.

---------- Post updated at 04:05 PM ---------- Previous update was at 03:55 PM ----------

http://burningsmell.org/mkisoboot.tar.gz

You have to extract it as root since it contains device files, so be careful not to extract it anywhere insane. tar -zxf ./mkisoboot.tar.gz

Once extracted you can just run ./mkisoboot.sh (this does not need to be done as root) and it will go through all the steps of turning the stuff in initramfs/ into linux's root ramdisk, then everything in cdimage/ into boot.iso, which I burned and booted on my end. It boots memtest86 by default, but if you enter 'linux' instead it will boot to the ramdisk.

It contains the following stuff:

cdimage/
        stuff that will appear in the raw CD image -- all bootloader stuff.

cdimage/isolinux/
        dump kernels, initrds, menus, etc. into here, so isolinux can find them.

cdimage/isolinux/vmlinuz
        A 32-bit x86 linux kernel copied from one of my systems.  It probably
        runs better on AMD than Intel, substitute with one of your choice.

cdimage/isolinux/memtest86
        just another example kernel.

initramfs/
        stuff that will appear in root when Linux boots.  Dump your own stuff
        in here.  Replace initramfs/init with a script of your choosing to make it
        boot your init script instead of mine.

        I put busybox, nano, and bash in it, all compiled to run safely on
        most 32-bit processors.  I didn't put anything kernel-specific
        in it, so it shouldn't puke when you replace vmlinuz with a kernel
        better suited to you.

mkisoboot.sh
        turns initramfs/ into cdimage/isolinux/init.gz, then turns cdimage/ into
        boot.iso.

clean.sh
        removes boot.iso and cdimage/isolinux/init.gz

OK, I'm kinda new to all this stuff and, I'm not quite sure I could "fill" all these requirements. My entire project at this point just consists of four modules. It's basically an L4 microkernel test run, sorry if I gave the idea that it was a Linux kernel.