ZeroBSD

A n00b's adventure in the wonderful realm of BSD.

Enabling softupdates

This may be quite trivial and it can be found also in the FAQ with a simple Google search, but I’ve somehow missed it until now. Enabling softupdates can really boost your desktop performance. It’s not something I can measure and prove it, but the general feeling is that Xfce feels faster and this time it’s usable and not that laggy. There’s room for speed improvements still, especially in the video card department, but I’m happy with how the things are for the time being.

Enabling softupdates is very simple, just edit /etc/fstab, by adding the softdep keyword, as in the following example:

fec2653dbd41594a.a / ffs rw,softdep 1 1

This is an example from an /etc/fstab file with UUID, but it’s trivial for the other, older type:

/dev/sda0a / /ffs rw,softdep 1 1

Next time you reboot, you’ll enjoy the performance improvements it brings.

Empty tar.bz2 file (follow-up)

Remember this problem I had? Well, thanks to Andrei Mureșan, it’s fixed now. Apparently, cron has no idea of environmental variables when running the backup script, so I had to add the following line at the begining of my script:

PATH=$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/games:.

Works like a charm now. For future reference, he’s the full, corrected and working backup script:

PATH=$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/games:.
NOWD=$(date +”%F”)
NOWT=$(date +”%T”)
/usr/local/bin/mysqldump -u root -password \
dbname > /root/databases/db.sql
/bin/tar cvfj /home/john/backup/backup-$NOWD-$NOWT.tar.bz2 \
/var/log /var/www /etc /root/databases
/bin/rm /root/databases/db.sql

Smart IP filter with pf

Not long ago I’ve talked about two ways of making a good IP filter with pf. The first methods involved a pf table created after failed ssh attempts, but the table was not persistent after reboot, and the second method had a static text file from where pf could load unwanted IP for filtering. Let’s merge the two methods.

Let’s say that we already have a text file, manually created, with a selection of unwanted IPs, called /etc/pf.blocked.ip.conf and you also want to filter the ones that keep knowcking on your ssh door. You’ll have to have this in your /etc/pf.conf:

# static text file
table <blockedips> persist file “/etc/pf.blocked.ip.conf”
block in on bnx0 from <blockedips> to any

# not persistent pf table
table <bruteforce> persist
block quick from <bruteforce>
pass inet proto tcp from any to any port \
ssh flags S/SA keep state (max-src-conn 5, \
max-src-conn-rate 5/30, overload <bruteforce> flush global)

Now we would like to dump the bruteforce table into the /etc/blocked.ip.conf file, to have a record of our unwated IPs. A simple dump command is this one:

# pfctl -t bruteforce -T show

but this creates unwanted spaces that must be eliminated. We’ll use sed for this:

# pfctl -t bruteforce -T show | sed ‘s/ //g’

Now the space is gone and we have a properly formatted list of blacklisted IPs. We cannot dumped it right into /etc/blocked.ip.conf, because there might be the same IPs on different lines and we don’t want to have a bloated file loaded by pf. Let’s crate a temporary file with both the content of the bruteforce table and /etc/blocked.ip.conf:

# pfctl -t bruteforce -T show | sed ‘s/ //g’ » /tmp/ip.conf
# cat /etc/blocked.ip.conf » /tmp/ip.conf

Not we have to eliminate the IPs that are found more than one time in that list. We can do this with uniq, but for this, our list have to be ordered with sort.

sort /tmp/ip.conf | uniq » /tmp/ip.final.conf

The file /tmp/ip.final.conf contains now a list with unique blacklisted IP form both out manual /etc/blocked.ip.conf and from what the system catched automatically. If an IP was found on both lists, at the end it will be present in our filter only once. So, after moving along some files and cleaning, we can have a nice procedure for pf IP filtering.

rm /etc/blocked.ip.conf
cp /tmp/ip.final.conf /etc/blocked.ip.conf
rm /tmp/ip.conf
rm /tmp/ip.final.conf

We can make a shell script out of these commands and have cron run it once a day for a manual and automatic, persistent pf IP filter.

Powering down your OpenBSD

