# PXE TFTP network installations



## Max_nl (Jan 28, 2012)

Did anyone succeed in performing a FreeBSD 9 network installation using PXE+TFTP (*not* NFS)? With previous versions of FreeBSD the installation CD contained a mfsroot ramdisk image, which could easily be modified for use in TFTP network installations. However I'm not sure how to transform the new FreeBSD 9 live cd format to a mfsroot image.

What I tried is simply creating a blank 200 mb mfsroot file with mdconfig, format it with newfs, mount it, and copy the contents of the CD with rsync. However FreeBSD doesn't seem to like the resulting image. The pxeboot stage goes fine, in the sense that it downloads the kernel files and the mfsroot:







But once it tries to boot I get a screen full of "page fault while in kernel mode" errors  that are printed so fast they are hardly readable:






Also I'm not sure if my loader.rc is correct. I'm using this 5-line one which works fine with FreeBSD 8:


```
echo Loading Kernel...
load /boot/kernel/kernel
echo Loading MFS root...
load -t mfs_root /mfsroot
set autoboot_delay=0
```

Do I perhaps need additional boot options for FreeBSD 9?


----------



## Max_nl (Jan 29, 2012)

Turns out the kernel does not support large ramdisks by default.
Managed to solve the problem by increasing NPKT in /usr/src/sys/amd64/include/pmap.h


----------



## techtonik (Feb 7, 2012)

Max_nl said:
			
		

> Turns out the kernel does not support large ramdisks by default.



Why?


----------



## wblock@ (Feb 7, 2012)

Because NKPT is too small, apparently.


```
116 /* Initial number of kernel page tables. */
117 #ifndef NKPT
118 #define NKPT            32
119 #endif
```


----------



## techtonik (Feb 8, 2012)

And how do kernel page tables affect inability to load over PXE TFTP?

Why there is a problem to create 200Mb RAM disk?


----------



## wblock@ (Feb 8, 2012)

I would guess it's not PXE specifically, but that a kernel image or memory allocation is larger than the default is built to allow.  Best to ask on one of the mailing lists, like freebsd-hackers.


----------



## bunnylover (Feb 10, 2012)

As a sidenote to the original post, I'd like to mention that I had success in using mfsBSD from 9.0-RELEASE to create a 28 MB FreeBSD installer that can be sent using PXE+TFTP (without NFS).  The CD appears to simply use /etc/rc.local to start the installer and this seems to work well if one puts in a little time to build a few shell scripts and create new bsdinstall targets.


----------



## Schorschi (Feb 27, 2012)

Anyone figure out how to use bootonly ISO as source for memdisk image?  Trying to create a variant of FreeBSD that uses our existing Linux based SysLinux/PxeLinux based DHCP/TFTP environment for PXE.  Unfortunately, we can't dedicated server for FreeBSD based PXE/TFTP/DHCP resources.

I created an img file that PXELinux can load, but after I got the boot loader successfully, and I added a referece to /dev/md0 in the loader.conf file, I get a failure.  
	
	



```
mountroot: waiting for device /dev/md0, Mounting from ufs:/dev/md0 failed with error 19
```
?


```
Download the FreeBSD boot only image to the virtual instance.
# cd /tmp
# wget ftp://ftp.freebsd.org/pub/FreeBSD/ISO-IMAGES-<architecture>/9.0/FreeBSD-9.0-RELEASE-<architecture>-bootonly.iso
Where <architecture> is i386 or x86_64.

# ls -al | grep Free
-rw-r--r--   1 root  wheel  134739968 Feb 25 08:25 FreeBSD-9.0-RELEASE-<architecture>-bootonly.iso

Establish memory disk for boot only disc, then mount boot only disc file to memory diskâ€¦
# mdconfig -a -t vnode -f FreeBSD-9.0-RELEASE-<architecture>-bootonly.iso -u1
# mkdir /tmp/iso
# mount -t cd9660 /dev/md1 /tmp/iso

Establish memory disk file for boot only image, be sure to size the file to allow for file system overheadâ€¦
# dd if=/dev/zero of=./bootonly.img bs=1m count=200
# ls -al | grep bootonly
-rw-r--r--   1 root  wheel  134739968 Feb 25 08:25 FreeBSD-9.0-RELEASE-i386-bootonly.iso
-rw-r--r--   1 root  wheel  209715200 Feb 26 16:10 bootonly.img

Initialize, label, and format memory disk for boot only imageâ€¦
# mdconfig -a -t vnode -f bootonly.img -u0
# bsdlabel -w -B md0 auto
# bsdlabel -A md0
# /dev/md0:
type: unknown
disk: amnesiac
label:
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 16
sectors/cylinder: 1008
cylinders: 406
sectors/unit: 409600
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # milliseconds
track-to-track seek: 0  # milliseconds
drivedata: 0
8 partitions:
#          size     offset    fstype   [fsize bsize bps/cpg]
  a:     409584         16    unused        0     0
  c:     409600          0    unused        0     0     # "raw" part, don't edit

Set file system for memory disk boot only image, and then mount memory disk boot only imageâ€¦
# newfs -b 8192 -f 1024 /dev/md0a
/dev/md0a: 200.0MB (409584 sectors) block size 8192, fragment size 1024
        using 5 cylinder groups of 45.16MB, 5781 blks, 11584 inodes.
super-block backups (for fsck -b #) at:
 144, 92640, 185136, 277632, 370128
# mkdir /tmp/img
# mount /dev/md0a /tmp/img

Replicate boot specific files, from mounted boot only disc image to mounted boot only imageâ€¦
# cp -vR /tmp/iso/* /tmp/img

Customize boot configurationâ€¦
# echo 'vfs.root.mountfrom="ufs:/dev/md0"' >> /tmp/img/boot/loader.conf

Release mounts and memory disk referencesâ€¦
# umount /tmp/iso
# umount /tmp/img
# mconfig â€“l
md1 md0
# mdconfig -d -u1
# mdconfig -d -u0
# mconfig â€“l
# rm -rf /tmp/iso
# rm -rf /tmp/img

Compress boot only memory disk imageâ€¦
# gzip -c bootonly.img > bootonly.img.gz
# ls -al | grep bootonly
-rw-r--r--   1 root  wheel  134739968 Feb 25 08:25 FreeBSD-9.0-RELEASE-i386-bootonly.iso
-rw-r--r--   1 root  wheel  209715200 Feb 26 17:33 bootonly.img
-rw-r--r--   1 root  wheel   60502254 Feb 26 17:36 bootonly.img.gz
# rm â€“rf bootonly.img
# mv bootonly.img.gz bootonly.img

Stage compressed boot only image on TFTP boot server, and then within the PXELinux environmentâ€¦
# scp bootonly.img.gz 192.168.1.36:/var/lib/tftpboot/images/FreeBSD/9.0/<architecture>/ bootonly.img.gz
Where <architecture> is i386 or x86_64.

# vi /var/lib/tftpboot/pxelinux.cfg/default
LABEL FreeBSD-9.0-i386-Installer
        MENU LABEL i386 Installer
        MENU INDENT 6
        KERNEL memdisk
        APPEND initrd=/images/FreeBSD/9.0/i386/initrd.img.gz raw
```


----------

