6

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 
mahmood
  • 962
  • 7
  • 18
  • 31
  • What is the linux server VM supposed to do? Elaborate on your setup. – fuero Aug 02 '14 at 02:08
  • It is Scientific linux (similar to redhat and centos). See the updated post – mahmood Aug 02 '14 at 02:13
  • In this case, you don't need VirtualBox' built-in PXE feature _at all_. 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. – fuero Aug 02 '14 at 02:22
  • 3
    http://serverfault.com/questions/195055/pxe-booting-virtualbox-guests-in-internal-networking-mode – fuero Aug 02 '14 at 02:23
  • Regarding the network adapter, should I use the same network type and adapter in both VMs (server & client)? – mahmood Aug 02 '14 at 02:26
  • Yes, see my updated answer. – fuero Aug 02 '14 at 02:27

2 Answers2

5

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.

Cu635
  • 51
  • 1
  • 3
  • In your final working directory tree you have some files with arrows after them and another file name as if representing some redirection feature. Are this Windows "Shortcuts" created by Windows Explorer (Copy the file after the arrow, Paste Shortcut, then rename the new shortcut to have the name before the arrow)? I did that but I got a "Permission Denied" error when trying to boot which isn't present when those files are copies - however, then I get a plain hang. – codeshot Mar 06 '17 at 00:15
  • @codeshot Answer updated – Cu635 Apr 28 '17 at 13:28
  • Thanks for the update. So you've enabled softlinks in Windows somehow? Is this done merely by unpacking from within cygwin ? – codeshot Jul 16 '17 at 20:57
  • 2
    Important point, on Linux it has to be "TFTP". Took me a while to figure that out... – BHS Jul 18 '17 at 20:50
  • @codeshot Sorry for the very late reply. I use Cygwin to operate the link. I convert the extract directory structure to hard link with Cygwin and it works. Also you can copy the file/directory and not use link anymore – Cu635 Jul 05 '18 at 18:06
  • @BHS Thanks for mentioning, I use Windows and didn't notice that. – Cu635 Jul 05 '18 at 18:07
  • 1
    Thanks that worked really well. For Archlinux in Mac, All I had to do was move the pxe file from https://www.archlinux.org/releng/netboot/ to `/Users/YOURUSERHERE/Library/VirtualBox/TFTP` with the same name as the Virtualbox image. So `/Users/bibstha/Library/VirtualBox/TFTP/Archlinux.pxe` and it worked great. – Bibek Shrestha Feb 12 '19 at 02:31
3

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

chicks
  • 3,639
  • 10
  • 26
  • 36
fuero
  • 9,413
  • 1
  • 35
  • 40
  • NO it doesn't work for me. I will create a new post and notify you here – mahmood Aug 02 '14 at 02:31
  • 4
    I suggest salvaging this post. Just saying "NO, doesn't work" isn't information people can help you with. – fuero Aug 02 '14 at 02:34
  • I appreciate your help. But I am struggling with this problem for two days. Your solution is welcomed http://serverfault.com/questions/617362/pxe-e51-no-dhcp-or-proxydhcp-offers-were-received-in-virtualbox-environment – mahmood Aug 02 '14 at 02:47
  • If you just "want it to boot" off PXE (not have to set up files or anything) possibly see http://serverfault.com/a/334444/27813 – rogerdpack Dec 19 '14 at 16:53