After running halt command, the system shuts down nicely, but one thing bugged ever since I’ve first played with OpenBSD: the system did not powered down without pressing the power button. I can live with that, but it’s rather frustrating and I thought that’s probably because OpenBSD doesn’t love my motherboard, though every modern operating systems knows how to power down my system without having me pressing the button (since my hardware is not the most recent one, it has around six years already).

After a quick online search, the solution for my problem revealed itself: it wasn’t a driver problem, it was just a script, /etc/rc.shutdown with a lonely line in it that reads:

powerdown=NO   # set to YES for powerdown

So, I obviously modified that into:

powerdown=YES   # set to YES for powerdown

and voilà, my system now is powering down nicely.

And if you want to be able to restart or halt your system as normal user, without sudo, just add your user to operator group:

$ sudo user mod -G operator john

Making things pretty

As part of my OpenBSD workstation project, making things pretty is a vital task. I can’t work in an ugly environment, so things have to be simple, functional and more important, coherent.

One of the first things I do on a fresh OpenBSD system intended for desktop use is to install msttcorefonts pack. Probably due to license reasons, you can only install this from ports, so if you don’t have ports yet, just follow the FAQ and do this:

$ cd /tmp
$ ftp ftp://ftp.openbsd.org/pub/OpenBSD/5.1/ports.tar.gz
$ cd /usr
$ sudo tar xzf /tmp/ports.tar.gz

Now that we have the ports installed, do this:

# cd /usr/ports/fonts/msttcorefonts
# make install

It’s all on the FAQ, just pointing it out.

Now, for one reason or another, you may need some GTK3 application. I use Xfce and I’m actually pretty satisfied with it, but I also need gedit for reasons mentioned in another post. While gedit is a GTK3, if you don’t choose the right theme, it may fallback to an ugly GTK variant which looks weird. So while your daily GTK2 theme look nice (Firefox, gFTP, XChat), the gedit will be different. There’s nothing I hate most than inconsistency. You need to find themes with support for both GTK2 and GTK3 versions to have theme consistency. A good starting point is gnome-looks.com website, from where you can download them and put them in your ~/.themes folder. If you don’t have it, create it and copy theme’s folders, after you’ve extracted them from the archive. The form the Xfce menu, Setting, Appearance and you can have a look on your new themes.

These packages might be useful, before starting theme hunt:

# pkg_add -vi gtk-engines2
# pkg_add -vi gtk2-murrine-engine

I’ve settled for Clearwaita from the Clearlooks-Phenix package, it looks simple, clean and fresh on both GTK2 and GTK3 applications (I love the old Clearlooks for GTK2 back in the days).

Credit for this posts goes to Igneous, from Freenode’s #openbsd.

LaTeX in BSD

I was surprised to see that a TeX Live meta-package is missing for FreeBSD, but there is one for OpenBSD. And it also installs nicely as a dependency for gedit-latex, a plugin for gedit that is probably the best LaTeX editor I could find in GTK.

The magic of gedit-latex plugin is that it adds cite-autocompletion and it’s beyond me why this feature is not available in every other LaTeX editor, considering what an excruciating pain dealing with biography is and how much a simple feature like this can help. I think there is only one more editor with cite-autocompletion, namely TexStudio, but it won’t compile on OpenBSD nor FreeBSD and it’s Qt4 and too bloated for my taste. Also, gedit is a nice, clean, simple design application that integrates well in my Xfce’s GTK medium.

FreeBSD 9 has binaries of Gnome 2 while OpenBSD 5.1 got Gnome 3 already. Hence, the ugliness of gedit in OpenBSD, but some theme tweaking I guess could make it better, that’s the only annoyance of my current setup. gedit 2 looked way better in FreeBSD’s Xfce with GTK2 themes, but I’ll dig for some beauty tips in the following days. The gedit 3 is the way to go anyway, no reason to look back.

Although installing TeX Live from official ports in FreeBSD is not possible, there is an alternate solution but I find it convoluted and I prefer the OpenBSD way: installing it from packages. Just type:

pkg_add -vi gedit-latex

