Rebuild FreeBSD Ports

To rebuild a specific FreeBSD port and the ports that it depends on, for example, with pydf, do:

# portmaster -fR sysutils/pydf

To rebuild all install FreeBSD ports, it’s important to firstly read /usr/ports/UPDATING for any update advisories.

Then, to list ports with issued warnings, do:

# portaudit -a

Once you are confident that the advisories for installed packages are negligible, issue:

# DISABLE_VULNERABILITIES=yes portmaster -R -a -f -B -C -d -G

From portmaster(8):

-R skips ports updated on the previous run
-a checks all ports and updates when needed
-f forces build
-B prevents portmaster from creating a backup package
-G retains custom build config options
-C prevents # make clean from being executed before the build
-d always clean distfiles

DISABLE_VULNERABILITIES=yes prevents portmaster from aborting when an ‘unsafe’ port is encountered.

Import FreeBSD Root ZPool to Other Environments

While testing various memory disk filesystems in FreeBSD, I intelligently made changes to /etc/fstab that pointed to non-existent mountpoints (zroot/usr/home did not exist until later in the boot process - and the system refused to boot into FreeBSD due to mounting errors.)

To remedy this, I booted into my Ubuntu Oneiric installation, which fortunately supported native ZFS (follow this guide). Using the following commands, I was able to mount my root partition zpool - zroot - to make the necessary adjustments to /etc/fstab.

In Ubuntu, as root, list the available zpool imports with:
# zpool import

This will reveal all existing zpools found on all disk drives. Check to see if the zpool can be properly imported by reading the state, status, and action descriptions of the zpool.

Continuing on, create a temporary mountpoint for the zpool:
# mkdir -p /mnt/zpool_temp

Then import the zpool:
# zpool import -N -R /mnt/zpool_temp zroot

To confirm this worked, do:
# zfs list

Also, note the dataset’s original mountpoint value with:
# zfs get mountpoint zroot

Then:
# zfs set mountpoint=/mnt/zpool_temp zroot
# zfs mount zroot

This will temporarily mount the root zpool R/W at /mnt/zpool_temp, allowing you to make the necessary changes.

After you are done making changes to the mounted dataset, while making sure that it is no longer in use:
# zfs unmount zroot

Then, reset the mountpoint to it’s original value:
# zfs set mountpoint=/ zroot

Now reboot the machine without exporting the zpool - this is very important.

Your FreeBSD should now boot properly.

Move Chromium's Cache to MFS Memory Disk on FreeBSD

It is possible to use FreeBSD’s MFS Memory Disk to speed up access times of cached web objects.

From md(4):

The md driver provides support for four kinds of memory backed virtual disks:

swap:
Backing store is allocated from buffer memory. Pages get pushed out to the swap when the system is under memory pressure, otherwise they stay in the operating memory. Using swap backing is generally preferable over malloc backing.

Chromium’s cache is at $HOME/.cache/chromium, and so, my /etc/fstab contains:

1
2
3
# 256M mfs for google chrome
/dev/md0 /home/ootput/.cache/chromium mfs rw,-s256m,-wootput:ootput,noauto 2 0

From mount_mfs(8):

-s256m specifies a memory reservation of 256 M;

-wootput:ootput hands ownership of the mountpoint from root to the user; and

noauto prevents the system from failing to boot properly if the mountpoint does not (yet) exist.

The following additions to /etc/rc.conf were also made:

1
2
3
4
mdconfig_md0="-t swap -s 256m"
mdconfig_md0_owner="ootput:ootput"
mdconfig_md0_perms="1777"

which lists arguments to mdconfig(8) for device md0.

At mininum the -t type must be specified and either a -s size for malloc or swap backed md(4) devices or a -f file for vnode backed md(4) devices.

The redundancies found in fstab and rc.conf allows automatic mounting at boot, or manual mounting after boot.

To test the changes made, as root:

# /etc/rc.d/mdconfig restart

On to the $USER/bin/pack_chrome executable script that will both mount the md device, and/or sync contents from the cache at RAM to a backup cache on the HDD:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/local/bin/bash
CACHE="$HOME/.cache/chromium"
BACKUP="$CACHE.bak"
for DIR in $CACHE $BACKUP; do
if [ ! -d "${DIR}" ]; then
mkdir -p ${DIR}
fi
done
if test -z "$(/sbin/mount | grep -F "$CACHE" )"; then
sudo /sbin/mount "$CACHE"
fi
if test -f "$CACHE/.synced"; then
rsync --exclude '.synced' --exclude '.snap' --delete -avrPx
"$CACHE/" "$BACKUP"
else
rsync --delete -avrPx "$BACKUP/" "$CACHE"
touch "$CACHE/.synced"
fi

