Setting Up a New FreeBSD System

Richard Neswold

FreeBSD contains a terrific installation program that allows you to get a system up and running in short order. The resulting configuration, however, isn't quite the way I like it. This document describes the extra configuration I end up doing to give my FreeBSD systems my personal touch.

Note: This document is a work in progress. Some of the later sections are pretty sparse.




Table of Contents
1. Introduction
2. Customizations
2.1. Souping up the consoles
2.1.1. Increasing the number of lines
2.1.2. Adding mouse support
2.2. Installing bash
2.3. Installing cvsup
2.4. Moving /tmp to Memory
2.4.1. Making /tmp truly temporary
2.4.2. Just do it!
2.5. Create accounts
2.6. Creating links to X directories
List of Figures
2-1. Specifying console fonts.
2-2. Setting 50-line mode as default.
2-3. Activate console settings at boot time.
2-4. Documenting device usage.
2-5. Setting up the mouse.
2-6. Activate virtual terminal mouse at boot time.
2-7. Contents of /usr/share/skel/dot.bash_logout.
2-8. Contents of /usr/share/skel/dot.bash_login.
2-9. Contents of /usr/share/skel/dot.bashrc.
2-10. Entry added to /etc/fstab.

Chapter 1. Introduction

This document describes some extra configuration you can do to make your FreeBSD system more enjoyable. It assumes that you have already installed FreeBSD, and that you have successfully shutdown and rebooted the system. It also assumes you have some experience with a Unix editor. The ee editor is a simple editor that beginners should find easy to use and should be available on newly installed systems. Use this editor until you have time to learn vi or emacs.

Let's start customizing the system!


Chapter 2. Customizations

Although many of these modifications aren't dependent upon each other, some may be. Modifications that require previously applied modifications will indicate where to begin.


2.1. Souping up the consoles

Ever since MS-DOS was able to run in 43 or 50-line mode, I have disliked 25 line mode screens; 25 lines simply do not display enough information! Fortunately, the FreeBSD virtual terminals support these modes. An added bonus is that the terminals also support mouse interaction!

This section describes how to enable these modes and make them become the "default" setting (i.e. they automatically get set each time you boot your system.)


2.1.1. Increasing the number of lines

To understand how to increase the number of lines, I think it's useful to explain some details of the video hardware.


2.1.1.1. Background

The original CGA hardware had a 25-line display. It allocated 8 scan lines to each character and, therefore, fit 25 character rows in the 200 scan lines it displayed. EGA introduced 350 scan lines per screen and VGA increased it further to 400. By loading a font with 14 scan lines or 16 scan lines per character (for EGA and VGA, respectively), the 25 rows of characters were retained. If the font used by the graphics card had only 8 scan lines per character (and the video controller chip was programmed slightly different), we could get to higher character row layouts.

Fortunately, the vidcontrol command does all this work for us! After logging into a virtual terminal, we tell it to use an 8 by 8 character font and then switch to a higher character row format.

    # vidcontrol -f 8x8 cp437-8x8
    # vidcontrol VGA_80x50

