Tag Archives: openbsd

Running OpenBSD off a flash drive

 
I’m planning on reducing the power consumption of and the noise from my VIA EPIA EN12000EG based home server. The server acts as media center, file server, backup server and authoritative DNS server. In a not so distant future it will probably also act as router and IPv6 tunnel endpoint. My plan is to replace its ordinary PSU with a more efficient and fanless picoPSU and to make its hard drive spin down when it hasn’t been used for a while. In addition, I will connect the server to my LAN with a cable rather than through wireless, which means I can retire the Linksys WRT54G that acts as a wire-wireless bridge for the server. I expect to go from approx 50 to 30 watts, on average, which is a saving of approx 0.02 kW · 24 hours/day · 365.25 days/year · 2 DKK/kWh = 350 DKK/year. Do you also smile when the units fit? 🙂

Okay, let’s get down to business. In order to have the hard drive spin up only when I access my music, videos and stuff, I need to move the server’s operating system – OpenBSD – to another disk. I will use a USB flash drive, as I happen to have one lying around and since they are silent and practically don’t consume power. The downside is that they are slow and die if you write to them often. That is solved using the server’s memory and a little ingenuity – the main topic of this post.

Frankly, I’m shocked at how little it takes to make OpenBSD run off a flash drive with some of its file systems in memory. You only need to follow seven steps:

1. Add a number of mfs’es to your /etc/fstab:

614940548185a78b.b none swap sw
614940548185a78b.a / ffs rw 1 1
swap /dev mfs rw,nosuid,-P=/mfs_backup/dev,-i=256 0 0
swap /var mfs rw,nodev,nosuid,-P=/mfs_backup/var,-s=60M 0 0
swap /root mfs rw,nodev,nosuid,-P=/mfs_backup/root 0 0
swap /home mfs rw,nodev,nosuid,-P=/mfs_backup/home,-s=20M 0 0
swap /tmp mfs rw,nodev,nosuid,-s=20M 0 0

(Note 1: The special “swap” entails default configuration parameters for mfs;
Note 2: The option “-i=256” ensures that we have enough inodes on /dev)

2. Install rsync (of course there is a precompiled package).

3. Create a synchronization script in e.g. /bin/mfs_sync.sh:

#!/bin/sh

RSYNC=/usr/local/bin/rsync
DEST=/mfs_backup

[ -d $DEST ] || mkdir $DEST

echo -n "Synchronizing directories to $DEST..."

for dir in dev var root home; do
    $RSYNC -a --delete /$dir $DEST/
    echo -n " $dir"
done

find $DEST -type s | xargs rm

echo

4. Test the script!

5. Let the script be run at shutdown by calling it from /etc/rc.shutdown.

6. Let the script be run e.g. once a day at 3:30 AM by adding the following line to root’s crontab:

30 3 * * * /bin/mfs_sync.sh >/dev/null

7. Reboot.

You should end up with something like this:

$ df -hi
Filesystem     Size    Used   Avail Capacity iused   ifree  %iused  Mounted on
/dev/sd1a      3.4G    798M    2.5G    24%   37452  430258     8%   /
mfs:24156      6.9M   32.0K    6.5M     0%    1263    6927    15%   /dev
mfs:11736     58.0M    6.0M   49.2M    11%     679   14679     4%   /var
mfs:29956      7.7M    9.0K    7.3M     0%       9    2037     0%   /root
mfs:27787     19.3M   10.0K   18.3M     0%      12    5106     0%   /home
mfs:1527      19.3M    4.0K   18.3M     0%       5    5113     0%   /tmp

I would like to thank Stephane Kattoor and Joel Knight for inspiration.

Now go and read the bloody details in mfs(8), fstab(5), rsync(1), find(1), rc.shutdown(8) and crontab(5) and make yourself worthy of their use.

Silence!

I have been really happy with my Sennheiser CX-380 earphones, since I bought them approx one year and a half ago. They have been great for running, weight training and commuting with bus, train and airplane. It was therefore a sad moment when I recently discovered a loose connection in their jack. As is evident from the above picture, there are only a few copper wires for each of the four inner cables in their wiring. I am not saying that it is impossible to attach a new jack, but it requires a very steady hand and probably a magnifying glass.

