~
~
:wq

Sunday, 12 December 2010

gPXE boot from Grub2

spanish version - all english posts

The problem that I'm facing is that I need to boot a PC in a LTSP's environment to do some debugging and testing. Unfortunately, the PXE's BIOS functionality of that PC seems to be broken.

In case you need to boot a thinclient via PXE but its firmware doesn't support that function, you can solve the problem with gPXE as long as the network card is recognized as a PCI device (sadly that doesn't work if the device is PCMCIA or USB on most occasions). Also you'll must have a block device where to install grub (in this case grub2).

As I don't want to loose the data in that PC, installing gPXE directly in the HD (and thus converting the PC in a thinclient) is not an option. That would have been done by:

dd if=gPXE-for-usb.img of=/dev/sda

Don't do that ;-)

I know I can use a gPXE image for USB or CD, but that is a bit odd. The best option for me is to add an entry tro grub, so I can choose at grub menu to boot into my PC's own OS or doing a netboot.

Hands on!

The first thing we will do is getting a gPXE image from rom-o-matic.net. In order to get it we'll leave the default options as they are, and we'll just specify that the type of image we want is a «Linux kernel bootable image (.lkrn)»

Once we have it, we'll put the resulting .lkrn image at /boot/ directory:

/boot/gpxe-1.0.1-gpxe.lkrn

The way of working with grub2 is quite different from the classic grub; now we cannot edit a menu.lst. Instead, to add new entries in the grub menu we'll have to edit the file /etc/grub.d/40_custom (at least for debian or ubuntu).

We will edit /etc/grub.d/40_custom as follows:

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry "gPXE boot" {
linux16 /boot/gpxe-1.0.1-gpxe.lkrn
}

Finally execute update-grub2 that will update /boot/grub/grub.cfg:

update-grub2

In the next restart we will be able to choose the network boot option from the Grub menu.

7 comments:

  1. you my friend are a legend!

    ReplyDelete
  2. Just very useful! perfect, its the solution for old computers with no PXE availability!

    ReplyDelete
  3. I got a file not found error when I did this at first.
    The trick was to not include /boot, just have the line like this:
    linux16 /gpxe-1.0.1-gpxe.lkrn

    ReplyDelete
  4. iPXE has replaced gPXE, but this should still work. Download the iPXE .lkrn instead

    http://boot.salstar.sk/ipxe/

    ReplyDelete
  5. UEFI requires grub2. Grub2 doesn't support linux16. iPXE requires linux16. Memtest faces the same issue, but memtest v5 finally addresses (supposedly).
    Lots of folks talking about second and third tier booting "possibilities", but I'm so ux illiterate - I haven't even comprehended what the difference between a bootloader and bootstrap is.
    I know this isn't a forum - just dreaming this post could have a successor.

    ReplyDelete
  6. UEFI requires grub2. Grub2 doesn't support linux16. iPXE requires linux16. Memtest faces the same issue, but memtest v5 finally addresses (supposedly).
    Lots of folks talking about second and third tier booting "possibilities", but I'm so ux illiterate - I haven't even comprehended what the difference between a bootloader and bootstrap is.
    I know this isn't a forum - just dreaming this post could have a successor.

    ReplyDelete