FreeBSD

From wikinotes

Install Media Creation

Download one of the .img files from https://www.freebsd.org/where.html

Install Documentation: https://www.freebsd.org/doc/handbook/bsdinstall-pre.html

# dd to raw disk, not partition
# (same 'dd' params on bsd and linux)
dd if=FreeBSD-10.2-RELEASE-amd64-memstick.img of=/dev/da0 bs=1M conv=sync

Installation can also be scripted using the FreeBSD bsdinstall commandline tool.

Release Management

Updates from FreeBSD version (ex: 11.1 -> 11.2) are possible. See freebsd release management.

Package Management

Important Package Locations
/usr/local/share/ Typical Package install location
/etc/rc.d

/usr/local/etc/rc.d

Init script locations (find out what variables to use in rc.conf here)
http://pkg.FreeBSD.org/FreeBSD:12:amd64/quarterly/All packages downloaded from here

FreeBSD has three methods of installing programs. Ports, pkg_add, and pkg.

  • Ports are the source code and makefiles, which must be compiled.
  • Pkg_add are precompiled binaries.
  • pkg, or PackageNG are also precompiled binaries, but they have \

been compiled from the ports tree. This is the preferred method of\ package management.

pkgng
freebsd-ports

Freebsd still supports pkg_add, but it's main package manager is pkgng.

Kernel Sourcecode

# Fetch kernel sourcecode, extract to /usr/src
fetch -o /tmp ftp://ftp.freebsd.org/pub/`uname -s`/releases/`uname -m`/`uname -r | cut -d'-' -f1,2`/src.txz
tar -C / -xvf /tmp/src.txz

Kernel Modules

/boot/kernel/ Kernel Module Location
sudo kldload fuse					## Load a kernel module (by name)
sudo kldstat						## Show all loaded kernel modules
# /boot/loader.conf
# this file contains all kernel-modules to be started on boot
fuse_load="YES"

See Also kld.

FileSystem

BSD FileSystem
FreeBSD devfs

Volume Management

camcontrol devlist    # lists diskname/device (ada0, da0, ..)
gpart show /dev/ada0  # list partition table
ls /dev/disk/         # lists available disks/partitions
ls /dev/diskid/       # lists disks by id


Create new UFS

gpart destroy -F da1            ## delete MBG/gpt
gpart create -s gpt da1         ## create GPT partition system.
gpart add -t freebsd-ufs da1    ## create partition covering entire disk
newfs -U /dev/da1s1		## new ufs filesystem
df -h /dev/da1s1                ## confirm size of filesystem is appropriate

Mount ZFS

zpool import -fR /mnt -a	## mount a zpool to /mnt

Mount ext2/3/4

# see: https://www.freebsd.org/doc/handbook/filesystems-linux.html
# requires port: sysutils/fusefs-ext2fs
kldload ext2fs
mount -t ext2fs /dev/ad1s1 /mnt

Mount exfat

# requires port: sysutils/fusefs-exfat
mount -t exfat /dev/ad1s1 /mnt

Mount fat32

sudo mount -t msdosfs /dev/da0p1 /mnt

Kernel Event Queue

See kqueue.

Init/Services System

See FreeBSD-init.

Logging

See FreeBSD syslogd.

Startup/Shutdown

shutdown -p now
reboot

Date/Time

## Query Date
date 										## prints current date/time

## Timezone
ln -s /usr/share/zoneinfo/America/Toronto /etc/localtime

## Sync Current Time
ntpdate -v -b in.pool.ntp.org		## set current date with ntp

Networking

See freebsd networking.

start/stop/restart network

# restart network
service netif restart
service routing restart

# connect to network
dhclient en01

TTY

FreeBSD currently uses freebsd vt as a console driver.
For historical drivers, see tty.

Firewall

See pf.

Email

# unable to set subjectline?
echo 'my body' | sendmail \
  -fnoreply     `# ${user}@domain.com -- where domain.com is rc.conf hostname` \
  -F'No Reply'  `# sender name` \

Containers

FreeBSD jails

Linux Emulation

See FreeBSD linuxlator .

Resource Management

Documentation

memory https://wiki.freebsd.org/Memory
virtual memory https://www.freebsd.org/doc/en_US.ISO8859-1/books/arch-handbook/vm.html

CPU

bsd top

Memory

freebsd procfs
bsd ps
bsd top
procstat
bsd vmstat

Network

tcpdump
pflog
sockstat
netstat

Backups & Restoration

freebsd dump