Exercises: Post FreeBSD Install: ccTLD Workshop Nairobi

September 12, 2005

Please do not change the root password on your machine for any reason!

Your instructor may indicate some updates or changes to these exercises. The initial exercises are to finalize our machine configurations for use later today, and throughout the week, as well as to highlight some areas that are different from Linux - particularly methods by which you can install software.

Note that the machine "noc.domain" is the classroom server, or our "noc box".

 
Exercises

    To Be Done by Everyone: Final Configuration

  1. Use pw to create a new userids that you will use instead of root
  2. Use /stand/sysinstall and pkg_add to install lynx, bash, sudo and joe
  3. Installing two more packages (gmake, unzip)
  4. Installation of software using ports
  5. Setup sudo for privileged commands
  6. Installing/configuring X11 (Xorg), Gnome and gdm
  7. Some Differences from Linux

  8. Process startup and the RC system
  9. Disk partitions: how to view your disk
  10. Getting help using manpages, docs, and the FreeBSD Handbook
  11. Shutdown and reboot your system
  12. Initial login, virtual terminals, command line manipulation

For Those who Want More Practice

Ask your instructor. Additional exercises are available covering the follwing topics:

Note: The "#" and "$" characters before commands represents your system prompt and is not part of the command itself. "#" indicates a command issued as root while "$" indicates a command issued as a normal user.

Note 2: If you install software, update your environment as root and the change is not immediately available try typing rehash at the root shell prompt. This is only necessary when running a C shell (e.g., like /bin/csh).


1.) Use pw to create a new userid that you will use instead of root [Top]

First login to your computer if you have not already done so. Login as userid "root" using the password given at the start of class and that you used while installing FreeBSD.

Now that you are root you can create a new user account on your machine. If more than one person is using your machine, then be sure that you create an account for each and every person.

To create or remove a user account you should use the "pw" command. To get a feel for the power and complexity of this command take a look at its man pages:

# man pw
So, first pick a username that you want to use. For example, use your first name, last name, a combination of both, or whatever you prefer. For purposes of this example we use username. So, to add a new user to your system type:
# pw useradd username -m -s /usr/local/bin/bash
This creates the user username. The "-m" says add a new home directory of /usr/home/username and copies files from /usr/share/skel to the new user's home directory. The default shell "bash" will be used. Note that at this point the bash shell has not been installed on your machine. We'll be doing this in the upcoming exercises.

Next you need to set the password for the new userid, otherwise you won't be able to use the account properly. To do this use the passwd command like this:

# passwd username
You will be prompted to enter in a new password, then to enter it again to verify. You need to pick a secure password. Note, as root (OK, and by default on FreeBSD!) you are allowed to pick any password you want, but you need to pick a secure password for your new account. Here are some quick guidelines to picking a secure password:

For example, something like "CcTld2k5.KE!" is OK ("ccTLD 2005, Kenya!") isn't bad. Please don't pick this for this exercise.

So, finally, let's change your new user's password using the command:

# passwd username
Please complete these steps:

Create the userid admin. This account may be used later for ssh exercises, and to allow your instructor access to your machine during the week if necessary. The password for the admin should be written at the front of the room. If not, please ask your instructor for the admin password now. The pw useradd command format will be a bit different. This will be explained in exercise 5.

# pw useradd admin -m -s /usr/local/bin/bash -G wheel
# passwd admin        (password for admin account given in class)

 

2.) Use /stand/sysinstall and pkg_add to install lynx, bash, and joe [Top]

For this exercise you need to be logged in as root.

