Difference between revisions of "Debian/ImagingServer"

From Servfire
Jump to: navigation, search
 
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
 
= Work in progress =
 
= Work in progress =
 +
 
== Base Installation ==
 
== Base Installation ==
 +
 +
=== TFTP and NFS server setup ===
 
<pre>
 
<pre>
 
apt-get install tftpd-hpa syslinux initramfs-tools nfs-kernel-server
 
apt-get install tftpd-hpa syslinux initramfs-tools nfs-kernel-server
Line 9: Line 12:
  
 
mkdir -p /srv/nfs/imageclient
 
mkdir -p /srv/nfs/imageclient
 +
echo '/srv/nfs/imageclient *(ro,sync,no_subtree_check,no_root_squash)' >> /etc/exports
  
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
 
exportfs -av
 
</pre>
 
</pre>
  
== Building the initramfs ==
+
 
=== Add squeeze-backports to sources.list ===
+
=== /srv/tftp/pxelinux.cfg/default ===
 
<pre>
 
<pre>
echo 'deb http://backports.debian.org/debian-backports squeeze-backports main' >> /etc/apt/sources.list
+
UI menu.c32
apt-get update
+
DEFAULT 0
apt-get install unionfs-fuse
+
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
 
</pre>
 
</pre>
 +
 +
 +
 +
 +
== Building the initramfs ==
  
 
=== Copy out config ===
 
=== Copy out config ===
 
<pre>
 
<pre>
 
cp -r /etc/initramfs-tools ~/irfs
 
cp -r /etc/initramfs-tools ~/irfs
 
echo 'fuse' >> ~/irfs/modules
 
 
</pre>
 
</pre>
  
Line 61: Line 79:
 
</pre>
 
</pre>
  
== /srv/tftp/pxelinux.cfg/default ==
+
 
 +
== Bootstrap for clients to load ==
 +
=== Base system ===
 
<pre>
 
<pre>
UI menu.c32
+
debootstrap --variant=minbase squeeze /srv/nfs/imageclient
DEFAULT 0
+
</pre>
TIMEOUT 50
+
PROMPT 1
+
  
LABEL local
+
=== /srv/nfs/imageclient/imageComputer ===
MENU LABEL Boot HD
+
<pre>
LOCALBOOT 0
+
#!/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"
  
LABEL imageclient
 
MENU LABEL Imaging
 
KERNEL vmlinuz-++KERNEL_VERSION++
 
APPEND initrd=initramfs-++KERNEL_VERSION++ boot=nfs nfsroot=++NFSSERVER++:/srv/nfs/imageclient
 
 
</pre>
 
</pre>

Latest revision as of 19:28, 27 December 2012

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"