Difference between revisions of "Debian/ImagingServer"

From Servfire
Jump to: navigation, search
(Created page with "== Work in progress == === Base Installation === <pre> apt-get install tftpd-hpa syslinux initramfs-tools nfs-kernel-server mkdir -p /srv/tftp cp /boot/*-$(uname -r) /srv/tftp/...")
 
 
(7 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 6: Line 9:
 
mkdir -p /srv/tftp
 
mkdir -p /srv/tftp
  
cp /boot/*-$(uname -r) /srv/tftp/
+
cp /boot/vmlinuz-$(uname -r) /usr/lib/syslinux/{pxelinux.0,menu.c32} /srv/tftp/
 
+
ln -s /usr/lib/syslinux/{pxelinux.0,menu.c32} /srv/tftp/
+
  
 
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) >> /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>
  
=== /srv/tftp/default ===
+
 
 +
=== /srv/tftp/pxelinux.cfg/default ===
 
<pre>
 
<pre>
 
UI menu.c32
 
UI menu.c32
 
DEFAULT 0
 
DEFAULT 0
PROMPT 30
+
TIMEOUT 50
 +
PROMPT 1
  
 
LABEL local
 
LABEL local
Line 30: Line 35:
 
MENU LABEL Imaging
 
MENU LABEL Imaging
 
KERNEL vmlinuz-++KERNEL_VERSION++
 
KERNEL vmlinuz-++KERNEL_VERSION++
APPEND initrd=initramfs-++KERNEL_VERSION++
+
APPEND initrd=initramfs-++KERNEL_VERSION++ boot=nfs nfsroot=++NFSSERVER++:/srv/nfs/imageclient images=++NFSSERVER++:/srv/nfs/images
 +
</pre>
 +
 
 +
 
 +
 
 +
 
 +
== Building the initramfs ==
 +
 
 +
=== Copy out config ===
 +
<pre>
 +
cp -r /etc/initramfs-tools ~/irfs
 +
</pre>
 +
 
 +
 
 +
=== Add script - ~/irfs/scripts/nfs-bottom/ro-nfs ===
 +
<pre>
 +
#!/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
 +
</pre>
 +
 
 +
=== Build initramfs ===
 +
<pre>
 +
mkinitramfs -d ~/irfs -o /srv/tftp/initramfs-$(uname -r) -v
 +
</pre>
 +
 
 +
 
 +
== Bootstrap for clients to load ==
 +
=== Base system ===
 +
<pre>
 +
debootstrap --variant=minbase squeeze /srv/nfs/imageclient
 +
</pre>
 +
 
 +
=== /srv/nfs/imageclient/imageComputer ===
 +
<pre>
 +
#!/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"
 +
 
 
</pre>
 
</pre>

Latest revision as of 18: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"