The script requires that the $USER is in sudoers(5), and is able to use the /sbin/mount command.

Finally, after $ crontab -e:

1
2
*/30 * * * * $HOME/bin/pack_chrome >/dev/null 2>&1

.. and the script gets called every half-hour by cron to automate the syncing process. This also requires that $USER is specifically allowed in /var/cron/allow.

Upgrading to FreeBSD 8-Stable

As a reminder to myself:

# pkg_add -r fastest_cvsup
# fastest_cvsup -c all

In /root/stable-supfile, have:

1
2
3
4
5
6
7
8
*default host=cvsup.au.freebsd.org
*default base=/var/db
*default prefix=/usr
*default release=cvs tag=RELENG_8
*default delete use-rel-suffix
*default compress
src-all

# csup /root/stable-supfile

# cd /usr/src
# rm -r -f /usr/obj

Customize /etc/make.conf (read notes). Mine contains:

1
2
3
4
5
6
7
8
9
10
11
CPUTYPE?= core2
NO_LPR= YES
NO_NIS= YES
CUPS_OVERWRITE_BASE= YES
NO_INET6= YES
WITH_NVIDIA_GL= YES
WITH_NVIDIA= YES
WITHOUT_NOUVEAU= YES

# script /var/tmp/buildworld-$(date "+%Y%m%d%H%M.%S")

# make -jX buildworld

( where X == number of CPUs + 1 )

# exit
# script /var/tmp/buildkernel-$(date "+%Y%m%d%H%M.%S")

# make buildkernel KODIR=/boot/testing KERNCONF=CUSTOM64

( where CUSTOM64 is documented here )

# make installkernel KODIR=/boot/testing KERNCONF=CUSTOM64
# exit
# nextboot -k testing
# shutdown -r now

# cd /boot
# rm -r -f OLD
# mv kernel OLD
# mv testing kernel

# adjkerntz -i
# rm -rf /etc.old && cp -Rp /etc /etc.old
# mergemaster -p
# cd /usr/src
# make installworld
# mergemaster -iU
# make delete-old
# shutdown -r now

NB: NO_NIS in /etc/make.conf requires the following changes in /etc/nsswitch.conf:

1
2
3
group: files
passwd: files

If you’re feeling game, you can try the following commands to save yourself some keystrokes and delays:

# csup /root/stable-supfile && rm -r -f /usr/obj && cd /usr/src && make -j5 buildworld && make buildkernel KODIR=/boot/testing KERNCONF=CUSTOM64 && make installkernel KODIR=/boot/testing KERNCONF=CUSTOM64 && cd /boot && rm -r -f OLD && mv kernel OLD && mv testing kernel && reboot

Here, you can revert back to the old kernel if you experience boot up problems. Otherwise, continue with:

# adjkerntz -i && rm -rf /etc.old && cp -Rp /etc /etc.old && mergemaster -p && cd /usr/src && make installworld && mergemaster -iU && make delete-old && reboot

Custom Kernel Config for FreeBSD 8-Stable

For FreeBSD system upgrades, my # make buildkernel is instructed to use a custom kernel config at /usr/src/sys/amd64/conf/CUSTOM64. It includes:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
include GENERIC
machine amd64
cpu HAMMER # aka K8, aka Opteron & Athlon64
nocpu i486_CPU
ident CUSTOM64
nomakeoption DEBUG
## No IPv6
nooptions INET6
nooptions SCTP # Stream Control Transmission Protocol
## No Debugging stuff
nooptions INVARIANTS
nooptions INVARIANT_SUPPORT
nooptions WITNESS
nooptions WITNESS_SKIPSPIN
nodevice eisa
nodevice fdc
## Disable various ATA systems we will never have
nodevice atapicd # ATAPI CDROM drives
nodevice atapifd # ATAPI floppy drives
nodevice atapist # ATAPI tape drives
nooptions MSDOSFS # MSDOS Filesystem
nooptions CD9660 # ISO 9660 Filesystem
device ahci
nodevice urio
nodevice uscanner
nodevice aue
nodevice axe
nodevice cdce
nodevice cue
nodevice kue
nodevice rue
# PCMCIA and cardbus bridge support
nodevice cbb # cardbus (yenta) bridge
nodevice pccard # PC Card (16-bit) bus
nodevice cardbus # CardBus (32-bit) bus
# Parallel port
nodevice ppc
nodevice ppbus # Parallel port bus (required)
nodevice lpt # Printer
nodevice plip # TCP/IP over parallel
nodevice ppi # Parallel port interface device
# FireWire support
nodevice firewire # FireWire bus code
nodevice sbp # SCSI over FireWire (Requires scbus and da)
nodevice fwe # Ethernet over FireWire (non-standard!)
nodevice fwip # IP over FireWire (RFC 2734,3146)
nodevice dcons # Dumb console driver
nodevice dcons_crom # Configuration ROM for dcons

