Debian/ImagingServer

From Servfire
Jump to: navigation, search

Work in progress

Base Installation

TFTP and NFS server setup

apt-get install tftpd-hpa syslinux initramfs-tools nfs-kernel-server

mkdir -p /srv/tftp

cp /boot/vmlinuz-$(uname -r) /usr/lib/syslinux/{pxelinux.0,menu.c32} /srv/tftp/

mkdir -p /srv/nfs/imageclient
echo '/srv/nfs/imageclient *(ro,sync,no_subtree_check,no_root_squash)' >> /etc/exports

mkdir -p /srv/nfs/images
echo '/srv/nfs/images *(rw,sync,no_subtree_check,no_root_squash)' >> /etc/exports

exportfs -av


/srv/tftp/pxelinux.cfg/default

UI menu.c32
DEFAULT 0
TIMEOUT 50
PROMPT 1

LABEL local
MENU LABEL Boot HD
LOCALBOOT 0

LABEL imageclient
MENU LABEL Imaging
KERNEL vmlinuz-++KERNEL_VERSION++
APPEND initrd=initramfs-++KERNEL_VERSION++ boot=nfs nfsroot=++NFSSERVER++:/srv/nfs/imageclient images=++NFSSERVER++:/srv/nfs/images



Building the initramfs

Copy out config

cp -r /etc/initramfs-tools ~/irfs


Add script - ~/irfs/scripts/nfs-bottom/ro-nfs

#!/bin/sh -e

case "$1" in
  prereqs)
    echo ""
    exit 0
  ;;
esac

tmpmount() {
  mkdir -p /mnt
  mount -t tmpfs none /mnt
  cp -a $1/. /mnt
  mount -o move /mnt $1
}

tmpmount /root/etc
tmpmount /root/var
tmpmount /root/srv
tmpmount /root/tmp
tmpmount /root/home

Build initramfs

mkinitramfs -d ~/irfs -o /srv/tftp/initramfs-$(uname -r) -v


Bootstrap for clients to load

Base system

debootstrap --variant=minbase squeeze /srv/nfs/imageclient

/srv/nfs/imageclient/imageComputer

#!/bin/bash

set -e

if ! mountpoint /images; then
        echo Mounting images
        IMAGES=
        for i in $(cat /proc/cmdline); do
                case $i in
                        images=*)
                                IMAGES=${i#images=}
                                ;;
                esac
        done
        if [ -z "$IMAGES" ]; then
                echo images NFS not passed on kernel cmdline
                exit 1
        fi
        mount -o ro,nolock "$IMAGES" /images
fi

ANS=$(tempfile)

OPTS=()
for i in /images/*; do
        if [ -e "$i/desc" ]; then
                echo adding $(basename "$i") - $(cat "$i/desc")
                OPTS=("${OPTS[@]}" "$(basename "$i")" "$(cat "$i/desc")")
        fi
done

OPTS=("${OPTS[@]}" "exit" "Exit to shell")

dialog --menu 'Choose image' 0 0 0 "${OPTS[@]}" 2> $ANS

IMAGE="$(cat $ANS)"

if [ "$IMAGE" = "exit" ]; then
        echo Exiting
        exit 0
fi

rm $ANS

"/images/$IMAGE/restore"