FreeBSD for Linux Users
by Dru Lavigne, author of BSD Hacks11/11/2004
Over the past year, I've had the opportunity to teach introductory Linux and BSD classes. Since BSD users primarily attended the Linux classes and the Linux users primarily attended the BSD classes, both groups had an interest in finding out more about their open source counterparts.
Students expected to find differences, but they often found the particulars surprising. Some of the commands they customarily used had different switches or were missing entirely, and certain features had totally different implementations.
In today's article, I'll cover some of the big-picture differences from the perspective of a Linux user being introduced to FreeBSD. In Part 2, I'll discuss command equivalents between Linux and FreeBSD.
SysV vs. BSD: Runlevels
Most introductory Unix courses start with the differences between SysV and BSD. Students, unimpressed by this fascinating bit of theoretical trivia, tend to jot down a few notes dutifully, and then wait patiently for the hands-on portion of the class. Within the hour, though, someone will make a panicked discovery and shout out, "Where are my runlevels?" There's an inevitable and incredulous follow-up of "What do you mean there aren't any runlevels?" and "Where'd all my startup scripts go?"
Herein lies one of the tangible design differences between a SysV system such as Linux and a BSD system. Both systems manage to start and run just fine--they just do it differently. It's equally difficult convincing a Linux user that a Unix administrator can achieve all of the functionality of runlevels without using runlevels as it is to convince a BSD user that it takes an entire subdirectory structure of symlinks to manage services.
|
Related Reading
BSD Hacks |
While there are some variations in number, most Linux distros will provide
runlevels representing shutdown, reboot, single user, multiuser with command
line, and multiuser with GUI modes. The /etc/inittab describes these
runlevels, and the telinit command allows administrators to tell
the init process to change its current runlevel.
Editor's note: The commands described in the next paragraph work on every Linux system I can remember using.
A BSD system is also capable of each of these init states, though it does so
without using the inittab file or the telinit command. To
reboot, use reboot or shutdown -r. To halt
the system, use halt or shutdown -h. To enter
single-user mode on a running system, type shutdown now and press
Enter when prompted to do so. To return to multiuser mode, type
exit.
Whereas /etc/inittab sets the default runlevel on a Linux system, a BSD
system uses /etc/ttys to determine whether the system will boot into
multiuser command line or multiuser GUI. (Use the boot menu to select
single-user mode at boot-up.) Like /etc/inittab, this file configures
how many virtual terminals--those that accept keyboard input--to
make available. The default configuration allows nine virtual terminals with the
GUI residing on ttyv8 (accessible with Alt-F8). By default, the system boots
into command-line mode and the user must type startx to start the
GUI. However, if you miss having the system boot directly into a GUI login,
edit /etc/ttys as the superuser and change the word off
to on in the ttyv8 line.
Startup Scripts
On a Linux system, each runlevel has an associated subdirectory:
rc0.d for runlevel 0, rc1.d for runlevel 1, and so on.
Depending on the distribution, these subdirectories fall under either
/etc or /etc/rc.d. Each subdirectory contains symlinks to
startup scripts residing in /etc/init.d. The symlink names begin with
either S (for start) or K (for kill) and tell
init to act accordingly whenever the system enters that runlevel.
After the letter comes a number that represents the order in which to run the
scripts.
You won't find init.d or any of the runlevel subdirectories
on a BSD system. Instead, the system startup scripts live in /etc/rc.d,
and the startup scripts for third-party applications stay in
/usr/local/etc/rc.d. Instead of using symbolic links beginning with S or K, a handful of scripts in /etc whose
names start with rc control which scripts run at startup and
shutdown. man rc gives the names of these scripts and describes
their operation. As an admin, you'll leave most of those rc
scripts as is. To configure which services start at boot-up, instead edit the
one file /etc/rc.conf.
Most of the scripts found in Linux's /etc/init.d and BSD's /etc/rc.d share similar behavior. If you type only the script name, you'll receive a syntax message indicating which parameters you can send to that service. Here's an example from a FreeBSD 5.x system:
# /etc/rc.d/named
Usage: /etc/rc.d/named [fast|force] (start|stop|restart|rcvar|reload|status|poll)
You're probably unfamiliar with the rcvar parameter. It helps
to determine the current /etc/rc.conf parameters of the service.
The Kernel
Instead of describing the design differences between a Linux and a FreeBSD kernel, I'll concentrate on the differences you'll encounter when recompiling a kernel.
The first thing you'll notice is the different method of numbering stable and unstable releases. Linux kernels use three numbers wherein:
- The first number (usually 2) represents the major version number.
- If the second number is even, the kernel is stable; if it is odd, it is still in development. Most recent distros use a second number of 4 or 6.
- The higher the third number, the more patched the kernel.
To see which Linux kernel came with your distro, type uname
-r.
In FreeBSD, the first number also refers to the major version number. As I write this, version 4 is the stable production release and version 5 is the new technology release. Both versions provide a development kernel known as CURRENT and various stable releases indicated by the second number. FreeBSD Release Engineering describes the release process in more detail.
The steps required to recompile a kernel also differ. Some Linux distros
provide a mechanism to download Linux kernel
source, or you can download it directly. After uncompressing the source,
cd into your system's src directory and choose from one
of three front ends available for modifying the kernel configuration file:
make configis a text-based series of many, many questions.make menuconfigprovides anncursesmenu from the command line.make xconfigprovides a menu from an X session.
Each front end provides an explanation for each kernel configurable and allows you either to compile in that option statically or build it as a loadable module. Once you've saved your changes, use these commands to check for dependencies and to compile the kernel:
Editor's note: this is the process for a 2.4 kernel; the 2.6 kernel is simpler.
# make dep
# make clean
# make bzImage
If you've chosen to create modules, do these two commands next:
# make modules
# make modules_install
Finally, install the kernel and update your boot loader:
# make install
Always double-check the changes to your boot loader configuration file; I've
found that make install doesn't always make the
modifications required to boot successfully into the new kernel.
On a FreeBSD system, use /stand/sysinstall to download the
kernel sources. Better yet,
use cvsup to keep your kernel sources up to date.
Once you have the sources, make a copy of
/usr/src/sys/i386/conf/GENERIC and use your favorite editor to
prepend # (the comment character) to the options you don't want to
configure into your kernel. Refer to a file called LINT or
NOTES in that same directory to see what each option means and to
research other options you may wish to add. Once you've saved your changes,
compile and install the new kernel. In this example I've saved the file as
NEWFILE. The commands are:
# cd /usr/src
# make buildkernel KERNCONF=NEWFILE
# make installkernel KERNCONF=NEWFILE
By default, this compiles all kernel options as modules. If you prefer to compile everything statically, include this line in your kernel configuration file:
makeoptions MODULES_OVERRIDE=""
Installing Software
When it comes to installing software on an open source operating system, you usually have three choices available. The first is to install a precompiled binary. The advantage to this method is that it is very quick and usually painless, with the program and its dependencies recorded into a package management system. The disadvantage is that a precompiled binary may not be available for your particular operating system and architecture. If one is, keep in mind that it probably won't take advantage of your particular CPU's features and you will have no control over which features the distributor compiled into the binary. This usually isn't a big deal with desktop applications, but it can be for server applications.
Installing a precompiled binary in Linux depends upon which package
management system came with your distro. Examples of popular package management
system utilities are Red Hat's rpm, Debian's apt-get,
and Gentoo's emerge. Some package management systems require you
to find and download the binary and resolve dependency issues, while others fetch the binary and its dependencies for you.
Ease of use and syntax issues aside, having a package management system is always a good thing. It will maintain databases to keep track of which programs you have installed and which programs depend on which others. In theory, this should make it much easier to properly upgrade software without breaking dependencies and to monitor software for outstanding security patches. In reality, your mileage will vary with the package management system used, but it will still be much better than trying to remember what you installed and when.
FreeBSD provides a robust package management system. To install a
precompiled binary in FreeBSD, use the pkg_add command with the
remote fetch switch. For example, to install curl, type:
# pkg_add -r curl
If there are any missing dependencies available as a precompiled binary, the command will also download and install them for you.
If you prefer to select packages from an ncurses menu, use
/stand/sysinstall and choose Configure, then Packages.
The second method for installing software is to compile the binary yourself
using your system's package management system. This will track the program
itself and all of its dependencies; you also have a pretty good guarantee that
the compile should succeed for your CPU and operating system type. Compiling
your own binary allows you to take advantage of the program's make
options. The assumption is that you've taken the time to research the
available options for the particular application you wish to compile. The
disadvantage is that it takes time to compile a binary, depending on the size
of the binary and how much CPU and RAM is on the compiling system.
As an example, if your distro supports RPMs, you can download and compile a source RPM. These end in src.rpm as opposed to something like i386.rpm. In FreeBSD, you instead use the ports collection. For example, to install Apache:
# cd /usr/ports/www/apache13
# make install clean
Of course, before issuing the make command, experienced admins
read the Makefile in that directory to see which options to use for
that compile.
The third method is to download and extract a source tarball. This method works on any Unix system but comes with a big disadvantage: the package management system in place usually cannot track the installed files. This means you have to remember what you installed, when you installed it, and what dependencies come with or rely on that program. It will also be very difficult to keep those programs up to date and to remember to check for security fixes on each program.
Sometimes this third method is a necessary evil. Perhaps you need to take advantage of a feature or security fix now and there currently isn't a precompiled binary or source RPM/port for that application for your operating system. Unless you really can't wait, however, you're better off waiting.
Documentation
One of the biggest improvements to open source operating systems over the past few years has been the proliferation of quality online documentation. Linux has The Linux Documentation Project. While everything here obviously comes from the Linux perspective, many of the articles concern third-party shells or software that apply well to non-Linux systems.
FreeBSD has the FreeBSD
Handbook and FreeBSD
FAQ. These and other documentation resources also appear on FreeBSD systems
in /usr/share/doc. Use cvsup to update them. The
documentation describes pretty much anything you could ever want to do with a
FreeBSD system.
One of the more noticeable differences between Linux distros and BSD systems
is the quality of the man pages. An example that comes up in a Linux+ class is
the man page for ls. For the exam, students need to know the
-F. Here's the explanation from man ls on a Linux
system:
-F, --classify
append indicator (one of */=@|) to entries
Here's the explanation from a BSD system:
-F Display a slash (`/') immediately after each pathname that is a
directory, an asterisk (`*') after each that is executable, an at
sign (`@') after each symbolic link, an equals sign (`=') after
each socket, a percent sign (`%') after each whiteout, and a ver-
tical bar (`|') after each that is a FIFO.
One of the lessons students learn is that if you don't find the information you want from a man page, see if there is a better man page! I've always had good luck with FreeBSD Hypertext Man Pages.
The other man page that students find helpful is man hier, as it
describes the file system hierarchy or directory structure layout. This is
always a good command to run whenever you find an unfamiliar Unix
operating system.
In the next article, I'll move on to particular commands that differ between Linux and FreeBSD.
Dru Lavigne is a network and systems administrator, IT instructor, author and international speaker. She has over a decade of experience administering and teaching Netware, Microsoft, Cisco, Checkpoint, SCO, Solaris, Linux, and BSD systems. A prolific author, she pens the popular FreeBSD Basics column for O'Reilly and is author of BSD Hacks and The Best of FreeBSD Basics.
Return to the BSD DevCenter.
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 16 of 16.
-
Using both.
2007-11-04 08:15:37 farofa [Reply | View]
I have 6.2 for x86 currently installed and have been using FreeBSD for about a year and a half. Linux for about two years. BSD has been easier for me to learn and use with fewer problems being encountered.
-
Hi.. Mrs. Dru
2006-01-07 13:01:21 fooues [Reply | View]
I got FreeBSD (6.0) this week and installed it on my laptop. I really enjoyed it and I liked the ports system ... but are all the *BSD systems like FreeBSD? I know that are NetBSD, OpenBSD, DesktopBSD and others distros. Have they the same bootsystem style and package managers and the same ports? 'cause I saw that you talked 'bout FreeBSD and thousands of Linux Distros and not FreBSD and a Linux(Slack or Debian or SUSE ...). If all *BSD are like each other (in the base) I agree with you but if not you can't compare a BSD-distro with 'n' Linux-distros!!!
fooues
X) Thankss -
Hi.. Mrs. Dru
2006-01-11 11:22:19 Dru Lavigne [Reply | View]
You'll find the BSDs to be quite similar and many features that are developed on one BSD make there way into the other BSDs.
For software, pkg_add is consistent across all of the BSDs and is the best way for new users to install software. All of the BSDs support pkgsrc and most of the BSDs support ports.
You might find this document (http://www.bsdcertification.org/downloads/20051027_BSDA_command_reference_en-en.pdf) handy as it shows the most common BSD commands and whether they come with the OS.
-
minor typo
2004-11-13 14:45:10 n4hhe [Reply | View]
# make installkernel KERNCONF-NEWFILE
should be:
# make installkernel KERNCONF=NEWFILE
(replace '-' with '=')
-
Small typo
2004-11-13 07:48:22 jehousley [Reply | View]
ttyv8, the ninth virtual terminal where the GUI is would be ALT-F9. Since the ALT-F1 is ttyv0.
Jim
-
A bit confusing
2004-11-13 04:22:27 LeonYendor [Reply | View]
Many references are made to BSD or BSDs when they may be inaccurate if BSDs means other than FreeBSD.
For example:
"You won't find init.d or any of the runlevel subdirectories on a BSD system. Instead, the system startup scripts live in /etc/rc.d, and the startup scripts for third-party applications stay in /usr/local/etc/rc.d." doesn't apply to openBSD.
My job calls for me to use several Linuxes (Linuces?) and several *BSDs so it didn't fool me.
Others may have a problem. Maybe substitute FreeBSD for all " BSD" references. Even then I'm not up on 5.? so that may be inaccurate.
-
FreeBSD 5-STABLE
2004-11-12 18:17:50 taosecurity [Reply | View]
Excellent article Dru. To update readers -- with last week's release of FreeBSD 5.3, the 4.x tree is now considered a "legacy" line. FreeBSD 5.3 now carries the STABLE tag and is recommended for general use. FreeBSD 6.0 is now CURRENT and used mainly by developers working on new features.
-
Documentation
2004-11-12 08:54:34 sukrutikves [Reply | View]
Linux utilities do not actively maintain man pages. They have their own "info" documents which contain much detailed and better organized information.
(For example while bash man page is over 4000 lines, bash info starts with a two page index).
And most of the distributions come with a nice utility called "pinfo" which will allow lynx like (nicer and easier) navigation of info pages.
Extract from ls man page:
The full documentation for ls is maintained as a Texinfo
manual. If the info and ls programs are properly installed
at your site, the command
info ls
should give you access to the complete manual.
Corrosponding info part:
`-F'
`--classify'
`--indicator-style=classify'
Append a character to each file name indicating the file type.
Also, for regular files that are executable, append `*'.
The file type indicators are `/' for directories, `@'
for symbolic links, `|' for FIFOs, `=' for sockets,
and nothing for regular files.
-
alternative man pages
2004-11-21 07:38:25 scotttsai [Reply | View]
Modern linux distros also ship the POSIX/SUS specifications as manpages.
ex: man 1p ls, excerpt
-F Do not follow symbolic links named as operands unless the -H or
-L options are specified. Write a slash ( / ) immediately
after each pathname that is a directory, an asterisk ( * )
after each that is executable, a vertical bar ( | ) after each
that is a FIFO, and an at sign ( @ ) after each that is a sym-
bolic link. For other file types, other symbols may be written.
-
Documentation
2004-11-15 19:01:52 pappires [Reply | View]
By "Linux utilities" you mean GNU utilities, right?
I don't know why GNU sabotages manpages. While I understand that interactive documents may be useful for seeking specific information in several thousand lines of documentation, simply replacing manpages with .info files has clear disadvantages.
First of all, info(1) is not available everywhere. While this is especially true for commercial unices, it may well apply to many open source systems, even in the Linux camp. Also, not every application in a generic unix box is a GNU application, and its documentation may not be in GNU's texinfo format. BSDs generally include info(1) and .info files for the GNU utilities they use, but programs like ls(1), awk(1) or make(1) are not GNU applications in BSD systems -- actually, GNU didn't even exist when they and their manual entries were written. Although, by definition, "GNU's not Unix", if it is Unix-like and, most especially, if it want its users to use it as they would use any other Unix system, it should allow its users to retrieve relevant information with manpages.
While there is still a handful of other serious problems with texinfo, when intended to replace manpages, I will go back to one of your first statements, and say that I disagree that .info documents provide for more well organized information. Being "navigable" doesn't at all mean that a document is well organized, and much less does it mean that it is well written and can be easily read. Even the most powerful tool can become useless or wasteful in the hands of an inept writer, and I am pretty sure that I am not the only one that knows lots of plain text documents that beat many full-featured hypertext documents regarding the same information, not only in clearness, cleverness and accuracy, but even in visual cleanness.
Best regards.
Paulo
-
Crux Linux
2004-11-12 08:00:35 houp [Reply | View]
Hi,
The Crux Linux distrubution (www.crux.nu) also use BSD styled init scripts ans has it's own ports system with commends like pkgadd/pkgrm similar to BSD ones.
-
Slackware Linux has BSD boot scripts
2004-11-12 07:25:54 tshubitz [Reply | View]
Folks,
Slackware Linux is not like other Linux distributions that separate the startup scripts across individual directories. It instead follows a more BSD-like startup method. See http://www.slackware.org/config/init.php for more info. First line of this page reads "Slackware Linux uses the BSD-style file layout for its system initialization files."
- tim






http://en.wikipedia.org/wiki/Pkgsrc
So you don't need to learn new syntax or wait for PS3 support (which linux has had for a year now), but you can have an excellent multi-distribution portage system. No more learning brand new linux-distro-specific port tools.
I don't understand why there are so many distributions trying to re-implement the same wheel (with apt, rpm, {gentoo ports, crux ports, arch ports}, etc.) when they should all be working towards two single well maintaned trees (precompiled packages (like .deb), or source ports(like pkgsrc, which isn't just for BSD anymore)).
I DO understand why different distributions exist (newbies who need ease and multimedia (ubuntu/mandrake) vs. geeks who need the latest hardware support (linux w/ src compilation & loadable kernel drivers) vs. server admins who need a stable all in one distro with a reputation and easy uprading (BSD)).