FreeBSD has a large collection of preconfigured binary packages for each release that can be installed in a number of ways, including:

  1. Using the post-installation configuration utility /stand/sysinstall (don't use this now).
  2. Directly from the FreeBSD installation CD-ROMs using pkg_add.
  3. From a local network collection of FreeBSD packages specifying the network path and protocol using pkg_add.
  4. Blindly across the network using the "-r" option of the pkg_add command
The core package utilities available in FreeBSD are:
pkg_add
pkg_delete
pkg_info
You can read about each of these package commands using the "man" command, i.e.:
# man pkg_delete

# man pkg_add

Remember, the pkg utilities under FreeBSD are very powerful as they can resolve dependencies, let you test installation before actually installing software, and keep track of what is installed with utilities to query the package database and assocated files.

For our first package we are going to install a text-based web browser called lynx. We'll use the /stand/sysinstall program to install lynx from the first disc of the FreeBSD CD-ROM installation set.

First,you can see if lynx is already installed on your system. Use the pkg_info command to do this. To get an idea of what packages are installed and what the default pkg_info output looks like type:

# pkg_info | more
You'll notice a pause while your machine prepares to show all the packages installed, in alphabetical order. Press space to scroll down the list, or ctrl-c to stop the list.

Now to check for just the lynx package type:

# pkg_info | grep lynx
or
# pkg_info lynx\*
If you don't understand what "grep" is doing type "man grep". In optional exercises we go in to detail about the use of "grep", and the pipe facility represented above by the "|" character.

If lynx is already installed, for purposes of this exercise, first remove the package from our system (it's good practice!). You can do this by typing:

# pkg_delete lynx-2.8.5
Now type again:
# pkg_info | grep lynx
And, assuming that lynx is now not installed you should just get your prompt back.

Now to install lynx using the FreeBSD install CD-ROM do the following:

Insert the FreeBSD Disc 1 Installation CD in your machine's CD-ROM drive.
Be sure that you are logged in as the root user:

Now start the "sysinstall" utility by typing:

# /stand/sysinstall

At this point you take the following steps in the sysinstall menu system to choose the lynx package and install it: After exiting this utility your FreeBSD install CD-ROM may still be mounted. You can type "df" and look for an entry like this:

Filesystem  1K-blocks     Used    Avail Capacity  Mounted on
/dev/acd0      660384   660384        0   100%    /cdrom
If you don't see the "/cdrom" entry, then type:
# mount /cdrom
again to make sure your CD-ROM (FreeBSD disc 2) is correctly mounted.

Installation of bash

Now let's install the bash package using a single command. As your FreeBSD CD-ROM is mounted under /cdrom, and as your instructor knows where the bash package resides on your CD, you could install bash by typing:

# pkg_add /cdrom/packages/shells/bash-3.0.16_1.tbz
But, rather than doing this, let's do this a bit differently. First use the cd (Change Directory) command to change to the initial cd-rom directory. Then we'll change to the directory /cdrom/packages/All. The "All" directory contains a list of all packages available to be installed on the cd-rom. It has the advantage that if you use pkg_add installing from this directory that if there are dependent packages that are needed, then they will be found and installed as well. So, first do:
# cd /cdrom

# cd packages/All

Now let's look for the bash package. We can use the ls command to do this with a wildcard. You'll be practicing and learning much more about these basic system commands in a few more exercises. OK, so do:
# ls bash*
You should see bash-3.0.16_1.tbz on your screen. This is how you know the exact name of the package you want to install. In addition, once you have installed and are using the bash package it will be easy to use command completion to figure out complicated filenames like these. You'll see more of this in exercise 7. So, now that you know you want to install the package called bash-3.0.16_1.tbz (we're going to use the newer version vs. the 2.05b version that's listed), and you are already in the directory where this file resides, then you can simply type:
# pkg_add bash-3.0.16_1.tbz
and the bash package will be installed. By the way, bash is an alternate shell environment that you can use which has more features than the default shell sh. Notice the file extension of "tbz" on the file bash-3.0.16_1.tbz, this means that the file is actually a group of files that have been compressed and saved as a single file.

Installation of joe

Some of you may practice the use of the "vi" editor in later, optional exercises. vi is not as friendly as the optional "joe" editor. There are reasons for this, which we'll explain. But, for later exercises let's install "joe" right now, but this time we'll install from our local workshop server.

Note: If the server name is different than what is shown below your workshop instructor will let you know. It's likely that we will have configured DHCP in the classroom to automatically update your /etc/resolv.conf file with the correct domain. In this case you could simply use "noc" instead of "noc.ws.cctld.ke" (if you administer DNS, then this is pretty obvious).

To install the "joe" editor from the local workshop server you can simply type the following:

# pkg_add ftp://noc.ws.cctld.ke/pub/FreeBSD/packages/All/joe-2.8_5.tbz
This will download and install the joe 2.8_5 package to your machine from the local workshop server. Note that this editor has been added by us. It no longer ships with the default FreeBSD installation.

Do a little bit of exploring about what you have just installed by entering the following commands:

# man lynx (we'll discuss man a bit later)

# man bash

# man joe

# pkg_info lynx-2.8.5

# lynx www.freebsd.org

'q' (to 'q'uit lynx)

# joe

ctrl-c (to abort, you can say "no" to saving data)

 

3.) Installing two more packages (gmake, unzip) [Top]

For this exercise you need to be logged in as root.

During the week we will need two additional packages to do our work. The two packages we need are:

Both of these items are packages available on the first FreeBSD CD-ROM. We have placed these files on our classroom server in the /pub/FreeBSD/packages directory. So, to install these three packages simply issue the following three commands
# pkg_add ftp://noc.ws.cctld.ke/pub/FreeBSD/packages/All/gmake-3.80_2.tbz

# pkg_add uftp://noc.ws.cctld.ke/pub/FreeBSD/packages/All/unzip-5.52_1.tbz

If you want to learn more about these three packages you can type:
# man gmake

# man unzip

 

4.) Installation of software using ports [Top]

