Introduction
Hetzner no longer offers a FreeBSD rescue system. For dedicated servers with full UEFI support there is a tutorial showing how to install FreeBSD with OpenZFS from the Linux rescue system: Installing FreeBSD with OpenZFS via the Linux rescue system
For older servers that only have minimal UEFI support and require legacy BIOS boot, there is a different way to install FreeBSD.
Prerequisites:
- Hetzner dedicated server booted in Linux rescue mode with working SSH access
- IPv6 network configuration parameters:
- IPv6 address assigned
Optional:
- IPv4 network configuration parameters:
- IP address and network length
- Default gateway
Note: Dedicated servers without an IPv4 address must be configured correctly since DHCP and autodetect does not work.
Example terminology
- IPv4:
192.168.0.2/27
- IPv4 Gateway:
192.168.0.1
- IPv6:
2a01:4f8:0:0::2/64
- NIC: Intel(R) PRO/1000 Network Driver
- Drive 1:
/dev/nvme0n1
- Drive 2:
/dev/nvme1n1
Use /dev/sda
and /dev/sdb
on systems with SATA drives.
We will install FreeBSD 14.0-RELEASE in our example.
Step 1 - Download the FreeBSD distribution archives
Download base.txz
and kernel.txz
from a FreeBSD mirror:
curl -O http://ftp2.de.freebsd.org/pub/FreeBSD/releases/amd64/14.0-RELEASE/base.txz
curl -O http://ftp2.de.freebsd.org/pub/FreeBSD/releases/amd64/14.0-RELEASE/kernel.txz
Step 2 - Download the mfsBSD installation VM container
We use mfsBSD virtual machine to install FreeBSD on the system drives.
Download the ISO image:
curl -O https://mfsbsd.vx.sk/files/iso/14/amd64/mfsbsd-14.0-RELEASE-amd64.iso
Step 3 - Launch the mfsBSD virtual machine from the ISO image
The server disks are passed through to the VM as SCSI devices using virtio.
In the command below, replace
/dev/nvme0n1
and/dev/nvme1n1
as needed.
qemu-system-x86_64 -net nic -net user,hostfwd=tcp::1022-:22 -m 2048M -enable-kvm \
-cpu host,+nx -M pc -smp 2 -vga std -k en-us \
-cdrom ./mfsbsd-14.0-RELEASE-amd64.iso \
-device virtio-scsi-pci,id=scsi0 \
-drive file=/dev/nvme0n1,if=none,format=raw,discard=unmap,aio=native,cache=none,id=n0 \
-device scsi-hd,drive=n0,bus=scsi0.0 \
-drive file=/dev/nvme1n1,if=none,format=raw,discard=unmap,aio=native,cache=none,id=n1 \
-device scsi-hd,drive=n1,bus=scsi0.0 \
-boot once=d -vnc 127.0.0.1:0,password=on -monitor stdio
The SSH service inside the VM is made available on port 1022 of the rescue system.
Note:
The disk devices of the servers will be attached as SCSI disks in the VM no matter what they are on the host.
This means that inside the VM the disks are always mapped to /dev/da0
and /dev/da1
.
Set a VNC password to allow VNC access (Optional)
You need to forward port 5900 using SSH to connect to VNC!
(qemu) set_password vnc mfsroot
(qemu)
Step 4 - Copy the distribution files to the VM
On a root shell of the rescue Linux system, run the following command:
scp -o Port=1022 base.txz kernel.txz root@localhost:
The root password inside the virtual machine is mfsroot
.
Step 5 - Login to the VM
Use SSH to log into the VM from a shell on the rescue system:
ssh -p 1022 root@localhost
The password is mfsroot
.
Verify that the drives are visible:
dmesg | grep QEMU
cd0: <QEMU QEMU DVD-ROM 2.5+> Removable CD-ROM SCSI device
da0: <QEMU QEMU HARDDISK 2.5+> Fixed Direct Access SPC-3 SCSI device
da1: <QEMU QEMU HARDDISK 2.5+> Fixed Direct Access SPC-3 SCSI device
Step 6 - Install FreeBSD
Install FreeBSD with the zfsinstall script:
zfsinstall -d /dev/da0 -d /dev/da1 -r mirror -p zroot -s 16G -u .
This will install FreeBSD on a ZFS pool zroot
using RAID-1 (mirror
) on both disks with 16GiByte swap space on each disk.
The installed FreeBSD root filesystem will be mounted on /mnt
. Since we are running the current version of FreeBSD inside the VM, we can now already just use chroot to configure the new installation:
mount -t devfs devfs /mnt/dev
chroot /mnt
Step 7 - Configure FreeBSD
Once we used chroot to get a shell running inside the installed FreeBSD environment, we can complete the configuration.
-
Set a root password
passwd
-
Enable root login with password
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config
Note: You may want to disable this later after you created user accounts
-
Set the hostname, and enable sshd & our newly created autodhcpd script
Create the file
/etc/rc.conf
with the following content:cat << EOF > /etc/rc.conf zfs_enable="YES" hostname="myhost.mydomain" sshd_enable="YES" EOF
Step 8 - Configure the network settings
If your server uses a RealTec based network card, the name of your interface is most likely re0
.
If your server uses an Intel based network card, the name is either em0
or igb0
.
If in doubt, use Google to find out what your NIC would be called in FreeBSD.
In our example we need to use em0
as the name of our network card.
Add the following lines to the /etc/rc.conf
file:
In the command below, replace
em0
,192.168.0.2/27
,192.168.0.1
, and2a01:4f8:0:0::2/64
as needed.
cat <<EOF >>/etc/rc.conf
ifconfig_em0="192.168.0.2/27"
static_routes="gateway default"
route_gateway="-host 192.168.0.1 -interface em0"
route_default="default 192.168.0.1"
ifconfig_em0_ipv6="inet6 2a01:4f8:0:0::2/64"
ipv6_defaultrouter="fe80::1%em0"
EOF
Step 9 - Clean up
Exit the chroot environment and unmount the filesystems
exit
sync
umount /mnt/dev
umount /mnt/var
umount /mnt/tmp
umount /mnt
You can either shut down the qemu virtual machine or terminate the qemu process.
With everything set up, you can reboot the server into the FreeBSD distribution:
reboot
Conclusion
Congratulations! You now have a working FreeBSD installation that does not require full UEFI support.
Additional note:
If your installation gets broken and doesn't boot anymore, you can use the Linux rescue system to access it:
The vKVM way
Use QEMU to boot your system
- Boot into the Linux rescue system
- Boot your FreeBSD system inside a QEMU VM:
In the command below, replace
/dev/nvme0n1
and/dev/nvme1n1
as needed.qemu-system-x86_64 -net nic -net user,hostfwd=tcp::1022-:22 -m 2048M -enable-kvm \ -cpu host,+nx -M pc -smp 2 -vga std -k en-us \ -device virtio-scsi-pci,id=scsi0 \ -drive file=/dev/nvme0n1,if=none,format=raw,discard=unmap,aio=native,cache=none,id=n0 \ -device scsi-hd,drive=n0,bus=scsi0.0 \ -drive file=/dev/nvme1n1,if=none,format=raw,discard=unmap,aio=native,cache=none,id=n1 \ -device scsi-hd,drive=n1,bus=scsi0.0 \ -boot once=d -vnc 127.0.0.1:0,password -monitor stdio
- Use either VNC or SSH to connect to the VM and make your changes
- Shutdown your VM guest
poweroff
- Reboot the rescue system
reboot
The OpenZFS way
Use the Linux rescue system to access the file system:
- Boot into the Linux rescue system
- Install OpenZFS using
zfs
zfs
- Import your root pool without mounting its datasets
zpool import -o cachefile=none -f -N zroot
- Mount your root dataset
mount -t zfs zroot/root /mnt
- Make any modifications you need and reboot
reboot