There are cases the default image does not suit for one. In this exercise, I practice installing FreeBSD version 11 from scratch. I go beyond the standard procedure by partitioning the drive manually with commands. This is to leave space I can create partitions purely for payload later. (If you just want to go automatic, you can refer to the FreeBSD handbook.)
Some errors take place so I get to correct the boot loader manually. If you have tried fixing the boot loader of some other “freedom” operating system, you will appreciate how easy it is!
Inserting the Disc and Boot
Instead of selecting the default boot image, we pick an installation disc. In Vultr, There are two ways. The first way is to let the system download the installation disc. For example, you find a link for the FreeBSD installation disc, copy the URL, and pass it to the interface. The second way is to reuse the existing library of installation discs.
It takes quite some time for the system to boot. Depending whether you are lucky or not, you may or may not see the beastie welcome screen. This is so-called the boot loader, or simply the loader, with just a few tens of kilobytes.
Inside the Installer
The system boots and the installer (precisely, “bsdinstall”) automatically executes. From now on, there are a few keystrokes you need to know. The action buttons, quoted in brackets, can be selected with left and right arrow keys. To toggle the action button, press enter key. The items above the action buttons are selected with up and down. To toggle the item on or off, press spacebar. At any one time, an action button and a selectable item are highlighted. When there are multiple fields, press the tab, not enter, to jump between.
Question 1 – mode selection: In the screen below, you can press enter to run the installer. You can alternatively press right arrow to select the shell, then enter to run the shell. Here we select “install” directly.
Question 2 – keymap: If you want to select an alternative keymap, use up and down arrow keys, and press spacebar to select. Then, press enter to confirm.
Question 3 – hostname: You are going to enter a hostname. If you are creating a machine to be cloned, you can pick a generic name.
Question 4 – distributions: You are asked what distribution components to select. Usually I just pick “lib32” only. By default, they propose installing “ports”, I deselect it (with spacebar) most of the time. The updated ports can be downloaded by “postsnap” command later.
Partitioning and Formatting the Drive
Question 5 – partition method: You are given several ways to partition, the “auto” one are the most easy but they may generate something you do not like. The “manual” shows a dialog where you can create the partitions yourself, but not control the partition alignments. So let us select “shell”.
Question 6 – partition: You are given a shell and instructed to type in commands, edit a file, and mount the effective file system. Use the following commands to partition the only virtual hard drive, “vtbd0”, and then install the bootloader.
# gpart show # gpart create -s gpt /dev/vtbd0 vtbd0 created # gpart show => 40 52428720 vtbd0 GPT (25G) 40 52428720 - free - (25G) # gpart add -t freebsd-boot -a 512K -s 512K /dev/vtbd0 vtbd0p1 added # gpart add -t freebsd-swap -a 1M -s 2047M /dev/vtbd0 vtbd0p2 added # gpart add -t freebsd-ufs -a 1M -s 5120M /dev/vtbd0 vtbd0p3 added # gpart show => 40 52428720 vtbd0 GPT (25G) 40 984 - free - (492K) 1024 1024 1 freebsd-boot (512K) 2048 4192256 2 freebsd-swap (2.0G) 4194304 10485760 3 freebsd-ufs (5.0G) 14680064 37748696 - free - (18.0G) # gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 /dev/vtbd0 bootcode written to /dev/vtbd0
Previous step, we partition the drive into three, a boot partition, a swap partition, and a unix file system partition. We install the GPT boot loader into the boot partition. Then, format the last partition, define the file system table as previously instructed, then we are done. The installer starts installation without a question asked.
# newfs -U /dev/vtbd0p3 (message truncated) # mount /dev/vtbd0p3 /mnt # cat >> /tmp/bsdinstall_etc/fstab << EOF /dev/vtbd0p2 none swap sw 0 0 /dev/vtbd0p3 / ufs rw 1 1 EOF # exit
Final Touches to the Installation
Question 7 – root password: Pick and enter a password carefully, twice.
Question 8 – network configuration: You are asked what network devices you like to configure. Select the only virtual network device, “vtnet0”. Enable IPv4 and DHCP. Disable IPv6 (unless you know why not).
Question 9 – name resolver configuration: Simply press “ok” for the DNS configuration. The DNS server setting will be overridden soon.
Question 10 – time zone selection: Select the continent you are in, and then the city. You are then asked if the abbreviation is appropriate, and confirm the system date and time.
Question 11 – services: I would select “local_unbound”, “sshd”, and “ntpd”.
Question 12 – security: Since version 11, the FreeBSD installer asks if the user wants any additional security measures. I think most of them can be enabled, except the debugging. (This is because I do debug programs.)
Question 13 – additional users: This is up to you. I prefer customisation before user creation.
Question 14 – final configuration: Just skip…
Question 15 – final modification: Just skip…
Question 16 – what next: Instead of rebooting, I prefer going to the live CD mode, login and “poweroff”.
Take a snapshot before booting the system again. On the first system boot, the SSH generates its identities. If you want multiple hosts having their distinct identities, taking the snapshot before the first boot is the laziest and the most correct way.
Last but not least, remove the virtual optical drive image. Then you are good to boot from the virtual hard drive.
Troubleshooting and Fixing the Boot Loader
Missing boot loader: When generating the screenshots, I forgot to install the boot code. The boot screen looks like this and is stuck. This is a sign of missing the boot loader. I booted with the installation disc again, then choose shell mode, and finally rerun the “gpart bootcode” command.
# gpart show => 40 52428720 vtbd0 GPT (25G) 40 984 - free - (492K) 1024 1024 1 freebsd-boot (512K) 2048 4192256 2 freebsd-swap (2.0G) 4194304 10485760 3 freebsd-ufs (5.0G) 14680064 37748696 - free - (18G) # gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 /dev/vtbd0 bootcode written to /dev/vtbd0
Damaged file system table: On the next boot attempt, I drop into single user mode because of bad file system table. This was because I wrote “rw” instead of “sw” for the swap. I then corrected the “/etc/fstab” with an editor. Then I “exit” to continue the boot.
For you reference, the security options I made in installation turns out to be the following. So they can be incorporated in other installation tools, without actually running the “bsdinstall”.
clear_tmp_enable="YES" syslogd_flags="-ss" local_unbound_enable="YES"
security.bsd.see_other_uids=0 security.bsd.see_other_gids=0 security.bsd.unprivileged_read_msgbuf=0 security.bsd.stack_guard_page = 1
nameserver 127.0.0.1 options edns0