vidcontrol uses its standard input to determine which terminal needs to be modified (that's why we needed to log into a virtual terminal.) If you are running as root, you can specify other virtual terminals by redirecting the input of vidcontrol from the terminal of choice.

    # vidcontrol -f 8x8 cp437-8x8 < /dev/ttyv0
    #vidcontrol VGA_80x50 < /dev/ttyv0

Now that your virtual terminal is set up, you need to set your TERM environment variable to reflect the extra lines (don't worry, this too can be automated.)

    # TERM=cons50
    #export TERM

2.1.1.2. Just Do It!

Rather than entering this sequence everytime we boot, we can have it automatically done. FreeBSD has a configuration file which is used during a system boot, /etc/rc.conf. Bring /etc/rc.conf up in an editor. Search for the font entries in this file. These entries load in the fonts necessary to support 43 and 50 line mode. Edit the three lines to the following values.

Figure 2-1. Specifying console fonts.

    font8x16="cp437-8x16"   # font 8x16 from /usr/share/syscons/fonts/* (or NO).
    font8x14="cp437-8x14"   # font 8x14 from /usr/share/syscons/fonts/* (or NO).
    font8x8="cp437-8x8"     # font 8x8 from /usr/share/syscons/fonts/* (or NO).

Now we set the default terminal type to cons50. Edit /etc/ttys. Change the virtual terminal settings so they indicate the terminal type is cons50 instead of cons25. The fourth virtual terminal is shown to be configured for my X server. This will be described further in a later section.

Figure 2-2. Setting 50-line mode as default.

    ttyv0   "/usr/libexec/getty Pc"         cons50  on secure
    ttyv1   "/usr/libexec/getty Pc"         cons50  on secure
    ttyv2   "/usr/libexec/getty Pc"         cons50  on secure
    ttyv3   "/usr/X11R6/bin/xdm -nodaemon"  xterm   off secure

The last thing we need to do is have vidcontrol switch the video mode and set the foreground/background colors[1] when we boot. We can add these commands by editing /etc/rc.local. Go near the end of the file, where local customization is expected, and add the following lines:

Figure 2-3. Activate console settings at boot time.

    echo -n '[Setting up VTs] '
    for ii in /dev/ttyv*
    do
        /usr/sbin/vidcontrol < $ii VGA_80x50
        /usr/sbin/vidcontrol green black > $ii 2>&1
    done

Your system system will now switch to 50-line mode every time it boots.


2.1.2. Adding mouse support

2.1.2.1. Background

If you have used an X-Windows interface, you are probably familiar with copying text from one part of the screen to another using the mouse. If you find yourself needing that functionality in a virtual terminal, fear not! The FreeBSD virtual terminals have that capability -- it's just that you have to do a few things to enable it.

Enabling the virtual terminal mouse is a two (possibly three) step process. First you have to load the mouse driver. Then you have to indicate which terminal should use the mouse. The third possible step requires the rebuilding of your kernel if your mouse attaches to "exotic" hardware.


2.1.2.2. Examples

2.1.2.2.1. Case 1

Let's set up a sample mouse. I have a MouseSystems three-button serial mouse, so let's start with my configuration. Since the sio drivers are usually installed (you need them to operate a modem), we won't have to rebuild the kernel. So our first step, in this case, is to load moused as root (the superuser account.)

    # moused -t mousesystems -p /dev/cuaa1 -D

In this command, we've specified that the mouse uses the MouseSystems protocol. We also specified the serial port with which the mouse is attached. Lastly, we specified the -D option. This option is a MouseSystems-specific option than tells the driver to use the DTR signal when communicating with the mouse.

Now that moused is running, we need to enable it in the virtual terminal. We use vidcontrol to do this.

    # vidcontrol -m on

At this point, when the mouse is moved, a cursor should move as well. Also, the virtual terminal now has support for marking and pasting text.


2.1.2.2.2. Case 2

This time we'll set up a PS/2 style mouse. This type of mouse requires the psm driver to be added to the kernel. The generic kernel already has this driver enabled, so you may not have to rebuild your kernel (rebuilding the kernel is explained in the Handbook.)

First load moused.

    # moused -t ps/2 -p /dev/psm0

Next, enable it in a virtual terminal.

    # vidcontrol -m on

To see a list of mouse protocols that moused supports, check its man pages.


2.1.2.3. Interesting moused Side Effect

moused command has an interesting property. It creates a pipe, /dev/sysmouse, and sends the stream of mouse commands it receives to this pipe. Any application (like, for instance, an X server) that opens this pipe will get the mouse commands!

Furthermore, moused simplifies the matter by only sending the MouseSystem protocol, regardless of the type of mouse being used. Thus, if you can get moused to work properly, you will have no problem getting the mouse to work under X.


2.1.2.4. Just Do It!

Because each system tends to use the serial ports in different ways, I like to "document" the setup. What I mean is that it would be easier to remember that the mouse is connected to /dev/mouse rather than /dev/cuaa0. To help me remember, I set a symbolic link to the correct device. I create a similar link to the modem device.

Figure 2-4. Documenting device usage.

    # ln -sf /dev/cuaa0 /dev/mouse
    # ln -sf /dev/cuaa1 /dev/modem

Now, if I ever move the mouse to a different port, I only need to update the symbolic link rather than all the scripts and configuration files that refer to the mouse. The savings are even more dramatic with the modem device.

The startup scripts are already set up to run moused if certain variables are defined in /etc/rc.conf. Bring /etc/rc.conf up in an editor. We're going to edit a section which describes the mouse you have (in this case, I have a MouseSystems mouse.)

Figure 2-5. Setting up the mouse.

    mousedtype="mousesystems"
    mousedport="/dev/mouse"
    mousedflags="-D"

Next, we'll have to edit /etc/rc.local to enable the mouse at boot time.

Figure 2-6. Activate virtual terminal mouse at boot time.

    echo -n '[Setting up VTs] '
    for ii in /dev/ttyv*
    do
        /usr/sbin/vidcontrol < $ii -m on
    done

2.2. Installing bash

I like using bash as my shell. Unfortunately, it's not one of the shells that gets included with the base system, so it needs to be installed from the ports. Start /stand/sysinstall as root and load the bash package.

Once bash is loaded, set up some default files in /usr/share/skel so that new accounts get these defaults.

The first file I add to /usr/share/skel is called dot.bash_logout. This file is executed by bash when the shell is exited. In this case, I simply clear the screen.

Figure 2-7. Contents of /usr/share/skel/dot.bash_logout.

    clear

Now add another file, dot.bash_login. This file is executed by bash when a user logs in. I set this file up to simply look for a .bashrc file and execute it, if it exists. This allows me to put common set-up stuff (like environment variable) in one location. Since this script gets executed only during interactive logins, I also set the prompt. The last thing this file does is set up the backspace key.

Figure 2-8. Contents of /usr/share/skel/dot.bash_login.

    if [ -f ~/.bashrc ]; then source ~/.bashrc; fi
    
    export PS1='[\h:\w]\$ '
    stty erase ^H

Finally, add one more file, dot.bashrc. The user can use this file to set-up environment setting common to login shells and non-interactive shells.

Figure 2-9. Contents of /usr/share/skel/dot.bashrc.

    umask 027

Now any new accounts you make that use bash, will have some nice default behavior (IMO). You can now use passwd to change your login shell.


2.3. Installing cvsup

If you're interested in keeping a current list of software that has been ported to FreeBSD or if you want to stay up to date with the FreeBSD source code, then you need to install cvsup.

The easiest way to do this is through the "packages" collection. As root, run /stand/sysinstall. You select the "Configure" option from the main menu. Next, select "Packages". You are then asked to specify the source of the packages. If you installed FreeBSD from an FTP site, or if you have your Internet connection already working, you can get the packages an FTP site. This gives you the most up to date versions of software that are available. You can also install some of the packages from the CDROM.

From the menu of categories, select "net". Select "cvsup-bin" from the list of network applications.

For an in-depth discussion on using cvsup, look in the Handbook.


2.4. Moving /tmp to Memory

If you went with the default filesystem configuration, when installing FreeBSD, you currently have three partitions: /, /usr, and /var. Unfortunately, this isn't quite perfect. You see, the root partition also includes the /tmp directory. Since this directory is writable by anyone, anyone can create an enormous file in it and use up most of your / partition.

This section shows you the steps needed to isolate the /tmp directory and how to speed it up at the same time.


2.4.1. Making /tmp truly temporary

The trick is to place the /tmp in a filesystem that resides in memory. Some operating systems refer to this as a RAM Drive. FreeBSD refers to this as a memory file system (MFS). Mounting a memory file system onto /tmp has several benefits:

  1. The directory is isolated from the root directory. Anyone can fill the /tmp directory, but it won't affect the capacity of other partitions.

  2. The contents are lost across boots of the system -- making it a true temporary directory.

  3. Because the contents reside in memory, access to this directory is typically very fast [2].

  4. Processes that use memory-mapped files that reside in /tmp perform better because the file contents don't have to be backed out to disk[3].


2.4.2. Just do it!

All you need to do to move /tmp to memory is add an entry to /etc/fstab. The entry is a little unusual in that the device that is specified isn't what is getting attached to the filesystem. In the case of MFS, the device should be your partition that is being used for swap space. Since the memory filesystem is backed by the virtual memory system, it needs to know the layout of the swap space.

Add the following entry to /etc/fstab. Make sure the device your specify (which is the first field) is the same device used by your swap partition. The options field allows you to size the MFS drive (in this example, I reserved 50 meg). Just make sure you don't size your MFS drive larger than your swap partition!

Figure 2-10. Entry added to /etc/fstab.

    /dev/wd0s2b             /tmp            mfs     rw,-s=100000,nodev,noexec 0 0

Since your system probably already has stuff in the /tmp directory, you'll probably want to wait until the next reboot to mount this.


2.5. Create accounts

Now that bash is installed, I can create accounts. The first account is toor, which is a root account that uses bash. Run vipw to edit the password file. Copy the entry for root, but change the username to toor and specify bash as the login shell:

    toor::0:0:Bourne-again Superuser:/root:/usr/local/bin/bash

Login as toor and add a password.

Since you already have a toor account, you'll have to copy these three files to /root and remove the "dot" prefix (e.g. dot.bashrc is renamed to .bashrc, etc.)

Take the time to make some accounts with adduser.


2.6. Creating links to X directories

If you've installed the X-Window interface on your system, and you plan on compiling a few X applications, you might want to create the links in this section. I've found that creating these links has made several of the ports compile cleanly (where they didn't compile before.)

By the way, you'll have to create these links as root.

    # ln -s /usr/X11R6/bin /usr/bin/X11
    # ln -s /usr/X11R6/lib/X11 /usr/lib/X11
    # ln -s /usr/X11R6/include/X11 /usr/include/X11

Notes

[1]

Thanks to Ivan Pascal (pascal@info.tsu.ru) for correcting a mistake I made in setting the colors.

[2]

The memory file system is backed by the swap partition. This means that, if the system is running low on memory, the contents of the memory file system can be swapped out to the hard drive! This has another implication: anyone filling the /tmp directory is using up virtual memory, which may degrade the performance of the system.

[3]

Thanks to Sean Kelly (kelly@plutotech.com) for pointing this out.