Tuesday, March 24, 2009

Tip: Build ports on multiple processing cores

Ports framework supports building ports on multiple processing cores as announced today in the project's mailing list. This is achieved by passing -jX flag to make(1) running on vendor code.

Do notice that not all ports support this feature so ports that support this feature have their Makefile updated with MAKE_JOBS_SAFE=yes.

This feature is now enabled by default with the level of parallelization being equal to a number of processing cores in your computer. This value can however be overridden, for example if you want 6 jobs:
  • % su
  • # echo "MAKE_JOBS_NUMBER=6" >> /etc/make.conf
However if you want to disable this feature:
  • % su
  • % echo "DISABLE_MAKE_JOBS=yes" >> /etc/make.conf
You can read the announcement at http://lists.freebsd.org/pipermail/freebsd-ports/2009-March/053736.html.

HowTo: Install and configure NVIDIA drivers on FreeBSD

FreeBSD's Ports collection contains the official NVIDIA binary drivers for hardware OpenGL rendering in X, using the GLX extensions.The x11/nvidia-driver points to NVIDIA's latest stable driver set.

If you are using a legacy card check NVIDIA's site to see which driver set supports your card and browse the Ports tree for the suitable driver version and install that instead.

Bellow are the steps needed to install NVIDIA drivers on i386 FreeBSD 7.1:
  • % su
  • # portsnap fetch update
  • # cd /usr/ports/x11/nvidia-drivers
  • # make config
  • # make install clean
  • # echo 'nvidia_load="YES"' >> /boot/loader.conf
  • # echo 'linux_enable="YES"' >> /etc/rc.conf
  • # echo 'hint.agp.0.disabled="1"' >> boot/device.hints
Basically start by updating your ports tree, installing the driver and preparing FreeBSD to load the NVIDIA kernel module it at boot time. Consider selecting ACPI (enable support for ACPI Power Management) and LINUX (build with support for Linux compatibility) port options.

Now let's proceed by editing /etc/X11/xorg.conf to have it use the NVIDIA driver and add some options to increase performance:
  • edit /etc/X11/xorg.conf and change the driver value from "nv" to "nvidia":
Driver "nvidia"
  • under the Device section of xorg.conf add the following option:
Option "NvAGP" "1"
Additional performance options can be enabled, however these might affect stability. To enable Side Band Addressing and Fast Writes add the following sysctls to /etc/sysctl.conf:
  • # echo "hw.nvidia.registry.EnableAGPSBA=1" >> /etc/sysctl.conf
  • # echo "hw.nvidia.registry.EnableAGPFW=1" >> /etc/sysctl.conf
  • # reboot
Further reading material can be found at:

Monday, March 23, 2009

Tip: Use SUB_LIST to discover a port's VAR paths on FreeBSD

I was looking for man pages, READMEs and assorted information on the nvidia-driver port and couldn't recall where I'd seen the port's installed documentation.

Enter SUB_LIST for the rescue:
  • % cd /usr/ports/x11/nvidia-driver
  • % make -V SUB_LIST
PREFIX=/usr/local LOCALBASE=/usr/local X11BASE=/usr/local DATADIR=/usr/local/share/nvidia-driver DOCSDIR=/usr/local/share/doc/NVIDIA_GLX-1.0 EXAMPLESDIR=/usr/local/share/examples/nvidia-driver WWWDIR=/usr/local/www/nvidia-driver ETCDIR=/usr/local/etc/nvidia-driver
SUB_LIST kindly outputs a list of VAR=VALUE pairs, showing useful information such as PREFIX and DOCSDIR.

Pretty nice eh? ;)

Point to http://www.freebsd.org/doc/en/books/porters-handbook/using-sub-files.html for further information on ports and SUB_LIST.

HowTo: Fix SATA DMA timeout issues on FreeBSD

Update: added instructions for those using FreeBSD 8.x.

I've experienced heavy problems with a recently purchased 1TB SATA drive from Samsung on ICH7 motherboard running a fresh FreeBSD 7.1 install. The system was issuing loads of SATA timeout errors that culminated in system crashes, drive disconnection and data loss.

Here's a snip of my /var/log/messages:
kernel: ad4: WARNING - WRITE_DMA UDMA ICRC error (retrying request) LBA=26003999
kernel: ad4: WARNING - WRITE_DMA UDMA ICRC error (retrying request) LBA=56856991
kernel: ad4: WARNING - WRITE_DMA UDMA ICRC error (retrying request) LBA=57609503
kernel: ad4: TIMEOUT - READ_DMA retrying (1 retry left) LBA=174249023
kernel: ad4: TIMEOUT - READ_DMA retrying (1 retry left) LBA=190428031
kernel: ad4: WARNING - WRITE_DMA48 UDMA ICRC error (retrying request) LBA=1351930207
kernel: ad4: TIMEOUT - WRITE_DMA48 retrying (0 retries left) LBA=1351930207
Upon searching for solutions I came across Jeremy Chadwick's page on wiki.freebsd.org. Jeremy has been registering issues that are commonly reported by FreeBSD users and also published troubleshooting methods for ATA/SATA issues.