For this exercise you need to logged in as root.

The ports collection, which we installed during the FreeBSD install, is larger than the packages collection available on the first FreeBSD install cd-rom. As of June 2005 there were over 13,000 ports available! The FreeBSD Handbook has an excellent discussion of using Ports in section 4.5. In a nutshell these are the key points to remember about ports: The very first thing we are going to do is to update a master configuration file so that when you attempt to install a port it will look on our local server for the distfiles rather than using our single outgoing link to fetch distfiles from the internet.

To do this you should edit the file (use joe or vi) /etc/make.conf and add the following two lines to the end of the file:
If "ws.cctld.ke" is not correct replace this with the correct domain in use for the workshop!

MASTER_SITE_BACKUP=ftp://noc.ws.cctld.ke/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR}/
MASTER_SITE_FREEBSD=yes
First do the following:
# cd /usr/ports
# make search name=lsof
This will output something like:
Port:   lsof-4.72.2
Path:   /usr/ports/sysutils/lsof
Info:   Lists information about open files (similar to fstat(1))
Maint:  obrien@FreeBSD.org
B-deps:
R-deps:
WWW:    http://people.freebsd.org/~abe/
From this you can see that the lsof utility resides in /usr/ports/sysutils/lsof. So, to install lsof on your system you do the following:
# cd /usr/ports/sysutils/lsof
# make
# make install
Make will download the lsof source (hopefully from our local server!), and then compile the source. "Make install" will place the compiled binary files in the appropriate directories on your system and update the appropriate configuration files if necessary. You can issue the single command "make install" instead.

You can now type:

