PXE boot with Virtualbox

networkingpxe-bootvirtualbox

I have a linux guest and that is my server. I also have created another guest as the client with no disk.

I want to know, which network type and adapter is correct? NAT or Internal Network? AMD or Intel chips?

According to the manual,

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

What is the content of vmname.pxe? it is an empty file?

Virtualbox is running on Windows 7 and I have installed One linux (scientific linux 6.3 which is similar to redhat and centos 6) as a server and another diskless linux as THE client.

On the server, I have installed tftp related files.

# ls /var/lib/tftpboot/ -R
/var/lib/tftpboot/:
menu.c32  pxelinux.0  pxelinux.cfg  sl6

/var/lib/tftpboot/pxelinux.cfg:
default

/var/lib/tftpboot/sl6:
initrd.img  vmlinuz


# cat /var/lib/tftpboot/pxelinux.cfg/default 
timeout 100
default menu.c32
menu title ########## PXE Boot Menu ##########
label 1
   menu label ^1) Install Scientific Linux 6
   kernel sl6/vmlinuz
   append initrd=sl6/initrd.img method=http://10.0.2.51/sl6 devfs=nomount
label 2
  menu label ^2) Boot from local drive
  localboot 

Best Answer

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.