For Debian 6 and 7, there's an easy way to create a cluster diskless. Isc-dhp-server an atftpd can be used to serve IP addresses, kernel, initrd and a minimal root disk ready to be loaded in memory.
Script /etc/initscript/hooks/tftp
Shell
# -*- shell-script -*- | |
# Cluster specific mount sequence | |
| |
mountroot () | |
{ | |
| |
# configure ethernet | |
ipconfig -c dhcp eth0 | |
ipconfig -c dhcp eth1 | |
| |
mount -t ramfs /dev/ram0 ${rootmnt} | |
| |
# download all tarballs | |
for f in $(echo ${tarballs} | sed 's/,/ /g'); do | |
log_begin_msg "download $f" | |
tftp -b 32764 -g -r $f ${tftpserver} | |
log_begin_msg "Extract $f into ${rootmnt}" | |
log_end_msg | |
tar xzf $f -C ${rootmnt} || exec /bin/sh | |
rm -f $f | |
done | |
| |
# remove files predeced by tilde | |
for f in $(find ${rootmnt} -name '~*'); do | |
o=$(echo $f | sed 's/\/~/\//') | |
[ -f $o ] && rm -rf $o $f | |
done | |
| |
# execute files predeced by plus | |
for f in $(find ${rootmnt} -name '+*'); do | |
[ -x $f ] && ./$f | |
[ -f $f ] && rm -f $f | |
done | |
} |
Generate new initrd
image:
Shell
update-initramfs -u |
Create root.tgz
tarball script:
Shell
#!/bin/bash | |
| |
PROGNAME=$(basename $0) | |
TFTP=/srv/tftp | |
EXCLUDE=/tmp/$PROGNAME-exclude-$$ | |
IMAGE=$TFTP/root.tgz | |
TMPLOG=/tmp/$PROGNAME-$$.log | |
VER=2.0 | |
| |
# help function | |
| |
function usage () { | |
echo "usage: $PROGNAME [-h] [-v]" | |
echo " -h: help message" | |
echo " -v: version message" | |
exit $@ | |
} | |
| |
# formating functions | |
| |
function title () { echo -e "\033[0;1m$*\033[0;0m"; } | |
function pass () { echo -e "\033[1;32m$*\033[0;0m"; } | |
function warn () { echo -e "\033[1;33m$*\033[0;0m"; } | |
function fail () { echo -e "\033[1;31m$*\033[0;0m"; } | |
# check command | |
| |
function check () { | |
echo -n "$@: " | |
{ eval $@; } >&$TMPLOG && pass OK || { fail KO; cat $TMPLOG; ERR=yes; } | |
rm -f $TMPLOG | |
test ! "$TEST" = yes | |
} | |
| |
# argument processing | |
| |
while [ $# -gt 0 ]; do | |
case "$1" in | |
-h) usage 0;; | |
-v) echo "$PROGNAME: version $VER"; exit;; | |
*) echo "unknown argument ($1)"; exit 1;; | |
esac | |
shift | |
done | |
| |
# create exclude list | |
cat - << EOF > $EXCLUDE | |
backup | |
boot | |
dev/* | |
etc/udev/rules.d/70-persistent-net.rules | |
home | |
lost+found | |
media/* | |
proc/* | |
root/* | |
run/* | |
srv/* | |
sys/* | |
tmp/* | |
usr/share/doc | |
usr/share/i18n | |
usr/share/info | |
usr/share/locale | |
usr/share/man | |
usr/share/zoneinfo | |
var/backups/* | |
var/cache/apt/* | |
var/cache/debconf/* | |
var/cache/fontconfig/* | |
var/cache/man/* | |
var/lib/apt | |
var/lib/aptitude | |
var/lib/dpkg | |
var/lib/samba/* | |
var/lock/* | |
var/log/* | |
var/run/* | |
EOF | |
check test -f $EXCLUDE | |
| |
# checks | |
[ -f $IMAGE ] && check rm -f $IMAGE | |
_OLDPWD=$(pwd) | |
cd / | |
check tar czf $IMAGE --exclude-from $EXCLUDE . | |
cd $_OLDPWD | |
| |
# clean exclude list | |
check rm -f $EXCLUDE | |
exit 0 |
Typical of a slave.tgz
tarball:
Code
-rw-r--r-- 1 mazet users 3515 nov. 13 2014 /etc/chrony/chrony.conf | |
-rw-r--r-- 1 mazet users 164 nov. 13 2014 /etc/default/atftpd | |
-rw-r--r-- 1 mazet users 1226 nov. 13 2014 /etc/default/hddtemp | |
-rw-r--r-- 1 mazet users 0 nov. 13 2014 /etc/default/~isc-dhcp-server | |
-rw-r--r-- 1 mazet users 799 nov. 13 2014 /etc/default/nfs-common | |
-rw-r--r-- 1 mazet users 551 nov. 13 2014 /etc/default/ntpdate | |
-rw-r--r-- 1 mazet users 276 nov. 13 2014 /etc/default/samba | |
-rw-r--r-- 1 mazet users 428 nov. 13 2014 /etc/default/smartmontools | |
-rw-r--r-- 1 mazet users 722 nov. 13 2014 /etc/default/snmpd | |
-rw-r--r-- 1 mazet users 1209 nov. 13 2014 /etc/exports | |
-rw-r--r-- 1 mazet users 1356 juil. 23 2015 /etc/fstab | |
-rw-r--r-- 1 mazet users 13 nov. 13 2014 /etc/hostname | |
-rwxr-xr-x 1 mazet users 73 nov. 13 2014 /etc/+hostname | |
-rw-r--r-- 1 mazet users 1332 nov. 13 2014 /etc/inetd.conf | |
-rw-r--r-- 1 mazet users 2012 nov. 13 2014 /etc/inittab | |
-rw-rw-r-- 1 mazet users 1184 avril 4 14:03 /etc/network/interfaces | |
-rwxrwxr-x 1 mazet users 439 sept. 21 2015 /etc/rc.local | |
-rw-r--r-- 1 mazet users 0 nov. 13 2014 /etc/resolv.conf | |
-rw-r--r-- 1 mazet users 2794 nov. 13 2014 /etc/rsyslog.conf | |
-rwxr-xr-x 1 mazet users 73 nov. 13 2014 /etc/ssmtp/+ssmtp.conf | |
-rw-r--r-- 1 mazet users 581 nov. 13 2014 /etc/ssmtp/ssmtp.conf | |
-rw-r--r-- 1 mazet users 0 déc. 4 2014 /home/.empty | |
-rw-rw-r-- 1 mazet users 0 mars 23 10:10 /-rec | |
-rw-r--r-- 1 mazet users 728 nov. 13 2014 /root/.bashrc | |
-rw-r--r-- 1 mazet users 140 nov. 13 2014 /root/.profile | |
-rw-r--r-- 1 mazet users 780 nov. 13 2014 /root/.screenrc | |
-rw-r--r-- 1 mazet users 416 nov. 13 2014 /root/.ssh/authorized_keys | |
-rw------- 1 mazet users 1679 nov. 13 2014 /root/.ssh/id_rsa | |
-rw-r--r-- 1 mazet users 416 nov. 13 2014 /root/.ssh/id_rsa.pub | |
-rw-r--r-- 1 mazet users 1 nov. 13 2014 /root/.vimrc | |
-rw-r--r-- 1 mazet users 0 nov. 13 2014 /usr/sbin/~winbindd | |
-rw-rw-r-- 1 mazet users 0 févr. 17 2015 /var/media/prod/.empty | |
-rw-rw-r-- 1 mazet users 0 févr. 17 2015 /var/media/rec/.empty |