OpenBSD Test Drive
The OpenBSD project just announced release 5.3 of their UNIX-like operating system. OpenBSD is a minimalist (by default) OS with a major focus on security out-of-the-box. The Alberta-based project has also produced the widely-used UNIX programs Pf, OpenSSH, OpenNTPD, and others. Every now and then, when one of the big three BSDs (FreeBSD, OpenBSD, NetBSD) release a new version, I get the urge to give it a test drive, mostly just out of curiosity, but also as a brain exercise. Although BSD and Linux are both UNIX-like OSes, there are some fairly significant differences. Since I use Linux daily, I find that playing with a BSD OS is an interesting change of pace and a good way to encourage active thinking about UNIX rather than simply following routine. So let’s get started!
What we will be doing in this exercise is:
- Creating a new virtual machine
- Installing OpenBSD
- Setting up OpenBSD’s package management system
- Installing software packages
For this exercise, we will need the following:
- VirtualBox
- OpenBSD Installer Disk Image (install53.iso)
- At least 2 gigs of free hard drive space
- We will be using the main OpenBSD site for installing packages, but you should replace all references with the mirror that is closest to you from this list.
Creating a new virtual machine
I’m going to assume that you know how to create a new empty virtual machine with VirtualBox. If you don’t, watch this video first. Once your new virtual machine is set up, you will need to tell it where your OpenBSD installer disk image is, so select your VM from the list in VirtualBox and click Settings->Storage, then select the “Empty” CD/DVD drive and click the CD icon to “Choose a virtual CD/DVD disk file…”. Select the install53.iso file that you downloaded.
Installing OpenBSD
If you’re familiar with Linux, the OpenBSD install should not seem too alien, although it is completely text-based. The installer prompts you for configuration settings one step at a time, but for our purposes, we will mostly be sticking to the default answer to each prompt. First the installer will ask you if you’d like to (I)nstall, (U)pgrade, or (S)hell. Enter “i” and the installer will begin. It’s safe to mostly accept the installer’s defaults for each prompt, however you will want to specify a hostname, root password, and user account. You should only configure the em0 network interface, making sure to use dhcp for the IPv4 address, and the default package selections are fine.
The installer will now copy all the required files to the virtual machine’s hard disk. This will take a few minutes. It will then ask you again for “Location of the set(s)”. Type “done” or just hit enter. The installer might ask you if it’s okay to correct the time settings, say “yes”.
Once the install has finished, you will be dropped to the installer’s shell. Before we forget, we should go into our virtual machine’s storage settings and “Remove disk from virtual drive” so that the installer doesn’t start again when we reboot. That’s it! You have successfully installed OpenBSD on your virtual machine! Type the command “reboot” into the shell and you will exit the installer and restart the virtual machine with your OpenBSD installation.
Setting up OpenBSD’s package management system
If you’ve used Ubuntu, Debian, or another deb-based Linux distribution, you will have probably used the apt-get command to install and upgrade software packages. The apt system uses a file (usually /etc/apt/sources.list) that contains a list of servers that host .deb software packages. When you run a command like “apt-get install firefox-browser”, apt uses it’s list of sources to find the software package you asked for, download it, and install it.
OpenBSD’s packages system is similar, but more minimalist. Instead of a file containing a list of servers, OpenBSD looks at the PKG_PATH environment variable, so the first thing you should do is configure your user account to automatically set this variable when you log in. You will need the URL of your local OpenBSD mirror. In my case, this is ftp://ftp.openbsd.org/pub/OpenBSD. You will need to add the path to your specific version of OpenBSD (in this case, /5.3/packages/`machine -a`/ [machine -a is a command that returns your machine’s CPU architecture, in this case, i386]) to the end of this URL and put the whole thing in your .profile file in your home folder. Log in to the user account you created during the installation and using the vi editor (vi .profile), add the following line to your .profile (replacing the URL with your local mirror):
PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/5.3/packages/`machine -a`/
Then, at the end of the file, add “PKG_PATH” to the end of the “export” line. Save this file and close vi. This file will be loaded automatically each time you log in to your account, so type “exit” and then log back in to your account.
One more thing you’ll have to do: since installing software packages requires root access, you’ll have to add your user account to the /etc/sudoers file. Type “su” and login with your root password, then run the command “visudo”. Find the section called “User privilege specification” and add the following line (where <username> is your user name):
<username> ALL=(ALL) SETENV: ALL
Save the file and log out of the root account with the “exit” command. You’re now ready to install software packages!
Installing software packages
Let’s say we want to install the client software for git. The way to do this in OpenBSD’s package system is to run the command:
sudo pkg_add git
pkg_add will ask you what version of rsync you want to install to fulfil git’s dependencies; select 0. pkg_add will then download and install git and it’s dependencies. You can see a list of all the packages you’ve installed on your system with the command “pkg_info”.
If you wanted to remove a package you’ve previously installed (let’s use git as an example again), you would run the command:
sudo pkg_delete git
Unfortunately, this only removes the git package, and not the dependencies that were installed with it. Use pkg_info to see what other packages are installed that you might no longer require. Much more information on package management in OpenBSD can be found in the OpenBSD FAQ.
This is, of course, just enough to get OpenBSD up and running in a virtual machine. The project has excellent documentation though, so the next step would be to consult the FAQ and check out the OpenBSD Journal blog. Good luck!
Leave a Reply