Thursday, January 29, 2009

Tip: Mount ReiserFS partitions in FreeBSD

My desktop dual boots Gentoo Linux and FreeBSD. When I installed Gentoo at the time I decided on splitting certain directories in distinct partition, so then I created a partition strictly for portage and opted for the ReiserFS filesystem.

Today I wanted to cut down on the bandwith and decided to copy over a needed distfile from the ReiserFS partition to FreeBSD.

Bellow you'll find the procedure to mount a ReiserFS in read-only mode. Do notice than the entire procedure is performed only on the FreeBSD system:
  1. % man reiserfs
  2. % su
  3. # kldload reiserfs.ko
  4. # mount -t reiserfs -o ro /dev/ad4s5 /mnt
On step 1 read reiserfs' man page, next become the superuser and proceeded to load the kernel module and finally mount the filesystem.

The -t switch lets you specify the filesystem and with -o decide in which mode should the filesystem be mounted (in this case in read-only mode).

My target partition was /dev/ad4s5 so change accordingly to your system. In my case I just viewed Gentoo's /etc/fstab and ran ls /dev/ad* to check if it added up ok.

Pretty simple eh?

Monday, January 26, 2009

Book Review: Absolute FreeBSD: The Complete Guide to FreeBSD, 2nd Edition

In the past holidays I bought a few books about FreeBSD: Absolute FreeBSD: The Complete Guide to FreeBSD 2nd Edition, The Best of FreeBSD Basics, The Book of PF and Building a Server with FreeBSD 7.

I'm pretty happy with all of them and I recommend them, under certain criteria, to anyone looking into FreeBSD. Why under certain criteria? If you're looking for a book on desktop usage of FreeBSD you'll find The Book of PF pretty disapointing.

Absolute FreeBSD: The Complete Guide to FreeBSD, 2nd Edition is the perfect combination for FreeBSD's own Handbook. At times the Handbook might seem too straightforward by not offering advices or sharing experiences. Michael Lucas' Absolute FreeBSD on the other hand presents the reader with rich information, background, advice and reasoning although focusing on the network administrator and setting aside the desktop user.

If you are looking into a nice FreeBSD book to get your feet wet on Unix-like systems so that you can carry out mundane desktop tasks then I'm afraid that Absolute FreeBSD simply isn't for you. If you on the other hand enjoy FreeBSD, know Unix basics and want to expand your horizons and maybe setup a personal server and even make a living out of FreeBSD, Absolute FreeBSD is definitely for you.

