The Swede in the middle of Silicon Valley

Saturday, June 21, 2008


Egg with caviar and shrimp.

Monday, June 16, 2008

Diskless linux boot



# yum install dhcp

# emacs /etc/dhcpd.conf

allow bootp;
allow booting;

ddns-update-style interim;
subnet netmask {
default-lease-time 3600;
max-lease-time 4800;
option routers;
option domain-name-servers;
option subnet-mask;

filename "pxelinux.0";

# yum install tftp-server dhcp syslinux
# emacs /etc/xinet.d/tftp
disabled = no

# mkdir /tftpboot/pxelinux.cfg
# cp /usr/lib/syslinux/pxelinux.0 /tftpboot/

# cd /tftpboot/pxelinux.cfg
# emacs 01-FF-FF-FF-FF-FF-FF
prompt 0
default linux
timeout 1000

label linux
kernel vmlinuz-.nfsboot.
append init=/sbin/init root=/dev/nfs rw nfsroot= noapic acpi=off

Install CHROOT environment

# mkdir -p /nfsroot/slave1
# emacs



cp /var/cache/yum/fedora/mirrorlist.txt /nfsroot/slave1/var/cache/yum/fedora/
cp /var/cache/yum/updates/mirrorlist.txt /nfsroot/slave1/var/cache/yum/updates/

cp -r /etc/yum* $MYCHROOT/etc
touch $MYCHROOT/etc/fstab

mknod $MYCHROOT/dev/null c 1 3
chmod 666 $MYCHROOT/dev/null

mount --bind /proc $MYCHROOT/proc
mount --bind /sys $MYCHROOT/sys

yum --installroot=$MYCHROOT groupinstall "Base"

umount $MYCHROOT/proc
umount $MYCHROOT/sys


# emacs /etc/exports

Build kernel
$ su -c 'yum install yum-utils rpmdevtools'
$ rpmdev-setuptree
$ yumdownloader --source kernel
$ su -c 'yum-builddep kernel-.src.rpm'
$ rpm -Uvh kernel-.src.rpm
$ cd ~/rpmbuild/SPECS
$ rpmbuild -bp --target=`uname -m` kernel.spec
$ cd ~/rpmbuild/BUILD/kernel-/linux-./
$ cp configs/ .config
$ make oldconfig
$ make menuconfig
$ cp .config ~/rpmbuild/SOURCES/config-
$ cd ~/rpmbuild/SPECS
$ emacs kernel.spec
% define buildid .nfsboot

$ rpmbuild -bb --with baseonly --without debuginfo --target=`uname -m` kernel.spec
$ cp ~/rpmbuild/RPMS//kernel-..rpm /nfsroot/slave1
# chroot /nfsroot/slave1
# rpm -ivh ~/rpmbuild/RPMS//kernel-..rpm
# exit
# cp /nfsroot/slave1/boot/vmlinuz-.nfsboot. /tftpboot

emacs /nfsroot/slave1/etc/rc.local
/bin/mount /


Thursday, June 12, 2008

Wednesday, June 4, 2008

Automatic update of DNS with Time Capsule and BIND dyndns

I doubt that anyone has the same setup as I have, but anyhow here's a
script I made to update the DNS record of my home-server:

To get a sense of what the script is doing let me explain my setup.

I've a hosted server where I host all my domains. One of the record is pointing at my home-server. As this server is on a consumer Internet transit it tends to change IP every now and then which can be a pain in the neck when you need to access it from a remote location and don't know the IP.

So what this script is doing is:
- Pulls IP information from my Time Capsule (which also is my router).
- Compares the IP information with a file containing the last known IP, if this file doesn't exist it is created once the updates are finished.
- Provided that the IP pulled from the Time Capsule doesn't match the last known IP the script logs into my DNS server, executes a script that updates the record pointing at my home server
- Once an update is finished it sends an email to AT&T which converts to an SMS with me as the recipient

This runs with cron every minute.


use IO::File;
my $oldip_file = "/root/oldip";

open (SNMP, "/usr/bin/snmpgetnext -cpublic -v1 IP-
MIB::ipAdEntIfIndex |");
while (<>) {
$data = $_;
close SNMP;

@ip = split('\.|\ ', $data);
$ip = $ip[1].".".$ip[2].".".$ip[3].".".$ip[4];

my $oldip = new IO::File('<'.$oldip_file); if ($ip != <$oldip>) {
system ("ssh -i /root/.ssh/id_rsa.dnsadmin dnsadmin
\@**** '/home/dnsadmin/scripts/ ".$ip."'");
system ('echo "**** has a new IP '.$ip.'" | sendmail 408*******

open FILE, ">".$oldip_file;
print FILE $ip;
close (FILE);

If you're going to use this remove the spaces by "< SNMP >" blogspot thinks this is a HTML tag and wont let me post it.