GlusterFS and cloned systems

I’ve been playing with RedHat storage server which runs GlusterFS under the hood and cloned the nodes from a single master but got an error about “overlapping export directories from the same peer” when creating a new volume on GlusterFS.

Turns out if you have cloned the nodes then you need to make sure you have updated the UUID in /etc/glusterd/glusterd.info to actually be unique again.

Quick cheat is to do:

service glusterd stop
echo "UUID=$(uuidgen)" > /etc/glusterd/glusterd.info
service glusterd start

Making mod_write and mod_userdir work together

After fighting with Apache for a while I’ve finally managed to get a redirect from a users public_html to a new domain.

The main problem is how mod_rewrite and mod_userdir interact, but the magic syntax to put in the .htaccess inside the user’s public_html is this:

RewriteEngine On
RewriteBase /~user
RewriteRule ^(.*)$ http://newdomain.example.com/$1

Tidying up old kernels on Debian and Ubuntu

I’ve never found a good way from the command line to clear out old kernels on Debian or Ubuntu systems, I know there are systems like computer janitor for GUIs but nothing as useful or simple as package-cleanup for rpm based systems.

I’ve hacked up a bash script that works for me, and hopefully other people might find it useful. The script works by figuring out what the running kernel and the latest kernels are and then removing any kernels that don’t match that, and at the end of the script there is a forced dkms module rebuild to ensure that dkms modules are current for all installed kernels.

#!/bin/sh
sudo apt-get update

runningversion=$(dpkg -l 'linux-image*' | grep ^ii.*`uname -r` | awk '{print $3}')
latestversion=$(dpkg -l 'linux-image*'| awk '{print $3}' | grep -- - | sort -V | tail -n 1)
metapackage=generic

dpkg -l 'linux-image-*'| grep ^ii |\
egrep -v "$runningversion|$latestversion|linux-image-$metapackage" |\
awk '{print $2}' |\
xargs sudo apt-get -y purge

dpkg -l 'linux-headers-*'| grep ^ii |\
egrep -v "$runningversion|$latestversion|linux-headers-$metapackage" |\
awk '{print $2}' |\
xargs sudo apt-get -y purge

sudo apt-get autoremove
sudo apt-get autoclean

# Force a rebuild of all dkms modules
if [ -f /usr/sbin/dkms ] ; then
dkms status | sed s/,//g | awk '{print "-m",$1,"-v",$2}' | uniq |\
while read line; do
ls /var/lib/initramfs-tools | xargs -n 1 sudo dkms install $line -k
done
fi

The script can also downloaded from here: http://www.night-shade.org.uk/~tim/Ubuntu/ubuntu-kernel-tidy.sh.gz

More storage on an OpenWRT router

Even with a modified WR703N you will still likely run out of space quite quickly if you try and use some of the larger OpenWRT packages like Samba or Asterisk. The best way to add more storage is one of the tiny USB flash drives that fit in side the USB port on the router, something like a 16GB SanDisk Cruzer Fit flash drive.

You can also do clever things such as using different memory sticks for different setups, so you have a memory stick setup that starts up as a PirateBox, while a different one setup to join your wireless and share files from the USB memory stick. Because of the way that the overlay works, effectively the entire system state is stored on the overlay filesystem.

I have a little script that does all the setup for you, it assumes that the drive is setup with 2 primary partitions, the first one formatted with ext4 and the second as swap, you will need to do the partitioning and formatting on a normal Linux box. Once the drive is setup you just need to run the following script, it downloads and installs the correct packages and sets up the usb memory stick as an overlay.

#!/bin/sh
packages="kmod-fs-ext4 kmod-usb-storage block-mount"
dev=sda1
swapdev=sda2
fstype=ext4
options=rw,sync,noatime

enable()
{
echo "Stopping automounting"
/etc/init.d/fstab stop

opkg update
opkg install $packages

sleep 10

while [ ! -b /dev/$dev ] ; do
echo "/dev/$dev not found please insert the USB storage device"
read junk
done

mkdir -p /mnt/$dev
mount /dev/$dev /mnt/$dev -t $fstype -o $options

tar -C /overlay -cvf - . | tar -C /mnt/$dev -xf -

uci add fstab mount
uci set fstab.@mount[-1].device=/dev/sda1
uci set fstab.@mount[-1].options=$options
uci set fstab.@mount[-1].enabled_fsck=0
uci set fstab.@mount[-1].enabled=1
uci set fstab.@mount[-1].target=/overlay
uci set fstab.@mount[-1].fstype=$fstype

uci add fstab swap
uci set fstab.@swap[-1].device=/dev/sda1
uci set fstab.@swap[-1].enabled=1

uci commit fstab

/etc/init.d/fstab enable

echo "Overlay enabled, you need to reboot to activate it"
}

enable

The script can be downloaded here: http://www.night-shade.org.uk/~tim/OpenWRT/usb-overlay.sh.gz