Monthly Archives: September 2010

Installing Samba (for windows file sharing) in FreeBSD

People keep telling me that they have trouble getting Samba to work properly.  I found it difficult to get working properly too, so here’s a guide that should make it a lot easier…

First of all, we need to install it!  Make sure you have updated your Ports tree (see other posts) and then, as root:

cd /usr/ports/net/samba34
make config

This will show the configuration dialog box for options for the port.  Using the space bar and cursor keys, deselect ALL the options, and then enable only these:


Press TAB to go to OK and press enter.  Now you can build and install the port with:

make install distclean

It will go off and install dependencies if it needs to.  If you see any other configuration boxes, just accept the defaults and move on.

This takes a while as it has to install quite a few packages/ports, mostly for the file alteration monitor support – but it’s worth it so be patient.  If you already have X/gnome2 installed, this process will be much quicker.

Once the port is installed, we need to make a few changes to the limits within FreeBSD to make samba a little happier…  edit /etc/sysctl.conf and add the following:


And we also need to add another kernel module.  edit /boot/loader.conf and add the following:


Now, we need to tell samba to start on bootup, edit /etc/rc.conf and add the following:


And finally, we need to make ourselves a config file.  Edit /usr/local/etc/smb.conf and remove its entire contents.  Replace with the following template:

server string = Server Name
interfaces = em0
bind interfaces only = Yes
map to guest = Bad User
passdb backend = tdbsam
log file = /var/log/samba34/log.%m
max log size = 500
name resolve order = wins lmhosts bcast host
load printers = No
os level = 10
preferred master = No
domain master = No
dns proxy = No
wins support = No
ldap ssl = no
hosts allow =,,
hosts deny =
case sensitive = Yes
level2 oplocks = Yes
oplocks = Yes

comment = Temp Folder
path = /tmp
guest only = Yes
guest ok = Yes
read only = No

Replace ‘interfaces’ with your network interface name (mine is em0)

Your windows netbios name, by default, will be the hostname of your FreeBSD server up to the first dot.  E.g. for the netbios name is TEST.

Reboot to startup samba with all the relevant changes.  Browse to the server and you will see “tmp” share which is a user nobody access to /tmp.

Check the samba documentation on how to define other shares, such as per-user homedir shares.

Switching from MD5 to Blowfish/SHA512 password hashes in FreeBSD

By default, FreeBSD uses MD5 hashes for its encrypted passwords for users (SHA512 for FreeBSD 9.1+).  However, blowfish is available in all recent versions of FreeBSD and it’s really easy to change the default…

edit the file /etc/login.conf and change the following line:


To read the following:


Then rebuild the login database with the following command:

cap_mkdb /etc/login.conf

Now all passwords you change or set when adding a user will be encrypted using blowfish.  You can change your current password with passwd and when changed, your password will be blowfish encrypted.

If your system uses MD5, it’s preferrable to change over to Blowfish as it’s more secure… However, if your system supports SHA512 you should prefer this (passwd_format=sha512) – except for very few situations. (SHA512 is supported in FreeBSD 9.1+ only)

DirectAdmin requires the system to use md5 not blowfish or sha512, otherwise you will never be able to login to your DA web console.


Upgrading FreeBSD (using source method)

From time-to-time you will want to upgrade your FreeBSD system.  My preferred method is the source method.

To start, we need to create a file to define our source update.  Part of this requires you to choose a release engineering tag.  This is quite simple to generate.  It is the word RELENG followed by an underscore and the version number.  For example, if your system is running FreeBSD 8.1-RELEASE then your release engineering tag is RELENG_8_1.  If your system is FreeBSD 7.2-RELEASE, your tag is RELENG_7_2.

You can also, if you’re slightly braver, choose the ‘stable’ branch for your version of FreeBSD.  This is the tag with only the major number.  e.g. RELENG_8 for FreeBSD 8 stable.  This is my preferred version so I will use this in my examples.

Edit/create a file called /root/bsdsrc containing:

*default tag=RELENG_8
*default prefix=/usr
*default release=cvs delete use-rel-suffix compress


You can change the host to be your local mirror.  See my post on updating the ports tree for a list of mirror sites.

Now, to update your source tree (the files in /usr/src), make sure you’re connected to the internet and run the following command:

csup /root/bsdsrc