and the rest will follow automatically, the system will fetch and install texlive_texmf-minimal package with all the necessary dependencies and you’ll have a nice TeX environment on your OpenBSD 5.1 machine. Sweet. It took me a while to find out about this, as I thought there are no binary packages for TeX Live (don’t ask why I didn’t just look into the ports directory), so I compile it from ports not a few day ago.

gedit-latex package texlive_texmf-minimal and this could be enough for some tasks, but trying to compile my .tex files spilled out a lot of errors concerning special characters like ăîșțâ, so I knew that I needed ut8x and ucs package, which wasn’t in the installed Tex Live distribution. To fix this, we can install the following:

pkg_add -vi texlive_texmf-full

Now we’ll have utf8x, ucs (I know it’s not recommended to use ucs, but it’s the only way to type spcial characters directly in editor and not having to wrapt my fingers for LaTeX codes in each and every word) and mchem package for easily typing chemical symbols.

There are others editors besides gedit-latex that have syntax highlighting for LaTex, but they are either ugly, bloated, Qt4 and old (kile, texmaker, texmakerx) or just ugly (gummi). None of them, with the exception of TeXStudio, a newer one that won’t compile on BSD just yet, won’t have cite-autocompletion which for me is a must. So I guess I’ll stick with gedit-latex for a while, it seems to work just fine for my needs, although it uses to crash a lot.

/usr disk space problem

I use the proposed auto-layout of my OpenBSD disk that is suggested during install. The problem is that, while /home partition is generous enough, /usr might be to small for some operations. For example, on a 20 GB hard-disk drive, the OpenBSD installer thinks that 2 GB is enough for /usr. Well, probably it is for some stuff, but when trying to compile TexLive from ports I’ve noticed that those 2 GB gets filled up near the end, making impossible to complete install the needed packages. The probem can be overcome simply and the process is described in OpenBSD FAQ, section 15.3.3. All we have to do to ease the stress on the /usr partition is to move the package handling operations to a partition with plenty of space, say /home. So edit your /etc/mk.conf like I did (if the file doesn’t exist, create it and add the following lines):

WRKOBJDIR=/home/john/ports/obj/ports
DISTDIR=/home/john/ports/distfiles
PACKAGE_REPOSITORY=/home/john/ports/packages

Don’t worry if you don’t have the /home/<user>/ports directory, the scripts will create it for you.

That’s it, now TexLive compiled and installed gently. The process took a few hours on my Intel Core2 Duo E6300.

Installing Xfce 4.8 on OpenBSD 5.0

After playing with FreeBSD for a few days, I’m back on my OpenBSD. First time I tried installing Xfce I gave up, due to some mouse problems and window manager issues. Now I’m back on track for installing this simple desktop environment, ready to fix all the problems.

The mouse problem arise probably due to the fact that my moue is a PS2 mouse, but it connect to my PC trough a PS2-to-USB adapter. I needed that so that my OS X could run on my system, since Apple’s operating system doesn’t had drivers for PS2 mouses. In OpenBSD, everytime I exited Xorg, my mouse would disconnect and stayed that way. Frustrating. So I removed the adapter and plugged my mouse in it’s intended location. Problem solved.

So let’s get on installing Xfce. I’ve used this website as a guide, but with some modifications (some packages couldn’t be found and some of them have different name now). If you already have a clean OpenBSD installed, just run this commands to have your Xfce desktop ready (there is no meta-package for Xfce, so we have to manually install everything):

