~
~
: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.

Configurar en Grub2 un arranque vía gPXE

english version - all spanish posts

El problema es que necesito arrancar un PC en un entorno de LTSP. Desgraciadamente la funcionalidad de PXE propia de su BIOS no parece funcionar.

Si necesitamos un thinclient que arranque vía PXE pero el firmware no soporta dicha función podemos solventar el problema con gPXE siempre y cuando la tarjeta de red sea reconocida como PCI (no valen las PCMCIA o USB en la mayoría de las ocasiones) y siempre y cuando dispongamos de un dispositivo de bloques dónde instalar grub (en este caso grub2).

No quiero perder los datos de dicho PC por lo que no me vale instalar gPXE directamente en el disco como haría si quisiera convertir el PC en un thinclient de manera definitiva. Algo así:

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

Podría usar una imagen gPXE para usb o para CD, pero me parece muy poco práctico. La mejor opción para este caso es añadirle una entrada a grub de modo que pueda elegir en el menú de grub el sistema operativo del PC o el arranque por red.

Lo primero que haremos es obtener una imagen gPXE de rom-o-matic.net que guardaremos en /boot/. Dejaremos las opciones por defecto de rom-o-matic.net y únicamente especificaremos el tipo de imagen «Linux kernel bootable image (.lkrn)»

Con esto ya tendremos nuestra imagen lkrn:

/boot/gpxe-1.0.1-gpxe.lkrn

La forma de trabajar con grub2 cambia mucho respecto al grub clásico, ya no hay un menu.lst que podamos editar. Ahora, para añadir nuevas entradas en el menú de grub tendremos que editar el fichero /etc/grub.d/40_custom (al menos para debian/ubuntu).

La entrada para nuestra lkrn en /etc/grub.d/40_custom quedará como:

#!/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
}

Finalmente ejecutaremos update-grub2 que se encargará de actualizar /boot/grub/grub.cfg:

update-grub2

En el próximo reinicio podremos elegir la opción de arranque por red desde el menú de Grub.