The pkg_* commands

Command Option Example Details
pkg_add -r pkg_add -r package_name download and install package_name and fix dependencies
pkg_version pkg_version summarize installed version of packages
pkg_version -vl "<" list all obsolete packages

How to install software

There are 2 methods to install software :

Method + -
using the ports tree
  • better system stability
  • optimized for the hardware
  • compilation is a LOOONG process
  • sometimes leads to the "dependencies hell"
installing pre-compiled packages
  • faster method
  • not optimized for the hardware

Installing pre-compiled packages is done through the command :

pkg_add -r package_name

kern.maxpipekva exceeded, please see tuning(7)

Situation The system is filling console with kern.maxpipekva exceeded, please see tuning(7), it denies ssh login, and even refuses launching processes once locally logged in.
Details Kernel memory has "pipes", and "kva pipes".
  • The maximum number of "kva pipes" is set in the kern.ipc.maxpipekva sysctl variable.
  • The current number of "kva pipes" is set in kern.ipc.pipekva.
It seems this error appears due to a change to the kernel in the FreeBSD 5.2 release. Details : here, and here.
Solution Found here, but not sure :
  • Edit /etc/login.conf
  • browse to the openfiles parameter
  • change it from unlimited to 1024

When I got this error, the root cause was something tricky : due to a power failure, the machine crashed and HDDs where not properly unmounted. Upon reboot, the system launched an automatic fsck on the disks. It's been fast on the first disk, but it lasted way longer for the other. During that time, the system had rebooted and was trying to run "normally".

In the "normal" operations handled by this machine was a Cron job, run every minute, listing the content of the 2 HDDs. Then, since one of them was still busy being fsck'd, the script never ended, and stayed in memory until it was loaded hundreds of times and running out of "pipe kva".

Switching between single user and multi-user mode

From multi-user, down to single user :

shutdown now

And back to multi-user :

exit

This can also be done through the boot options, but rebooting resets the uptime. And rebooting isn't necessary : we're not running a Windoze machine ;-)

network parameters (IP @, mask, gateway, ...)

Everything is available in /etc/rc.conf

su: Sorry

Situation When logged as any standard user and trying to log as root via su, an error appears :

su: Sorry

Details Investigation shows :

-bash-2.05b$ ls -l /usr/bin/su
-r-sr-xr-x   1   root   wheel   12460   Feb 23 2004   /usr/bin/su

The setuid root s bit, together with the group x bit state that su can only be executed by members of the wheel group, and that it'll be run with root privileges.
Solution Just add the user willing to "su" into the wheel group:
  1. Open /etc/group in your favorite text editor
  2. Browse to the line starting with :

    wheel:*:0:root

  3. Append ,user_name at the end of the line. (Don't forget the comma between user names !)
  4. Save, exit, it should no more say su: Sorry ;-)

HDD naming conventions

Connected on : FreeBSD name Linux name
IDE 1 - Master ad0 hda
IDE 1 - Slave ad1 hdb
IDE 2 - Master ad2 hdc
IDE 2 - Slave ad3 hdd

On top of this, FreeBSD partitions also have a s1 added, then a purely conventional suffix :

Suffix Meaning
a reserved for the / filesystem
b reserved for swap filesystem
c wildcard referring to all filesystems (whole disk)
d reserved for the /var filesystem, which is specially designed for anything varying constantly such as log files
e reserved for (?) filesystem
f reserved for (?) filesystem
g reserved for (?) filesystem
h reserved for (?) filesystem

So, on my system, I have :

... which is not very compliant to the convention :-(

How to create a new partition ?

FreeBSD organizes HDDs in slices then partitions. When installing a new HDD, the procedure is :

  1. Create a new slice
  2. Create one or more partitions
  3. Install (or not) a Boot Manager
  4. Create a new File System

All of this can be done rather easily with the sysinstall tool :

  1. As root, just type sysinstall in any tty
  2. Browse to the Configure | Fdisk option
  3. Select the physical HDD to be edited (let's consider it's ad1) and enter Fdisk
  4. Type A to use the entire HDD (or edit manually), then Q to leave this editor
  5. If required, install a Boot Manager, then leave Fdisk
  6. Then, enter the partition editor, called Disklabel
  7. Make sure the disk label is displayed on top of the screen (for the example : ad1) and create partition like in any usual Fdisk
  8. At this step, you can already specify the mount point (or you'll have to come back to this utility to set it, or manually edit /etc/fstab)
  9. When finished, press W to write changes, then Q to leave.
  10. Now, you just have to put tons of mp3's to fill up this new storage space ;-)

The ports tree : installing and keeping it up-to-date with CVSup

FreeBSD ports come as an easy way of installing software (from source !). To take benefits of these :

  1. install the ports infrastructure during the system setup or with the sysinstall tool
  2. install CVSup. This utility is designed to upgrade the ports tree only, not the ports themselves. To do so :
    cd /usr/ports/net/cvsup-without-gui && make install distclean
  3. create /root/ports-supfile
  4. edit it with edit ports-supfile so that it contains :
    *default host=cvsup.fr.freebsd.org
    *default base=/usr
    *default prefix=/usr
    *default release=cvs tag=.
    *default delete use-rel-suffix
    *default compress
    ports-all
  5. and launch the tree upgrade with cvsup -g -L2 ports-supfile. This can take a while.
  6. to see which ports need to be updated : pkg_version -vl "<"
  7. install /usr/ports/sysutils/portupgrade
  8. to upgrade a single port : portupgrade port_name
  9. to upgrade all the ports that need it : portupgrade -a
  10. For a massive upgrade of all installed ports : portupgrade -Rraf

The ports tree : installing ports

Once the ports tree is available (make sure it's up-to-date), installing a FreeBSD port is just a matter of few steps :

  1. find the directory of the port you're going to install : whereis port_name
  2. launch installation : cd /usr/ports/port_type/port_name && make install distclean
  3. the latest source of the port will be downloaded and compiled locally. This may take a while.

Or :

portinstall port_name

Configure the system with the sysinstall wizard

sysinstall is a utility used for the system initial setup and for post-install operations such as configuration or applications installation. It must be run as root (in tty mode), with /usr/sbin/sysinstall.

To install the ports tree after the system setup, just run sysinstall, then go to the Distribution | Ports menu.

Being a DHCP client, playing with dhclient

Notes:

Action Command Notes
Release a DHCP lease dhclient -r rl0 Once the lease has been released, the client exits.
request a new DHCP lease dhclient rl0

How to mount floppy, USB key, ...

How to enable the graphical login (XDM)

XDM is the X Display Manager. It's a daemon managing X sessions on the local machine. It can be launched at any time with /usr/X11R6/bin/xdm by the root user.

To start it automatically at boot time :

  1. open /etc/ttys
  2. seek the line starting with ttyv8
  3. change the parameter off into on
  4. run init q to rescan the ttys(5) file and make changes effective. (man init for details)