SABnzbd and SICKbeard on FreeBSD

For my own archives, I have reproduced installation instructions for SABnzbd and Sickbeard on FreeBSD from Syah of the FreeBSD forums (titled: FreeBSD +Sabnzbd/Sickbeard/CouchPotato):

1. install sabnzbd+ from ports.

# cd /usr/ports/news/sabnzbdplus; make install clean

2) install some dependencies if they are not already present on your system. Needed to run & acquire python scripts (Sick Beard, Couch Potato, Headphones)

Python # cd /usr/ports/lang/python; make install clean

Cheetah # cd /usr/ports/devel/py-cheetah; make install clean

Git # cd /usr/ports/devel/git; make install clean

3. Fetch most recent builds of the three tools

Sick Beard # cd /usr/local ; git clone git://github.com/midgetspy/Sick-Beard.git sickbeard

4. Configure auto-start for python scripts and sabnzbd+

Sick Beard # cp /usr/local/sickbeard/init.freebsd /usr/local/etc/rc.d/sickbeard

Add the following to /etc/rc.conf:
sabnzbd_enable="YES"
sickbeard_enable="YES"

5. configure all the tools to play nice together.

Totally beyond the scope of a quick & dirty update. You should read the installation instructions and refer to the individual websites for each of these projects to fully leverage this tool set.

Hopefully this gets you a bit further towards your goal.
To keep track of upstream changes to SickBeard:
# cd /usr/local/sickbeard && git pull

A few notes:

  • Step 4. will fail as SickBeard currently only comes with an Ubuntu startup script. Hatchling, from the SickBeard Forums (A FreeBSD rc.d script), kindly published a working copy of a FreeBSD rc script that is available here (and duplicated here.)
    It appears that an init script for FreeBSD is now provided with the latest git pull - unfortunately, it’s not perfect, and needs to be modified for SickBeard to shut down properly.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    diff --git a/init.freebsd b/init.freebsd
    index 8d9ba4b..3f65b31 100755
    --- a/init.freebsd
    +++ b/init.freebsd
    @@ -69,7 +69,7 @@ verify_sickbeard_pid() {
    sickbeard_stop() {
    echo "Stopping $name"
    verify_sickbeard_pid
    - ${WGET} -O - -q --user=${SBUSR} --password=${SBPWD} "http://${HOST}:${PORT}/home/shutdown/" >/dev/null
    + ${WGET} -O - -q --user=${SBUSR} --password=${SBPWD} "http://${HOST}:${PORT}/home/shutdown/?pid=${pid}" >/dev/null
    if [ -n "${pid}" ]; then
    wait_for_pids ${pid}
    echo "Stopped"

Flash and Java for Google Chromium in FreeBSD 8

According to the official FreeBSD handbook (Ch 7.2 Browsers), perform the following steps to have a Java and Flash capable Chromium browser for FreeBSD 8:

As root:

# portmaster www/chromium \ java/openjdk6 \ java/icedtea-web \ www/nspluginwrapper \ www/linux-f10-flashplugin10

Then:

# mkdir -p /usr/local/share/chromium/plugins

# ln -s /usr/local/lib/IcedTeaPlugin.so /usr/local/share/chromium/plugins/

# ln -s /usr/local/lib/npapi/linux-f10-flashplugin/libflashplayer.so \ /usr/local/lib/browser_plugins/

The Linux process file system, linprocfs(5) has to be mounted on /compat/linux/proc:

# mount -t linprocfs linproc /compat/linux/proc

To mount the proc fs at each system boot, in /etc/fstab, have:

1
linproc /compat/linux/proc linprocfs rw 0 0

As a user:

% nspluginwrapper -v -a -i