An Absolute Beginners Guide to FreeBSD

This is An Absolute Beginners Guide to Setting up a FreeBSD Server.

If you have any questions that you don't see addressed by this page. Please send any comments to fbsd-book@vmunix.com

Contents

1.  Configuring your .cshrc File
2.  Setting up More Virtual Terminals
3.  Adding a Hard Disk
4.  System Configuration File Options
5.  Adding and Installing Software
6.  How to install Linux Emulation

1.   Configuring your .cshrc File

This is the Standard .cshrc files that comes with your system.

#csh .cshrc file

alias h		history 25
alias j		jobs -l
alias la	ls -a
alias lf	ls -FA
alias ll	ls -lA
alias su	su -m

setenv	EDITOR	vi
setenv	EXINIT	'set autoindent'
setenv	PAGER	more

set path = (~/bin /bin /usr/{bin,games} /usr/local/bin /usr/X11R6/bin)

if ($?prompt) then
	# An interactive shell -- set some stuff up
	set filec
	set history = 1000
	set ignoreeof
	set mail = (/var/mail/$USER)
	set mch = `hostname -s`
	set prompt = "${mch:q}: {\!} "
	umask 2
endif

The path statement tells your shell where to look for programs when you try to execute them. It starts with the first directory listed and looks there for any match to the command you have just entered. If it finds it, it executes that program.

If the directory is not listed in the path statement, it will not look there for executable files. Not even in your current directory. So even if you are in the same directory as the file you want to execute, it will not find it if that directory is not listed in your path statement.

If you want to execute a command in your current path, you have to precede the command with ``./''. For example, you are in the /usr/local/www/cgi-bin directory and want to test out a program you have written. The program is getdata.pl, and you have just tried to run it by typing getdata.pl, however instead of the HTML output you expect, you just get the error, getdata.pl: Command not found. This is because you did not include the ``.'' directory in your path statement. Remember that in UNIX, the ``.'' represents the current directory. To get this file to execute you would need to type:

./getdata.pl

Now you should see the HTML output you expect, unless you messed up in your program and then you will get error messages pertaining to the language you wrote the program in.

A TCSH Example

As we mentioned earlier, the tcsh has a few extra features over the base csh that make life on the command line a little easier. Here is an example .cshrc file that takes advantage of tcsh's goodies:

#tcsh .tcshrc file

alias h		history 25
alias j		jobs -l
alias la	ls -a
alias lf	ls -FA
alias ll	ls -lF
#alias su	su -m  -- bad for su'ing to root..

setenv	EDITOR	vim
setenv	PAGER	less

set path = ( ~/bin /usr/local/bin /bin /usr/{bin,games} /usr/sbin /sbin /usr/local/samba/bin /usr/X11R6/bin /usr/local/java/bin .)

setenv IRCNICK ringzero
setenv IRCSERVER irc2.magic.ca
setenv NNTPSERVER news.sentex.ca

if ($?prompt) then
	# An interactive shell -- set some stuff up
	set filec
	set fignore = .o		# ignore object files for filec
	set showmatch			# for programming
	set history = 100 
	set savehist = 75		# tcsh version of history..
	set ignoreeof
	set mail = (/var/mail/$USER)
	set prompt="vinyl:{%h}%~ %% "	# tcsh version of above!

	set watch = (1 gabor any mike any adrian any pwardrop any)

	umask 2
endif

The first things to note are the setenv lines. In this case, they are setting some environment variable that are used by my news reader software and IRC client software. The next point of interest is the set fignore = .o, which makes the file completion (set filec) ignore files that end in ``.o''. This is nice if you're a C programmer since you never would want to edit or manually do much with a .o file - you want the ``.c'' file! The showmatch option is another addition to the file completion mechanism of tcsh. Try it out and see what it does for yourself! The set prompt option sets up a very friendly prompt for your shell. It will show you what directory you are in all the time. Here's what it looks like:

mark:{123}~ % cd /usr/src
mark:{124}/usr/src %

