AnneliseAnderson
August 15, 1997
Congratulations on installing FreeBSD! Thisintroduction is for people new to both FreeBSDand Un*x--so it starts with basics. Itassumes you‘re using version 2.0.5 or later of FreeBSD as distributedby Walnut Creek or FreeBSD.ORG, your system (for now) has a singleuser (you)--and you‘re probably pretty good with DOS/Windows orOS/2.
Log in (when you see login:) as a user you created duringinstallation or as root. (Your FreeBSDinstallation will already have an account for root; root can goanywhere and do anything, including deleting essential files, so becareful!) The symbols % and # in the following stand for the prompt(yours may be different), with % indicating an ordinary user and# indicating root.
To log out (and get a new login: prompt) type
#exit
as often as necessary. Yes, press enter aftercommands, and remember that Unix iscase-sensitive--exit, notEXIT.
To shut down the machine type:
#/sbin/shutdown -h now
Or to reboot type
#/sbin/shutdown -r now
or
#/sbin/reboot
You can also reboot withCtrl-Alt-Delete.Give it a little time to do its work. This is equivalent to/sbin/reboot in recent releases of FreeBSD, and ismuch, much better than hitting the reset button. You don‘t want tohave to reinstall this thing, do you?
If you didn‘t create any users when you installed the system andare thus logged in as root, you should probably create a user now with
#adduser
The first time you use adduser, it might ask for some defaults to save. Youmight want to make the default shell csh instead of sh, if it suggestssh as the default. Otherwise just press enter to accept each default.These defaults are saved in /etc/adduser.conf,an editable file.
Suppose you create a user jack withfull name Jack Benimble. Give jack a passwordif security (even kids around who might pound on the keyboard) is anissue. When it asks you if you want to invite jack into othergroups, type wheel
Login group is ``jack‘‘. Invite jack into other groups:wheel
This will make it possible to log in as jack anduse the su command to become root. Then you won‘tget scolded any more for logging in as root.
You can quit adduser any time by typingCtrl-C, and atthe end you‘ll have a chance to approve your new user or simply typen for no. You might want to create asecond new user (jill?) so that when you edit jack‘s login files,you‘ll have a hot spare in case something goes wrong.
Once you‘ve done this, use exitto get back to a login prompt and log in asjack. In general, it‘s a good idea to do asmuch work as possible as an ordinary user who doesn‘t have thepower--and risk--of root.
If you already created a user and you want the user to be ableto su to root, you can log in as rootand edit the file /etc/group, adding jack to thefirst line (the group wheel). But first you need to practicevi, the text editor--or use the simpler texteditor, ee, installed on recent version ofFreeBSD.
To delete a user, use the rmuser command.
Logged in as an ordinary user, look around and try out somecommands that will access the sources of help and information withinFreeBSD.
Here are some commands and what they do:
Tells you who you are!
Shows you where you are--the currentworking directory.
Lists the files in the current directory.
Lists the files in the current directory with a* after executables, a / afterdirectories, and an @ after symbolic links.
Lists the files in long format--size,date, permissions.
Lists hidden ``dot‘‘files with the others. If you‘re root, the``dot‘‘ filesshow up without the -a switch.
Changes directories. cd.. backs up one level; note thespace after cd. cd/usr/local goes there. cd~ goes to the home directory of theperson logged in--e.g., /usr/home/jack.Try cd /cdrom, and thenls, to find out if your CDROM is mounted andworking.
Lets you look at a file (namedfilename without changing it. Tryview /etc/fstab.:q to quit.
Displays filename on screen. Ifit‘s too long and you can see only the end of it, pressScrollLock and use the up-arrow tomove backward; you can use ScrollLock with man pagestoo. Press ScrollLock again to quit scrolling. Youmight want to try cat on some of the dot files inyour home directory--cat.cshrc, cat.login, cat.profile.
You‘ll notice aliases in .cshrc for some of thels commands (they‘re very convenient).You can create other aliases by editing .cshrc.You can make these aliases available to all users on the system byputting them in the system-wide csh configuration file,/etc/csh.cshrc.
Here are some useful sources of help.Text stands for something of your choicethat you type in--usually a command or filename.
Everything containing string textin the whatis database.
The man page for text. The majorsource of documentation for Un*x systems. manls will tell you all the ways to usethe ls command. Press Enter tomove through text,Ctrl-b to goback a page, Ctrl-f togo forward, q orCtrl-c toquit.
Tells you where in the user‘s path the commandtext is found.
All the paths where the string textis found.
Tells you what the command textdoes and its man page. Typing whatis * will tellyou about all the binaries in the current directory.
Finds the file text, giving its fullpath.
You might want to try using whatis on somecommon useful commands like cat,more, grep,mv, find,tar, chmod,chown, date, andscript. more lets you read apage at a time as it does in DOS, e.g., ls -l |more or morefilename. The* works as a wildcard--e.g., lsw* will show you files beginning withw.
Are some of these not working very well? Bothlocate and whatisdepend on a database that‘s rebuilt weekly. If your machine isn‘tgoing to be left on over the weekend (and running FreeBSD), you mightwant to run the commands for daily, weekly, and monthly maintenancenow and then. Run them as root and give each one time to finishbefore you start the next one, for now.
#/etc/periodic daily
output omitted#/etc/periodic weekly
output omitted#/etc/periodic monthly
output omitted
If you get tired waiting, pressAlt-F2 to getanother virtual console, and log in again.After all, it‘s a multi-user, multi-tasking system. Neverthelessthese commands will probably flash messages on your screen whilethey‘re running; you can type clear at the promptto clear the screen. Once they‘ve run, you might want to look at/var/mail/root and/var/log/messages.
Basically running such commands is part of systemadministration--and as a single user of a Unix system, you‘reyour own system administrator. Virtually everything you need to beroot to do is system administration. Such responsibilities aren‘tcovered very well even in those big fat books on Unix, which seem todevote a lot of space to pulling down menus in windows managers. Youmight want to get one of the two leading books on systemsadministration, either Evi Nemeth et.al.‘s UNIX SystemAdministration Handbook (Prentice-Hall, 1995, ISBN0-13-15051-7)--the second edition with the red cover; orÆleen Frisch‘s Essential SystemAdministration (O‘Reilly & Associates, 1993, ISBN0-937175-80-3). I used Nemeth.
To configure your system, you need to edit text files. Most ofthem will be in the /etc directory; and you‘llneed to su to root to be able to change them. Youcan use the easy ee, but in the long run thetext editor vi is worth learning. There‘s anexcellent tutorial on vi in/usr/src/contrib/nvi/docs/tutorial if you havethat installed; otherwise you can get it by ftp toftp.cdrom.com in the directoryFreeBSD/FreeBSD-current/src/contrib/nvi/docs/tutorial.
Before you edit afile, you should probably back it up. Suppose you want to edit/etc/rc.conf. You could just use cd/etc to get to the /etc directory anddo:
#cp rc.conf rc.conf.orig
This would copy rc.conf torc.conf.orig, and you could later copyrc.conf.orig to rc.conf to recover the original. But evenbetter would be moving (renaming) and then copying back:
#mv rc.conf rc.conf.orig
#cp rc.conf.orig rc.conf
because the mv command preserves the original dateand owner of the file. You can now editrc.conf. If you want the original back, you‘dthen mv rc.conf rc.conf.myedit
(assuming you want to preserve your edited version) and then
#mv rc.conf.orig rc.conf
to put things back the way they were.
To edit a file, type
#vi filename
Move through the text with the arrow keys. Esc (theescape key) puts vi in command mode. Here are somecommands:
delete letter the cursor is on
delete the entire line (even if it wraps on the screen)
insert text at the cursor
insert text after the cursor
Once you type i or a, you can enter text.Esc puts you back in command mode where you can type
to write your changes to disk and continue editing
to write and quit
to quit without saving changes
to move the cursor to text;/Enter (the enter key) to findthe next instance of text.
to go to the end of the file
to go to line n inthe file, where n is a number
to redraw the screen
go backand forward a screen, as theydo with more and view.
Practice with vi in your home directory by creatinga new file with vi filename and addingand deleting text, saving the file, and calling it up again.vi delivers some surprises because it‘s really quitecomplex, and sometimes you‘ll inadvertently issue a command that willdo something you don‘t expect. (Some people actually likevi--it‘s more powerful than DOS EDIT--find outabout the :r command.) Use Esc one ormore times to be sure you‘re in command mode and proceed from therewhen it gives you trouble, save often with :w, anduse :q! to get out and start over (fromyour last :w) when you need to.
Now you can cd to /etc,su to root, use vi to edit the file/etc/group, and add a user to wheel so the userhas root privileges. Just add a comma and the user‘s login name tothe end of the first line in the file, press Esc, and use:wq to write the file to disk and quit. Instantlyeffective. (You didn‘t put a space after the comma, did you?)
At this point you probably don‘t have the printer working, so here‘s away to create a file from a man page, move it to a floppy, and thenprint it from DOS. Suppose you want to read carefully about changingpermissions on files (pretty important). You can use the commandman chmod to read about it. The command
%man chmod | col -b > chmod.txt
will remove formatting codes and send the man page tothe chmod.txt fileinstead of showing it on your screen. Now put a dos-formatteddiskette in your floppy drive a, su toroot, and type
#/sbin/mount -t msdos /dev/fd0 /mnt
to mount the floppy drive on /mnt.
Now (you no longer need to be root, and you can typeexit to get back to being user jack) you can go to thedirectory where you created chmod.txt and copy the file to the floppywith:
%cp chmod.txt /mnt
and use ls /mnt to get a directory listing of/mnt, which should show the filechmod.txt.
You might especially want to make a file from/sbin/dmesg by typing
%/sbin/dmesg > dmesg.txt
and copying dmesg.txt to the floppy./sbin/dmesg is the boot log record, and it‘suseful to understand it because it shows what FreeBSD found when itbooted up. If you ask questions onfreebsd-questions@FreeBSD.ORG or on a USENETgroup--like ``FreeBSD isn‘t finding my tape drive, what doI do?‘‘--people will want to know what dmesghas to say.
You can now dismount the floppy drive (as root) to get the diskout with
#/sbin/umount /mnt
and reboot to go to DOS. Copy these files to a DOS directory, callthem up with DOS EDIT, Windows Notepad or Wordpad, or a word processor, make aminor change so the file has to be saved, and print as you normallywould from DOS or Windows. Hope it works! Manual pages come out best ifprinted with the dos print command. (Copying files fromFreeBSD to a mounted dos partition is in some cases still a littlerisky.)
Getting the printer printing from FreeBSD involves creating anappropriate entry in /etc/printcap and creatinga matching spool directory in/var/spool/output. If your printer is onlpt0 (what dos calls LPT1), you may onlyneed to go to /var/spool/output and (as root)create the directory lpd by typing:mkdir lpd, if it doesn‘t alreadyexist.Then the printer should respond if it‘s turned on when the system isbooted, and lp or lpr should send a file to the printer. Whether ornot the file actually prints depends on configuring it, which iscovered in the FreeBSDhandbook.
shows file space and mounted systems.
shows processes running. ps ax is a narrower form.
remove filename.
removes a directory dir and allsubdirectories--careful!
lists files in the currentdirectory and all subdirectories;I used a variant, ls -AFR > where.txt,to get a list of allthe files in / and (separately)/usr before I found betterways to find files.
to change user‘s password (or root‘s password)
man page on the Unix file system
Use find to locate filename in /usror any of its subdirectories with
%find /usr -name "filename"
You can use * as a wildcard in"filename" (which should be inquotes). If you tell find to search in /instead of /usr it will look for the file(s) onall mounted file systems, including the CDROM and the dospartition.
An excellent book that explains Unix commands and utilities isAbrahams & Larson, Unix for the Impatient(2nd ed., Addison-Wesley, 1996). There‘s also a lot of Unixinformation on the Internet. Try 8. Next Steps
You should now have the tools you need to get around and editfiles, so you can get everything up and running. There is a greatdeal of information in the FreeBSD handbook (which is probably onyour hard drive) and FreeBSD‘sweb site. A wide variety of packages and ports are on theWalnut Creek CDROM as wellas the web site. The handbook tells you more about how to use them(get the package if it exists, with pkg_add/cdrom/packages/All/packagename,where packagename is the filename of thepackage). The cdrom has lists of the packages and ports with briefdescriptions in cdrom/packages/index,cdrom/packages/index.txt, andcdrom/ports/index, with fuller descriptions in/cdrom/ports/*/*/pkg/DESCR, where the*s represent subdirectories of kinds of programsand program names respectively.
If you find the handbook too sophisticated (what withlndir and all) on installing ports from the cdrom,here‘s what usually works:
Find the port you want, say kermit. There will bea directory for it on the cdrom. Copy the subdirectory to/usr/local (a good place for software you addthat should be available to all users) with:
#cp -R /cdrom/ports/comm/kermit /usr/local
This should result in a /usr/local/kermitsubdirectory that has all the files that thekermit subdirectory on the CDROM has.
Next, create the directory /usr/ports/distfilesif it doesn‘t already exist using mkdir. Now checkcheck /cdrom/ports/distfiles for afile with a name that indicates it‘s the port you want. Copy thatfile to /usr/ports/distfiles; in recent versionsyou can skip this step, as FreeBSD will do it for you.In the case of kermit, there is nodistfile.
Then cd to the subdirectory of/usr/local/kermit that has the fileMakefile. Type
#make all install
During this process the port will ftp to get any compressedfiles it needs that it didn‘t find on the cdrom or in/usr/ports/distfiles. If you don‘t have yournetwork running yet and there was no file for the port in/cdrom/ports/distfiles, you will have to getthe distfile using another machine and copy it to/usr/ports/distfiles from a floppy or your dospartition. Read Makefile (with cat ormore or view) to find out where to go (themaster distribution site) to get the file and what its name is. Itsname will be truncated when downloaded to DOS, and after you get itinto /usr/ports/distfiles you‘ll have to renameit (with the mv command) to its original name so it canbe found. (Use binary file transfers!) Then go back to/usr/local/kermit, find the directory withMakefile, and type make all install.
The other thing that happens when installing ports or packagesis that some other program is needed. If the installation stops witha message can‘t find unzip or whatever, youmight need to install the package or port for unzip before youcontinue.
Once it‘s installed type rehash to make FreeBSDreread the files in the path so it knows what‘s there. (If you get alot of path not found messages when you usewhereis or which, you might want tomake additions to thelist of directories in the path statement in.cshrc in your home directory. The pathstatement in Unix does the same kind of work it does in DOS, exceptthe current directory is not (by default) in the path for securityreasons; if the command you want is in the directory you‘re in, youneed to type ./ before the command to make itwork; no space after the slash.)
You might want to get the most recent version of Netscape fromtheir ftp site. (Netscaperequires the X Window System.) There‘s now a FreeBSD version, so lookaround carefully. Just use gunzipfilename and tar xvffilename on it, move the binary to/usr/local/bin or some other place binaries arekept, rehash, and then put the following lines in.cshrc in each user‘s home directory or (easier)in /etc/csh.cshrc, the system-wide csh start-upfile:
setenv XKEYSYMDB /usr/X11R6/lib/X11/XKeysymDBsetenv XNLSPATH /usr/X11R6/lib/X11/nls
This assumes that the file XKeysymDB and the directorynls are in /usr/X11R6/lib/X11; ifthey‘re not, find them and put them there.
If you originally got Netscape as a port using the CDROM (orftp), don‘t replace /usr/local/bin/netscape withthe new netscape binary; this is just a shell script that sets up theenvironmental variables for you. Instead rename the new binary tonetscape.bin and replace the old binary, whichis /usr/local/lib/netscape/netscape.bin.
Your shell is the most important part of your working environment.In DOS, the usual shell is command.com. The shell is what interpretsthe commands you type on the command line, and thus communicates withthe rest of the operating system. You can also write shellscripts, which are like DOS batch files: a series of commands to berun without your intervention.
Two shells come installed with FreeBSD: csh and sh. csh is good forcommand-line work, but scripts should be written with sh (or bash). You canfind out what shell you have by typing echo $SHELL.
The csh shell is okay, but tcsh does everything csh does and more. ItIt allows you to recall commands with the arrow keys and edit them.It has tab-key completionof filenames (csh uses the escape key), and it lets you switch to thedirectory you were last in with cd -. It‘s also mucheasier to alter your prompt with tcsh. It makes life a lot easier.
Here are the three steps for installing a new shell:
1. Install the shell as a port or a package, just as youwould any other port or package. Use rehash andwhich tcsh (assuming you‘re installing tcsh) tomake sure it got installed.
2. As root, edit /etc/shells, addinga line in the file for the new shell, in this case /usr/local/bin/tcsh,and save the file. (Some ports may do this for you.)
3. Use the chsh command to change your shell totcsh permanently, or type tcsh at the prompt tochange your shell without logging in again.
Note: It can be dangerous to change root‘s shellto something other than sh or cshon early versions of FreeBSD and manyother versions of Unix; you may not have a working shell when the systemputs you into single user mode. The solution is to use su -mto become root, which will give you the tcsh shell as root, because theshell is partof the environment. You can make this permanent by adding it to your.tcshrc file as an alias with
alias su su -m
When tcsh starts up, it will read the/etc/csh.cshrc and /etc/csh.loginfiles, as does csh. It will also read the.login file in your home directory and the.cshrcfile as well, unless you provide a .tcshrcfile. This you can do by simply copying .cshrcto .tcshrc.
Now that you‘ve installed tcsh, you can adjust your prompt. You canfind the details in the manual page for tcsh, but here is a line toput in your .tcshrc that will tell you how manycommands you have typed, what time it is, and what directory you are in.It also produces a > if you‘re an ordinary user anda # if you‘re root, but tsch will do that in anycase:
set prompt = "%h %t %~ %# "
This should go in the same place as the existing set prompt lineif there is one, or under
if($?prompt) then
if not.Comment out the old line; you can always switch back to it if you preferit. Don‘t forget the spaces and quotes. You can get the .tcshrc reread by typing source .tcshrc.
You can get a listing of other environmental variables thathave been set by typing env at the prompt. Theresult will show you your default editor, pager, and terminal type,among possibly many others. A useful command if you log in from aremote location and can‘t run a program because the terminal isn‘tcapable issetenv TERM vt100.
As root, you can dismount the CDROM with /sbin/umount/cdrom, take it out of the drive, insert another one, and mount itwith /sbin/mount_cd9660 /dev/cd0a /cdrom assumingcd0a is the device name for your CDROM drive. Themost recent versions of FreeBSD let you mount the cdrom with just/sbin/mount /cdrom.
Using the live file system--the second of FreeBSD‘s CDROMdisks--is useful if you‘ve got limited space. What is on thelive file system varies from release to release. You might tryplaying games from the cdrom. Thisinvolves using lndir, which gets installed with the XWindow System, to tell the program(s) where to find the necessaryfiles, because they‘re in the /cdrom file systeminstead of in /usr and its subdirectories, whichis where they‘re expected to be. Read man lndir.
If you use this guide I‘d be interested in knowing where it wasunclear and what was left out that you think should be included, andif it was helpful. My thanks to Eugene W. Stark, professor ofcomputer science at SUNY-Stony Brook, and John Fieber for helpfulcomments.
Annelise Anderson, andrsn@andrsn.stanford.edu