 2009/07/04
|
Last update 2009/05/04
 The Labs - Design & Functionality For The NetBSD based UNIX Implementation
- Introduction
- Installation with VMWare
- World & Kernel
- Ports & Packages
- Tuning
- Disk Tuning
- Virtual Domains
- Keeping FreeBSD Machines Up-To-Date
- FreeBSD Within FreeBSD (Virtualizing)
- Live-System Install
- More Resources
I started to use FreeBSD in summer 1998 as I ran Linux
first on my server but after switching to FreeBSD realized better performance,
system-resource accounting and integrity of the system. Even as workstation I use
FreeBSD now (May 2000) and Linux I use only when required (e.g. VMware, Win4Lin, and some
other 'linux-only' stuff).
I mostly appreciated the pgk_add command (and the /usr/ports),
it's powerful and RPM from RedHat doesn't look good in that light anymore.
I never trusted rpm-files as I got tired to error-messages of missing libs
etc. with pgk_add or making /usr/ports selection it does all
automatically, even remote download for you and you save a lot of
time installing (or removing) packages properly.
| FreeBSD2. Installation with VMWare
|
We use FreeBSD for our servers, and also on some small machines, as
well with VMWare which is very
handy:
- create new config with the Wizard, after the machine is configured and booted
you get into the install (e.g. FreeBSD-4.1-RELEASE CD): the installation is very user-friendly (among *BSD the best).
- "Express Installation" is quite handy, and indeed fast.
- disk-layout: FreeBSD lives within a partition (aka a slice in BSD terminology) defined with fdisk and within this
slice the BSD-partitions are allocated (using disklabel), for simplicity create two partitions:
- / (root partition)
- swap
VMWare booting FreeBSD-4.1 (K6-2/500 with 64MB)
Next steps:
- define in /etc/rc.conf your hostname and domain-name (e.g. local),
as well defaultrouter (e.g. 192.168.0.1)
- edit /etc/resolv.conf and add (assuming your dns runs at 192.168.0.1)
|
search local
|
|
nameserver 192.168.0.1
|
- create /etc/start_if.lnc0 with following line (having 192.168. network)
|
ifconfig lnc0 192.168.0.52 netmask 255.255.255.0 broadcast 192.168.0.255
|
Check the dmesg :-)
See also FreeBSD FAQ: Admin (e.g.
adding more pty's)
FreeBSD's clean UNIX setup can be overviewed like this:
- World: all system applications (ls, ps, gcc, perl and libs etc.), source under /usr/src/
- Kernel: the /kernel itself plus /modules/*, source under /usr/src/sys/
- Ports: the /usr/ports/ tree
World

| | Within /usr/share/examples/cvsup/ are example cvsup-files to use
to update the /usr/src/ source-tree. To make world:
|
% cd /usr/src/
|
|
% make buildworld
|
|
% make installworld
|
|
Kernel

| | The kernel source is part of /usr/src/, usually one does config a
dedicated kernel:
|
% cd /sys/i386/conf
|
|
% cp GENERIC MYKERNEL
|
then edit MYKERNEL, check LINT which provides an overview of all
switches and settings possible, then
|
% config MYKERNEL
|
|
% cd ../../compile/MYKERNEL
|
|
% make install
|
/sys/i386/conf/ is the same as /usr/src/sys/i386/conf/, another
way to do the kernel within /usr/src/
|
% cd /usr/src/
|
|
% make buildkernel KERNEL=MYKERNEL
|
|
% make installkernel KERNEL=MYKERNEL
|
Some tuning hints below.
|
| FreeBSD4. Ports & Packages
|
Ports are the jewel of the *BSD distributions, also FreeBSD in this
case.
and explore the ports there are available.
Installing apache + mod_perl (as root)
|
% cd /usr/ports/www/mod_perl
|
|
% make install
|
and it does all: fetching apache-source and all dependend packages and libs,
configuring them and compiling. If you want to just make it without
install, obmit 'install'. If you want to remove the port, just type make deinstall
and the install is undone.
Updating

| | Updating the ports is easy, check /usr/share/examples/cvsup/*
there are example files which also contain the HOW-TO. Once you
edited your ..-stable-cvsup file it is very easy to keep the
ports, but also system-sources (/usr/src) up-to-date.
cvsup is a pain to compile from the sources as it is
(odd enough) written in modula3, but luckely there is a port of
the cvsup-bin available: /usr/ports/net/cvsup-bin.
To keep your installed ports up-to-date and redo those which required (never version than installed),
an up-to-date /usr/ports tree (via cvsup) is required:
|
% pkg_version -c > update.sh
|
and then edit the update.sh, e.g. replace 'make install' with 'make reinstall' etc, and
remove the first few lines (since 4.3-RELEASE required). Then just run ./update.sh,
or alternatively use /usr/ports/sysutil/portupgrade.
|
Packages

| | The difference of Ports vs. Packages is that Packages are precompiled
where as Ports are source-based and you compile the source. Both
have advantages: Ports you can configure by hand if you need, and
also may integrate better into your setup. Packages you save time
and get things fast to work.
To install a package first check if there is a package available:
|
% grep mod_perl /usr/ports/INDEX
|
and once you know the exact name of the package then add it (e.g. mod_perl is simple):
Install /usr/ports/sysutils/pib/ for a X11-frontend for the port-collection.
To keep your installed packages up-to-date run pgk_update (available since 4.3-RELEASE),
or use /usr/ports/sysutil/portupgrade.
|
Kernel

| | Assuming you did your own kernel-config in
/sys/i386/conf/ like MYKERNEL, then adjust all settings you require with your favourite text-editor,
ie. busy web-server require a
lot of file-handles (open files), and cpu-resources if you run CGIs or database (MySQL or alike).
(see also /sys/i386/conf/LINT as reference)
|
maxusers 256
|
|
options NMBCLUSTERS=4096
|
Prior 4.0 following settings were possible:
|
options OPEN_MAX=1024 # Max open files per process
|
|
options CHILD_MAX=1024 # Max processes per user
|
Since 4.0 use sysctl or define it in /etc/sysctl.conf:
|
kern.maxfiles=2048
|
|
kern.maxfilesperproc=2048
|
See also man sysctl and man sysctl.conf.
Then call in /sys/i386/conf/
then
|
% cd ../../compile/MYKERNEL
|
|
% make
|
after the linking, you have a new kernel; now you must install it:
This will save the old kernel (/kernel) to /kernel.old
install the new kernel as /kernel
Then you have to reboot. More hints you find at The Effects of Tuning a FreeBSD Box for High Performance from
DaemonNews.
|
New Swap Space

| | To add new swap space without repartion your disk choose swap-files:
you require pseudo-device vn enabled within your kernel (which usually is)
swapsize in kilo-bytes (e.g. 256000 are 256MB).
|
% dd if=/dev/zero of=/your/swapfile bs=1024 count=swapsize
|
|
% chmod 600 /your/swapfile
|
|
% cd /dev/; ./MAKEDEV vn[012]
|
this creates three vn's (vn0 vn1 vn2) then add in /etc/vntab
for the first swap-file (and for each new swap-file another line):
|
/dev/vn0c /your/swapfile swap
|
then call
To have it startup everytime create /usr/local/etc/rc.d/vnconfig.sh:
|
#!/bin/sh
|
|
/usr/sbin/vnconfig -ae
|
and make it executable (chmod +x); or you add
|
swap_file="/your/swapfile"
|
to /etc/rc.conf (useful when you have only one swap-file).
swapinfo displays all active swap-devices.
|
50/60 rows console

| | To have 50/60 lines on the console:
- run /stand/sysinstall and go for "Configure" -> "Console" -> "Font"
and define new font (e.g. IBM 437)
- optional: edit /etc/ttys from 'cons25' to 'cons50' or 'cons60'
- add following line to /etc/rc.conf
|
allscreens_flags="VGA_80x60"
|
or VGA_80x50
- reboot
|
Software RAID: CCD

| | FreeBSD supports software RAID called 'CCD' (Concatenated Disk Driver)
which allows mirroring and interleaving (aka striping).
For speeding we use interleaving ('striping') which in the best
case should double the write/read accesses with two disks, theoretically at least.
In the /sys/i386/conf/MYKERNEL add
and config and compile it, and reboot, then
configure (using /stand/sysinstall) a large slice on each disk (da1, da2 as example)
and then:
|
% cd /dev; sh MAKEDEV ccd0
|
|
% ccdconfig ccd0 32 0 /dev/da1s1e /dev/da2s1e
|
|
% newfs /dev/rccd0c
|
|
% mount /dev/ccd0c /mnt/ccd0
|
|
% cd /mnt/ccd0
|
Hints:
The blocks for the CCD-disk you may choose at least a full track,
to know how many sectors (and blocks) a track has, call disklabel, e.g.
|
% disklabel /dev/da1s1e
|
|
....
|
|
bytes/sector: 512
|
|
sectors/track: 63
|
|
tracks/cylinder: 255
|
|
sectors/cylinder: 16065
|
|
cylinders: 2230
|
|
sectors/unit: 35840952
|
Since sectors and blocks are the same size, we should choose 63 at
least, to choose a lower number might even slow down the CCD-disk.
For our two 18GB 10krpm we made following measurements:
|
ccdconfig ccd0 32 15MB/s
|
|
ccdconfig ccd0 63 28MB/s
|
|
ccdconfig ccd0 94 30MB/s
|
|
ccdconfig ccd0 126 30MB/s
|
The single disk without CCD gives 20MB/s, so with CCD you get 50% speed
plus.
You might get an error-message when doing the newfs, in that case
do this before newfs:
|
% dd if=/dev/zero of=/dev/rccd0 count=2
|
|
% disklabel ccd0 > /tmp/disklabel.tmp
|
|
% disklabel -Rr ccd0 /tmp/disklabel.tmp
|
To have the CCD available after booting, add to /etc/ccd.conf
|
ccd0 94 0 /dev/da1s1e /dev/da2s1e
|
and into /etc/fstab
|
/dev/ccd0c /mnt/fast ufs rw 2 2
|
|
Software RAID: Vinum

| | In comparison to CCD allows VINUM far more complex setups, I cover here
only the stripe (interlaced) approach.
First of all fdisk the disks (can be different sizes); then disklabel so get e partition for each disk,
for this example I have /dev/ad2 and /dev/ad3, and got after disklabel also /dev/ad2s1e and
/dev/ad3s1e which we will use for vinum.
Then call disklabel -e /dev/ad2 and change 'unused' to 'vinum' (near bottom of the vi edit),
do so with the other disk as well.
Then call vinum:
|
% vinum stripe -v /dev/ad2s1e /dev/ad3s1e
|
Which gives this output:
|
drive vinumdrive0 device /dev/ad2s1e
|
|
drive vinumdrive1 device /dev/ad3s1e
|
|
volume vinum0
|
|
plex name vinum0.p0 org striped 256k
|
|
sd name vinum0.p0.s0 drive vinumdrive0 size 90060062b
|
|
sd name vinum0.p0.s1 drive vinumdrive1 size 90060062b
|
|
V vinum0 State: up Plexes: 1 Size: 85 GB
|
|
P vinum0.p0 S State: up Subdisks: 2 Size: 85 GB
|
|
S vinum0.p0.s0 State: up PO: 0 B Size: 42 GB
|
|
S vinum0.p0.s1 State: up PO: 256 kB Size: 42 GB
|
The first part I copied into /etc/vinum.conf:
|
drive vinumdrive0 device /dev/ad2s1e
|
|
drive vinumdrive1 device /dev/ad3s1e
|
|
volume vinum0
|
|
plex name vinum0.p0 org striped 256k
|
|
sd name vinum0.p0.s0 drive vinumdrive0 size 90060062b
|
|
sd name vinum0.p0.s1 drive vinumdrive1 size 90060062b
|
The /dev/vinum/vinum0 is ready, and a file-system can be done:
|
newfs -v /dev/vinum/vinum0
|
-v switch tells newfs to use entire space (no partitions used).
After that, just mount /dev/vinum/vinum0 like any other disk.
|
Memory Filesystem

| | Another way to increase the disk-access speed is to copy content to a memory
based filesystem, called MFS under FreeBSD (or most *BSD systems).
To setup one, call swapinfo and check where the swap-partion is, and
add following line in
/etc/fstab:
|
/dev/da0s1b /mnt/mfs mfs rw,-s131072 0 0
|
mkdir /mnt/mfs and call mount /mnt/mfs and you have 128MB
diskspace in your memory under /mnt/mfs, but be aware it's gone when
unmounted, or system is rebooted. Best just copy an existing disk-tree
into the memory-fs (e.g. /usr/local/etc/rc.d/rc.memfs).
|
| FreeBSD7. Virtual Domains
|
In order to host several domains (web and mail) you can alias your
network interface card (e.g. device-name rl0 as example) and this way host virtual domains:
|
% ifconfig rl0 alias myvirtual.com netmask 255.255.255.255
|
|
% ifconfig rl0 alias myvirtual2.com netmask 255.255.255.255
|
|
% ...
|
Of course the domains you host must have a valid DNS entry already. If you
don't know the device-name of your network-card then call dmesg or
netstat -i.
The same is achieved to list the aliases in /etc/rc.conf:
|
ifconfig_rl0_alias0="inet myvirtual.com netmask 255.255.255.255"
|
|
ifconfig_rl0_alias1="inet myvirtual2.com netmask 255.255.255.255"
|
|
...
|
| FreeBSD8. Keeping FreeBSD Machines Up-To-Date
|
FreeBSD allows very good to keep all your machines up-to-date:
- export /usr/src/ from main-server to all other FreeBSD machines,
e.g. /etc/exports of main-server (assuming we have an 192.168.0 network)
|
/ -maproot=root:0 -alldirs -network 192.168.0 -mask 255.255.255.0
|
NFS export works only on filesystems (not directories), so if you
have /usr/src or /usr not as seperate filesystem then you must export / (which
is not a good thing usually, but we assume we are speaking here of an intranet anyway, don't run nfs on any
machine connected to the internet).
- nfs-mount on the client-machines:
|
server:/usr/ports/distfiles /usr/ports/distfiles nfs rw 0 0
|
|
server:/usr/src /usr/src nfs ro 0 0
|
|
server:/usr/obj /usr/obj nfs rw 0 0
|
- keep track of src-all and ports with cvsup (check /usr/share/examples/cvsup for info) on
the main-server, and make buildworld/installworld as well make buildkernel/installkernel
(check /usr/src/Makefile for documentation) for each machine then.
We trace -STABLE and -CURRENT separately, this means we have /usr/src and /usr/obj we update (cvsup) the -STABLE from the main-machine,
and export to the clients. For the -CURRENT tree we export current-usr.src and current-usr.obj to the clients, and
the clients first test it before the main-machine boots it (the client cvsups the -CURRENT).
| main-server: | client: | type: | cvsup: |
| /usr/src/ | /usr/src | -STABLE | server |
| /usr/obj/ | /usr/obj | -STABLE | server |
| /mnt/scratch/current-usr.src | /usr/src | -CURRENT | client |
| /mnt/scratch/current-usr.obj | /usr/obj | -CURRENT | client |
|
go into /sys/i386/conf/ and configure your kernel
|
cp GENERIC CLIENT
|
|
config CLIENT
|
then go into /usr/src/ on server:
|
make buildkernel KERNEL=CLIENT
|
|
[make buildworld]
|
on client in /usr/src/ (mounted from server):
|
make installkernel KERNEL=CLIENT
|
|
[make installworld; mergemaster]
|
The [] are optional when you make world as well.
More in-depth infos you find
in FreeBSD Tutorials
and FreeBSD FAQ: Admin.
| FreeBSD9. FreeBSD Within FreeBSD (Virtualizing)
|
FreeBSD has a nice feature called jail and
enables to run FreeBSD within itself essentially,
check man jail.
The jail command was just added with FreeBSD-4.0. We
developed a few scripts to handle jails with JailTools.
| FreeBSD10. Live-System Install
|
To transfer FreeBSD to another disk from a live-system FreeBSD running,
here the procedure step-by-step:
- determine on which new disk you like to install FreeBSD,
let's assume in our case it's /dev/ad1 -
use /stand/sysinstall to partition (fdisk) and make slices (disklabel):
|
ad1s1a / ffs 290MB
|
|
ad1s1b none swap 32MB
|
- mount the 2nd disk to /mnt/newdisk:
|
mkdir /mnt/newdisk
|
|
mount /dev/ad1s1a /mnt/newdisk
|
- transfering FreeBSD system; assuming your /usr/src "world" and "kernel" is made (make buildworld buildkernel):
|
cd /usr/src
|
|
make hierarchy DESTDIR=/mnt/newdisk
|
|
make install DESTDIR=/mnt/newdisk
|
|
make installkernel DESTDIR=/mnt/newdisk
|
|
cd etc
|
|
make distribution DESTDIR=/mnt/newdisk
|
|
cd /mnt/newdisk/dev/
|
|
sh MAKEDEV ad0s1a
|
|
sh MAKEDEV ad0s1b
|
|
mkdir /mnt/newdisk/stand
|
|
cp /stand/sysinstall /mnt/newdisk/stand
|
If you
have a config'ed kernel then instead of make installkernel do
|
cd /usr/src/sys/compile/kernel-name
|
|
make install DESTDIR=/mnt/newdisk
|
The entire (minimal) FreeBSD installation takes up aprx. 120MB.
- edit /mnt/newdisk/etc/fstab
|
/dev/ad0s1a / ufs rw 1 1
|
|
/dev/ad0s1b none swap sw 0 0
|
|
proc /proc procfs rw 0 0
|
- umount the /mnt/newdisk, and define boot0 (1st level of booting)
|
cd /
|
|
boot0cfg -B -v /dev/ad1
|
- unplug the 2nd disk (ad1) and plug it into your new machine and boot it.
After it boots just config the rest of the live-system using /stand/sysinstall.
This "Live-System Install" is particularly useful to install FreeBSD
medias like PCMCIA ATA disk, or other medias which aren't supported
using the CD-Install (see Stylistic-1000 FreeBSD install).
Resources

| | | MAN HIER(7)MAN page of hier(7) explaining the FreeBSD disk-layout (useful reference) |
PicoBSDFreeBSD on a single floppy - compiled/configed within FreeBSD itself |
FreeSBIEFreeBSD Live-CD (no HD required) |
| FreeBSD LiveCDAnother project |
|
| FreeBSD11. More Resources
|

Hipocrisy of the finest: "I agree that no single company can create all the hardware and software. Openness is central because it's the foundation of choice." -- Steve Balmer (Microsoft) blaming Apple regarding iPhone, February 18, 2009Last update 2009/05/04 
All Rights Reserved - (C) 1997 - 2009 by The Labs.Com |