Archive for February 2008

Wanna reset your MySQL root password on Ubuntu?

Its easy!

sudo /etc/init.d/mysql reset-password

SVN: Converting from BerkeleyDB to FSFS

I’ve been working with Marcello on http://2draw.net/ and after posting up the Alt framework we’re working on (http://alt.cellosoft.net/) onto ajaxian.com our SVN suddenly stopped working. What a mess, eh? Indeed. BerkeleyDB was apparently at fault, since our DB got corrupted as we were being hit by the masses.

Since we have about 8 repositories, I wrote up a little shell script to do the housekeeping in making the transition. The usage case is pretty simple:

$ ./convert.sh repo_dir

be sure to run this with the pure repository directory, no trailing slash!

<br />#!/bin/sh<br />echo "Converting $repo from BerkeleyDB to FSFS"<br />repo=$1<br />echo "Dumping to $repo.svn.backup"<br />svnadmin dump $repo > $repo.svn.backup<br />mv $repo $repo.bdb<br />svnadmin create --fs-type fsfs $repo<br />svnadmin load $repo < $repo.svn.backup<br />chown -R svn:svn $repo && chmod -R g+r $repo<br />cp -R $repo.bdb/conf/ $repo/<br />cp -R $repo.bdb/hooks/ $repo/<br />rm -rf $repo.bdb<br />rm $repo.svn.backup<br />

Shaders!


I’m late and I have interviews to get to, but here is the fruits of my night’s labor in writing shading algorithms. My first real C++ program, so proud!

Wiring the apartment – setting up DHCP and Routing on Ubuntu

I have a confession to make. I live with 11 engineers. In two connected apartments. And when we moved it, there was no wiring in the house… Only a telephone jack in each room. And now, we all have ethernet drops and multiple wifi access points through the area. I do hope our landlord sees this as a significant improvement!

In the process I bumped up my networking skill quite significantly. The network layout looks something like this:

[Border Router]
| |
[Switches for Subnet 0]
| |
{eth0}[Server]{eth1}
| |
[Switches for Subnet 1]
| |
[Border Router]

Each switch is connected to about 8 desktops and two wireless access points, forming their own network. The idea is that each apartment (thus each subnet) has its own internet access point, but the fileserver is accessible from both apartments, and also routes between the two apartments so that it appears that they are both on the same network to things like SMB and the like.

I use DHCP on the server itself to set the correct information on all the hosts. Here is my dhcpd.conf file:

# Custom DHCP3 server for the EECS House
# Niels Joubert njoubert@gmail.com

### Add classless-static-routes option:
option classless-static-routes code 121 = array of { ip-address, ip-address };
option new-static-routes code 249 = string;
###

lease-file-name "/var/lib/dhcp3/dhcpd.leases";

default-lease-time 86400;
max-lease-time 604800;

authoritative;

subnet 192.168.0.0 netmask 255.255.255.0 {
option ip-forwarding off;

range 192.168.0.100 192.168.0.200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.0.255;

#option domain-name "";
option domain-name-servers 192.168.1.1, 68.87.76.178, 68.87.78.130;

option netbios-name-servers 192.168.0.10;
option netbios-node-type 8;
option routers 192.168.0.10;

#This is to get the machines on the two subnets to talk:
option new-static-routes 18:c0:a8:01:c0:a8:00:0a;

}

subnet 192.168.1.0 netmask 255.255.255.0 {
option ip-forwarding off;

range 192.168.1.100 192.168.1.200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;

#option domain-name "";
option domain-name-servers 192.168.1.1, 68.87.76.178, 68.87.78.130;

option netbios-name-servers 192.168.1.10;
option netbios-node-type 8;
option routers 192.168.1.1;

#This is to get the machines on the two subnets to talk:
option new-static-routes 18:c0:a8:00:c0:a8:01:0a;

}

There is a couple of hacks in here:
- to get machines from the one subnet to see the other subnet, i use the classless-static-routes DHCP option, that puts an entry into any host that gets a DHCP offer from this box. Unfortunately this only works for windows hosts! This is a huge caveat that I have not been able to solve.
For SMB use, I set the server itself as the netbios name server (more on this later). For each subnet, I set the default route as its border router. With this setup it is enough that each subnet has internet and should be able to talk to the other subnet through the server.

IPTABLES

To forward anything through the server itself, I use a custom iptables setup that resides in a script that gets automatically run, as follows:

# NIELS JOUBERT
# Custom iptables script

# Clean up iptables (flush it)
iptables -F
iptables -t nat -F
iptables -X

# Enable IP MASQUERADING/NAT
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

# Set firewall policies (default behaviour)
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

The idea here is to set up a nat table to masquerade ips, and the forwarding table to accept all forwarding. Simple, straight-forward and general. Possibly not the best security, but we are self-contained within the border routers right now, so if one of my roommates wants to be an ass and attack someone else, its easy enough to go hit him physically, right?

SAMBA

Samba itself also needs to be configured. Now, Samba is HUGE, as are its config files. I recommend a good book on Samba if you are going to do anything more than the most basic sharing with it. I personally prefer “The Official Samba-3 HOWTO and Reference Guide”.

The gist of my smb.conf setup looks like this:

[global]
workgroup = workgroup
netbios name = ubuntu
server string = Niels Server
dns proxy = no
name resolve order = lmhosts wins host bcast
smb ports = 139 240
# This tells Samba to use a separate log file for each machine
log file = /var/log/samba/log.%m
max log size = 1000
syslog = 0

####### WINS Services ######
wins support = yes

# Forces us to be the local master browser for WINS
local master = yes
preferred master = yes
os level = 34
domain master = yes

# Cache TTL
max ttl = 86400
max wins ttl = 86400

The important thing to note is that samba works on all interfaces and is the local wins browser (netbios name server).

This is the setup! It works fairly well too.

Reliability through two interfaces!

The one apartment’s internet died today because we’re in the middle of switching from ComCast (ewww) to DSLExtreme (YAY!). I remedied 7 very angry internet-less engineers by a very simple change in routing.

1) Change the subnet without border router to use the server as border router
2) Change the server to use as default route the border router of the other subnet

This took about 5 minutes, and we were piping the internet through the other apartment into our without a hiccup. Hooray for networking!

Feel free to ask me about my setup or use my config files.

Why I took my Shuttle XPC Back – Linux on the Shuttle XPC SG33G5

I returned my Shuttle XPC to Fry’s Electronics over the weekend. Not because I didn’t like it, but because of my issues to run Linux on it.

I managed to get Ubuntu 7.10 working on it as I outlined in a previous blog post, but Windows was complaining about the BIOS settings needed to get Linux working. Frankly, although I’m fairly certain that it is possible to run Linux and windows XP dual-boot on the shuttle, it is far too much of a hassle to get this working. Thus, back it goes. It was a nice box, but alas I won’t be running it anymore! My hard drive was also running far too hot in it to be happy with. Thus, on to the next post for my new baby…