Desktop FreeBSD

Installing FreeBSD 12.1, Desktop!

FreeBSD 12.1 minimal install:

Encrypting root:

At the partition menu during install, select "shell"
In shell, view disks:
# sysctl kern.disks

With a blank disk run:
# gpart create -s gpt ada0

If there is data already, blank it:
# gpart destroy -F ada0

Create boot record, boot partition, and root for OS:
# gpart add -t freebsd-boot -s 512k -a 4k ada0
# gpart add -t freebsd-ufs -l bootfs -s 1g -a 1m ada0
# gpart add -t freebsd-ufs -l encrypted -a 1m ada0

Install boot code:
# gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ada0

Encrypt and attach partition:
# geli init -b -s 4096 ada0p3
# geli attach ada0p3

Format and mount:
# newfs -U /dev/ada0p2
# newfs -U /dev/ada0p3.eli
# mount /dev/ada0p3.eli /mnt
# mkdir /mnt/unenc
# mount /dev/ada0p2 /mnt/unenc
# mkdir /mnt/unenc/boot
# ln -s unenc/boot /mnt/boot

Create fstab:
# vi /tmp/bsdinstall_etc/fstab
----------------------------------------------------
# Device        Mountpoint      FStype  Options      Dump    Pass#
/dev/ada0p2     /unenc          ufs     rw,noatime      1       1
/dev/ada0p3.eli /               ufs     rw,noatime      2 

Load kernel modules:
# vi /tmp/bsdinstall_boot/loader.conf
----------------------------------------------------
geom_eli_load="YES"
vfs.root.mountfrom="ufs:ada0p3.eli"

Exit from the shell, proceed with the rest of the installation.  After boot the system should prompt for password before completing boot.

Installing Packages:

# Base Desktop
pkg install xfce
pkg install xorg
pkg install slim
# nVidia only
# Before installing, make sure to kldload linux and kldload linux64
pkg install nvidia-driver # Latest and ... greatest?
pkg install nvidia-driver-304 # GeForce 210
pkg install nvidia-driver-340 # GeForce 750 Ti
pkg install nvidia-xconfig nvidia-settings

# Ports for LAME
pkg install gettext gmake libiconv libtool nasm zip texi2html cmake ninja pkgconf binutils dav1d opencv-core automake libogg libvorbis libva libvpx libx264 libx265 libxvid
portsnap fetch
portsnap extract
cd /usr/ports/audio/lame
make install
cd /usr/ports/multimedia/ffmpeg
make install
cd /usr/ports/www/youtube_dl
make install

# Applications
pkg install audacious audacious-plugins clusterssh firefox libreoffice transmission stellarium xpra galculator thunderbird

# Utilities
pkg install xfce4-weather-plugin dsbmixer xfce4-datetime-plugin xfce4-screenshooter-plugin xscreensaver

# Graphics
# pkg install gnome-mplayer gthumb
pkg install smplayer mpv xpdf gimp dia inkscape feh viewnior ImageMagick7

# VM Hosting
pkg install virtualbox-ose
pw groupmod vboxusers -m username 

# Games
# pkg install nexuiz
pkg install xonotic minetest nestopia
# Network Security
pkg install tor polipo
# Scanners
pkg install xsane epkowa

Xorg -configure

vi /boot/loader.conf
autoboot_delay="0"
beastie_disable="YES"
linux_load="YES"
nvidia_load="YES"
vboxdrv_load="YES"
coretemp_load="YES" # For Intel CPU Temp
amdtemp_load="YES"  # For AMD CPU Temp

vi /etc/rc.conf
hald_enable="YES"
dbus_enable="YES"
slim_enable="YES"
vboxnet_enable="YES"
lpd_enable="YES"
#cupsd_enable="YES"

echo "/usr/local/bin/startxfce4">~/.xinitrc

// Printing with lpr
mkdir -p /var/spool/lpd/lp
chown daemon:daemon /var/spool/lpd/lp
chmod 770 /var/spool/lpd/lp

The /etc/printcap below should work for any network laser,
make sure to point to the proper ip address in your /etc/hosts for "laser":
lp:\
        :lp=9100@laser:\
        :sh:\
        :mx#0:\
        :sd=/var/spool/lpd/lp:\
        :lf=/var/log/lpd-errs:

echo 'lpd_enable="YES"'>>/etc/rc.conf
service lpd start

// Add some fonts
cp ttf_fonts.ttf /usr/local/lib/X11/fonts/TTF
http://www.freebsd.org/doc/en/books/handbook/x-fonts.html

// Tor it up
pkg install tor
cp /usr/local/etc/tor/torrc.sample /usr/local/etc/tor/torrc
// Uncomment RunAsDaemon 1
echo tor_enable="YES">>/etc/rc.conf
rm -r /var/db/tor /var/run/tor
mkdir -p /var/db/tor/data /var/run/tor
touch /var/log/tor
chown -R _tor:_tor /var/db/tor /var/log/tor /var/run/tor
chmod -R 700 /var/db/tor


pkg install polipo
cp /usr/local/etc/polipo/config.sample /usr/local/etc/polipo/config
// Uncomment socksParentProxy and diskCacheRoot
echo polipo_enable="YES">>/etc/rc.conf
// Point Firefox to localhost:8123

// Screencasting with RecordMyDesktop
RecordMyDesktop is an awesome tool for screencasting.
It can be run via command line or with a GUI (gtk-recordmydesktop)
Using the command-line can give better uniformity from video to video 
as far as window location and size.  720p is 1280x720 so run with this:
recordmydesktop --width 1280 --height 720 --s_quality 10 --delay 1 --fps 15 --no-wm-check --buffer-size 65538 --quick-subsampling --v_bitrate 2000000 -x 150 -y 120
FPS seems to make the biggest difference with audio getting ahead of video 720p example:
recordmydesktop --width 1280 --height 720 --s_quality 10 --delay 1 --fps 30 --buffer-size 65538 --quick-subsampling --no-wm-check --full-shots -x 160 -y 120
To pull audio off of an ogv:
ffmpeg -i out.ogv -acodec copy audio.ogg

Getting a USB headset to work in freebsd is as easy as, plug-in, dmesg:
ugen1.6:  at usbus1
uaudio0:  on usbus1
uaudio0: Play: 48000 Hz, 2 ch, 16-bit S-LE PCM format, 2x8ms buffer.
uaudio0: Play: 44100 Hz, 2 ch, 16-bit S-LE PCM format, 2x8ms buffer.
uaudio0: Record: 48000 Hz, 1 ch, 16-bit S-LE PCM format, 2x8ms buffer.
uaudio0: Record: 44100 Hz, 1 ch, 16-bit S-LE PCM format, 2x8ms buffer.
uaudio0: No MIDI sequencer.
pcm5:  on uaudio0
uaudio0: HID volume keys found.
sysctl -w hw.snd.default_unit=5 (modify /etc/sysctl.conf for perm)

Disable Recent Items:
rm ~/.local/share/recently-used.xbel
mkdir ~/.local/share/recently-used.xbel

Helpful things for hi-res eInk screen:
eInk-XFCE (Settings -> Appearance -> Fonts Tab -> DPI (140 default is 96)
Thunderbird (Edit -> Preferences -> Config Editor -> layout.css.devPixelsPerPx (2 default is 1)
Firefox (Default Zoom 200%)

References:
https://www.tubsta.com/2021/03/freebsd-13-0-full-desktop-experience/
TOTP Auth: https://github.com/chroma-x/php-oath-server-suite
Firefox Sound: add media.cubeb.backend=oss