PXE boot with Virtualbox

Solution 1:

Oh, the section "PXE booting with NAT" in manual has said it but not very clear.

"6.3.2. PXE booting with NAT PXE booting is now supported in NAT mode. The NAT DHCP server provides a boot file name of the form vmname.pxe if the directory TFTP exists in the directory where the user's VirtualBox.xml file is kept. It is the responsibility of the user to provide vmname.pxe."

--Here, the manual tell us Who provides the boot file: NAT DHCP server.
OK, let's have a question: where is the NAT DHCP server?

--On the host machine, it's integrated in the VirtualBox software.
(6.3. Network Address Translation (NAT): The virtual machine receives its network address and configuration on the private network from a DHCP server integrated into VirtualBox. )

So, where will VirtualBox search the configuration file? Of course on host machine.
That means virtualbox will try to search the "vmname.pxe" on host machine. Not on your scientific linux server.

And the manual tells us that we should put a "tftp" directory besides VirtualBox.xml.

On windows 7, VirtualBox.xml is in C:\Users<your username>.VirtualBox\ .
(VirtualBox version 5.1.14, the manual doesn't say that default configuration location is changed after 4.0 )

When I read the section, I was trying to PXE boot install a Debian system. So I had a guess that "vmname.pxe" is the file pxelinux.0 and renamed.

I tried several times and find that "vmname.pxe" should be "<vmname>.pxe", where <vmname> is your virtual machine's name.

At last, my successful PXE booting with NAT is this:
On host (my host is also windows 7), directory structure is:

%USERPROFILE% (mostly it is C:\Users\<username>\)
 |-.VirtualBox
    |-VirtualBox.xml
    |-TFTP
    |  |-pxelinux.cfg
    |  |  |-default-> ..\debian-installer\amd64\boot-screens\syslinux.cfg
    |  |-DebianSid.pxe->pxelinux.0 (DebianSid is my virtual machine's name)
    |  |-pxelinux.0
    |  |-ldlinux.c32
    |  |-version.info
    |  |-debian-installer\ 
    |-other files

On VirtualBox guest, my network setting is "NAT" mode, network card is "Intel PRO/ 1000MT desktop(82640EM)"

My VirtualBox version is 5.1.14.

No need tftp-hpa install, no need the second interface nor "Do not use Intel cards", and it is using built-in PXE feature。

A diskless PXE booting should be the similar.

So the problem is that the manual is totally a mess, PXE booting with NAT in Virtualbox is actually very simple. The point is, PXE server is your host virtualbox software.

Update about tftp directory structure: (question by @codeshot in comment) The tftp boot file is download from (debian sid for example): https://<debian-mirror>/debian/dists/sid/main/installer-<arch>/current/images/netboot/netboot.tar.gz

(If you are not using sid, change it). Ubuntu is similar.

tar xvf netboot.tar.gz and rename the directory to "tftp" and move to appropriate location as VirtualBox demonds.

If this is not working, then change the softlink to hardlink manually with Cygwin, or just simply copy and rename the files.

New information: besides Cygwin, we can also use wsl on Win10 to change the softlink to hardlink.

Only exception is "directory hardlink" of pxelinux.cfg.We have to use cmd's mklink command to create directory junction.

Solution 2:

Update:

After clarification, not using VirtualBox's built-in PXE feature at all seems the way to go. Instead, assign a secondary NIC with "host only" or "internal" networking to server and client, and bind the DHCP server to listen at the second interface. Do not use Intel cards for the second interface: PXE Booting Virtualbox guests in internal networking mode?

Answer to VirtualBox NAT and PXE:

vmname.pxe contains the code your VM runs after downloading it, the so called NBP (Network Bootstrap Program)

See Wikipedia for further info on PXE.

I'm quoting an example using PXELinux:

  1. get tftp-hpa installed. (you don’t need the daemon. just the program)

  2. set up the pxe directory root.

    mkdir $HOME/.VirtualBox/TFTP
    mkdir $HOME/.VirtualBox/TFTP/pxelinux.cfg
    
  3. Copy pxelinux.0 to $HOME/.VirtualBox/TFTP and make symbolic link to pxelinux.0 named <guest-vmname>.pxe.

  4. copy kernel and perhaps initrd to $HOME/.VirtualBox/TFTP

  5. edit $HOME/.VirtualBox/TFTP/pxelinux.cfg/default, sample:

    LABEL linux
    KERNEL vmlinuz
    APPEND root=/dev/sdxY
    

Source: http://thegnar.org/sync/?p=68