I don't have an IT background though I know my way around Unix-like systems so I've found chapters like Chapter 6: The Network extremely useful to cement some disperse concepts that I have (had thanks to Lucas' book).

People new to FreeBSD and Unix-like systems in general will find the first two chapters filled with helpful advices on how to prepare yourself for the tasks of installing FreeBSD and seeking help, especially the Preinstall Decisions section. To help explore FreeBSD Chapter 10: Exploring /etc is simply golden as it goes over the files available in /etc while describing what each does.

I found Chapter 3: Start me Up! The Boot Process very insightful. Chapter 4 brought RCS to my bag of tricks. The security chapters (7 and 9) were also very interesting reading namely the part regarding Jails.

Personal favorites were Chapter 5: Kernel Games, Chapter8: Disks and Filesystems, Chapter 11: making your system useful, Chapter 12: Advanced Software Management, Chapter 13: Upgrading FreeBSD, Chapter 18: Disk Tricks with GEOM. These are the chapters I'll ended reading time and time again and are largely FreeBSD focused.

Chapters 15 and 17 focus on adding services to FreeBSD and go over SSH, FTP, NTP, Inetd and Apache web server. Pretty useful as I'm planning on setting up some personal web serving stuff.

I'm not much into email and DNS stuff so I didn't payed much attention to chapters 14 and 16, however if the reader is into the subjects I'm sure he'll find both chapters very important.

Props to chapter 20, 21 and the Afterword expand on what FreeBSD is, what it can be, how can you interact with it and what can you do to improve it.

To sum up, just go out and buy the book. It's worth every penny and more.

Tuesday, January 20, 2009

Tip: Remove all installed packages and ports on FreeBSD

This post provides the steps required to remove every installed package and port on a FreeBSD system. By following the bellow steps you'll end up with a barebones system composed by FreeBSD's userland and kernel without any third party applications.
  1. % su
  2. # pkg_delete -f -a
  3. # rm -rf /var/db/pkg /var/db/ports /usr/local
We've started by using pkg_delete to remove all packages and ports and finished by deleting every traces of them in the system (including ports selected build options).

And that's it!

Monday, January 19, 2009

HowTo: Using ccache on FreeBSD

ccache is a compiler cache. It speeds up re-compilation of C/C++ code by caching previous compiles and detecting when the same compile is being done again.

The following is a step by step guide to how to enable and use ccache on FreeBSD 7.1:
  1. % su
  2. # cd /usr/ports/devel/ccache
  3. # make install clean
  4. # vim /etc/make.conf
.if (!empty(.CURDIR:M/usr/src*) || !empty(.CURDIR:M/usr/obj*)) && !defined(NOCCACHE)
Basically we've started by installing ccache (steps 1 through 3) and proceeded by editing /etc/make.conf as to enable ccache on builds.

Now we need to update the environment.

If you are using csh/tcsh shell add the following to /root/.cshrc:
setenv PATH /usr/local/libexec/ccache:$PATH
setenv CCACHE_PATH /usr/bin:/usr/local/bin
setenv CCACHE_DIR /var/tmp/ccache
setenv CCACHE_LOGFILE /var/log/ccache.log
If you are using zsh add the following to your /root/.zshrc file:
export PATH=/usr/local/libexec/ccache:$PATH
export CCACHE_PATH=/usr/bin:/usr/local/bin
export CCACHE_DIR=/var/tmp/ccache
export CCACHE_LOGFILE=/var/log/ccache.log
After updating the dotfiles we update the environment. Users of csh/tcsh shells can update by:
  • # source /root/.cshrc
Anyone using zsh can update the environment by running the following command:
  • # source /root/.zshrc
And that's it: ccache is installed and the environment is updated. Your next build will be performed with ccache enabled.

To display statistics summary:
  • % ccache -s
To zero statistics:
  • % ccache -z
To check out the help file for a list of ccache options:
  • % ccache -h
If you come across a port that fails to build, disable ccache and try again:
  • # make NOCCACHE=yes install clean
You can find more information regarding ccache through:

Thursday, January 15, 2009

Tip: Disable beep in Fedora

The first thing I realized I just had to change on Fedora 10 was the bloody beep. Fedora ships with a kernel module for the PC speaker named pcspkr.ko that if left loaded will drive you mad.

With this module loaded you get to hear a lovely beep while using a terminal. To turn off the beep, simply remove the kernel module and blacklist it to have it gone for good.

Here's how:
  1. $ su
  2. # rmmod -v pcspkr
  3. # echo "blacklist pcspkr" >> /etc/modprobe.d/blacklist
On step 1 become superuser, on step 2 we've removed the module for the running session and on step 3 we've prevented it from loading at boot.

These steps can be performed similarly in other distros.

Tip: Disable shutdown beep in FreeBSD

Beeps are annoying and the one at shutdown is no different.

Here's how to get rid of shutdown beeps:
  1. % su
  2. # sysctl hw.syscons.bell=0
  3. # echo "hw.syscons.bell=0" >> /etc/sysctl.conf
  4. # exit
We've started by becoming the superuser and then on step 2 we've disable the console bell. To guarantee that on next boot that horrible beep doesn't crop up we've added a sysctl to disable it in /etc/sysctl.conf.

Tuesday, January 13, 2009

Tip: Log console messages in FreeBSD

If you run FreeBSD without X11 you've noticed already that messages are presented in the console. Well you can log these messages with the help of syslog.

Here's how:
  • % su
  • # touch /var/log/console.log
  • # chmod 600 /var/log/console.log
  • # vim /etc/syslog.conf
Make sure that that the /var/log/console.log is uncommented.
  • # /etc/rc.d/syslogd restart
And that's it!

Wednesday, January 7, 2009

HowTo: Upgrade FreeBSD 7.0 to 7.1

Disclaimer: this post is for those that instead of using FreeBSD's excellent documentation maintain the bad habit of googling for things already covered in the project's official documentation. This is more or less a copy-paste of the FreeBSD 7.1-RELEASE Announcement instructions for upgrading 7.0 to 7.1.

These are needed steps to upgrade, through the binary path, the kernel and userland utilities to 7.1-RELEASE:
  1. % su
  2. # freebsd-update upgrade -r 7.1-RELEASE
  3. # freebsd-update install
  4. # reboot
  5. % su
  6. # freebsd-update install
  7. # reboot
On step 1 we've started of by becoming the superuser. Step 2 initiates the freebsd-update utility pointing the upgrade to 7.1-RELEASE, after that we proceed with the installation of the kernel on step 3.

Upon rebooting the new kernel is enabled and we move into step 6. Here we end the upgrade process by updating the userland utilities.

That's it!

If you found this post useful that's actually a bad news: you aren't reading the project's official documentation! So please point to and educate yourself on FreeBSD ;)