Skip to contentSkip to conversation

Using GRUB2 for booting from CD

DISCUSSION Alex Roman 4 participants 11 messages Aug 12, 2007 – Nov 10, 2007

lore
Share & tools
lore

Alex Roman

author
#0 lore raw

Hello list,

I've managed to (finally :( ) use GRUB2 as a bootloader on a CD-ROM. It loads the kernel and all modules I tell grub-mkimage to include.

The problem is that it doens't know how to mount the root to be able to load other modules, read configuration files, etc. There is an iso9660 already there, but how can I tell grub2 to actually mount the CD-ROM drive as an iso9660 filesystem?

Thanks!

Signature · 1 line
Alex Roman <[email protected]>
#1 lore raw

"Alex Roman" <[email protected]> writes:

Hi,

Quoted 7 lines

I've managed to (finally :( ) use GRUB2 as a bootloader on a CD-ROM. It loads the kernel and all modules I tell grub-mkimage to include.

The problem is that it doens't know how to mount the root to be able to load other modules, read configuration files, etc. There is an iso9660 already there, but how can I tell grub2 to actually mount the CD-ROM drive as an iso9660 filesystem?

Does this mean you implemented IDE support, etc? :-)

The filesystem should automatically be detected. What you can do is dumping the first sector of the CDROM to see if it is read correctly.

Have a look at grub_iso9660_mount. It first tries to read the superblock. Next it does is checking if it is actually an ISO9660 filesystem (by checking for "CD001"). This function should reach "return data" if it is indeed a ISO9660 filesystem.

What you could do first is checking if grub-emu can read your filesystem image. That way you can easily see if the problem is in my code or in your code.

--
Marco

author
#2 lore raw
Quoted 3 lines · Marco Gerards

"Alex Roman" <[email protected]> writes:

Does this mean you implemented IDE support, etc? :-)