# rehash       (to re-read items in your directory path)
# man lsof
For more information. Finally, if you want to deinstall a port once it is installed, for instance lsof, you would do the following (please don't do this):
# cd /usr/ports/sysutils/lsof
# make deinstall
And, if you decided that was a mistake, you can now do the following to reinstall a port (after it's been installed once):
# cd /usr/ports/sysutils/lsof
# make reinstall
If you do a "make clean" then "make reinstall" will no longer work for that port. If you want to see lsof in action you can type:
# lsof -i
In addition, FreeBSD installs the utilities fstat, and sockstat that can display the same information.

 

5.) Using sudo for privileged commands [Top]

When you created your own user account username you did not place it in the wheel group. This means that you cannot become the root user from your username using the command su. This is a useful thing to be able to do if you don't want to have to logout and log back in each time you need to be root. In addition, the change we are going to make to the "sudoers" file, which controls access to the sudo command is based on your username being in the wheel group. So, the first thing you need to do is be sure you are logged in as root:

$ exit

Login: root

Now we are going to use the pw command to make a change to your username account make it a member of the wheel group. The wheel group is a special group in Unix that allows members to become root. To do this type:
# pw usermod username -G wheel
The "-G" indicates "group list". If your user already belongs to other groups you must include all these groups in list format (e.g. "group1,group2,group3,etc.), otherwise your user will be removed from the other groups when you issue this command. To see what groups a user belongs to you can type:
# groups username

Once your user is a member of the wheel group you can use the su (Substitute User identity) command to become another user without having to login and logout of your session.

To practice this you need to login as your username account now:

# exit

$ Login: username

Now you can practice using su.
$ su - root
If you skip the "-" option, then you won't execute the root login scripts. In general you can type "su user", or "su - user", and switch to any user's environment.

Now let's drop back to your standard user account and try to do something that requires privileges:

# exit

$ less /etc/master.passwd

You should get the message, "/etc/master.passwd: Permission denied" - Now try running the same command like this:
$ sudo less /etc/master.passwd
You noticed that this did not work, right? First we need to add a package called "sudo" to your machine, then we need to configure the file /etc/sudoers to allow you to use this facility. Let's get the package installed first. We'll use pkg_add and we'll get it from our local server:
$ su - (you must be root to install this package)

# pkg_add ftp://noc.ws.cctld.ke/pub/FreeBSD/packages/All/sudo-1.6.8.7.tbz

Now we need to configure the file /etc/sudoers so that you can use the sudo command:
# visudo
This is a special utility to edit the /etc/sudoers file using vi, but to lock the file so that no one else can edit it while you are using visudo. So, remember your vi commands and scroll down the screen until you find the following lines in the file (if you need help with vi ask your instructor or one of the classroom helpers):
## root and users in group wheel can run anything on any machine as any user
#root           ALL = (ALL) ALL
#%wheel         ALL = (ALL) ALL
(Note/hint: there are other ways of finding this line in vi. You could search for something using "/".).

Now, once you are here, just make one, small change. Remove the "#" symbol (it's a comment symbol) from in front of "%wheel". Once you do this save and quit from the file. So, your file should now look like:

## root and users in group wheel can run anything on any machine as any user
#root           ALL = (ALL) ALL
%wheel         ALL = (ALL) ALL
And, to save and quite it's:
:wq
That's it. You are now ready to run "sudo" as a general user (or, at least a general user in the wheel group). Make sure you exit from the root shell you are in:
# exit
And, now as a general user, try issuing the command:
$ sudo less /etc/master.passwd
You will be prompted for a password, and the first time you use sudo you'll receive a warning. The password you should enter will be your user account's password. This is different from Linux. Type this in, and you should be able to view the /etc/master.passwd file even though you are running as a standard user. Try doing this again ("less /etc/master.passwd") and you'll notice that you are no longer prompted for the root password. You can issue any privileged command (pretty much) without needing a password at this point. Once you login and logout again, then you'll have to enter a password the next time you use sudo.

sudo is very useful to allow you to do system administration tasks on your machine without needing to be logged in as root. This can help to protect you from making mistakes running as root, which can be costly.

 

6.) Installing/configuring X11 (Xorg), Gnome and gdm [Top]

For this exercise you will need to be logged in as root.

Before we begin there are a few items to understand to put this in perspective:

  • A much more complete discussion of using X and Desktops under FreeBSD can be found in Chapter 5, The X Windows System, of the FreeBSD Handbook. I highly recommend reading this entire chapter if you wish to fully configure your X Window environment for FreeBSD.
  • FreeBSD is a server-based operating system. Configuration of X, display managers, and desktops like Gnome and KDE are not done during installation as this is not the objective of the OS.
  • You can configure FreeBSD to autostart in to a GUI environment, but I would not recommend this, except, possibly, for desktop and laptop use.
  • To automate the use of X Window you can edit /etc/ttys (see the Handbook), xinitrc, .xinitrc, .xsession, Xsession, and KDE config files to your liking. For our purposes we are going to install Gnome and manually call the Gnome Dislpay Manager (gdm) when we wish to use an X Window environment.
  • X11 is the implementation of the X Windows environment. Xorg is the X11 implementation that FreeBSD uses by default. You can still use XFree86 if you wish, but configuring Xorg is easier. Gnome and KDE are Desktop environments that include Window managers and entire sets of desktop applications.
  • You can clean up and make your font environment considerably nicer under X, particularly fonts used by OpenOffice, Netscape/Mozilla/Firefox, and The Gimp. This is easier to do using Xorg. Read Chapter 5 of the FreeBSD Handbook for more details.
  • The Gnome and KDE installations that come with the FreeBSD 5.4 CD-ROM installer are quite up-to-date (as of June 2005). The Gnome version is 2.10 and KDE is version 3.4. Gnome version 2.10.1 is available via the ports tree, and you can read about Gnome on FreeBSD here:
    http://www.freebsd.org/gnome/
    You can read about KDE on FreeBSD here:
    http://freebsd.kde.org/
  • If you plan on installing both Gnome and KDE and/or possibly offering up Desktop environment via your network from a server, then you will most likely use the KDE Display Manager (kdm) or, possibly the X Display Manager (xdm). kdm can offer access to both Gnome and KDE Desktop environments at log in.
For this workshop we are going to install Gnome from your FreeBSD CD-ROM install set and we are going to use gdm manually to start our X Window environment. We have already configured an Xorg configuration file for your particular machines setting the correct monitor refresh rates and setting your desktops to use 24-bit color at a depth of 1024x768. You will be copying this file from our classroom server, noc, to the appropriate location.

During our initial installation of FreeBSD we installed Xorg, but we have not yet configured it to run on our hardware. First, let's install Gnome using the sysinstall utility.

Start the sysinstall utility (as root) by typing:

# /stand/sysinstall

At this point you take the following steps in the sysinstall menu system to choose the Gnome packages and install them:
  • Choose "Configure" (you can press "C" and ENTER)
  • Arrow down to "Packages" and press ENTER
  • For installation media choose "CD/DVD" and press ENTER (note you can use network options here)
  • If prompted choose "acd0" for your CD-ROM drive
  • Scroll down the list of presented categories (using the down arrow key) until you see "gnome", and press ENTER
  • Scroll down the list to "gnome2-2.10.0" to highlight this then press the spacebar to choose the package, then press ENTER
  • You should have noticed that multiple Gnome packages are automatically chosen as dependencies (a "D" appears in the selection boxes vs. an "X") when you choose just gnome2-2.10.0.

  • Now choose "Install" and press ENTER to install Gnome version 2.10.0 on your system
  • At this point you will be prompted for disc 2 of the FreeBSD installation set. Most of the FreeBSD packages have been moved to this disc. Go ahead and follow the on-screen instructions to swap cd-roms.

    If there are problems with this let your instructor know. There are many possible bits and pieces to this that can go wrong. An easy work-around is to download the entire gnome folder from noc/pub/FreeBSD/packages/All to your local drive and then use pkg_add in the Gnome directory to install everything at once.

  • Once installation is complete you will be presented with the initial FreeBSD Configuration Menu - Scroll to the top of the screen and choose "X" for "Exit" and press ENTER
  • Finally choose "Exit Install" to leave the "sysinstall" utility
At this point both Xorg (the X11 X Window system) and Gnome are installed on your system.

If you're lucky and your hardware is relatively new, supported by Xorg, etc., then you can simply type:

# gdm
as root and the opening Gnome Display Manger screen will appear in a reasonable resolution. If this does not work your instructor will discuss your next steps and, possibly, make available an appropriate xorg.conf file for your system.

 

Some Differences from Linux

7.) Process startup and the RC system [Top]

This is a rather complex topic. But, in a nutshell, under FreeBSD 5.4, when your machine boots processes (that is daemons or services) are configured and/or started like this:

  • Items that are configured or referenced to start in the file /etc/defaults/rc.conf contain corresponding script entries in /etc/rc.d/.
  • You can override settings in /etc/defaults/rc.conf by placing settings in /etc/rc.conf.
  • Every script in /etc/rc.d/ will attempt to run, but if it does not see:
    script_enable="YES"
    in /etc/defaults/rc.conf or /etc/rc.conf then the script will not run to start the corresponding service.
  • Some third party software will place entries in /etc/rc.conf and corresponding third party startup script packages in /usr/local/etc/rc.d/.
  • Some third party packages will place startup/config scripts in /usr/local/etc/rc.d/ that do not look in any file, but simply execute upon system boot.
  • Some older software may still place startup items in /etc/rc.local, but this has been deprecated, even though it is still supported.
  • Generally third party software with scripts in /usr/local/etc/rc.d/ with the execute bit set will automatically run:
    /usr/local/etc/rc.d/script-name.sh start
    at system boot time. They may, or may not look in /etc/rc.conf for configuration settings.
  • Always read the contents of any new third party script placed in /usr/local/etc/rc.d/ to understand how it works and if you need to edit /etc/rc.conf for the script to run properly.
To get a better feel for this you should read:
$ man rc
Then, you should probably read this again...

Now, if you want to start a process each time your machine boot you generally add an item to /etc/rc.conf to indicate this. For instance, if you wanted to enable the ssh daemon (server) each time your machine started then you would add the line:

sshd_enable="YES"
to /etc/rc.conf. If you look at /etc/defaults/rc.conf you'll see that sshd is not enabled in this file by default. By enabling sshd in /etc/rc.conf this overrides the setting in /etc/defaults/rc.conf. In addition, if you look in /etc/rc.d/ you'll find an sshd script file that starts this service.

To see how sshd is enabled initially do this:

$ grep sshd /etc/defaults/rc.conf
You should see something like:
sshd_enable="NO"                # Enable sshd
sshd_program="/usr/sbin/sshd"   # path to sshd, if you want a different one.
sshd_flags=""                   # Additional flags for sshd.
These are the lines in /etc/defaults/rc.conf that deal with the ssh daemon. When you specified to enable the ssh daemon during installation then in the file /etc/rc.conf the lines that read:
sshd_program="/usr/sbin/sshd"   # path to sshd, if you want a different one.
sshd_flags=""                   # Additional flags for sshd.
became active. So, if your ssh program was not "/usr/sbin/sshd" for some reason, then in /etc/rc.conf you could add:
sshd_program="/new/directory/sshd"   # new path to sshd
to override what's in /etc/defaults/rc.conf.

You could just put everything in /etc/defaults/rc.conf, but you don't want to do this. If you upgrade your system it's almost certain that /etc/defaults/rc.conf could be overwritten. In addition, this file is large and it would be hard to see the changes you had made if you were to do them in /etc/defaults/rc.conf.

To start a service manually you can use it's startup script by hand. For instance, try typing:

$ su - (you must be root to run these commands)

# /etc/rc.d/sshd

What is returned on the screen? It should be something like:
Usage: /etc/rc.d/sshd [fast|force|one](start stop restart rcvar keygen reload status poll)
So, you could type
# /etc/rc.d/sshd status
to see if ssh is running. If it is, then try:
# /etc/rc.d/sshd stop
to start the service. Now type:
# /etc/rc.d/sshd start
to restart the service. Note the startup script option "reload" - This would let you make changes to the ssh configuration file(s) and then reload the service without actually stopping it so that it reads the new configuration. Note that already connected clients would not see this new configuration change until the logoff and log back in again.

Finally, and this is not obvious, if a startup script in /etc/rc.d has not been enabled in /etc/defaults/rc.conf or /etc/rc.conf, then even if you manually invoke the script it will not run. You will not get any indication of this other than the service not starting (i.e. use "ps auxw| grep servicename" and you won't see it started).

At this point take a closer look at /etc/rc.d/

# ls /etc/rc.d
and use "man" to read about some of the services. If you want to try and start and stop some of these services feel free to do so now, but remember you'll need to add 'servicename_enable="YES"' in /etc/rc.conf for the service to start.

 

8.) Disk partitions: how to view your disk [Top]

First, make sure you are logged in as your user and not as root.

Now in a terminal lets look at the partitions. Type:

$ df
$ df -h
What difference did you see between "df" and "df -h". How can you see what your swap contains (note it was not listed using "df")? Use this:
$ swapinfo

If you want to see more detailed information about your disk slices you can use the "fdisk" command. As a general user you are not allowed to run this program, so you must use sudo. Try this by typing:

$ sudo fdisk
Be careful with fdisk as you can remove slices, partitions, etc.

If you are interested in how much space files are taking up in a directory or a group of directories you can use the "du" command. Try it out by typing:

$ du

$ du -h

As usual you can get more information by typing "man du".

Now that you've seen these methods for viewing disk information, you should be able to understand the output of the disklabel command a little better. The disklabel command is really the proper way to view the status of partitions in your FreeBSD slice at it will show you all your FreeBSD slice information no matter if a partition is mounted or not. In some cases this is critical if you are trying to troubleshoot problems and not all partitions have mounted. So, if FreeBSD resides on the slice /dev/ad0s1 on your disk, then to see disk information you can type (as a normal user): $ sudo disklabel /dev/ad0s1 This shows you output along these lines (will be different for this workshop):

# /dev/ad0s2:
8 partitions:
#        size   offset    fstype   [fsize bsize bps/cpg]
  a:   409600        0    4.2BSD     2048 16384 25608
  b:  1433600   409600      swap
  c:  8385930        0    unused        0     0         # "raw" part, don't edit

  d:  1843200  1843200    4.2BSD     2048 16384 28552
  e:  3072000  3686400    4.2BSD     2048 16384 28552
  f:  1627530  6758400    4.2BSD     2048 16384 28552
As you can see it includes the "c" partition and "b" or the "swap" partition as well as filetypes.

 

9.) Getting help using manpages, docs, and the FreeBSD Handbook [Top]

