# PXE booting



## balanga (Oct 13, 2014)

I'm attempting to get PXE booting working on my network and have almost got it working, save for setting up the intial bootloader, which according to various sources can use 
either gpxelinux.0 :- http://www.wonkity.com/~wblock/docs/html/pxe.html 

or /boot/pxeboot https://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/network-diskless.html

The first article, which I followed religiously, contains an outdated link, however I did manage to find a newer version of SYSLINUX although the archive did not contain the files mentioned, only the sources. Am I expected to build them on my system? The article does not suggest this is necessary


The other item, from The Handbook mentions a couple of options for dhcpd.conf namely:-


```
# path of boot loader obtained via tftp
     filename "FreeBSD/install/boot/pxeboot" ;

   # pxeboot boot loader will try to NFS mount this directory for root FS
   option root-path "192.168.0.1:/b/tftpboot/FreeBSD/install/" ;
```


How am I supposed to interpret FreeBSD/install in the above option?

I presume this isn't a literal string.


----------



## wblock@ (Oct 13, 2014)

You downloaded the wrong Syslinux archive.  The right one has the binaries, not the sources.  http://www.syslinux.org/ is temporarily down right now, so I can't post the exact link.

There is a port, which I have not tried recently, but it should build the binaries from source: sysutils/syslinux.

The PXE article is almost always in need of updating, sorry about that.


----------



## balanga (Oct 13, 2014)

Your article was really excellent and very clear, so much so that getting PXE booting was almost a breeze.  PXE booting was something I'd never managed successfully, although I first setup remote booting under OS/2 20 years ago.
IBM called it RIPL http://en.wikipedia.org/wiki/Remote_Initial_Program_Load.

As for your article, I only managed to get Reboot working initially . mfsbsd didn't work because of a typo:-


```
# cp /tmp/mfsbsd-9.1-RELEASE-i386.img /usr/tftpboot/images/mfsbsd/mfsbsd
```

I'm now trying to iron out what I've missed in the other options, but I'm very please to have it set up. It's a great alternate to having a YUMI multiboot USB pendrive, although I'd still like to add a few options which have with YUMI such as being able to initiate a Windows install from an ISO on a USB stick.


----------



## balanga (Oct 13, 2014)

Just as a followup, I found the Hardware Detection Tool here:- http://www.hdt-project.org/raw-attachment/wiki/hdt-0.5.0/hdt-0.5.2.iso

which also contained newer version of some of the programs you referred to such as menu.c32 etc, so I just copied hdt.c32 pci.ids to /usr/tftpboot

Not sure what the pci.map is for...but it isn't included in the ISO.


----------



## wblock@ (Oct 13, 2014)

Sorry, could you be more specific about the typo?  It does look like I should be more specific and just gzip the mfsBSD image in the first place.

It should be possible to write a program that would take a complete menu-based PXE setup like this and put it on a memory stick.  Menu options that depend on network filesystems will not work, of course, but any that provide an image direct from the disk will.


----------



## balanga (Oct 13, 2014)

wblock@ said:
			
		

> Sorry, could you be more specific about the typo?



Shouldn't this:

`cp /tmp/mfsbsd-9.1-RELEASE-i386.img /usr/tftpboot/images/mfsbsd/mfsbsd`

be this?

`cp /tmp/mfsbsd-9.1-RELEASE-i386.img /usr/tftpboot/images/mfsbsd/mfsbsd.gz`


----------



## balanga (Oct 14, 2014)

wblock@ said:
			
		

> The PXE article is almost always in need of updating, sorry about that.



An update would be really useful...  particularly for Clonezilla which I can't get working at all... It ends up with:-

```
/bin/sh: can't access tty; job control turned off
(initramfs)
```


----------



## wblock@ (Oct 14, 2014)

balanga said:
			
		

> wblock@ said:
> 
> 
> 
> ...



No.  The tip mentions that it can be compressed, but that is a separate step.  The instructions should just gzip() it as part of the procedure.


----------



## balanga (Oct 16, 2014)

balanga said:


> I'm attempting to get PXE booting working on my network and have almost got it working, save for setting up the intial bootloader, which according to various sources can use
> either gpxelinux.0 :- http://www.wonkity.com/~wblock/docs/html/pxe.html
> 
> or /boot/pxeboot https://www.FreeBSD.org/doc/en_US.ISO8859-1/books/handbook/network-diskless.html
> ...