This will take a while as it updates any files required based on your released engineering tag.  Once completed, your FreeBSD kernel/OS sources are up-to-date.

Now, we need to build a new kernel and recompile the entire OS.  This sounds far worse than it is 😉

To rebuild the OS, type the following:

cd /usr/src
make buildworld

If you have multiple CPUs/cores in your computer, you can speed this process up by using:

make -j5 buildworld

The number after the ‘j’ should be the number of cores plus one for optimal usage.

This will take a while depending on your system specification.  Once it is complete, you can build a new kernel.  If you are running a custom kernel, you would replace the kernel configuration name with your custom one below.  To compile a new kernel, type:

make buildkernel KERNCONF=GENERIC

Again, you can use the “-j5” notation from above to speed things up.

Ok, now you have both the OS and kernel recompiled and ready to install.  At this point, you have not installed any updates, merely compiled them ready to install.

To install, type:

make installkernel KERNCONF=GENERIC
make installworld

This will install the new kernel and install the OS files.  Now, there’s just one step remaining.  The files in /etc/ are never replaced by the install process – but they may have changed between versions.

FreeBSD includes a handy little utility that compares RCS/CVS ids on these files and allows you to see the difference and install them.

To do this, type the following while in the /usr/src folder:

mergemaster -iFU

This will automatically install any files that the user has not modified, or new files.  Follow any instructions on the screen to handle other files.

Be weary about changes to /etc/group and /etc/master.passwd files.  If you’re unsure, pressing enter will make no changes to the file.

Once this process is complete, you just need to restart your computer and it will boot with the latest kernel and OS.

Formatting external disks for use with FreeBSD

A common question I get asked is how to reformat an external hard drive or USB penstick for use with FreeBSD.

NOTE: this will render the disk only usable in FreeBSD systems.  If you plug the disk into a windows computer, it will say it is not formatted.

First… plug the disk in, then check your console for details about the disk.  You can do this by typing:

tail /var/log/messages

You are looking for the disk name.  It will usually be something like da0 but it could be a different number at the end.

You may notice your disk has been automounted (if you’re running gnome for example) – check your current mounted disks with:


If your disk is mounted, you will need to unmount it before you can format it.  You can unmount it using is path (the bit after ” on ” in the output above).  If your disk was mounted on /media/usbdisk you would unmount with:

umount /media/usbdisk

Once the disk is unmounted (or if it wasnt already mounted) we need to wipe the start of the disk to remove any existing partitions.  You will need the disk name from the console earlier.  I will assume it is da0.  Wipe the start of the drive with:

dd if=/dev/zero of=/dev/da0 bs=1m count=128

This command will write zero’d (blank) data to the first 128MB of the disk at da0.

Next we are ready to format the disk for FreeBSD’s use using UFS2 filesystem.  You will need to decide a name/label for the drive.  I will assume it is usbdisk here.  Format with the following command:

newfs -L usbdisk -O2 -U -m 6 /dev/da0

Once the format is complete, any automounter will auto-mount the disk for you.  Check with the mount command to find out.

If the disk is not mounted, you can mount it with the following command:

mount /dev/ufs/usbdisk /mnt

By default, FreeBSD filesystems have ownership by root only.  You will most likely want to change the ownership to your user on the system.  If your username is ‘dan’ you would do this like so:

chown dan /mnt

That should be everything 🙂

Installing Flash Plugin 10 for Firefox in FreeBSD 8

Flash is annoying.  Adobe seem to have forgotten that other operating systems exist outside of windows, mac and linux.  Because of this, we have to use the linux-based flash plugin for FreeBSD.

However, this is (mostly) easy enough to configure if you know how.  Here’s a guide to do it.

First of all, update your ports tree (see other posts on my blog on how to do this)

Next we need to install the linux compatibility base system (if you haven’t already) – to do this, type the following as root:

cd /usr/ports/emulators/linux_base-f10
make install distclean

This will take a while as it installs a few helpers (like rpm), and downloads many linux RPM packages.

Once it is complete, we can install the linux flash plugin by typing:

cd /usr/ports/www/linux-f10-flashplugin10
make install distclean

This will fetch the linux flash plugin.  If it complains about size mismatches or MD5 checksum failures, then you have likely not updated your ports tree like you were told!

