The Swede in the middle of Silicon Valley

Saturday, June 21, 2008

Appetizer

Egg with caviar and shrimp.



Monday, June 16, 2008

Diskless linux boot

DRAFT!

Prep DHCP

# yum install dhcp

# emacs /etc/dhcpd.conf

allow bootp;
allow booting;

ddns-update-style interim;
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.10 192.168.0.254;
default-lease-time 3600;
max-lease-time 4800;
option routers 192.168.0.1;
option domain-name-servers 192.168.0.1;
option subnet-mask 255.255.255.0;

filename "pxelinux.0";
next-server 192.168.0.1;
}

Prep TFTP
# 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=192.168.0.254:0.0.0.0:192.168.0.1:255.255.255.0 noapic acpi=off


Install CHROOT environment

# mkdir -p /nfsroot/slave1
# emacs installslave.sh

MYCHROOT=/nfsroot/slave1

mkdir -p $MYCHROOT/etc $MYCHROOT/dev $MYCHROOT/dev $MYCHROOT/proc $MYCHROOT/sys

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

./installslave.sh

NFS
# emacs /etc/exports
/nfsroot/slave1 192.168.0.254(rw,no_all_squash,no_root_squash)

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 192.168.0.1:/nfsroot/slave1 /

pwconv

http://www.digitalpeer.com/id/linuxnfs
http://fedoraproject.org/wiki/Docs/CustomKernel

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.

#!/usr/bin/perl

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

open (SNMP, "/usr/bin/snmpgetnext -cpublic -v1 192.168.1.1 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/update.sh ".$ip."'");
system ('echo "**** has a new IP '.$ip.'" | sendmail 408*******@txt.att.net
');

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.

Tuesday, June 3, 2008