I have religiously followed the FreeBSD/install route today including things like `make buildworld` and `make buildkernel`  which took many hours and after correct many errors and omissions I thought I'd see how well it all went. It looked promising when I saw:

```
BTX loader 1.00 BTX version is 1.02
```
on my laptop. But then:

```
NFS MOUNT RPC error: 72
/
can't load 'kernel'
```

Please help.

I did notice a thread on the FreeBSD mailing list with a similar problem: http://FreeBSD.1045724.n5.nabble.com/Previously-working-PXE-setup-now-fails-td5919662.html but couldn't figure out what was wrong or how to fix it.


----------



## Beeblebrox (Oct 17, 2014)

> I did notice a thread on the FreeBSD mailing list with a similar problem


Nah, that was a different problem and I don't recall exactly what I did to solve it. The main lesson from that thread however, is how and why NFSv4 does not work for root:


> As I think I've mentioned before, a NFSv4 root fs won't work, so don't bother trying...
> (Because) client mount needs a unique identifier for the client machine.  The host uuid used for this is set during booting. To make an NFSv4 root fs to work, there needs to be some way to generate a unique identifier for the machine before it accesses the root fs.



Anyway, with regards to your problem:

Simplify your setup to get PXE working, then gradually add features you want. If a new feature (complication you add) results in breakage, you will have a better clue on where to look. Therefore, you are correct in using the BTX boot-loader for now before adding the custom boot-loader feature.
I assume that you are able to mount the exported NFS directories on your laptop when you boot it normally (non-PXE)? What is the NFS version shown for exported root (v3 vs v4)?
That error happens before the BTX menu gets displayed right? In the exported root path's boot folder: Do you have the kernel folder and have you placed correct settings in loader.conf (not system root but NFS exported root)?
Have you enabled these options in the kernel configuration file?


```
options    NFSCL     # Network Filesystem Client
options    NFS_ROOT   # NFS usable as /, requires NFSCL
```

Your first objective is to get to the BTX loader menu, where you will have some command capability (like list kernel modules and mount-paths).


----------



## balanga (Oct 19, 2014)

It looks as though nfsd is not working properly.

I'm using FreeBSD 10.0, so the nfsd that comes with that, but I notice when starting nfsd it says NFSv4 is disabled. I also notice `showmount` does not show /etc/exports correctly after it has been updated, I need to separately restart mountd first. I was under the impression that restarting nfsd automatically restarted mountd.


----------



## Beeblebrox (Oct 19, 2014)

As I suggested,

Get exports working on host
Connect to those exported NFS folders over the network from a separate (Linux laptop for example) client.


----------



## balanga (Oct 19, 2014)

Just as a follow up  the error 
	
	



```
NFS MOUNT RPC error: 72
```
 has now disappeared but I still get 

```
/
can't load 'kernel'
```

Any suggestions as to how to make some progress? Could this be a permissions problem or something to do with the path?


----------



## balanga (Oct 19, 2014)

I have just tried this which worked: `mount -t nfs 192.168.1.151:/b /mnt/b`.

/etc/exports contains 
	
	



```
/b -ro -alldirs
```
as per https://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/network-diskless.html

I did notice a /var/log/pxeboot but couldn't make any sense of it.


----------



## Beeblebrox (Oct 19, 2014)

Details of /etc/exports, please?


----------



## balanga (Oct 20, 2014)

Beeblebrox said:


> Details of /etc/exports, please?



`cat /etc/exports`

```
/b  -ro -alldirs
```

`showmount -e3 192.168.1.151`

```
Exports list on 192.168.1.151:

/b                                 Everyone
```


----------



## Beeblebrox (Oct 20, 2014)

It seems I misunderstood your previous post. I thought that entry was one of several in exports.

Does this file exist? _/b/tftpboot/FreeBSD/install/boot/kernel/kernel_?

Anything of significance in /var/log/xfer.log?

Can you confirm that the kernel you have placed in above directory was built with below? These are needed for the client machines to read from NFS. NFSCL is not loadable as a module when it comes to PXE, and needs to be in the kernel.


```
options    NFSCL     # Network Filesystem Client
options    NFS_ROOT   # NFS usable as /, requires NFSCL
```


----------



## balanga (Oct 20, 2014)