Now that you have FreeBSD up and running you probably want to have a way to figure out how to use it when there are no instructors around, or other FreeBSD-knowledgeable people. First and foremost, make it a habit to read the man pages (MANual pages) for the commands that you use. You might be surprised at some of the things these commands can do! In any case, as you have seen, when in doubt about what a command does, or how it works simply type:

$ man command
Optionally, you might find some additional information for some commands typing:
$ info command
And, to get information about both these commands type:
$ man man

$ info info

After this there is a large amount of documenation available to you in serveral ways. For instance, if you look in:

/usr/share/doc

you will find multiple FreeBSD articles in various languages available to you. In addition, the FreeBSD Handbook is available here under /usr/share/doc/handblook. If you wanted to start reading the FreeBSD Handbook from your local har drive you could either point a web browser to the file /usr/share/doc/handbook/index.html, or you could type the command:

$ lynx /usr/share/doc/handbook/index.html
Go ahead and type this command now to get a feel for what information is available to you in the FreeBSD Handbook. Now let's look at the FreeBSD FAQ by typing:
$ lynx /usr/share/doc/faq/index.html
After this, have a look at some of the available articles by doing:
$ cd /usr/share/doc/en/articles

$ ls

Finally, there are several papers available as well. Try:
$ ls /usr/share/doc/papers
If you have a network connection, then you can go to http://www.freebsd.org/docs.html for even more information. Become accustomed to the idea of using man to get specific information about commands, and then using these additional resources to get an overview of entire sub-systems of the FreeBSD operating system. If you want to read the FreeBSD Handbook online it is available here http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/index.html. If you want to understand FreeBSD concepts in more depth, then the FreeBSD Handbook is really where you should begin.

 