# pkg_add -vi xfce4-session
# pkg_add -vi gtk-xfce-engine
# pkg_add -vi xfdesktop
# pkg_add -vi xfce4-appfinder
# pkg_add -vi xfce4-battery
# pkg_add -vi xfce4-clipman
# pkg_add -vi xfce4-dict
# pkg_add -vi xfce4-diskperf
# pkg_add -vi xfce4-fsguard
# pkg_add -vi xfce4-genmon
# pkg_add -vi xfce4-mailwatch
# pkg_add -vi xfce4-modemlights
# pkg_add -vi xfce4-mount
# pkg_add -vi xfce4-mpc
# pkg_add -vi xfce4-netload
# pkg_add -vi xfce4-notes
# pkg_add -vi xfce4-notifyd
# pkg_add -vi xfce4-places
# pkg_add -vi xfce4-quicklauncher
# pkg_add -vi xfce4-screenshooter
# pkg_add -vi xfce4-smartbookmark
# pkg_add -vi xfce4-systemload
# pkg_add -vi xfce4-taskmanager
# pkg_add -vi xfce4-time-out
# pkg_add -vi xfce4-verve
# pkg_add -vi xfce4-wavelan
# pkg_add -vi xfce4-weather
# pkg_add -vi xfce4-wmdock
# pkg_add -vi xfce4-xkb
# pkg_add -vi xfce-utils
# pkg_add -vi xfce4-terminal
# pkg_add -vi mousepad
# pkg_add -vi orage
# pkg_add -vi xfce4-mixer
# pkg_add -vi xfwm4
# pkg_add -vi xfwm4-themes
My initial problem with window bars missing was caused by failing to install xfwm4. Now it works, beautifully.
Don’t forget to modify your .initrc file accordingly (and comment any other lines, if necessary):
$ echo 'exec startxfce4' > .xinitrc
$ chmod +x .xinitrc
I haven’t installed a login manager yet, but this operation should be trivial and I’ll let it as an exercise for the reader :)
Update: Same procedure works for OpenBSD 5.1 as well.

FreeBSD on my desktop

Since I haven’t tried FreeBSD in a long, long time (years), I gave it a shot these days and I must say I was surprised. After almost a day of using it, it didn’t feel different than any other modern Linux distribution. It even have a graphical update manager that didn’t work! Jokes aside, FreeBSD had made some huge progress in desktop usability and if we consider the server tools and its awesome documentation, it’s an interesting operating system. 

Installing GNOME was so easy that I really have nothing to add. There’s no tips and trick, just follow the manual and you’ll have GNOME installed in like half an hour. If you want to have an enjoyable experience as a desktop, you have to read and apply these tips from the handbook and… there you have it, a fully usable FreeBSD desktop. With Flash, NVIDIA driver and Java support just a few pkg_add command away.

FreeBSD is so simple to install that offers really no challenge so if I made a blog about me using it, I’m afraid there wouldn’t be much to write about. On the server side, FreeBSD brings a few tools on the table that really worth taking a look at: ZFS, jails and virtualization. Not bad FreeBSD, not bad.

I was also tempted to install Solaris 11, but after a quick IRC chat I found out that Oracle doesn’t supply free security updates. That’s not funny. Open source implementation of Solaris and its features are spread between different projects (SmartOS, ProjectIndiana, etc) so until they stabilize and deliver an usable product, I think FreeBSD have it all: really good server tools, best desktop experience, without being owned by a ruthless corporation.

So back to our OpenBSD, after a wonderful trip trough FreeBSD realm. It’s nice to know there is an operating system like this and it continues to evolve. I will probably fail to make OpenBSD my desktop operating system, but I’m pretty sure I could get used to FreeBSD as quickly as I could with any other Linux distribution.

My .vimrc

I learned to love vim. In the first days of my *NIX adventures, I was using nano, since it reminded me of Norton Commander’s editor, but I soon realized that vim was more elegant and it seems I was more quicker using it then nano or, God forbids, Emacs (who uses an operating system to write a text file, anyway?). When in X, I prefer other, more fancy, editors, but when stuck to command line, vim is a great tool and usually the first package I install (if it’s not installed already).

While vanilla vim is quite usable after you get used to it, having some options turned on just makes it more friendly. So here’s my .vimrc file:

set ai
set background=dark
set showtabline=3
set smartindent
set smarttab
set backspace=indent,eol,start
set ruler
syntax on
command WQ wq
command Wq wq
command W w
command Q q

While I saw some very complex .vimrc settings, I like not to deviate to much from default options, but, in the same time, still using vim without frustration.

When in GNOME, I use gnome-terminal with a white background and the above setup doesn’t look very nice for most files, due to syntax color, so I modify the second line like this:

set background=light

That’s all about vim for now.