new-install

Notes on OS intalls
git clone https://git.bracken.jp/new-install.git
Log | Files | Refs | LICENSE

freebsd_install.md (26000B)


      1 FreeBSD new install instructions
      2 ================================
      3 
      4 Download install image
      5 ----------------------
      6 
      7 First, we'll need to download an install image from
      8 https://www.freebsd.org/where.html. These instructions presume amd64
      9 architecture, so we'll use an amd64-memstick image.
     10 
     11 Once the image is downloaded, write it to a USB stick using `dd`. Using the
     12 instructions in the FreeBSD Handbook here:
     13 https://www.freebsd.org/doc/handbook/bsdinstall-pre.html.
     14 
     15 
     16 Install from USB stick
     17 ----------------------
     18 
     19 Boot from the USB stick in UEFI mode. The machine should now boot into the
     20 FreeBSD installer.
     21 
     22 1. Keyboard layout: USA (Caps Lock acts as Left Ctrl).
     23 2. Set hostname (should include domain name).
     24 3. Install `ports`.
     25 4. Auto disk partition. Entire disk. GPT.
     26 5. Network. Yes IPv4, no IPv6 unless you have IPv6 set up. For a non-networked
     27    install select 'no' for both. We can set this up later.
     28 6. Set clock to UTC.
     29 7. Enable `sshd`, `ntpd`, `powerd`, `dumpdev`.
     30 8. Set security hardening options (see below).
     31 9. Add user with `wheel` additional group.
     32 
     33 Once these steps are done, select the option to drop into a console session to
     34 complete a few additional steps.
     35 
     36 
     37 ### Set security hardening options
     38 
     39 For an internet-facing server, it's worth locking it down. Use the following
     40 options:
     41 1. hide_uids
     42 2. hide_gids
     43 3. hide_jail
     44 4. read_msgbuf
     45 5. proc_debug
     46 6. random_pid
     47 7. clear_tmp
     48 8. disable_syslogd
     49 9. disable_ddtrace
     50 10. enable_aslr
     51 
     52 
     53 ### Set the console keyboard layout
     54 
     55 The console keyboard layout can be temporarily changed using the `kbdcontrol`
     56 command:
     57 
     58     kbdcontrol -l jp.capsctrl
     59 
     60 It can be permanently set by adding a line to `/etc/rc.conf`:
     61 
     62     keymap=jp.capsctrl
     63 
     64 For US keyboard layout with Caps Lock as Control, use `us.ctrl` for a Japanese
     65 keyboard with Caps Lock as Control, use `jp.capsctrl`. You can find all layouts
     66 in the `/usr/share/vt/keymaps` directory.
     67 
     68 
     69 ### Configure the hostname
     70 
     71 First we'll get the hostname set:
     72 
     73 First, set domain-qualified hostname in `/etc/rc.conf`.
     74 
     75     hostname="myhost.bracken.jp"
     76 
     77 Next, update `/etc/hosts` to use domain name. Add raw hostname and
     78 domain-qualified hostname after localhost entries.
     79 
     80     ::1       localhost localhost.bracken.jp myhost myhost.bracken.jp
     81     127.0.0.1 localhost localhost.bracken.jp myhost myhost.bracken.jp
     82 
     83 
     84 ### Configure wired ethernet
     85 
     86 Next, configure wired ethernet for DHCP. In `/etc/rc.conf`, add:
     87 
     88     # SYNCDHCP forces startup to wait for dhclient to return, DHCP does not.
     89     ifconfig_em0="SYNCDHCP"
     90 
     91 Either SYNCDHCP or DHCP is acceptable. The default is DHCP.
     92 
     93 
     94 ### Configure WiFi
     95 
     96 If we need Intel WiFi, edit `/etc/rc.conf`:
     97 
     98     # Space-separated kernel module load list.
     99     kld_list="if_iwlwifi"
    100 
    101 and then configure DHCP for WiFi:
    102 
    103     wlans_iwm0="wlan0"
    104     ifconfig_wlan0="WPA DHCP"
    105 
    106 and set up the WiFi network and password in `/etc/wpa_supplicant.conf`:
    107 
    108     network={
    109      ssid="my_ssid_name"
    110      psk="my_password"
    111     }
    112 
    113 then ensure that no one but root can read the contents:
    114 
    115     chmod go-rwx /etc/wpa_supplicant.conf
    116 
    117 To assign a fixed IP address to always be returned by the router's DHCP server,
    118 get the WiFi MAC address using `ifconfig wlan0`, then in the router, manually
    119 assign a fixed IP address.
    120 
    121 
    122 ### Configure sendmail
    123 
    124 By default, sendmail operates localhost only. If you disable it, you'll need to
    125 enable an alternative mail handler since the system assumes mail is available.
    126 (See note below)
    127 
    128 Given that we generally want to disable root login on all hosts, it's useful to
    129 forward root's mail to a local user. To do so:
    130 
    131 1. Edit `/etc/mail/aliases`. Forward root's mail to a local user (e.g.  `chris`)
    132    or a domain-qualified email address such as `chris@bracken.jp`.
    133 2. Run `newaliases` to rebuild the random-access database populated from
    134    `/etc/mail/aliases`. This is exactly the same as `sendmail -bi`.
    135 
    136 See https://www.freebsd.org/doc/handbook/sendmail.html for details.
    137 
    138 Note: you can get away with disabling email completely, but the daily, weekly,
    139 monthly `periodic` jobs set up in `/etc/crontab` send email to root, so you'd
    140 want to configure `periodic` to log output instead of emailing it. You can do
    141 this by adding the following to `/etc/periodic.conf`:
    142 
    143     daily_output=/var/log/daily.log
    144     weekly_output=/var/log/weekly.log
    145     monthly_output=/var/log/monthly.log
    146 
    147 More details can be found in the `periodic` man page.
    148 
    149 
    150 ### Set the console font
    151 
    152 To list available fonts, run `vidfont`, an ncurses-based program that sets the
    153 font to something legible when running. When it exits, it'll dump the selected
    154 font name.
    155 
    156 To set the font from a script, run:
    157 
    158     vidcontrol -f FONTNAME
    159 
    160 where `FONTNAME` is the name dumped by vidfont.
    161 
    162 To permanently set the console font, edit `/etc/rc.conf`:
    163 
    164     allscreens_flags="-f FONTNAME"
    165 
    166 I find `terminus-b32` to be the most legible on a small screen. On a large
    167 screen, `vgarom-8x14` or `vgarom-8x16` might be better.
    168 
    169 A couple reference articles relating to framebuffer console fonts:
    170 
    171 * [How to change console font type and size](https://lists.freebsd.org/pipermail/freebsd-questions/2018-February/281063.html)
    172 * [CLI・CUIなワークステーションを作る](http://www.lufimia.net/cal/workstation/index.htm)
    173 * [FreeBSDで日本語コンソールvtを使う](https://www.next-hop.net/~hiraga/FreeBSD/japanese-vt.shtml)
    174 
    175 
    176 Reboot the machine
    177 ------------------
    178 
    179 Once the above steps are done, run exit the shell and select to end the
    180 installation and reboot.
    181 
    182 
    183 Install initial packages
    184 ------------------------
    185 
    186 Install general packages:
    187 1. `pkg update -f`
    188 2. Install doas: `pkg install doas` (alternatively install sudo)
    189 3. Install zsh: `pkg install zsh`
    190 4. Install bash: `pkg install bash` (only required for bazel)
    191 5. Install vim: `pkg install vim-console`
    192 6. Install tmux: `pkg install tmux`
    193 
    194 If running on a VM under XCP-NG:
    195 1. Install Xen guide utils: `pkg install xe-guest-utilities`
    196 2. In /etc/rc.conf, add: `xenguest_enable="YES"`
    197 
    198 Install file manager:
    199 1. Run `pkg install mc` to install midnight commander.
    200 
    201 Install mutt email support:
    202 1. Run `pkg install mutt` to install mutt email client.
    203 2. Run `pkg install abook` to install address book.
    204 3. Run `pkg install notmuch` to install notmuch email indexer.
    205 4. Run `pkg install isync` to install email syncing.
    206 5. Run `pkg install msmtp` to install an SMTP plugin mutt can use.
    207 6. Run `pkg install w3m` to install w3m browser.
    208 7. Run `pkg install zathura zathura-pdf-poppler zathura-ps` to install zathura
    209    PDF/PS viewer.
    210 
    211 Install a gemini client:
    212 1. Run `pkg install amfora` to install amfora gemini client.
    213 
    214 Install newsreader support:
    215 1. Run `pkg install newsboat` to install newsboard RSS reader.
    216 
    217 Install developer packages:
    218 1. Run `pkg install git` (agree to install all) to install git.
    219 2. Run `pkg install tig` to install tig git client.
    220 3. Run `pkg install python3 python` to install python.
    221 4. Run `pkg install go` to install golang.
    222 5. Run `pkg install nasm` to install nasm assembler.
    223 6. Run `pkg install bazel` (note: requires `bash` at runtime) for bazel build.
    224 7. Run `pkg install gn` to install generate ninja.
    225 8. Run `pkg install ninja` to install ninja.
    226 9. Run `pkg install cscope` to install cscope code analyzer.
    227 10. Run `pkg install meson` to install meson build.
    228 11. Run `pkg install cmake` to install cmake build.
    229 
    230 Install static web site support:
    231 1. Run `pkg install gohugo` to install hugo static site generator.
    232 
    233 
    234 Set up doas
    235 -----------
    236 
    237 Edit `/usr/local/etc/doas.conf` and add the following text:
    238 
    239     permit nopass :wheel
    240     permit :wheel cmd reboot
    241     permit :wheel cmd shutdown
    242     permit nopass keepenv root as root
    243 
    244 
    245 Set up sudo (alternative to doas)
    246 ---------------------------------
    247 
    248 Prefer installing `doas` as described above, but leaving instructions here for
    249 reference.
    250 
    251 1. Edit `/usr/local/etc/sudoers` and uncomment the following line to enable sudo
    252    access for members of the `wheel` group:
    253 
    254         %wheel ALL=(ALL) ALL
    255 
    256 1. Disable direct root login by editing the passwd file using the `vipw`
    257    command. Find the row starting with `root:` and replace the hashed password
    258    between the first and second colons on that line with `*`.  The line should
    259    look something like:
    260 
    261         root:*:0:0::0:0:Charlie &:/root:/bin/csh
    262 
    263 1. Type `:wq` to save and exit.
    264 
    265 Now that sudo is set up, log in as a user in the `wheel` group on another
    266 console (Use Ctrl-Alt-F1 through F8 to switch ttys) and run `sudo ls /root` to
    267 verify everything is configured properly, then exit the root shell and continue
    268 all further steps as a user in the `wheel` group.
    269 
    270 
    271 Configure sshd
    272 --------------
    273 
    274 Edit `/etc/ssh/sshd_config` and uncomment or edit each of the following lines to
    275 disable password-based logins and allow only key-based authentication:
    276 
    277     PasswordAuthentication no
    278     ChallengeResponseAuthentication no
    279     PubkeyAuthentication yes
    280 
    281 Edit `/etc/rc.conf` to add:
    282 
    283     sshd_enable="YES"
    284 
    285 As root, start the sshd server:
    286 
    287     service sshd start
    288 
    289 Connect to the host via ssh from another machine:
    290 
    291     ssh myhost
    292 
    293 Copy any existing public key you want to be able to log in into
    294 `~/.ssh/authorized_keys` on the new machine -- e.g. on the new host:
    295 `cat > ~/.ssh/authorized_keys`. Then paste the public key you want to use to log
    296 in, and type ctrl-d to save.  You can find your public key in
    297 `~/.ssh/id_rsa.pub` on the existing host you want to connect from.
    298 
    299 
    300 Configure audio
    301 ---------------
    302 
    303 We may want to disable the PC speaker and its annoying beep. Edit
    304 `/etc/sysctl.conf` and add the following:
    305 
    306     # Disable the terminal bell.
    307     kern.vt.enable_bell=0
    308 
    309 Audio volumes themselves can be controlled via the `mixer` tool, which is part
    310 of the FreeBSD base install.
    311 
    312 
    313 Set up NVIDIA drivers
    314 ---------------------
    315 
    316 For systems with an NVIDIA card, we'll install the drivers, configure them to
    317 load at boot, and add X11 config.
    318 
    319 First install the drivers:
    320 
    321     pkg install nvidia-driver
    322 
    323 Next add the following line to `/boot/loader.conf`:
    324 
    325     nvidia_load="YES"
    326 
    327 Then add the following line to `/etc/rc.conf`:
    328 
    329     kld_list="nvidia-modeset"
    330 
    331 Next, create the file `/usr/local/etc/X11/xorg.conf.d/driver-nvidia.conf` with
    332 the following contents:
    333 
    334     Section "Device"
    335         Identifier "NVIDIA Card"
    336         VendorName "NVIDIA Corporation"
    337 	Driver "nvidia"
    338     EndSection
    339 
    340 Finally, reboot the system or run `kldload nvidia-modeset` to manually load the
    341 driver.
    342 
    343 
    344 Change shell to zsh
    345 -------------------
    346 
    347 Log in as your user:
    348 
    349 1. `chsh -s /usr/local/bin/zsh`
    350 2. `exit`
    351 
    352 Log in as user again:
    353 
    354 1. `ssh-keygen -t rsa -b 4096 -C "chris@bracken.jp (hostname)"`
    355 
    356 
    357 Configure Wayland
    358 -----------------
    359 
    360 ### Install WM and apps
    361 
    362 Add yourself to the `video` group:
    363 
    364     pw groupmod video -m $USER
    365 
    366 Install the DRM kernel module:
    367 
    368     pkg install drm-kmod
    369 
    370 Then, for Intel graphics, add the following line to `/etc/rc.conf`:
    371 
    372     kld_list="i915kms"
    373 
    374 The seatd daemon will need to be running. Add the following to `/etc/rc.conf`:
    375 
    376     seatd_enable="YES"
    377 
    378 Install the sway window manager:
    379 
    380     pkg install sway      \  # window manager
    381                 swaylock  \  # lock screen
    382                 swayidle     \  # idle manager
    383                 swaybg       \  # background screen
    384                 dmenu        \  # app launcher
    385                 wofi         \  # Wayland-native app launcher
    386                 grim         \  # Wayland screenshot utility
    387                 slurp        \  # Select a region in Wayland
    388                 wl-clipboard \  # command-line interface to Wayland clipboard
    389                 jq           \  # command-line JSON parser
    390                 libnotify    \  # command-line notification sender (notify-send)
    391                 mako            # Notification daemon
    392 
    393 Screenshots use the `grimshot` utility that I've checked into my dotfiles repo.
    394 This can be found in the Sway repo `contrib` directory. This utility depends on
    395 the `grim`, `slurp`, `wl-clipboard`, `jq`, and `libnotify` packages listed
    396 above.
    397 
    398 Install the alacritty terminal emulator:
    399 
    400     pkg install alacritty
    401 
    402 Install fonts:
    403 
    404     pkg install webfonts
    405     pkg install twemoji-color-font-ttf
    406     pkg install noto
    407     pkg install ja-font-ipa ja-font-ipa-uigothic ja-font-ipaex
    408 
    409 Install Firefox web browser:
    410 
    411     pkg install firefox   # browser
    412     pkg install openh264  # H264 video plugin
    413 
    414 Install the mpv video player:
    415 
    416     pkg install mpv
    417 
    418 Install xdg-utils to get file associations to apps:
    419 
    420     pkg install xdg-utils
    421 
    422 
    423 Configure XWindows
    424 ------------------
    425 
    426 As of 2022, Wayland works pretty well, and `xwayland` does a good job of
    427 covering anything that still relies on X, but if you prefer an X11 desktop,
    428 these instructions will cover things.
    429 
    430 ### Install Xorg, WM, and apps
    431 
    432 Install XWindows:
    433 
    434     pkg install xorg
    435 
    436 Install the i3 window manager:
    437 
    438     pkg install i3        \  # window manager
    439                 i3status  \  # status bar
    440                 i3lock    \  # lock screen
    441                 dmenu     \  # app launcher
    442                 xautolock \  # lock screen timeout manager
    443                 sxiv         # image viewer
    444 
    445 Install dunst for notifications:
    446 
    447     pkg install dunst
    448 
    449 Optionally, install compton compositor:
    450 
    451     pkg install compton
    452 
    453 Install urxvt terminal:
    454 
    455     pkg install rxvt-unicode
    456 
    457 Install flameshot screenshotting tool:
    458 
    459     pkg install flameshot
    460 
    461 Install fonts:
    462 
    463     pkg install webfonts
    464     pkg install twemoji-color-font-ttf
    465     pkg install noto
    466     pkg install ja-font-ipa ja-font-ipa-uigothic ja-font-ipaex
    467 
    468 Then refresh the font cache:
    469 
    470     fc-cache -f
    471 
    472 Install Firefox web browser:
    473 
    474     pkg install firefox   # browser
    475     pkg install openh264  # H264 video plugin
    476 
    477 Install the mpv video player:
    478 
    479     pkg install mpv
    480 
    481 
    482 ### Configure X
    483 
    484 Add the following line to `/etc/rc.conf`:
    485 
    486     dbus_enable="YES"
    487 
    488 Add yourself to the `video` group:
    489 
    490     pw groupmod video -m $USER
    491 
    492 Install DRM kernel module:
    493 
    494     pkg install drm-fbsd12.0-kmod
    495 
    496 Then set it to load at boot time by adding the following line to
    497 `/etc/rc.conf`:
    498 
    499     kld_list="/boot/modules/i915kms.ko"
    500 
    501 In some instances, this seems to result in a kernel panic. If that
    502 happens, install DRM from the `graphics/drm-kmod` port in the ports
    503 tree.
    504 
    505 
    506 ### Configure keyboard layout
    507 
    508 In XWindows, the keyboard can be set using `setxkbmap`:
    509 
    510     setxkbmap jp
    511 
    512 It can be permanently set by adding the above line to `.xinitrc`.
    513 
    514 To map Caps Lock into a control key:
    515 
    516     setxkbmap -option ctrl:nocaps
    517 
    518 
    519 ### Configure mouse
    520 
    521 To configure natural scrolling, create the file
    522 `/usr/local/etc/X11/xorg.conf.d/mouse.conf` with the following contents:
    523 
    524     Section "InputDevice"
    525       Identifier "Mouse1"
    526       Driver "mouse"
    527       Option "Protocol" "auto"
    528       Option "Device" "/dev/sysmouse"
    529       Option "Buttons" "5"
    530       Option "ZAxisMapping" "4 5"
    531     EndSection
    532 
    533 
    534 ### Reboot
    535 
    536 Reboot the system and attempt to run `startx`.
    537 
    538 
    539 Configure Japanese input
    540 ------------------------
    541 
    542 ### Wayland
    543 
    544 Install the fcitx input method with Anthy:
    545 
    546     pkg install fcitx5 \
    547                 fcitx5-configtool-qt6 \
    548                 fcitx5-gtk3 \
    549                 fcitx5-gtk4 \
    550                 fcitx5-qt6 \
    551                 ja-fcitx5-anthy
    552 
    553 
    554 ### XWindows
    555 
    556 Setting Japanese keyboard layout with caps-lock as control:
    557 
    558     setxkbmap -layout jp -option ctrl:nocaps
    559 
    560 Install fcitx5 as documented above.
    561 
    562 In `~/.xinitrc`, before launching i3, add:
    563 
    564     # Use fcitx for Japanese IME.
    565     export GTK_IM_MODULE=fcitx5
    566     export QT_IM_MODULE=fcitx5
    567     export XMODIFIERS=@im=fcitx5
    568 
    569     # Start fcitx5 IME.
    570     /usr/local/bin/fcitx5 -d --replace
    571 
    572 Configure fcitx by running `fcitx5-configtool`. Using the *Input Method* pane,
    573 add *Anthy*. Remove US keyboard if present (unless you're using a US keyboard).
    574 
    575 
    576 ### Virtual console
    577 
    578 Download Japanese fonts:
    579 
    580     fetch http://people.freebsd.org/~emaste/newcons/b16.fnt
    581     fetch http://www.wheel.gr.jp/~dai/fonts/jiskan16u.fnt
    582     fetch http://www.wheel.gr.jp/~dai/fonts/jiskan16s.fnt
    583     fetch http://www.wheel.gr.jp/~dai/fonts/unifont-8.0.01.fnt
    584 
    585 As root, copy the fonts to a local font directory:
    586 
    587     mkdir /usr/local/share/fonts/vt
    588     cp *.fnt /usr/local/share/fonts/vt
    589 
    590 You can convert BDF or HEX fonts to console `.fnt` files using the
    591 `vtfontcvt` command. See the `vtfontcvt` man page for details.
    592 
    593 Use the mechanism described (`vidfont` and `vidcontrol`) elsewhere in
    594 this document to set the font.
    595 
    596 
    597 Optionally set up pf firewall
    598 ------------------------------
    599 
    600 Canonical reference in the FreeBSD Handbook:
    601 https://www.freebsd.org/doc/handbook/firewalls-pf.html
    602 
    603 An excellent tutorial on the OpenBSD packet filter:
    604 https://home.nuug.no/~peter/pf/en/
    605 
    606 Another decent starter reference: http://srobb.net/pf.html
    607 
    608 
    609 ### Enable pf
    610 
    611 We'll need to populate `/etc/pf.conf`. A minimal config file that blocks all
    612 incoming connections other than SSH (port 22):
    613 
    614     # Our external-facing network interface.
    615     ext_if="em0"
    616 
    617     # Block spoofed IP addresses on em0.
    618     antispoof for $ext_if
    619 
    620     # Allow all connections over loopback.
    621     # "quick" means if rule is matched, stop processing here.
    622     pass quick on lo0 all
    623 
    624     # Block all incoming connections.
    625     block in all
    626 
    627     # Allow incoming SSH connections.
    628     pass in proto tcp to port 22
    629 
    630     # Allow all outgoing connections.
    631     pass out all keep state
    632 
    633 To run a check on our config file without yet applying it:
    634 
    635     pfctl -nvf /etc/pf.conf
    636 
    637 Next, we'll start `pf`, but since many a system administrator has found
    638 themselves locked out of their own server by applying a bad config, it's useful
    639 to queue up a command to disable the firewall after two minutes.  In another
    640 terminal, log into the remote machine, get a *root* shell using `doas -s`, then
    641 run the following:
    642 
    643     # Sleep 2 minutes, then disable pf.
    644     sleep 120; pfctl -d
    645 
    646 Then, before the two minutes is up, run these commands in another root terminal
    647 to start the firewall:
    648 
    649     # Load the pf kernel module.
    650     kldload pf
    651 
    652     # Enable pf.
    653     pfctl -e
    654 
    655 It's likely your SSH sessions will hang when you enable the packet filter.
    656 Quickly try connecting via SSH to verify you can connect before the two minute
    657 timeout above expires. If it worked, re-enable the packet filter on the server
    658 using `pfctl -e`.
    659 
    660 Once everything checks out, enable the packet filter on startup by adding the
    661 following lines to `/etc/rc.conf`:
    662 
    663     pf_enable="YES"
    664     pflog_enable="YES"
    665 
    666 
    667 ### Reading pf logs
    668 
    669 To read the pf logs, run:
    670 
    671     tcpdump -netttr /var/log/pflog
    672 
    673 
    674 ### Enabling blacklistd
    675 
    676 Canonical reference in the FreeBSD Handbook:
    677 https://www.freebsd.org/doc/handbook/firewalls-blacklistd.html
    678 
    679 If you've got an external-facing SSH port, you'll be continuously spammed with
    680 bogus connection attempts from people attempting to get access to
    681 badly-configured machines. The less clever of these tend to attack your machine
    682 repeatedly from the same IP address. FreeBSD includes the `blacklistd` service
    683 which can be used to temporarily ban IP addresses after repeated failed
    684 connection attempts.
    685 
    686 First, we'll add a pf anchor for blacklistd blocks in `/etc/pf.conf`:
    687 
    688     anchor "blacklistd/*" in on $ext_if
    689 
    690 Next we'll enable it on boot. We start the daemon with the `-r` flag, which
    691 tells it to re-read the firewall rules from the internal database and remove
    692 then re-add them; this is useful for packet filters that don't retain state
    693 across restarts, though it's unclear to me whether this is the case for `pf`.
    694 Add following lines to `/etc/rc.conf`:
    695 
    696     blacklistd_enable="YES"
    697     blacklistd_flags="-r"
    698 
    699 Next, as root, start the blacklistd service:
    700 
    701     service blacklistd start
    702 
    703 Finally, we'll enable blacklist support in sshd. Edit `/etc/ssh/sshd_config` and
    704 uncomment the line:
    705 
    706     UseBlacklist yes
    707 
    708 Then we'll restart sshd:
    709 
    710     service sshd restart
    711 
    712 at this point, everything should be up and running.
    713 
    714 
    715 Editing kernel sources
    716 ----------------------
    717 
    718 When editing kernel sources in vim, the indentation settings should be:
    719 
    720     set autoindent      " Copy indent from current line when starting a new line
    721     set smartindent     " Attempt to autoindent when starting a new line
    722     set smarttab        " Use shiftwidth rather than tabstop at start of line
    723     set tabstop=8       " Number of spaces a tab counts for
    724     set shiftwidth=4    " Number of spaces for each step of autoindent
    725     set softtabstop=4   " Number of spaces a tab counts for when editing
    726     set noexpandtab     " Use tabs rather than spaces
    727 
    728 
    729 Using a serial cable
    730 --------------------
    731 
    732 FreeBSD includes built-in support for various UART serial cables including the
    733 Prolific PL-2303 and FTDI cables. Connecting the cable will create three
    734 character devices named `ttyUN`, `ttyUN.init`, and `ttyUN.lock` in the dev
    735 filesystem.
    736 
    737 * `ttyUN` is the serial device.
    738 * `ttyUN.init` is an initialisation device used to initialise communication port
    739   parameters each time a port is opened, such as `crtscts` for modems which use
    740   `RTS/CTS` signalling for flow control.
    741 * `ttyUN.lock` is used to lock flags on ports to prevent users or programs from
    742   changing certain parameters. See the man pages for `termios`, `sio`, and
    743   `stty` for information on terminal settings, locking and initialising devices,
    744   and setting terminal options, respectively.
    745 
    746 More info on serial port configuration can be found in the FreeBSD Handbook:
    747 
    748 * [25.2 USB Virtual Serial Ports](https://www.freebsd.org/doc/handbook/usb-device-mode-terminals.html)
    749 * [26.2 Serial Terminology and Hardware](https://www.freebsd.org/doc/handbook/serial.html)
    750 
    751 To connect to the serial line, use the `cu` command:
    752 
    753     cu -l /dev/ttyU0 -s 115200
    754 
    755 To disconnect the serial session, type `~.` from within `cu`.
    756 
    757 
    758 Troubleshooting
    759 ---------------
    760 
    761 ### ssh-add fails to run
    762 
    763 If, when running ssh-add, you get an error along the lines of
    764 
    765     Could not open a connection to your authentication agent.
    766 
    767 you likely need to start ssh-agent. You can do this via:
    768 
    769     eval $(ssh agent -s)
    770 
    771 
    772 ### Segfault on keyboard input in dmenu
    773 
    774 If you have the `XMODIFIERS` variable set but your IME isn't properly configured
    775 and running, you'll get a crash on keyboard input to dmenu.
    776 
    777 
    778 ### Can't doas or log in as root
    779 
    780 Imagine you delete the root password via `vipw` without actually editing the
    781 `/usr/local/etc/sudoers` file first, or that you did edit that file but that no
    782 user is in the `wheel` group. Time to boot to single-user mode. Reboot the
    783 machine and when prompted at the initial FreeBSD boot prompt, quickly select
    784 option `2` to boot to single-user mode.
    785 
    786 The root filesystem is mounted read-only by default, so first we'll need to
    787 remount the root filesystem as read-write:
    788 
    789     /sbin/mount -o rw /
    790 
    791 Next, edit `/usr/local/etc/doas.conf` or make whatever other changes are
    792 required to fix your mistakes. Finally, reboot.
    793 
    794 
    795 ### Force renew DHCP lease
    796 
    797 DHCP leases are cached in `/var/db/dhclient.leases.em0` (replace `em0` with your
    798 interface name).
    799 
    800 To force renewal of DHCP lease, run as root:
    801 
    802     service dhclient restart em0
    803 
    804 To manually unbind/remove an IP address from an interface:
    805 
    806     ifconfig em0 remove 192.168.1.x
    807 
    808 
    809 ### Force NTP time sync
    810 
    811 To force sync the time on the host, run as root:
    812 
    813     ntpdate -v -b in.pool.ntp.org
    814 
    815 
    816 ### Intel NUC6i3SYK-specific issues
    817 
    818 #### SD card reader doesn't work
    819 
    820 Intel NUC6i3SYK devices give a repeating error on startup:
    821 
    822     sdhci_pci0_slot0: Controller timeout
    823 
    824 and dump registers. It seems like there's an issue with support for the NUC's SD
    825 card reader. After a couple minutes, eventually it gives up and continues.  To
    826 eliminate the warning on startup, reboot and enter the BIOS by holding down F2,
    827 then disable the SD card reader in the *Devices* section of the *Advanced*
    828 options.
    829 
    830 Alternatively, edit `/boot/loader.conf` to contain:
    831 
    832     hw.sdhci.enable_msi=0
    833 
    834 If that doesn't work, edit `/boot/device.hints` to contain:
    835 
    836     hint.sdhci_pci.0.disabled="1"
    837 
    838 
    839 #### Bluetooth doesn't work
    840 
    841 Mostly from notes in FreeBSD
    842 [Bugzilla issue 237083](https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=237038).
    843 
    844 The NUC's Intel 8260 Bluetooth/wireless requires a custom firmware download.
    845 FreeBSD 12.0 doesn't ship with all the support needed for this chipset. Fixes
    846 were landed in July 2019, but will take time to get released. When it does,
    847 installation will be:
    848 
    849     pkg install iwmbt-firmware
    850 
    851 In the meantime, the firmware downloader can be found here:
    852 [](https://github.com/wulf7/iwmbt-firmware). Build the downloader:
    853 
    854     git clone git@github.com:wulf7/iwmbt-firmware
    855     cd iwmbt-firmware
    856     make
    857 
    858 There's no need to install this, since it's a one-off tool to download and
    859 install the firmware. However, before you run it, you need to prevent FreeBSD
    860 from trying to auto-attach the device. Edit `/etc/devd.conf` and comment out the
    861 following lines, then power off and power back on the machine (a reboot is
    862 insufficient to clear the hardware state):
    863 
    864     attach 100 {
    865     	device-name "ubt[0-9]+";
    866     	action "service bluetooth quietstart $device-name";
    867     };
    868 
    869 Next, to download the firmware, we run as root:
    870 
    871     ./iwmbtfw
    872 
    873 This should get the download to happen, writing the firmware to
    874 `/usr/local/share/iwmbt-firmware/ibt-11-5.sfi`. As root, you can then start the
    875 service with:
    876 
    877     service start bluetooth ubt0
    878 
    879 To list the attached Bluetooth nodes, try:
    880 
    881     ngctl list
    882 
    883 It should display something like:
    884 
    885     There are 6 total nodes:
    886     Name: ubt0            Type: ubt             ID: 00000007   Num hooks: 0
    887     Name: ubt0hci         Type: hci             ID: 0000000?   Num hooks: 0
    888     Name: ubt012cap       Type: 12cap           ID: 0000000?   Num hooks: 0
    889     Name: btsock_hci_raw  Type: btsock_hci_raw  ID: 00000008   Num hooks: 0
    890     Name: btsock_l2c_raw  Type: btsock_l2c_raw  ID: 00000009   Num hooks: 0
    891     Name: btsock_l2c      Type: btsock_l2c      ID: 0000000a   Num hooks: 0
    892     Name: btsock_sco      Type: btsock_sco      ID: 0000000b   Num hooks: 0
    893     Name: ngctl1441       Type: socket          ID: 00000019   Num hooks: 0
    894 
    895 I notice when I do it, I'm missing the `ubt0hci` and `ubt012cap` entries though.
    896 
    897 Once you're done, uncomment the section of `/dev/devd.conf` above and reboot.