10.) Shutdown and reboot your system [Top]

For this exercise you need to be root. It is better to close open files and programs (for example Firefox, vi, etc.), but it is not necessary. Before continuing read the man pages for shutdown, init, halt, and reboot (you'll see they are all connected):

# man shutdown
# man init
# man reboot
# man halt
Now, in a terminal do the following (save data, etc. as this will immediately reboot your machine!):
# shutdown -r now
Now your machine is rebooting. The "-r" stand for "reboot" and the "now" meant to take this action "now". This takes a moment. To stop your machine entirely you can use the command:
# halt
Or, you can also change your run level to run level 0, which is the same as "halt". So, you would write:
# init 0
And, to reboot this is the same as init 6, or:
# init 6
If you are running something like gdm for a graphical login prompt on your machine you can usually use provided menu choices to reboot or shutdown. The thinking is that once you have this level of access, then you can simply turn off the machine's power if you wish. At the very least it is much more friendly to use a software interface to shutdown or reboot than pulling the power as processes have a chance to clean up, save data, etc.

Note, sometimes it is useful to bring your machine down to runlevel 1, or "single user mode". For instance, if you are running X Windows and want to shut it down quickly (you'd really only do this on a desktop machine, by the way!), then you can open a terminal window as root (or use "su"), and then type"

# init 1
This will shut down X Windows, networking, and quite a bit more. Now you are in "single user mode". To get back to "multi-user mode" you simply type:
# exit
This exits your single-user modem shell and tells the system to go back to multi-user mode. Notice that the "runlevel" concept under FreeBSD is different than under Linux. The major difference are:
  • Linux uses runlevels 1, 3, and 5 (single user, network with no GUI, network with GUI [X]).
  • FreeBSD uses runlevel 1, single user mode. To get back to network mode with or without GUI you exit runlevel 1 (or you can reboot).
  • You can use init c if you with to block further logins under FreeBSD.
  • Both FreeBSD and Linux use runlevels 0 and 6 in the same manner (halt and reboot).

 

11.) Initial login, virtual terminals, command line manipulation [Top]

The first time you login on your system after installation you will be presented with a prompt that looks something like this:

FreeBSD/i386 (name.domain) (ttyv0)

login:
At this point you can enter in "root" and, when prompted, the password we gave you in class for the root account. Once you are logged in you can work with an additional 7 virtual terminals if you wish. Actually, you can login from any virtual terminal you want at any time. To do this simply press:

ALT-FN

With "FN" being anything from the F1 to the F8 key. By default you are in ttyv0 which corresponds to the ALT-F1 keyboard sequence. Go ahead and login and then press:

ALT-F2

and login again. Feel free to do this on F3, F4, F8, etc. as you wish. You can cycle through each terminal session easily. This is an extremely useful technique when you wish to do more than one thing at the same time, but you are not using a graphical interface. Since we are loading the mouse daemon (mouse support) you can, also, copy and paste text between your virtual terminals. To do this go back to your initial login terminal by pressing:

ALT-F1

Try typing in the command:

$ clear
and pressing ENTER. Note that your screen clears and goes to the top. Now, you can easily recover your last command by pressing the UP-ARROW key on your keyboard once. Get used to doing this as it can be very useful if you have entered in a long command and made a mistake. You can press UP-ARROW to get the command back, then you can use the LEFT-ARROW to move your cursor to where the mistake is and correct it, then simply press ENTER to reissue the command. Note, you do not need to go back to the end of the command line before pressing ENTER.

In any case, you've pressed UP-ARROW once and should have the command "clear" visible. Now take your mouse and highlight just the command using the left mouse button. Without doing anything else with your mouse now press:

ALT-F2

to get to one of your other terminal sessions. Now just press the middle mouse button once. What happened? The text "clear" should have pasted on to your command line. Now you can press ENTER to execute the command. You can use this same trick to copy and paste in to editor windows, long and complex commands, between applications in a graphical environment, etc.

One final useful tip when working in your terminal sessions. As you type each command it is being saved in to a file called your "history file". This has a very useful purpose. Go back to your original login terminal pressing:

ALT-F1

and type the command:

$ history
You should see a list of commands you have entered in earlier. This list is probably short and it will even include incorrect commands you may have typed in. To quickly and immediately recover and execute a prior command make note of the number in the left-hand column next to the command and then just type:
$ !N
Where N is the number. So, if "clear" had been the second command, and you typed in:
$ !2
Then clear would appear on the command line very quickly and immediately execute. During the week you are going to be typing in some long and complex commands. The use of history can save you considerable time. If you press the UP-ARROW key repeatedly you can scroll through the previous commands you have entered beginning with the last command. Give it a try.

One very useful trick when using XWindows. If you need to escape your graphical environment and go to a console for some reason you can use the same virtual terminals, except that you press the keyboard combination:

ALT-CTRL-F1 through F8

At this point you will exit your graphical environemnt (KDE, Gnome, etc.) and be presented with a text console login prompt. Your graphical environment is still running as you left it. To get back to your graphical environment press:

ALT-CTRL-F9

Why might you need to do this? Here's one scenario:

You've just installed your favorite MTA (email server/Mail Transport Agent) and you typed something like (don't do this now):

pw usermod username -G mail
to place your user in the "mail" group. What just happened if your user was also a member of the "wheel" group and this is how you are using su and sudo? You can no longer become root in your session. To fix this you could go to a virtual console window, log in as root, and reissue the command above, but this time correctly:
pw usermod username -G wheel,mail
To fix this problem.

[Return to Top]

Hervey Allen


Last modified: Thu Sep 8 19:26:43 ART 2005