I keep changing /etc/exports in an effort to try and make some progress. It currently has  that single entry which I am able to mount.

The kernel file does exist and as for building it, that was simply done by following the instructions in The Handbook

https://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/network-diskless.html

Those instructions do not mention the options you refer to. In any case I wouldn't know how to build with those options. I am assuming that the instructions in The Handbook are correct.


----------



## Beeblebrox (Oct 20, 2014)

In that Handbook document it also states:


> Refer to diskless(8) for more information.


The referenced man page states:


> The kernel for the diskless clients, which will be loaded using NFS or TFTP, must include support for the NFS client:
> options NFSCL
> options NFS_ROOT
> If you are using a boot mechanism that does not pass network configuration to the kernel using the kernel environment, you will also need to include the following options (MY EDIT: when using Grub for example):
> ...



Kernel configuration is documented: https://www.freebsd.org/doc/handbook/kernelconfig-config.html. Create the file MYKERNEL in /usr/src/sys/amd64/conf with:

```
include GENERIC
ident MYKERNEL

options NFSCL
options NFS_ROOT
```
`# make -C /usr/src/ buildkernel KERNCONF=MYKERNEL`


----------



## balanga (Oct 20, 2014)

Beeblebrox said:


> In that Handbook document it also states:
> 
> The referenced man page states:
> 
> ...



It looks as though these options are already in GENERIC, so the chances are that when I ran `make buildkernel` the KERNEL was built with the correct option, although maybe this is something I could check if I knew what to look for.


----------



## kpa (Oct 20, 2014)

balanga said:


> It looks as though these options are already in GENERIC, so the chances are that when I ran
> 
> `make buildkernel`
> 
> the KERNEL was built with the correct option, although maybe this is something I could check if I knew what to look for...



Run `sysctl kern.conftext | grep the_option_you_are_looking_for`.


----------



## balanga (Oct 20, 2014)

kpa said:


> Run `sysctl kern.conftext`




```
root@balanga:~ # sysctl kern.conftest
sysctl: unknown oid 'kern.conftest': No such file or directory
```


----------



## kpa (Oct 20, 2014)

You are misspelling it and so am I. This is the correct one:


```
% sysctl kern.conftxt | grep NFS
options NFS_ROOT
options NFSLOCKD
options NFSD
options NFSCL
```


----------



## Beeblebrox (Oct 20, 2014)

`sysctl kern.conftxt` will display the kernel configuration only if you have included

```
options INCLUDE_CONFIG_FILE
```



> It looks as though these options are already in GENERIC


Yep, you're right. The latest GENERIC seems to have that already.

What about the contents of /var/log/xfer.log? You should see something like:

```
RRQ from <IP> filename FreeBSD/install/boot/pxeboot
```
Also, dmesg and messages may yield some clues. Failing these, you'll have to run wireshark, or `tcpdump -w out.pcap -i <iface_name>` then read that out.pcap file in wireshark.

What architecture (amd64, i386, arm) are the clients?


----------



## balanga (Oct 20, 2014)

I finally figured out what I had done wrong!

It was simply a question of paths. Once I changed /usr/local/etc/dhcpd.conf to

```
option root-path "/b/tftpboot/FreeBSD/install";
```
rather than

```
option root-path "/b/tftpboot";
```
everything worked as it should... finally.

I think my confusion stems from The Handbook https://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/network-diskless.html

which states:


> *31.8.1. Setting Up the PXE Environment*
> Written by Craig Rodrigues.
> The steps shown in this section configure the built-in NFS and TFTP servers. The next section demonstrates how to install and configure the DHCP server. In this example, the directory which will contain the files used by PXE users is /b/tftpboot/FreeBSD/install. It is important that this directory exists and that the same directory name is set in both /etc/inetd.conf and /usr/local/etc/dhcpd.conf.
> 
> ...


----------



## balanga (Oct 22, 2014)

I have now built a PXE boot environment which will enable me to pxeboot FreeBSD 10.0 i386  from my amd64 server and it's nice to see that it works on most of my laptops, but now I would like to create a usable desktop using X. How do I go about adding X to the boot system?

Also, can how do I create my own boot menu? Do I need separate pxeboot programs or will the one from FreeBSD allow me to add non-FreeBSD tools such as Clonezilla or boot an alternative OS?


----------

