[HowTo] Diskless FreeBSD Setup
This article will discuss the opportunity to boot a virtual machine for diskless operation in FreeBSD.
Tips:
Guide
Create a root directory which will contain a FreeBSD installation for the NFS to mount during boot:
export NFSROOTDIR=/storage/tftpboot/FreeBSD/install
mkdir -p ${NFSROOTDIR}
Enable the NFS server by running following command:
sysrc nfs_server_enable=YES
Export the diskless root directory via NFS by adding the following line to /etc/exports:
/storage -ro -alldirs -maproot=root
Start the NFS server:
service nfsd start
Enable inetd by running following command:
sysrc inetd_enable=YES
Uncomment the following line in /etc/inetd.conf by making sure it does not start with a # symbol:
tftp dgram udp wait root /usr/libexec/tftpd tftpd -l -s /b/tftpboot
Start inetd:
service inetd start
Install the base system into?${NFSROOTDIR}, either by decompressing the official archives or by rebuilding the FreeBSD kernel and userland. To make your life easier, download base.txz kernel.txz lib32.txz and decompress them into the ${NFSROOTDIR}.
Test that the TFTP server works and can download the boot loader which will be obtained via PXE:
tftp localhost
tftp> get FreeBSD/install/boot/pxeboot
Received 264951 bytes in 0.1 seconds
Edit?${NFSROOTDIR}/etc/fstab?and create an entry to mount the root file system over NFS, changing the bolded part:
# Device Mountpoint FSType Options Dump Pass
<IP_ADDR>:/storage/tftpboot/FreeBSD/install / nfs ro 0 0
Replace?<IP_ADDR>?with the hostname or IP address of the NFS server. In this example, the root file system is mounted read-only in order to prevent NFS clients from potentially deleting the contents of the root file system.
Set the root password in the PXE environment for client machines which are PXE booting :
chroot ${NFSROOTDIR}
passwd
When booting from an NFS root volume,?/etc/rc?detects the NFS boot and runs?/etc/rc.initdiskless. In this case,?/etc?and?/var?need to be memory backed file systems so that these directories are writable but the NFS root directory is read-only:
chroot ${NFSROOTDIR}
mkdir -p conf/base
tar -c -v -f conf/base/etc.cpio.gz --format cpio --gzip etc
tar -c -v -f conf/base/var.cpio.gz --format cpio --gzip var
When the system boots, memory file systems for?/etc?and?/var?will be created and mounted and the contents of the?cpio.gz?files will be copied into them. By default, these file systems have a maximum capacity of 5 megabytes. If your archives do not fit, which is usually the case for?/var?when binary packages have been installed, request a larger size by putting the number of 512 byte sectors needed (e.g., 5 megabytes is 10240 sectors) in?${NFSROOTDIR}/conf/base/etc/md_size?and?${NFSROOTDIR}/conf/base/var/md_size?files for?/etc?and?/var?file systems respectively.
The DHCP server does not need to be the same machine as the TFTP and NFS server, but it needs to be accessible in the network.
DHCP is not part of the FreeBSD base system but can be installed using the?net/isc-dhcp44-server?port or package.
Once installed, edit the configuration file,?/usr/local/etc/dhcpd.conf. Configure the?next-server,?filename, and?root-path?settings as seen in this example:
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.2 192.168.0.3 ;
option subnet-mask 255.255.255.0 ;
option routers 192.168.0.1 ;
option broadcast-address 192.168.0.255 ;
option domain-name-servers 192.168.35.35, 192.168.35.36 ;
# IP address of TFTP server
next-server 192.168.0.1 ;
# 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.88.24:/storage/tftpboot/FreeBSD/install/" ;
}
Once the edits are saved, enable DHCP at boot time by adding the following line to?/etc/rc.conf:
领英推荐
sysrc dhcpd_enable="YES"
Then start the DHCP service:
service isc-dhcpd start
Additional Tips:
Since this is a diskless boot, you need to make some changes to rc.conf & resolv.conf. This configuration is not covered in the article.
Prepare a virtual machine, make sure the boot order is correct, meaning you boot from network first.
Once the system has booted, you should be able to login and perform a simple ping test to any server.
Advantages of using Diskless FreeBSD:
Using a diskless FreeBSD setup can offer several advantages in certain scenarios. Here are some of the benefits of running FreeBSD in a diskless environment:
Centralized Management:
Diskless setups allow for centralized management of the operating system and applications. All configurations, updates, and changes can be made on the server and applied uniformly to all diskless clients, simplifying administration.
Reduced Hardware Costs:
Diskless clients require less storage hardware since they don't have local hard drives or SSDs. This can result in cost savings, especially in large-scale deployments.
Lower Maintenance Overhead:
With no local storage, there are fewer components to maintain and replace in diskless clients. This can lead to reduced maintenance and hardware replacement costs over time.
Enhanced Security:
Diskless systems are less susceptible to data theft and tampering because sensitive data isn't stored locally. This can be advantageous in environments where security is a top concern.
Rapid Deployment and Scalability:
Setting up new diskless clients is relatively quick as it involves minimal hardware configuration. This makes scaling up your environment or deploying new workstations easier and faster.
Consistent Environments:
Diskless setups ensure that all clients run the same version of the operating system and software. This consistency can help avoid compatibility issues and streamline troubleshooting.
Reduced Downtime:
Diskless clients can be replaced or reimaged quickly in case of hardware failures or system issues. This can lead to reduced downtime and improved productivity.
Energy Efficiency:
Diskless clients generally consume less power since they don't have power-hungry hard drives spinning all the time. This can contribute to energy savings in the long run.
Resource Sharing:
In diskless environments, system resources like memory, CPU, and storage can be better shared among clients. This can lead to more efficient utilization of hardware resources.
Simplified Backups and Recovery:
Backing up and restoring diskless clients can be easier since you only need to focus on the server's data. In case of data loss or corruption, you can quickly restore the clients to a known state.
Reduced Noise and Heat:
Diskless clients generate less noise and heat compared to systems with spinning hard drives. This can contribute to a quieter and more comfortable working environment.
Easier System Upgrades:
Upgrading software, applying patches, or even changing the entire operating system version becomes more streamlined in a diskless setup. You can update the server image and have all clients use the updated version immediately.
Reference:
https://docs.freebsd.org/en/books/handbook/advanced-networking/#network-diskless