PXE boot with grub: root variable unset

grubpxe-boot

I configured a dhcp and tftp server, for my tests, I used at first time, syslinux to boot over PXE network successfully.

Now I want to use grub instead of syslinux to boot, in order to do that, I issued the command grub-mknetdir --net-directory=<my_tftp_root_dir>, and modified the file to be served in dhcpd.conf.

PXE boot works but I am always getting the error about root variable unset, and I get into grub rescue mode.

If I manually issue the commands:

set root=(tftp,10.50.1.10)
set prefix=(tftp,10.50.1.10)
insmod normal
normal

Then I can correctly see the grub.cfg menu entries and boot whatever is there..

But I want that to be done automatically and get the grub menu without manual intervention.

Already drove myself crazy reading without any positive feedback, so I am out of ideas of how to set, both root and prefix so grub can start correctly.

Thanks for any suggestions/hints, this PXE thing is a new world to me yet.

EDIT: Playing around, the best thing I could do is to generate again the image with:
grub-mkimage -O i386-pc-pxe --output /warehouse/TFTProot/boot/grub/i386-pc/core.0 --prefix='(tftp,10.50.1.10)/boot/grub' pxe tftp

And don't rely on the autogenerated one, but isn't there any better solution than to regenerate it manually? As grub-mknetdir generates it already.

Best Answer

1) You can build the core image, create a configuration file e.g

setvars.conf and reference with the mkimage command -c setvars.conf

grub-mkimage -O i386-pc-pxe --output /warehouse/TFTProot/boot/grub/i386-pc/core.0 --prefix='' -c setvars.conf ppxe tftp

2) save a file named grub.cfg in the root of the tftp-server with the following content:

set root=(tftp) set net_default_server=192.168.x.x set prefix=boot/grub