Jeremy informs that Volker Theile of the FreeNAS project had solved most of the problems by increasing a hard-coded arbitrary timeout value of 5 (seconds) in the ATA code to 10 or 15, while simultaneously making the timeout value adjustable via sysctl.
So I thought to myself "Might as well try the patch out and hope for the best". And I'm glad that I went along and tried it out as it fixed all of my issues.

Bellow are the needed steps to fetch the patch, apply it and compile a patched kernel:

  1. % fetch http://freenas.svn.sourceforge.net/viewvc/freenas/trunk/build/kernel-patches/ata/files/patch-ata.diff
  2. % su
  3. # csup -h cvsup2.uk.freebsd.org -L 2 /usr/share/examples/cvsup/standard-supfile
  4. # cd /usr/src/sys/dev
  5. # patch < /path/to/patch
  6. # cd /usr/src
  7. # make kernel
  8. # cp -Rp /boot/kernel.old /boot/kernel.SATA-ISSUES
  9. # reboot
Start by fetching the patch (step 1), next change to root and fetch FreeBSD's source code as detailed in step3.

Note: if you are running FreeBSD 8.x fetch the patch file using this URL instead http://www.avenard.org/files/ata_timeout.patch. Replace the step 1 URL with this one.

Next, with steps 4 and 5 patch the source code with FreeNAS' patch and build a patched kernel. Do notice that I used csup pointing to /usr/share/examples/cvsup/standard-supfile as I'm running FreeBSD 7.1 (of simply use your own supfile). Further information on how to build a kernel can be found at http://www.freebsd.org/handbook/kernelconfig.html.

As a safety precaution back up the old kernel as described in step 9.

Finally reboot to the new kernel and monitor /var/log/messages for SATA timeout issues. After I've applied the patch my problems have stopped.

Props to:
Jeremy Chadwick and Volker Theile for the FreeBSD 7.x patch.
Jean-Yves Avenard for providing the URL a FreeBSD 8.x patch.

Tuesday, March 17, 2009

Tip: Add color to man pages with most on FreeBSD

man pages are formatted using FreeBSD less and more utilities which display text in blank and white colors. most on the other hand introduces the ability to view man pages formatted with colors.

most is a pager (like less and more) that displays, one windowful at a time, the contents of a file on a terminal. It pauses after each windowful and prints the following on the window status line: the screen, the file name, current line number, and the percentage of the file so far displayed.

Let's install most:
  • % su
  • # cd /usr/ports/sysutils/most
  • # make install clean
  • # rehash
  • # exit
Users of csh or tcsh shells can try most out by setting the PAGER environment variable like so:
  • % setenv PAGER most
Those that use the zsh shell can set the PAGER environment variable like this:
  • % export PAGER=most
If you like it editing you user shell configuration file and set the PAGER variable to most.

As most is a third party application I'd suggest that you don't use it as the default pager for the root account. I'm sure you don't want to find yourself in single user mode with only the root partition mounted and realize that your .cshrc defines most has the pager ;)

Wednesday, March 11, 2009

HowTo: Determine the fastest CVSup mirror on FreeBSD

fastest_cvsup is a Perl script to find fastest CVSup server. Amongst it's feature it:
  • uses socket connections not just 'pings'
  • takes notice of server responses
  • connects to servers in countries specified on the command line - or - connects to the 'local' servers defined in the script - or - connects to ALL the servers in ALL the countries
  • returns either fastest server or top 3 (useful for scripts)
  • returns exit codes (useful for scripts)
  • can re-write itself to update the CVSup server list, obtained from the online FreeBSD Handbook
  • can easily add other CVSup servers (NetBSD/OpenBSD...etc)
Here's how to identify the fastest CVSup mirror:
  1. % su
  2. # cd /usr/ports/sysutils/fastest_cvsup
  3. # make install clean
  4. # rehash
  5. # exit
  6. % fastest_cvsup -Q -r -c all
We've started by becoming the superuser, proceeded by installing the port and finally ran it. After running the last command, the application will prompt the fastest mirror.

Change your /etc/make.conf or supfiles with the new mirror. In alternative pass the determined mirror at the command line when running csup.

For more options run:
  • % fastest_cvsup -h
  • % man fastest_cvsup
Some further examples of the script's usage:
  • times the FreeBSD CVSup servers in the United Kingdom, France and Germany:
% fastest_cvsup -c uk,fr,de
  • times the OpenBSD and NetBSD CVSup servers:
% fastest_cvsup -c openbsd,netbsd
  • shell script, finds the fastest UK FreeBSD CVSup server, then runs csup using that server:
if SERVER=`fastest_cvsup -q -c uk`; then
csup -h $SERVER /usr/share/examples/cvsup/standard-supfile
The project's website can be found at http://fastest-cvsup.sourceforge.net/.

Monday, March 9, 2009

Tip: Enable sudo completion in tcsh/csh shell

Having installed and setup sudo I realized that the C shell (e.g. tcsh/csh) didn't autocomplete commands issued after typing sudo.

Place the following in your .cshrc file:
set complete = enhance
complete sudo 'n/-l/u/' 'p/1/c/'
And finally source the changes:
% source .cshrc
For more information visit tcsh(1) in the REFERENCE section under complete.

Tip: Allow users to shutdown the system on FreeBSD

Operations such as shutdown and rebooting usually require root privileges. However, one may allow other users to run these commands with success.

To allow users to shutdown a FreeBSD system you basically have two options: add the user to the operator group or install and configure sudo to allow usage of the administrative command. I've already covered the latter option in a previous post so I'll only go over the remaining option here.

The steps consist in becoming root and using pw to add the user (in the example bellow username) to the operator group:
% su
# pw groupmod operator -m username
# exit
To reboot the system login to the user account that belongs to the operator group and run:
% shutdown -r now
If you want to power down the system run this instead:
% shutdown -p now
Do take a look at pw(8) and shutdown(8) manual pages for further information.

Friday, March 6, 2009

Tip: Solving the sudo redirect "problem"

Upon using sudo more frequently I came across an issue while using redirects, for example:
% sudo echo WITHOUT_IPFILTER=yes > /etc/make.conf
root: Permission denied.
The key to solve the "problem" was to run the command in a sub-shell to make the redirection work, like so:
% sudo sh -c 'echo WITHOUT_IPFILTER=yes > /etc/make.conf'
The answer to this lies in man sudo ;)

Thursday, March 5, 2009

HowTo: Using sudo on FreeBSD

sudo is a great tool for granting specific privileges to users other that the root user. This application allows a permitted user to execute a command as the superuser or another user, as specified in the sudoers file.

Today I'll detail the steps needed to install and configure sudo on FreeBSD from a desktop/workstation perspective, in other words I'll dwell more on less on the common user.

Let's start by install the application and then proceed to configure the sudoers file with visudo:
  1. % su
  2. # cd /usr/ports/security/sudo ; make install clean
  3. # visudo /usr/local/etc/sudoers

Uncomment the following line to allow users in the wheel group to run all commands:
%wheel ALL=(ALL) ALL
By enabing this line, users in wheel group will have full root privileges on the computer by providing their password in order to use administrative commands.

If you wish that users in the wheel to acquire these privileges without using a password then uncomment the next line instead:
sudo can also be used to allow more restrictive usage, for instance to allow the user freebsduser to mount and unmount /cdrom the following line could be added to /usr/local/etc/sudoers:
freebsduser ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
To allow members of the users group shutdown the computer add the following to the sudoers file:
%users localhost=/sbin/shutdown -h now
Add the following line to let user freebsduser access all privileges without entering password:
freebsduser ALL=(ALL) NOPASSWD: ALL
After editing the sudoers file you'll need to issue a :w! command in visudo as the file is read-only. To use sudo just prefix sudo before the command with specific privileges. For the %wheel ALL=(ALL) ALL example, if you are in the wheel group and want to shutdown the computer you'd type:
# sudo shutdown -h now
And insert your passoword.

Once you enter a correct passwo
rd, sudo records the time and for the next 5 minutes it won't ask you for a password. After those 5 minutes you must re-authenticate. You can change the timeout value from 5 to another value by setting the password_timeout value in the /usr/local/etc/sudoers file).

Every use of sudo is logged in /var/log/messages, so do take a look and check for yourself.

I've only touched the tip of the iceberg on sudo so do take a look at its man page.

Tuesday, March 3, 2009

Tip: Disable OpenOffice splash screen in FreeBSD

With time OpenOffice's splash screen becomes annoying so end up disabling it on all my machines. Today in FreeBSD mailing list I replied to fellow user who was asking on how to due this on FreeBSD so thought I should share the tip here also.

Here are the needed steps:
  1. % su
  2. # vim /usr/local/openoffice.org-3.0.0/openoffice.org3/program/sofficerc
  3. Change the Logo variable from 1 to 0 like so
We've started by becoming the superuser on step 1, and proceeded to change the Logo variable value defined in /usr/local/openoffice.org-3.0.0/openoffice.org3/program/sofficerc so that the splash is disabled.

If by any chance you want to renable the splash screen just change the Logo variable value back to 1.

Simple eh?