Not yet :( but that's coming :)

I'm doing it the Grub Legacy way of having a "stage 1" specifically for CD-ROM booting. So, instead of using diskboot.S, for "disk" booting, I use a cdboot.S which loads the kernel at the right address and boots it.

Quoted 8 lines

The filesystem should automatically be detected. What you can do is dumping the first sector of the CDROM to see if it is read correctly.

Have a look at grub_iso9660_mount. It first tries to read the superblock. Next it does is checking if it is actually an ISO9660 filesystem (by checking for "CD001"). This function should reach "return data" if it is indeed a ISO9660 filesystem.

I've been adding some debug prints in there...

I've modified biosdisk.c to recognize drives like (cd0) which basically start at 0xe0 and have no partitions.

When I try to do something like ls (cd0)/, QEMU freezes (and I don't see the prints I added), bochs quickly resets (and if the prints do show up, I don't have time to see them before it resets)... :( I'll probably step through with gdb or something...

Quoted 4 lines

What you could do first is checking if grub-emu can read your filesystem image. That way you can easily see if the problem is in my code or in your code.

How can I use grub-emu with a CD-ROM image?

Thanks!

Signature · 1 line
Alex Roman <[email protected]>
author
#3 lore raw

OK, I've done the following in grub-emu...

I have a map file that looks like this:
(fd0) floppy.img
(cd0) grub2-iso.iso

grub2-iso.iso is an iso I generate using genisoimage (mkisofs). I can mount it just fine.

floppy.img is a floppy image I generate... It contains grub, basically and a few modules.

I run grub-emu -d grub2 -m mapfile -r fd0

grub2 is my build directory.

I tried ls (cd0)/ but that did not work. The iso9660_mount function is saying that it couldn't read the superblock.

Then I saw on your (Marco) blog about the loopback command. So I tried it as follows:

loopback cd1 (host)/path/to/grub2-iso.iso

Now, ls (cd1)/ goes a bit further, it can read the superblock, but it says it couldn't find the magic "CD001". I printed the data it reads from the ISO and it's all 0's...

Am I doing anything wrong from what you can see here? I'd like to know if it's something I'm doing wrong in my procedure or in my code...

Thanks!

Signature · 1 line
Alex Roman <[email protected]>
#4 lore raw

At Mon, 13 Aug 2007 20:40:27 -0400,

Quoted 25 lines · Alex Roman

OK, I've done the following in grub-emu...

I have a map file that looks like this:
(fd0) floppy.img
(cd0) grub2-iso.iso

grub2-iso.iso is an iso I generate using genisoimage (mkisofs). I can mount it just fine.

floppy.img is a floppy image I generate... It contains grub, basically and a few modules.

I run grub-emu -d grub2 -m mapfile -r fd0

grub2 is my build directory.

I tried ls (cd0)/ but that did not work. The iso9660_mount function is saying that it couldn't read the superblock.

Then I saw on your (Marco) blog about the loopback command. So I tried it as follows:

loopback cd1 (host)/path/to/grub2-iso.iso

Quoted 7 lines

Now, ls (cd1)/ goes a bit further, it can read the superblock, but it says it couldn't find the magic "CD001". I printed the data it reads from the ISO and it's all 0's...

Am I doing anything wrong from what you can see here? I'd like to know if it's something I'm doing wrong in my procedure or in my code...

Read what's in the file directly and compare it to what grub-emu reads. If it reads something different than that's a bug in the grub-emu or loopback code.

Also don't forget about the possiblity that qemu might be buggy, especially if you're using bios functions that aren't really used that much. Testing on real hardware is really necessary sometimes.

And whether your code is wrong or not is very difficult to tell if you don't post your code...

Jeroen Dekkers

author
#5 lore raw
Quoted 3 lines · Jeroen Dekkers

Read what's in the file directly and compare it to what grub-emu reads. If it reads something different than that's a bug in the grub-emu or loopback code.

It reads something different... I just wanted to make sure I was using the right procedure...

Quoted 3 lines

Also don't forget about the possiblity that qemu might be buggy, especially if you're using bios functions that aren't really used that much. Testing on real hardware is really necessary sometimes.

Yes, I've gotten it to work farther along... It starts querying the CD-ROM device for information... The problem right now is that the c/h/s values that bochs/qemu returns when doing a diskinfo int13 extension check are all 0xFFFFFFFF... Same code on VMWare doesn't work because it seems that VMWare doesn't support that EDD extensions on their CD-ROM drive :(... I'll try it on my main PC today and let you know.

Quoted 2 lines

And whether your code is wrong or not is very difficult to tell if you don't post your code...

I wanted to see if the procedure is right... :)

Thanks!

Signature · 1 line
Alex Roman <[email protected]>
#6 lore raw

At Wed, 15 Aug 2007 09:54:58 -0400,

Quoted 6 lines · Alex Roman
Quoted 3 lines · Jeroen Dekkers

Also don't forget about the possiblity that qemu might be buggy, especially if you're using bios functions that aren't really used that much. Testing on real hardware is really necessary sometimes.

Quoted 7 lines

Yes, I've gotten it to work farther along... It starts querying the CD-ROM device for information... The problem right now is that the c/h/s values that bochs/qemu returns when doing a diskinfo int13 extension check are all 0xFFFFFFFF... Same code on VMWare doesn't work because it seems that VMWare doesn't support that EDD extensions on their CD-ROM drive :(... I'll try it on my main PC today and let you know.

Why are you using CHS and not LBA?

Jeroen Dekkers

author
#7 lore raw
Quoted 2 lines · Jeroen Dekkers

Why are you using CHS and not LBA?

The get diskinfo int13 extension will return a grub_biosdisk_drp structure which contains the c/h/s values along with the total number of sectors...

On my PC it looks like the drive number is different, I'm going to try to find the right drive number and query it to see what kind of response I get.

Basically the problem that happens is that the size of the CD is not read correctly, so at the kern/disk.c layer the reads are not even attempted because they "look" out of range, thus causing the iso9660 detection to fail.

I'll also try to fake the size of the CD to see if that helps...

Signature · 1 line
Alex Roman <[email protected]>
#8 lore raw
In reply to Alex Roman
Quoted 6 lines · Alex Roman
Quoted 3 lines · Marco Gerards

"Alex Roman" <[email protected]> writes:

Does this mean you implemented IDE support, etc? :-)

Not yet :( but that's coming :)

I heard from Patrick Georgi on IRC (CCed) that he already has an ATAPI implementation for GRUB as part of his LinuxBIOS work. Maybe you should coordinate with him so that the code can be shared with pc/bios targets.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)
author
#9 lore raw
Quoted 3 lines · Robert Millan

I heard from Patrick Georgi on IRC (CCed) that he already has an ATAPI implementation for GRUB as part of his LinuxBIOS work. Maybe you should coordinate with him so that the code can be shared with pc/bios targets.

Awesome, perhaps we'll be able to get it going after Summer of Code is finished and all is integrated in the CVS, or if Patrick can post a patch that'd work too.

Thanks!

Signature · 1 line
Alex Roman <[email protected]>
#10 lore raw

"Alex Roman" <[email protected]> writes:

Hi Alex,

Quoted 8 lines · Robert Millan
Quoted 3 lines

I heard from Patrick Georgi on IRC (CCed) that he already has an ATAPI implementation for GRUB as part of his LinuxBIOS work. Maybe you should coordinate with him so that the code can be shared with pc/bios targets.

Awesome, perhaps we'll be able to get it going after Summer of Code is finished and all is integrated in the CVS, or if Patrick can post a patch that'd work too.

Did you send in a patch+Changelog entry with your work?

I would be happy to review it so we can integrate your work soon.

--
Marco