The handbook is great, but this is the short one.
- Boot
- File Systems
- Firewall
- Hardware
- Jails
- Kernel
- Networking
- Permissions
- pkgng
- Ports
- rc.d
- Shell
- Software
- Time
- Updates
- ZFS
# /boot/loader.conf
autoboot_delay="3"
beastie_disable="YES"
seek
specifies the size.
dd if=/dev/zero of=filesystem.img bs=1 seek=100G count=1
dd if=/dev/zero of=filesystem.img bs=1 seek=200G count=1
mdconfig filesystem.img
newfs -U /dev/md0
mount /dev/md0 /path/to/local/mnt
umount /dev/md0
mdconfig -d -u md0
dd if=/dev/zero of=filesystem.img bs=1 seek=200G count=1
mdconfig filesystem.img
growfs /dev/md0
mount /dev/md0 /path/to/local/mnt
## Mount
mkdir /media/cdrom
mdconfig -a -t vnode -f /path/to/iso/file
mount -t cd9660 /dev/md0 /media/cdrom
## Unmount
umount /media/cdrom
mdconfig -d -u md0
kldload /boot/kernel/geom_linux_lvm.ko
pkg install fusefs-ext4fuse
ext4fuse /dev/linux_lvm/volumegroup-logicalvolume /mnt
ext_if = "em0"
tcp_pass = "{ ssh }"
# net_jail="127.0.1.0/24"
# nat on $ext_if from $net_jail to any -> $ext_if
set skip on lo1
block in all
pass out all
pass in on $ext_if proto tcp to any port $tcp_pass keep state
pass inet proto icmp all icmp-type echoreq keep state
pass in quick proto icmp6 all
camcontrol identify ada0
chflags -R noschg /usr/jails && \
rm -rf /usr/jails
In ascending level of obscurity, helpful when dealing with appliances based on FreeBSD.
freebsd-version
sysctl -n kern.osrelease kern.ostype
ident /boot/kernel/kernel
objdump -sj .data /boot/kernel/kernel | tail -n 22
svnlite checkout https://svn.freebsd.org/base/release/11.1.0 /usr/src
# IPv4
ifconfig vtnet0 alias 10.80.0.67/32
# IPv6
ifconfig vtnet0 inet6 2610:1c1:0:4::3 prefixlen 64 alias
# /etc/rc.conf
ifconfig_em0_alias0="inet 10.80.0.67/32"
ifconfig_em0_alias1="inet6 2610:1c1:0:4::3 prefixlen 64"
sockstat -46l | grep -E -e "\*:[[:digit:]]"
chflags schg /etc/resolv.conf
/etc/rc.d/netif restart && /etc/rc.d/routing restart
mount_smbfs -I 10.20.30.40 //username@server/share /path/to/local/mnt
# ~/.nsmbrc
[SERVER:USERNAME]
password=password
mount_smbfs -N -I 10.20.30.40 //username@server/share /path/to/local/mnt
route add default 10.20.30.1
# /etc/rc.conf
defaultrouter="10.20.30.1"
Confirm:
netstat -r
Command | Purpose |
---|---|
U | The route is active (up). |
H | The route destination is a single host. |
G | Send anything for this destination on to this gateway, which will figure out from there where to send it. |
S | This route was statically configured. |
C | Clones a new route based upon this route for machines to connect to. This type of route is normally used for local networks. |
W | The route was auto-configured based upon a local area network (clone) route. |
L | Route involves references to Ethernet (link) hardware. |
# /etc/rc.conf
hostname="freebsd.example.com"
### IPv4
ifconfig_em0="inet 192.168.0.6 netmask 255.255.255.0"
defaultrouter="192.168.0.254"
### IPv6 (multiple aliases possible)
ifconfig_em0_ipv6="inet6 2a03:4000:36:3f8::1/64"
ipv6_defaultrouter="fe80::1%em0"
## Enable
chflags schg /path/to/file
## Disable
chflags noschg /path/to/file
Fixes "sqlite error while executing INSERT OR ROLLBACK INTO pkg_search".
pkg info -ao > pkglist.txt
rm /var/db/pkg/local.sqlite
pkg update -f
pkg install `cat pkglist.txt`
pkg query --all '%o %n-%v %R'
Prints out all previously set options in make.conf
compatible format. Enables
creating pre-configured builds. Obviously only set the ones you absolutely
require, otherwise it will easily break on changes.
# process.sh
#!/bin/sh
FILE=$1
TMP=/tmp/process.tmp
NAME=`echo $FILE | sed -E 's#/var/db/ports/(.*)/.*#\1#'`
cat $FILE | \
sed -E '/^_|^#/d' | \
sed -E "s/OPTIONS_FILE/$NAME/" \
> $TMP
cat $TMP
find '/var/db/ports/' -name 'options' -exec ./process.sh '{}' \;
#!/bin/sh
#
# PROVIDE: fooapp
# REQUIRE: networking
# KEYWORD:
. /etc/rc.subr
name="fooapp"
rcvar="fooapp_enable"
fooapp_user="fooapp"
fooapp_command="/usr/local/fooapp/fooapp"
pidfile="/var/run/fooapp/${name}.pid"
command="/usr/sbin/daemon"
command_args="-P ${pidfile} -r -f ${fooapp_command}"
load_rc_config $name
: ${fooapp_enable:=no}
run_rc_command "$1"
Remember to create the fooapp
user, the pidfile
path and apply user permissions to it.
echo > ~/.history && history -c && exit
pkg query --all '%o %n-%v %R'
First, either mount FreeBSD CD-ROM or ISO to /dist
.
mkdir -p /usr/local/etc/pkg/repos
# /usr/local/etc/pkg/repos/cdrom.conf
cdrom: {
url: "file:///dist/packages/${ABI}",
mirror_type: "none",
enabled: yes
}
FreeBSD: {
enabled: no
}
pkg update
2 GB tmpfs
portmaster devel/ccache
mkdir /ram
echo 'none /ram tmpfs rw,size=2147483648 0 0' >> /etc/fstab
mount /ram
## ccache
WRKDIRPREFIX=/ram
CCACHE_DIR=/var/cache/ccache
WITH_CCACHE_BUILD=yes
## Build Optimizations
CPUTYPE?=native
OPTIONS_SET=OPTIMIZED_CFLAGS CPUFLAGS
BUILD_OPTIMIZED=YES
## Headless server options
OPTIONS_SET+=ICONV
OPTIONS_UNSET=CUPS DEBUG FONTCONFIG NLS X11
WITHOUT_MODULES=sound ntfs linux
## Disable sendmail
NO_SENDMAIL=true
## Fresh OpenSSL from Ports
DEFAULT_VERSIONS+=ssl=openssl
If ntpd
is installed:
service ntpd stop
ntpd -q -g
service ntpd start
With base ntp
:
ntpdate -v -b in.pool.ntp.org
# /etc/ntp.conf
interface ignore wildcard
ln -s /usr/share/zoneinfo/Asia/Calcutta /etc/localtime
cd /usr/ports/ports-mgmt/portmaster && \
make install clean
portsnap fetch extract
portsnap fetch update
freebsd-update fetch install
For a new release:
mv /usr/src /usr/src.bak
svn checkout https://svn.freebsd.org/base/releng/11.1 /usr/src
Always:
svn update /usr/src
less /usr/src/UPDATING
cd /usr/src
make -j4 buildworld
make -j4 kernel
shutdown -r now
cd /usr/src
make installworld
mergemaster -Ui
shutdown -r now
zpool create tank /path/to/filesystem.img
zpool import -d /path/to/folder/containing/filesystem.img tank
Useful for untrusted pools or ones that mount to system directories.
zpool import -f -R /mnt pool
Usually those are mirrors, which is what those instructions are for. The assumed failed disk is ada1
. Swap size could differ, check that before this action with gpart show
.
zpool offline <FAILED_DISK>
zpool detach <FAILED_DISK>
# ...physically swap defective disk for a working disk...
gpart add -b 40 -l gptboot1 -s 512K -t freebsd-boot ada1
gpart add -s 16G -l swap1 -t freebsd-swap ada1
gpart add -t freebsd-zfs -l zfs1 ada1
zpool attach zroot ada0p3 ada1p3
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada1
This comes in handy on unable to remount devfs under dev
errors, for example. Reboot machine from USB/CD/network image. Select "Live System", then:
mkdir /tmp/mnt
zpool import -f -R /tmp/mnt zroot
zfs mount zroot/ROOT/default
chroot /tmp/mnt
# ...make changes...
exit
zpool export zroot
reboot
zfs set readonly=off zroot