As Copenhagen Marathon is approaching, and I really need good earphones for my long training runs, I have temporarily given up on fixing my broken ones and have ordered a new pair. They actually arrived today. I chose the relatively cheap Sennheiser CX-300 II Precision – approx 300 DKK including postage. Well, as long as they do a decent job of eliminating noise and staying in my ears… I hope so 🙂

Oh, and what else is new?

Saturday, April 28, I set a new record with regard to how far I have ever run (running distance PR?). Unfortunately, I’m behind on my marathon training, so don’t expect anything close to the 42,195 meters. I ran 28.2 km. I was completely fried the rest of the day. Originally, I aimed at finishing the marathon in 3h 30m, requiring a pace of 4m 59s per km, but I might have to accept 3h 45m. My worst fear is cramp in my legs and other pains that cannot be ignored. My fitness will probably not let me down. A couple of excuses:

  1. It will be my first marathon, and
  2. I ran the 28.2 km without water and other supplies.

I really hope for relatively cold weather on the big day. Enough about running for this post…

At work I constantly learn new cool things. I have started to regularly perform tasks on our Cisco network infrastructure, and I have learnt about (and started to use) Splunk, which is a great tool for log analysis and reporting. I know it will provoke hatred in some of my geeky friends, when I say this, but together with the Riverbed Stingray Traffic Manager, Splunk is a member of the (though very small) set of closed source software that I feel good about. Both products work very well, they have active communities, and I haven’t yet seen open source replacements.

Last but not least, I have received OpenBSD 5.1 today. Thanks to the developers for yet another release of my favorite operating system. After a MacBook-only period of four months, I have once again started using OpenBSD -current on a daily basis on my Thinkpad X60 laptop. It just works[tm].

Update at 22:25 CEST: I have just used the new earphones in the gym, together with my new music player armband and sweatband. The earphones lacked a “clothespin” to secure their wires to my shirt, but I just used the one that came with my old ones. Sennheiser should consider supplying one with the CX-300’s too – or with all models where the lengths of the wire for each channel differ, i.e. the models where you probably will have the wire for the right channel behind your neck. The earphones fit nicely in my ears, deliver good music quality, eliminate noise from the surroundings and don’t fall out during exercises. Compared to the crappy Apple earphones, I used for a while, it is very clear that I don’t have to turn up the volume as much. That equals less stress on my ears and longer battery life for my player. All in all I am quite happy with the purchase.

OpenBSD installation stick

I have just installed OpenBSD on my Thinkpad X60, which is a laptop without a CD/DVD drive. After many searches, I have reached the conclusion that there is too little information on the internet on how to create a bootable USB stick from which you can start an OpenBSD installation. To help remedy that, I will present “my” procedure for creating one. The installation process started by the stick requires internet connectivity, as the OpenBSD file sets are not put on the stick. Do not thoughtlessly copy/paste the commands below – if you get the devices wrong, you might overwrite your system’s hard drive rather than the stick. The procedure requires local, privileged access to a running OpenBSD system. Download a desired bsd.rd file from a mirror, connect the stick and go ahead. It might take several seconds, or even minutes, to perform some of the writes to the stick, so be patient.

$ dmesg | tail -n 2
sd1 at scsibus3 targ 1 lun 0:  SCSI2 0/direct removable serial.18a503022D9C6807FA4F
sd1: 3823MB, 512 bytes/sector, 7829504 sectors
$ sudo fdisk -iy sd1
Writing MBR at offset 0.
$ sudo disklabel -E sd1
Label editor (enter '?' for help at any prompt)
> a a
offset: [64] (enter)
size: [7823591] 32M
Rounding size to cylinder (16065 sectors): 80261
FS type: [4.2BSD] (enter)
Rounding size to bsize (32 sectors): 80256
> q
Write new label?: [y] (enter)
$ sudo newfs /dev/rsd1a
/dev/rsd1a: 39.2MB in 80256 sectors of 512 bytes
4 cylinder groups of 9.80MB, 627 blocks, 1280 inodes each
super-block backups (for fsck -b #) at:
32, 20096, 40160, 60224,
$ sudo mount /dev/sd1a /mnt
$ sudo cp bsd.rd /mnt/bsd
$ sudo cp /usr/mdec/boot /mnt/
$ sudo /usr/mdec/installboot /mnt/boot /usr/mdec/biosboot sd1
$ sudo umount /mnt

Connect the stick to the laptop and boot from it.