Note that the tilde character (``~'') indicates your home directory. Now that you've seen some of what the tcsh and csh options are, the best way to learn more about them is to man tcsh! All of the features of both shells (such as the ``watch'' feature of tcsh) are documented in the man pages. Go ahead and take a look and experiment to see what fun tricks you prefer!

Note:

If you change your .cshrc file, you can re-read the changes by issuing a source .cshrc!

2.   Setting up More Virtual Terminals

A Virtual Terminal is a Terminal built into the Main Server Console. It allows you to have several screens open at once, however only one screen is visible at a time. By Default there are four Virtual terminals setup, but only three enabled for use.. To switch between them hold down the ALT key and press F2 or F3 (You start out at F1. This will switch you to the second or third Virtual terminal. Now you should have a login screen like the one you just left. There is nothing different about logging in here as opposed to the virtual terminal on F1. To get back to your original screen, hold down the ALT key and press F1

To add more Virtual terminals, you need SuperUser access to the /dev directory. Next you need to run the program MAKEDEV. MAKEDEV is a shell script, so you have to use the sh shell interpreter to execute it. At the command prompt type:

cd /dev

sh MAKEDEV vty 16

Note:

(Type MAKEDEV in all CAPS, Capitalization makes a big difference.)

This will create 16 Virtual terminals. They will be accessible with the ALT + F? keys. But Before you can use them, you have to enable them in the /etc/ttys file. Change directories to the /etc/ directory and use vi to edit the /etc/ttys file.

cd /etc

vi ttys

If you are running The X Windows System, you need to leave one of the Virtual Terminals turned off. By default, ttyv4 is turned off.

In the section labeled Virtual Terminals, you need to add a few lines. If you just made 16 virtual terminal devices, you now have 16 virtual terminals to configure. You need to have 16 lines that deal with virtual terminals in the /etc/ttys file; right now you only have 4. You can cut and paste the line that says:

ttyv2 "/usr/libexec/getty Pc" cons25 on secure

Move the cursor to that line and press yy then move the cursor down one line by pressing j and press 12p to paste the line 12 times. Now you have 12 copies of ttyv2, you need to change this, numbering them in HEX. Start numbering them at 4, then 5,6,7,8,9,a,b,c,d,e,f.

When you are done, you should have ttyv1 - ttyvf configured in the /etc/ttys file.

In vi you can do this easily by positioning the cursor over the number you wish to change and pressing r the next key you press will replace that digit, press 4 to start with. Then press j to move down and press r followed by the next number, repeat as necessary.

when you have finished editing, press ZZ to quit and exit vi Now you will have to restart the init process. You must have SuperUser access. Type: kill -HUP 1

Now you are ready to use your Virtual Terminals.

3.   Adding a Hard Disk

The hard drive needs to be physically installed. Make sure the cable is on properly, pin 1 is the closest to the power plug.(ie. the red stripe goes toward the power plug). And make sure that there is power to the Drive.

Now reboot to FreeBSD. During Boot up, FreeBSD should detect the drive. If it doesn't, reboot using the "-c" option. At the boot prompt and go in to the visual config and make sure that the appropriate controller is enabled. If you have built a custom kernel and have disabled the extra IDE drive, or are adding a first SCSI drive to a kernel that has SCSI disabled, this is most likely the problem. If the kernel has the controller merely *disabled*, not removed, you can enable it in the visual config. Otherwise you will have to rebuild the kernel adding the appropriate controllers and devices.

If you missed the boot up section, type dmesg at the prompt after you have logged in. This will display your boot-up messages again.

/usr/> dmesg | more

If you are installing SCSI, be sure the drives are found by the SCSI BIOS and that the proper SCSI termination is enabled.

Once everything has been found, you are ready to start the FreeBSD configuration.

***************************************************************

The first thing you will need to do is to clear out whatever might have been on the disk previously. Most hard-drive manufacturers ship new drives already partitioned and formatted to the DOS FAT filesystem. For the remainder of this example, we'll be using a hard-drive that was detected as sd1. In our case, it is the second SCSI device on the chain (with SCSI ID 1). Here's how to get rid of that FAT garbage:

dd if=/dev/zero of=/dev/rsd1 count=100

Now you need to prepare a ``disk label'' on the drive. We'll assume in this example that you plan on using the entire drive under FreeBSD:

disklabel -Brw sd1 auto

* substitute rsd1 and sd1 for the disk that you are adding, don't do this to a disk you are using. This basically kills everything on the disk, and prepares it for use by FreeBSD. If this works, you shouldn't need to use fdisk.

If you are planning to use the entire disk as one partition under FreeBSD, then you can use the single default partition just created by disk label, otherwise you will need to use the disklabel editor and create the smaller partitions. You might want to add a swap partition to the disk, for example.

To do get in to the disk label editor for IDE disk 1, type:

disklabel -e wd0

# /dev/rwd0c:
type: ESDI
disk: wd0s1	
label: 
flags:
bytes/sector: 512
sectors/track: 51
tracks/cylinder: 13
sectors/cylinder: 663
cylinders: 722
sectors/unit: 479298
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0		# milliseconds
track-to-track seek: 0	# milliseconds
drivedata: 0 

8 partitions:
#        size   offset    fstype   [fsize bsize bps/cpg]
  a:    65536        0    4.2BSD        0     0     0 	# (Cyl.    0 - 98*)
  b:    85936    65536      swap                    	# (Cyl.   98*- 228*)
  c:   479298        0    unused        0     0       	# (Cyl.    0 - 722*)
  e:    61440   151472    4.2BSD        0     0     0 	# (Cyl.  228*- 321*)
  f:   266386   212912    4.2BSD        0     0     0 	# (Cyl.  321*- 722*)

Now comes the tricky part, getting the numbers right. The easiest way to allocate a partition is to select the number of cylinders you want to allocate to the partition and calculate from there. The size is the size of the partition in sectors. The offset is the last sector of the previous partition. Partition a starts at sector 0. Partitions need to start and end on cylinder boundaries. To find the cylinder boundary, multiply the tracks/cylinder # by the sectors/cylinder # and then multiply that by the number of cylinders you want to allocate. (Sectors * Tracks * Cylinders = Size_of_Partition) To find the offset, add the size of the previous partition to the offset of the previous partition. (Size + Offset = Offset_Of_Next_Partition)

The fstype is the type of filesystem you are putting on that partition. 4.2BSD is the filesystem type for a normal FreeBSD filesystem. swap is the filesystem type for a swap file. FAT is the filsystem type for DOS partitions. Partition a is reserved for the boot sector. Leaving it blank implies that you don't have/need a boot sector.

Partition b is reserved for the swap file. It cannot start with an offset of 0. There must be a partition that starts before it. Partition e can start at offset 0 and be any size, then the swap partition can be placed starting at the offset where partition e ended.

Partition c should not be changed. Start making your filesystems on partition e

Now you need to create a file system on the drive, you use the newfs command to do this. If you are using the whole disk, use the c partition automatically created by disklabel.

newfs /dev/rsd1c

The c partition always represents the entire device - so in this case we've just created a filesystem that spans the entire drive.

If you have separated the disk into smaller parts, you will need to use newfs to create a file system on each partition, except the swap partition.

Finally, you want to mount the drive. We'll assume here that you've created a ``mount point'' of /d2 (using mkdir).

mount /dev/sd1c /d2

If all went well, you should now see something like this:

#vinyl % df -k

Filesystem  1K-blocks     Used    Avail Capacity  Mounted on
/dev/sd0a       31775    13530    15703    46%    /
/dev/sd0s1f   1913091  1086207   673837    62%    /usr
/dev/sd0s1e     29727    12663    14686    46%    /var
procfs              4        4        0   100%    /proc
/dev/sd1c     4108717   616594  3163426    16%    /d2

Now you will need to create an entry in the /etc/fstab file so that it will get mounted each time you reboot. Otherwise you will have to execute the mount each time by hand. A fstab entry will need to be made for each partition you created, including the swap partition.

Also reference the man pages for: fstab mount disklabel dmesg dd and newfs

4.   System Configuration File Options

4.1.   Important initial Boot-time options
4.2.  Network configuration sub-section
4.3.  Network daemon (miscellaneous) & NFS options:
4.4.   Network Time Services options:
4.5.  Network Information Services (NIS) options:
4.6.  Network routing options:
4.7.   System console options
4.8.   Miscellaneous administrative options
4.9.   Allow local configuration override at the very end here

Note:

All arguments must be in double or single quotes. Multiple entries are separated by spaces.

4.1.   Important initial Boot-time options

swapfile="NO"

# Set to name of swapfile if aux swapfile desired.

apm_enable="NO"

Set to YES if you want APM enabled.

pccard_enable="NO"

Set to YES if you want to configure PCCARD devices.

pccard_mem="DEFAULT"

If pccard_enable=YES, this is card memory address.

pccard_ifconfig="NO"

Specialized pccard ethernet configuration (or NO).

local_startup="/usr/local/etc/rc.d /usr/X11R6/etc/rc.d"

Local Startup Directories. During startup, FreeBSD searches certain directories and executes any programs in them. Sort of like the ``startup'' folders in Windows. The local_startup option lets you specify which directories to search during startup. Multiple directories, separated by spaces, can be listed. They will be searched in the order listed and every file will be executed. This is an alternate approach to using /etc/rc.local to start programs.

4.2.   Network configuration sub-section

Basic network options:

hostname="myname.my.domain"

This is the name of your machine. It also must include the domain that you are in if you are attached to the internet. This name should also appear in your DNS table.

nisdomainname="NO"

Set to NIS domain if using NIS (or NO).

firewall="NO"

firewall type (see /etc/rc.firewall) or NO.

tcp_extensions="YES"

# Allow RFC1323 & RFC1544 extensions (or NO).

network_interfaces="lo0"

This is where you setup all of your network cards. Each network card will have its own listing. lo0 is the loopback device, otherwise known as ``localhost''. Network cards such as ed0 (NE2000) and fxp0 (Intel Ether Express) would be added to the above.

ifconfig_lo0="inet 127.0.0.1"

This is the section that configures each network card that you listed above.

ifconfig_lo0_alias0="inet 127.0.0.254 netmask 0xffffffff"

This would setup an alias to the localhost via lo0.

4.3.   Network daemon (miscellaneous) & NFS options:

syslogd_enable="YES"

Syslog is your logging services. It logs all errors into /var/log/. It is configured with /etc/syslog.conf.

syslogd_flags=""

# Flags to syslogd (if enabled).

inetd_enable="YES"

These are all of your network services. If this is not enabled you can not telnet to this computer. It is configured through /etc/inetd.conf. It manages all dynamic services, i.e. services that start when you need them, such as: finger, telnet, rlogin, ftp, pop3 etc...

inetd_flags=""

# Optional flags to inetd.

named_enable="NO"

This runs your Internet Domain Naming Services, i.e. BIND. If you already have a DNS you won't need to start this here. Its configured through /etc/namedb/named.boot, unless you specify another. You should have atleast two DNS servers.

named_flags="-b /etc/namedb/named.boot"

This is where you specify where named gets it's configuration file, and other such things.

kerberos_server_enable="NO"

# Run a kerberos master server (or NO).

rwhod_enable="NO"

# Run the rwho daemon (or NO).

amd_enable="NO"

# Run amd service with $amd_flags (or NO).

amd_flags="-a /net -c 1800 -k i386 -d my.domain -l syslog /host /etc/amd.map"

Example

nfs_client_enable="NO"

# This host is an NFS client (or NO).

nfs_client_flags="-n 4"

# Flags to nfsiod (if enabled).

nfs_server_enable="NO"

# This host is an NFS server (or NO).

nfs_server_flags="-u -t 4"

# Flags to nfsd (if enabled).

weak_mountd_authentication="NO"

# Running PCNFSD / other non-root nfsd (or NO).

nfs_reserved_port_only="NO"

# Provide NFS only on secure port (or NO).

rpc_lockd_enable="NO"

# Run NFS rpc.lockd (*broken!*) if nfs_server.

rpc_statd_enable="YES"

# Run NFS rpc.statd if nfs_server (or NO).

portmap_enable="YES"

# Run the portmapper service (or NO).

portmap_flags=""

# Flags to portmap (if enabled).

xtend_enable="NO"

# Run the X-10 power controller daemon.

xtend_flags=""

# Flags to xtend (if enabled).

4.4.   Network Time Services options:

timed_enable="NO"

Run the time daemon (or NO).

timed_flags=""

Flags to timed (if enabled).

ntpdate_enable="NO"

Run the ntpdate to sync time (or NO).

ntpdate_flags=""

Flags to ntpdate (if enabled).

xntpd_enable="NO"

Run xntpd Network Time Protocol (or NO).

xntpd_flags=""

Flags to xntpd (if enabled).

tickadj_enable="NO"

Run tickadj (or NO).

tickadj_flags="-Aq"

Flags to tickadj (if enabled).

4.5.   Network Information Services (NIS) options:

nis_client_enable="NO"

We're an NIS client (or NO).

nis_client_flags=""

Flags to ypbind (if enabled).

nis_ypset_enable="NO"

Run ypset at boot time (or NO).

nis_ypset_flags=""

Flags to ypset (if enabled).

nis_server_enable="NO"

We're an NIS server (or NO).

nis_server_flags=""

Flags to ypserv (if enabled).

nis_ypxfrd_enable="NO"

Run rpc.ypxfrd at boot time (or NO).

nis_ypxfrd_flags=""

Flags to rpc.ypxfrd (if enabled).

nis_yppasswdd_enable="NO"

Run rpc.yppasswdd at boot time (or NO).

nis_yppasswdd_flags=""

Flags to rpc.yppasswdd (if enabled).

4.6.   Network routing options:

defaultrouter="NO"

This is where you set your default gateway. This is the router IP address that connects you to the Internet. If you don't set this, you will only be able to ping addresses on the same subnet as you. If your IP address is 10.1.1.3, and your subnetmask is 255.255.255.0, you will be able to see 10.1.1.2 but not 10.1.2.2, becuase you don't have a default route set.

static_routes=""

Static routes are advanced options for machines that act as routers or that sit on two different networks.

gateway_enable="NO"

Set to YES if this host will be a gateway. You need then set to YES when you have more than one network card in the computer doing routing, bridging, ipnat, or when you are acting as a dialup server.

router_enable="YES"

Set to YES to enable a routing daemon.

router="routed"

Name of routing daemon to use if enabled.

router_flags="-q"

Flags for routing daemon.

mrouted_enable="NO"

Do multicast routing (see /etc/mrouted.conf).

ipxgateway_enable="NO"

Set to YES to enable IPX routing.

ipxrouted_enable="NO"

Set to YES to run the IPX routing daemon.

ipxrouted_flags=""

Flags for IPX routing daemon.

arpproxy_all=""

replaces obsolete kernel option ARP_PROXY_ALL. You need then when acting as a dialup server.

4.7.   System console options

keymap="NO"

keymap in /usr/share/syscons/keymaps/* (or NO).

keyrate="NO"

keyboard rate to: slow, normal, fast (or NO).

keybell="NO"

bell to duration.pitch or normal or visual (or NO).

keychange="NO"

function keys default values (or NO).

cursor="NO"

cursor type {normal|blink|destructive} (or NO).

scrnmap="NO"

screen map in /usr/share/syscons/scrnmaps/* (or NO).

font8x16="NO"

font 8x16 from /usr/share/syscons/fonts/* (or NO).

font8x14="NO"

font 8x14 from /usr/share/syscons/fonts/* (or NO).

font8x8="NO"

font 8x8 from /usr/share/syscons/fonts/* (or NO).

blanktime="NO"

blank time (in seconds) or "NO" to turn it off.

saver="NO"

screen saver: blank/daemon/green/snake/star/NO. This sets the screensaver that is used when you do not have X running.

moused_type="NO"

See man page for rc.conf(8) for available settings.

moused_port="/dev/cuaa0"

Set to your mouse port (required if mousetype set).

moused_flags=""

Any additional flags to moused.

4.8.   Miscellaneous administrative options

cron_enable="YES"

Run the periodic job daemon. Cron is the ``daemon'' that schedules when things happen. There are three standard scripts that are run on a regular basis: /etc/daily /etc/weekly and /etc/montly. You can configure these to accomplish the tasks you need done.

lpd_enable="YES"

Run the line printer daemon. You need this to be able to print. It is configured through /etc/printcap

lpd_flags=""

Flags to lpd (if enabled).

sendmail_enable="YES"

Run the sendmail daemon (or NO). You need this to have e-mail services unless you have replaced it with another mailer daemon. It is configured through /etc/sendmail.cf

sendmail_flags="-bd -q30m"

-bd is pretty mandatory.

savecore_enable="NO"

Save kernel crashdumps for debugging (or NO).

dumpdev="NO"

Device name to crashdump to (if enabled).

check_quotas="NO"

Check quotas (or NO).

accounting_enable="NO"

Turn on process accounting (or NO).

ibcs2_enable="NO"

Ibcs2 (SCO) emulation loaded at startup (or NO).

linux_enable="NO"

Linux emulation loaded at startup (or NO). See the section on setting up Linux Emulation.

rand_irqs="NO"

Stir the entropy pool (like "5 11" or NO).

4.9.   Allow local configuration override at the very end here

if [ -f /etc/rc.conf.local ]; then
	. /etc/rc.conf.local
fi

5.   Adding and Installing Software

Adding/installing software in FreeBSD is easy. FreeBSD maintains a set of "packages" that are pre-built, ready to run binaries of almost all the popular programs out there. If you have the CD set, they are all on CD#1, which you can browse directly (there's a directory called packages..), or use the "/stand/sysinstall" tool, go to Post Configuration, and choose Packages. You'll get a nice little screen with all the packages categorized with a short description.

Often, you might want to ftp to ftp.freebsd.org to get the latest version of a package - ftp://ftp.freebsd.org/pub/FreeBSD/packages-stable is probably where you want to look. If you download a package, it will have a .tgz ending. You don't need to manually untar/expand this file. Just use the command pkg_add".

Ex: I've downloaded the packages called spaz-1.32.tgz

That's it! Now the package is installed and setup on your system. If you're using csh or tcsh, you should type rehash for your shell to rescan your system bin directories...

The package is registered in the /var/db/pkg directory - you can cd to there and get a directory listing to see what packages you have installed on your system. If you no longer want a package, you can remove it with the pkg_delete command: pkg_delete spaz-1.32.tgz (from the /var/db/pkg directory)

The FreeBSD ports system works exactly the same, with port registration making it easy to remove things you don't want afterwards.. The difference is that the ports are in "Source" form, and need to be compiled. If you have an Internet connection up, and have the ports tree installed (you were asked if you wanted it installed during the installation of FreeBSD) you can cd /usr/ports and take a look around.

Say you wanted to install the port from the /usr/ports/net/spaz directory -

Once again, you use the pkg_delete program in /var/db/pkg to remove the ports that you have installed.

6.   How to install Linux Emulation

Linux emulation allows you run linux binaries on your FreeBSD system. It actually works very well. There are two ways to run the emulation:

Either way you install it, you must first install the Linux libraries from the ports collection.

cd /usr/ports/emulators/linux_lib

make install

This will install all the linux libraries into /usr/compat/. It will install the script /usr/bin/linux, which loads the kernel loadable module needed for linux emulation.

If you wish to run linux emulation using the lkm, all you need to do after this is modify your /etc/rc.conf at the following line.

  linux_enable="YES"      # Linux emulation loaded at startup (or NO). 

This will enable Linux emulation at boot up. If you wish start Linux emulation with out rebooting, just type linux. (You need to be root to do this).

If you don't use the lkm, you need to rebuild your kernel and include

  options         COMPAT_LINUX 

in your kernel config file. Now, Linux emulation will always be enabled. You do not need to modify your rc.conf