Network boot with GRUB2

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
TryHarder
Member
Member
Posts: 28
Joined: Mon Aug 22, 2011 12:45 am

Network boot with GRUB2

Post by TryHarder »

Hey everybody,
I've brought up tftp server on my build machine (B), and I have GRUB2 at my work machine (W).
Obviously, I want to boot W from B via tftp. W has GRUB2 and several other OSes that I don't want to mess up, so
basically my question is how can I do that with single GRUB2 entry in menu?
I don't have DHCP, so let's say I will hardcode an IP of B. I'm looking for solution like this, but for GRUB2:
title Network Boot
# Obtain an IP address for this card
dhcp
# I don't have DHCP setup to deliver the TFTP server's IP address,
# so I set it manually this is my build machine
tftpserver 192.168.0.50
# The root device is the network
root (nd)
# My kernel is directly under the TFTP directory
kernel /kernel.exe
# I also load a module for testing out multitasking
module /module.exe
In GRUB2 manuals network booting section is a bit vague (for me)...
TryHarder
Member
Member
Posts: 28
Joined: Mon Aug 22, 2011 12:45 am

Re: Network boot with GRUB2

Post by TryHarder »

So silent here... Can't believe that nobody have to share something useful :(
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Network boot with GRUB2

Post by Brendan »

Hi,
TryHarder wrote:Hey everybody,
I've brought up tftp server on my build machine (B), and I have GRUB2 at my work machine (W).
Obviously, I want to boot W from B via tftp. W has GRUB2 and several other OSes that I don't want to mess up, so
basically my question is how can I do that with single GRUB2 entry in menu?
I don't have DHCP, so let's say I will hardcode an IP of B. I'm looking for solution like this, but for GRUB2:
I don't think many (any?) people have tried using network boot with GRUB2. I know I haven't.

The idea for network boot is that the firmware (or network card ROM) has a basic network card driver, UDP/IP stack, DHCP client and TFTP client. The firmware uses this to get DHCP information, and the server responds with DHCP that has an extra optional information (the IP address of the TFTP server to boot from, and the file name to download/boot).

For GRUB2 there'd be 3 different scenarios. The first is that GRUB2 boots from network and then boots the OS from network. In this case GRUB could use the firmware/network cards ROM's network driver, UDP/IP stack and TFTP client; but it gets messy if you want to use the "file name to download" from the DHCP server to tell GRUB2 what it should boot.

The next scenario is that GRUB2 boots from somewhere else (e.g. hard drive) and then boots the OS from network. This is what I think you're attempting. In this case GRUB2 can't use the firmware's/network cards ROM's network driver (because it didn't start from network itself so the PXE API isn't provided for it to use); and GRUB2 would need to have its own network card driver, DHCP client, UDP/IP stack and TFTP client. I'd assume GRUB2 is designed to allow these things to be loaded (as "GRUB modules") and used; but I don't know which network cards it supports, which "GRUB modules" you've enabled/installed, etc. I also don't know if GRUB2 actually does implement any of this (I'm only assuming it could).

The final scenario is that you don't use the network boot (e.g. DHCP, TFTP) at all; but instead GRUB2 downloads file/s to boot using FTP or HTTP. This is similar to the previous scenario (GRUB2 has to have drivers, etc) but requires more complex code in GRUB2 (TCP, FTP/HTTP). This would probably be the fastest option too; but I don't know if GRUB2 had the driver and code to support this either.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
TryHarder
Member
Member
Posts: 28
Joined: Mon Aug 22, 2011 12:45 am

Re: Network boot with GRUB2

Post by TryHarder »

Brendan,
Thank you for output (although it made me sad). You're right, I'm trying second scenario to work. One thing stays unclear for me:
In this case GRUB2 can't use the firmware's/network cards ROM's network driver (because it didn't start from network itself so the PXE API isn't provided for it to use);
What are the obstacles? As far as I understand, the fact that BIOS is configured to boot from network triggers the firmware code in NIC's ROM.
So, theoretically, why GRUB2 can't do the same? I mean, we have the relevant functionality hardcoded in NIC, so just use it to bring the relevant kernel image via TFTP! I'm not
familiar with PXE API and protocol, so maybe something is hiding out there.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Network boot with GRUB2

Post by Brendan »

Hi,
TryHarder wrote:
In this case GRUB2 can't use the firmware's/network cards ROM's network driver (because it didn't start from network itself so the PXE API isn't provided for it to use);
What are the obstacles?
The first problem will be finding all of the network card ROMs. This isn't too hard for PCI cards, but for "onboard ethernet" the code could be in the motherboard's firmware somewhere (and could be compressed somehow).

The next problem would be determining which specification the ROM is intended for (ISA ROM, Plug & Play BIOS specification, BIOS Boot Specification). Depending on the results of that, you end up with 2 or 3 different ways of starting the ROM (e.g. simulate POST so the ROM can hook Int 0x18 or Int 0x19; or try to extract a "Boot Entry Vector" from a Plug and Play header). Once you've done that you'd attempt to boot with each ROM until one of them works (while hoping the ROMs don't trash each other - e.g. hook the same interrupts in an incompatible way).

The next problem is that the network card's code will expect to be able to use RAM, and can/will trash any RAM you're using. You'd have to shift all your boot code above 0x10FFF0 just to be safe, but you also have to be in real mode(!).

Finally, if you work around all of that, the network card's ROM is designed to boot the computer - it won't return unless it fails to boot something else, and if it does return it'll uninstall itself first. Because of this, your boot loader won't be able to initialise the network card's ROM and then use the network card's ROM.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
TryHarder
Member
Member
Posts: 28
Joined: Mon Aug 22, 2011 12:45 am

Re: Network boot with GRUB2

Post by TryHarder »

Ok, now I see.... Thanks again Brendan.
Post Reply