0

I've just discovered the wonder that is iPXE.

Im running various versions of Debian on many different computers, and would like to remotely tell them to reboot into iPXE, and have iPXE automatically boot into a clonezilla auto-deploy .iso I have.

Is there a way to tell Linux to automatically boot into iPXE on next boot once, and have iPXE then automatically boot into an .iso from a server?

  • 1
    There appears a solution: https://specialistoff.net/question/661 . The page is in Russian, however I think it is clear how it works. You can try this approach, and write (and accept) a proper answer here instead of just a link. – Nikita Kipriyanov Nov 20 '21 at 08:31
  • 1
    (This is of course only a part of the solution. You need some agent which will recreate `grub.cfg` to actually choose this new boot menu item.) So I'd suggest a *reverse* solution. – Nikita Kipriyanov Nov 20 '21 at 09:05
  • Thanks! That Russian page seems yo be almost what I want to achieve. Thanks! – Moritz von Schweinitz Nov 21 '21 at 18:54
  • If you are running legacy then you should be able to boot the ipxe.lkrn from grub, in efi you could do something similar to start ipxe.efi but that might be buggy, or you could use efibootmgr to change to netboot on next startup and then use proxydhcp config see https://ipxe.org/appnote/proxydhcp as sample, then use http to get a script that can be dynamic and use serialnumber or mac if you need it to be automatic and configured. – NiKiZe Nov 23 '21 at 04:53

2 Answers2

2

I use similar setup, but in reverse. In the end, I can control from the server how my target machines boot.

However, I don't rely on the grub on the target machine and I don't use iPXE.

Instead, I installed a PXE boot server. It is extremly hard nowadays to find a computer with non-working PXE boot. So I configured all computers I need to control this way to boot from the network via PXE.

By the way, this is equally possible with old-style BIOS and modern UEFI machines, and it is DHCP server who distingushes between these cases and suggests the appropriate bootloader to the machine.

In any case, machines load some variant of PXELinux. It has a neat property, in that how it searches for a config file. It first requests a config file named after machine SMBIOS UUID, if it's not found, if requests a file named after the MAC address of the interface which was booted, IP address, and if nothing helps, it requests a file default.

So you can create some "base configs", one which boots machines from local hard disk tftp/pxelinux.cfg/harddisk:

default harddisk

label harddisk
    localboot 0

and the other, which boots clonezilla tftp/pxelinux.cfg/clonezilla:

default clonezilla

label clonezilla
#    clonezilla boot instructions here

and you may add several others, like the one for a diskless thin client (this is actual config I once used):

default stretch

label stretch
    linux thinclient/vmlinuz-4.9.0-7-amd64
    initrd thinclient/initrd.img-4.9.0-7-amd64
    append ISCSI_INITIATOR=iqn.1993-08.org.debian:01:a4c444f2b735 ISCSI_TARGET_NAME=iqn.2018-10.ru.rterm.office.test-storage:thinclient.lvm ISCSI_TARGET_IP=192.168.168.113 ISCSI_TARGET_PORT=3260 root=UUID=344ca052-8ea2-437f-9550-a5503d0e7b21 ip=dhcp quiet

Then you create symlinks that point to these templates:

cd tftp/pxelinux.cfg
ln -s clonezilla 01-10-32-54-76-98-ba
ln -s clonezilla 01-dc-fe-10-32-54-76
ln -s harddisk 01-98-ba-dc-fe-10-32
ln -s harddisk 01-54-76-98-ba-dc-fe
ln -s harddisk default
ln -s thinclient 00801536-e3ee-1610-9957-d68a52030736  

In this example, the machines with MAC addresses 10:32:54:76:98:ba and dc:fe:10:32:54:76 will boot a clonezilla config file (01 at the beginning of file names here means "Ethernet"), the machine with UUID 00801536-e3ee-1610-9957-d68a52030736 will boot a thinclient config, and other machines will boot harddisk, but the two with specified MACs will do this quieter (less "file not found" logs on the server and sligtly faster boot because the download attempt will succeed earlier).

Now, if you need some machine to boot, say, clonezilla, you create or change its symlink on the tftp server to clonezilla. After it was booted, you may revert the change (e.g. change to harddisk or whatever you want). You may create configs for Linux network installation — I don't even remember when I last time boot installer from USB, because I always install it this way for several years. You may use the PXELinux include directive and create a neat generic menu with all these options to select by hand and use it for a default instead. Technically, even Windows installation is (was) possible this way. The scheme is very flexible, and the only thing it depends on the client machine is that it boots from the network first.

Nikita Kipriyanov
  • 8,033
  • 1
  • 21
  • 39
  • My main issue is that I don't really have control over the network's DHCP server, and can't really send the PXE info via DHCP. That's why I'm looking into iPXE, in order to have the machine know where to get it's image from. – Moritz von Schweinitz Nov 21 '21 at 18:55
  • iPXE is a more capable NBP then what PXELinux is and can create a much cleaner and quicker setup than this. – NiKiZe Nov 23 '21 at 04:49
  • I don't mind. I described what I built around ten years ago. It still serves my needs very well (work for VMs too). Now it is not so important, as I am working remotely. If (when) I return to rebuilding this, I may give it a shot, or I can employ also netbooted GRUB more efficiently. – Nikita Kipriyanov Nov 23 '21 at 05:46
0

I simply added a iPXE entry (with a iPXE 'script' in an initrd file) to /etc/grub.d/ (starting with '99' so that it's at the end of the list), then run update-grub, then ran

grub-reboot `egrep '^menuen' /boot/grub/grub.cfg |wc -l`; reboot;

this simply counts the menuentries in the grub.cfg file, and tells grub-reboot to boot into the last option on next reboot.