Once this is installed, we need to install a plugin wrapper to make it work… To do this, we type:

cd /usr/ports/www/nspluginwrapper
make install distclean

Now we need to make a quick file link.  To do this, type the following:

cd /usr/local/lib/browser_plugins/
ln -fs /usr/local/lib/npapi/linux-f10-flashplugin/

Ok, just one final step now (honest!).  For each user that you want to use the plugin, open a terminal as that user and DO NOT “su root”.  Then type:

nspluginwrapper -v -a -i

If all is well, you’ll see some mention of flash.  Next time you open firefox, flash will be enabled and fully working – including sound.

Feel free to complain to Adobe about the existence of other Operating Systems 🙂

Updating the ports tree in FreeBSD 8

After you have installed your system, you will no doubt want to update your ports tree regularly.

To do this, edit/create a file called /root/bsdports which contains the following:

*default tag=.
*default prefix=/usr
*default release=cvs delete use-rel-suffix compress


You should change the host “” to be one of your local mirrors.  You can see a list of mirrors at

Now to update your ports tree, type:

csup /root/bsdports

This takes quite a while, and will report any files it is updating as it goes.  Once it completes, your ports tree will be up to date.

Loading soundcard drivers in FreeBSD

By default, FreeBSD does not load any sound card drivers for you.

However, almost all soundcards are supported.  First you need to identify your soundcard.  You can do this with:

pciconf -lv | more

This shows a list of PCI devices in your system.  You are looking for a device which has a “class” of “multimedia”.

Mine, for example, shows the following:

none0@pci0:0:27:0:      card=0x022e1028 chip=0x284b8086 rev=0x02 hdr=0x00
vendor     = ‘Intel Corporation’
device     = ‘Intel audio controller embedded with the 82801H chipset ( ICH8 chipset ) (82801H)’
class      = multimedia
subclass   = HDA

If “subclass” says “HDA” (most new soundcards do) then the driver you will need later is snd_hda.  If not, most likely you will want the snd_ich driver.  If your system is really old, you may need another driver – check the list of drivers available by typing:

ls -al /boot/kernel/snd_*.ko

and select the one that looks most promising.

To test the driver is correct, we need to manually load it.  Do this with the following command:

kldload snd_hda

(substitute snd_hda with your required driver)

If all is well, your console screen (or type tail /var/log/messages if you’re not using the console – e.g. if you’re using SSH) will show a few messages about “pcm”.  If the driver is incorrect, nothing will be shown.

If you’re happy with your selection, we need to tell FreeBSD to load the driver on boot every time.  Edit the file /boot/loader.conf and add:


If you’re using another driver (e.g. snd_ich) then alter the above line to match the driver name followed by _load=”YES”

Everytime you reboot, your computer will load the driver automatically.

Using ‘ee’ to edit files in FreeBSD

When you install FreeBSD, you have a choice of two editors… vi or ee – vi is, for most people, over complicated and scary… so here’s a brief introduction to using ee.

To edit or create a file, you issue the command

ee /path/to/filename.txt

This will bring you into an interactive editor.  You can use the cursor keys to move around and type wherever the cursor is.

At the top of the window, you will see a list of commands.  These are all prefixed with a “^” symbol – this means the Control key.

To do a search, it says to use ^y – press Ctrl Y and type the text you want to search for.  To repeat the last search, press Ctrl X.

To save and exit a file, press ESC then enter twice.  To exit without saving, press ESC, enter then select no save and press enter.

It takes a little getting used to, but it’s a very simple editor and definitely the easiest choice for you in FreeBSD.

Installing gnome GUI on FreeBSD 8

Most people seem to think installing a GUI on FreeBSD is a difficult task.  Here’s how to do it, including little tweaks to make it work even better 😉

Login to your computer as root (or su to root from a regular user)

Use your favourite editor (check my blog for instructions on using ‘ee’ which is included in FreeBSD) to edit /boot/loader.conf – add the following lines:




This will load the linux compatibility layer, and linux procfs compatibility modules (these will most likely be used later when you need to install flash plugins) and also the ATAPI scsi emulation driver.  This is used for cd/dvd recording tools within gnome.

Next make sure that the linux proc folder exists by typing:

mkdir -p /compat/linux/proc

And now we will edit the /etc/fstab file.  Add the following lines if they do not exist already:

proc /proc procfs rw 0 0

linproc /compat/linux/proc linprocfs rw 0 0

Next, we will tell FreeBSD to initialise the linux compatibility layer on boot-up.  Edit /etc/rc.conf and add:


Ok, now you’re ready to install gnome.  Make sure you’re connected to the internet, and type:

pkg_add -r xorg gnome2

This will install xorg (if needed) and gnome.  It will fetch all dependencies it needs, so it may take a while.  You will be returned to a prompt when it’s finished.

Now to help things move along smoothly, you need to find out your computer’s hostname and add it to your hosts file…  Run the following command to get your hostname:


Next edit /etc/hosts and add the following line at the bottom (replace ‘hostname’ with the output of the above command): hostname

Now just one thing left to do, and that is to tell FreeBSD to load the gnome components next reboot… Edit /etc/rc.conf and add:





reboot, and you will be presented with the gnome login prompt 🙂

Step-by-Step guide to install FreeBSD 8.1

A few people have asked me recently how to install FreeBSD 8.1.  A few managed it by themselves, but using auto defaults which can cause various problems.  So I decided to publish this guide.  It uses the simplest method for users (not always “the best”, but certainly working) – I have taken screenshots throughout the entire process to assist you in installing.

First of all, download and burn the installation CD (disc1) or DVD (dvd1) image from your nearest FreeBSD mirror.  For our purposes, there is no difference between the two images.

Boot from the CD/DVD, and you will reach the following screen:

Choose your language from the list.  As i’m in the UK I will select United Kingdom with the cursor keys, and press Enter.  You will see the next screen:

You need to select your keyboard layout here.  I will choose UK ISO for me and press Enter.  This will bring us to the next screen:

Select ‘Standard’ from the menu and press enter to move to the next screen:

This is just an information screen so press enter to move to the next screen:

NOTE: you will only see this screen if you have more than one disk drive in your computer.  If you do not see this screen, skip to the next screenshot.

Select the first disk (either ad0 or ad4 or da0 depending on your computer setup) using the space bar to go to the next screen (if you have a single disk only, you will automatically go to the next screen):

If you are using an existing disk, you will have more than one line shown here.  Use the cursor keys to go down to all the entries and press D to delete them.  Repeat until you only have one line (unused).  Press A for use entire disk followed by Q to go to the next screen.  (If you have multiple disks, you will go back to the previous image – press TAB then enter to continue to the next screen if so)

This page allows you to select a boot manager.  You don’t need a boot manager for FreeBSD, so choose ‘Standard’ and press enter to continue to the next page:

This is an informational page again, press enter to continue to the next screen:

This is where most people choose Auto defaults – but this is almost always not suitable for you.  Instead, press C to create which goes to this screen:

Delete the number with the backspace key.  We need to enter a suitable value for swap space here.  Take your memory size to the nearest 1GB and double the figure. (e.g. if you have 1GB ram, use the figure 2G) – note you must only put G not GB.  press enter to go to this screen:

Use the cursor keys to go to “Swap” and press enter.  This will take you back to the black screen again.  Press C again to go to this screen:

Leave the number that is given in the box for you and press Enter to go to the next screen:

Select “FS” and press enter to go to the next screen:

Enter “/” into this box and press enter to go back to the black screen.  On this screen, use the cursor keys to go down to the entry listed as mount “/” and press the S key.  You will see the newfs item change to “UFS+S” like this image:

On this screen, you should now just have the “swap” and “/” entries.  Press Q to continue to the next step:

Use the cursor keys to go down to “Custom” and press the space bar to continue to the next step:

Using the cursor keys and space bar, select the following items on this page: base, lib32, man, catman, proflibs, ports, kernels. When you press space on “kernels”, you will be shown this screen:

Go down to GENERIC and press space, then back up to Exit and press space.  This will return you to the previous screen.

Select SRC using the space bar, when you do, you will be shown the following screen:

Go down to ALL and press space to select all items, then go to Exit and press space to return to the previous screen like this:

Go back up to Exit at the top of the page and press space to move onto the next step:

Go up to Exit and press space to move onto the next page:

Select CD/DVD here and press enter to move to the next step:

Ok, up to this point you haven’t made any changes to your disks.  This is your last chance (as it says) to change your mind.  Press enter to start formatting your drives:

After formatting (only takes a minute or two – similar to a quick format), you will see the following page as it installs files:

Once all the files have been copied, it will start to install the ports collection.  This has no progress bar and will take a while so be patient.  The screen looks like so:

Once everything is installed, and ports copied over – it will confirm the installation with the following page:

Press enter to move onto the post-installation questions.  You will enter the next step:

This will allow you configure WIRED networking (if you have wireless networking and do not wish to configure a wired network select NO here!)

If you would like to configure wired networking, select yes and press enter to move to the next step:

Your network card(s) will be shown here.  Network card names depend on your specific card.  If you have multiple network cards, you will see multiple lines here.  Ignore the plip0 device.

Select the network card you wish to configure and press enter to go to the next step:

Select NO here and press enter.  (If you want to use IPv6, enable it after installation).  This will bring you to the next step:

If your network uses DHCP for IP assignments, select YES and continue.  Otherwise select NO for static configuration.  The next page is identical regardless of which you choose – except with DHCP it will part-fill out IP addresses for you as given by DHCP.  The next page looks like this:

Fill out the host name and press tab.  This will auto-populate the domain section unless DHCP already did it for you.  If you chose not to use DHCP (or no DHCP servers were found), you will need to fill out gateway, nameserver, ip address and netmask fields.  Use the tab key to move between fields.  When done, tab until OK is highlighted and press enter to move onto the next screen:

Select NO here and press enter to move to the next step:

Select NO and press enter to move to the next step:

If you require access from outside of your computer (e.g. if it is a server, or if you like to remote access it from other computers etc), select YES here.  Otherwise select NO.  Either choice will move to the next screen:

Select NO here and press enter to continue to the next step:

Select NO here as we can configure this later if you want to use it.  This will continue onto the next stage:

Select NO here to move onto the next step:

Select YES here as we want to configure our console settings to something a little nicer.  This will move onto the next page:

Move down to FONT and press space to move to the next page:

Select the best font for you.  For me, this is IBM 437.  Press enter to return to the previous page.

Select KEYMAP and press space to move to the next page:

Select the best codepage for you.  For me, this is UK ISO.  Press enter to return to the previous page.

Select REPEAT and press space to move to the next page:

Select FAST and press enter to return to the previous page.

Select SCREENMAP and press space to move onto the next page:

Select the best screenmap for you.  For me, this is ISO 8859-1 TO IBM437.  Press enter to return to the previous screen.

Move up to EXIT and press enter to move onto the next page:

Select YES to set our timezone, this will move onto the next screen:

Select NO here to move onto the next screen:

Select your region from the list.  For me, this is EUROPE.  Press enter to go to the next screen:

Select your country/region from the list.  For me, this is UNITED KINGDOM.  Press enter to move to the next screen:

Check the timezone abbreviation is correct and say YES if it is.  For me, this is BST or GMT depending on summer time.  If you select NO you will go back to the previous page to reselect.  Selecting YES moves to the next step:

Select YES to move to the next step:

Don’t bother selecting any details in this page (they will be autodetected) – just go to EXIT and press enter to move to the next screen:

Select NO so that we do not install any packages.  This will move to the next page:

Select YES to add a user to the system.  This will move onto the following page:

Move down to USER and press enter to move onto the next page:

Add your username (all in lowercase) and use TAB to move between fields.  Enter a password and confirm in the relevant boxes.  In ‘Member groups’ put wheel (in lowercase).  Your home directory will automatically be set based on your login id.  The default shell is /bin/sh however I prefer /bin/tcsh.  TAB to OK and press enter to continue.

This will go back to the add user menu, select EXIT and press enter to move onto the next page:

Select OK to set a new root password for your computer.  The screen will look like this:

Enter your new root password twice to continue to the next page:

Select NO to continue to the next screen (the original installation screen):

Use the right cursor key to select EXIT INSTALL and press enter to continue.

Select YES to confirm you want to reboot.

Remove the CD/DVD from the drive and press ENTER to reboot.

When the computer as rebooted (assuming no problems) you will be presented with a login prompt like this:

Your computer is now installed and ready to use.  See my other posts for information on how to perform other tasks.

I hope this helps anyone hoping to install FreeBSD, and I welcome any questions.