Installing FreeBSD over a network (PXE) from a linux server (dnsmasq + nfs)
There was a need to install FreeBSD on a laptop. Since the laptop is ancient, it does not support booting from a USB flash drive. There was no blank at hand either, it was decided to test the installation through PXE (Preboot eXecution Environment). Googling, I found several articles on this topic, however, they describe installing linux from a linux server, or FreeBSD from a FreeBSD server. I do not pretend to create any special method, I just post my instructions on how to quickly deploy FreeBSD 10.1 over the network.
The theoretical part of the PXE download is well described in the article: http://xgu.ru/wiki/PXE
So, let's get started. We will need: dhcp, tftp, nfs.
The computer with Debian 7 installed will act as the server. I already have dnsmasq installed on it, which is both a dhcp and dns server. This is very convenient for a small home network, so as not to raise dhcp and bind separately. In addition, dnsmasq has its own tftp-server, so it is ideally suited for our task, as they say - "all in one bottle." It remains to install the nfs server and configure the whole thing. The PXE bootloader is in the FreeBSD distribution image.
Install the necessary packages:
Download the iso-image of FreeBSD from the official site freebsd.org. I used a minimal bootonly image:
Mount it:
Copy all the image files to a directory that will be accessible via nfs:
Add the nfs ball to / etc / exports
Restart nfs:
Now we need to tweak something:
Comment out or delete the line in / srv / nfs / freebsd / etc / fstab so that the system does not try to mount the disk at boot (the image is intended for recording on a blank), but mounts our nfs as the root file system ball:
Delete the symbolic link /srv/nfs/freebsd/etc/resolv.conf, which refers to the non-existent file /srv/nfs/freebsd/tmp/bsdinstall_etc/resolv.conf. In theory, the dns server address should have been obtained via dhcp and written to this file by the FreeBSD installer at startup. However, this does not happen: the installer creates an empty file, and if the file is already created, it overwrites it. Therefore, instead of a symlink, we create a new file /srv/nfs/freebsd/etc/resolv.conf and write the address of our dns server into it:
We edit the file /etc/dnsmasq.conf, I give only those options that are required to solve our problem, i.e. dhcp + tftp without dns:
Restart dnsmasq:
That's all. We go into the BIOS, select the boot order from the LAN (PXE). The network card loads pxe-loader, then the kernel is copied and launched via tftp, the root file system is mounted via nfs, the FreeBSD installer starts, and then the standard FreeBSD installation. Do not forget only at the end of the installation to change the boot order in the BIOS to the previous one.
The theoretical part of the PXE download is well described in the article: http://xgu.ru/wiki/PXE
So, let's get started. We will need: dhcp, tftp, nfs.
The computer with Debian 7 installed will act as the server. I already have dnsmasq installed on it, which is both a dhcp and dns server. This is very convenient for a small home network, so as not to raise dhcp and bind separately. In addition, dnsmasq has its own tftp-server, so it is ideally suited for our task, as they say - "all in one bottle." It remains to install the nfs server and configure the whole thing. The PXE bootloader is in the FreeBSD distribution image.
Install the necessary packages:
apt-get install dnsmasq nfs-kernel-server
Download the iso-image of FreeBSD from the official site freebsd.org. I used a minimal bootonly image:
wget ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/i386/ISO-IMAGES/10.1/FreeBSD-10.1-RELEASE-i386-bootonly.iso
Mount it:
mount -o loop FreeBSD-10.1-RELEASE-i386-bootonly.iso /mnt
Copy all the image files to a directory that will be accessible via nfs:
cp -a /mnt /srv/nfs/freebsd
Add the nfs ball to / etc / exports
/srv/nfs/freebsd 192.168.0.0/24(rw,sync,no_subtree_check)
Restart nfs:
service nfs-kernel-server restart
Now we need to tweak something:
Comment out or delete the line in / srv / nfs / freebsd / etc / fstab so that the system does not try to mount the disk at boot (the image is intended for recording on a blank), but mounts our nfs as the root file system ball:
# /dev/iso9660/10_1_RELEASE_I386_BO / cd9660 ro 0 0
Delete the symbolic link /srv/nfs/freebsd/etc/resolv.conf, which refers to the non-existent file /srv/nfs/freebsd/tmp/bsdinstall_etc/resolv.conf. In theory, the dns server address should have been obtained via dhcp and written to this file by the FreeBSD installer at startup. However, this does not happen: the installer creates an empty file, and if the file is already created, it overwrites it. Therefore, instead of a symlink, we create a new file /srv/nfs/freebsd/etc/resolv.conf and write the address of our dns server into it:
nameserver 192.168.0.101
We edit the file /etc/dnsmasq.conf, I give only those options that are required to solve our problem, i.e. dhcp + tftp without dns:
interface=eth0 #интерфейс, на котором слушаются dhcp-запросы
dhcp-range=192.168.0.200,192.168.0.250,12h #Диапазон выдаваемых ip-адресов и время аренды
dhcp-option=17,/srv/nfs/freebsd/ #Указываем корень для nfs
dhcp-boot=/srv/nfs/freebsd/boot/pxeboot #Указываем путь к PXE-загрузчику
enable-tftp #Включаем встроенный tftp-сервер
tftp-root=/srv/nfs/freebsd/ #Указываем корень tftp
Restart dnsmasq:
service dnsmasq restart
That's all. We go into the BIOS, select the boot order from the LAN (PXE). The network card loads pxe-loader, then the kernel is copied and launched via tftp, the root file system is mounted via nfs, the FreeBSD installer starts, and then the standard FreeBSD installation. Do not forget only at the end of the installation to change the boot order in the BIOS to the previous one.