Creating Dsmanager templates

From ISPWiki

Jump to: navigation, search

Templates for new operating systems are described in this article [1]

Contents

Linux

CentOS

Creating a disk template

  • Download netinstall;
  • Put the kernel with initrd into TFTP.
  • Install the minimum version as required (new interface network cards are not supported; choose another hardware).
  • Partition the hard disk manually.
  • When booting for the first time, the system prompts to customize the interfaces. You should agree not to do it manually. The interface configuration is located in /etc/sysconfig/networking/devices/ifcfg-*.
  • Not to use chkconfig, disable all the services, except mcstrans, network, portmap, sshd and syslog.
  • Go to RecoveryMode; mount our root partition.
  • Overwrite:
rm -f /mnt/var/log/*
rm -f /mnt/root/.bash_history
  • and the modules as you do not need them any more:
rm -rf /mnt/lib/modules/*
  • Disable SELinux, write the following line into /mnt/etc/selinux/config:
SELINUX=disabled
  • archive:
tar -cpjf root.tar.bz2 /mnt/*
  • and place into the template.

Setting up the kernel

  • Note that you do not need initrd:
#CONFIG_BLK_DEV_INITRD is not set

If you wish to boot this kernel over the network, the followings are not required either:

CONFIG_BLK_DEV_LOOP=y
CONFIG_BLK_DEV_NBD=y
CONFIG_IP_PNP=y
CONFIG_IP_PNP_DHCP=y
CONFIG_NFS_FS=y
CONFIG_NFS_V3=y
CONFIG_ROOT_NFS=y

After setting up, archive the modules and place them to the template.

You also need the grub.conf template:

default=0
timeout=5
hiddenmenu
title CentOS 
        root (hd0,0)

We have the following template:

grub.conf       kernel          modules.tar.bz2      root.tar.bz2

Add install.4.sh:

#!/bin/sh
# these functions and variables that are not clear enough are listed below: 
fdisk_default
extract_default
install_grub
set_password
# Put the grub-a config 
cp grub.conf /mnt/boot/grub/grub.conf
echo "        kernel /kernel ro root=/dev/$HD_root" >> /mnt/boot/grub/grub.conf
# and the kernel
cp kernel /mnt/boot/kernel
tar -xpjf modules.tar.bz2 -C /mnt/lib/modules/
# Delete the old ssh keys 
rm -f /mnt/etc/ssh/ssh_host_*
# Put the devices below
umount /mnt/dev
cp -r /dev/console /mnt/dev/
cp -r /dev/urandom /mnt/dev/
cp -r /dev/null /mnt/dev/
# Specify the configs
echo "/dev/$HD_root           /                ext3    defaults    1 1" > /mnt/etc/fstab
echo "/dev/$HD_boot           /boot            ext2    defaults    1 2" >> /mnt/etc/fstab
echo "/dev/$HD_swap           swap             swap    defaults    0 0" >> /mnt/etc/fstab
echo "devpts              /dev/pts         devpts  gid=5,mode=620  0 0" >> /mnt/etc/fstab
echo "sysfs               /sys             sysfs   defaults        0 0" >> /mnt/etc/fstab
echo "proc                /proc            proc    defaults        0 0" >> /mnt/etc/fstab
cp /etc/resolv.conf /mnt/etc/resolv.conf
echo "$IP $NAME." >> /mnt/etc/hosts
ifcfg="/mnt/etc/sysconfig/networking/devices/ifcfg-$IF"
echo "DEVICE=$IF" > $ifcfg
echo "HWADDR=$MAC" >> $ifcfg
echo "ONBOOT=yes" >> $ifcfg
echo "TYPE=Ethernet" >> $ifcfg
echo "NETMASK=$NETMASK" >> $ifcfg
echo "IPADDR=$IP" >> $ifcfg
echo "NETMASK=$NETMASK" >> $ifcfg
echo "IPADDR=$IP" >> $ifcfg
echo "GATEWAY=$GATEWAY" >> $ifcfg 
# The followings are used by DSmanager in order to deny access to NFS, even though it was quickly rebooted. 
echo "#!/bin/sh" > /mnt/etc/rc.d/rc.local
echo "$WGET $URL&ip=$IP" >> /mnt/etc/rc.d/rc.local
echo 'echo "#!/bin/sh" > /etc/rc.d/rc.local' >> /mnt/etc/rc.d/rc.local #и замести следы

The installation script:

#!/bin/sh -x
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
DS=/DS
MNT=/DS/mnt
WGET="/usr/bin/wget --no-check-certificate -O /dev/null -q "
FIRST_START=YES 
# Detect network interface name and local IP
IF=`ifconfig | head -n 1 | cut -f1 -d\ `
IP=`ifconfig $IF | grep inet | sed -re 's/^.*addr:([^ ]*) .*$/\1/'`
MAC=`ifconfig $IF | grep $IF| sed -e 's/^.*HWaddr //g'` 
# Ok now we need to know our DSmanager server IP and share names
# Besides in this script can be functions for server customization
. local.conf
#
# MISC
#
install_grub()
{
 umount /mnt/boot
 chroot /mnt /bin/mount -t ext2 /dev/$HD_boot /boot 
 #not to edit /mnt/etc/mtab manually
 #required for grub 
 chroot /mnt /sbin/grub-install /dev/$HD            
} 
set_password()
{
 chroot /mnt /usr/sbin/usermod -p $PASSWORD root
}
fdisk_default()
{
 # Erase existing data from hard disk
 dd if=/dev/zero of=/dev/$HD bs=512 count=32
sfdisk -uM /dev/$HD << EOF
0,100,L,*
,1024,S
,,L
,1024,S
,,L
EOF
 mkfs.ext2 /dev/$HD_boot
 mkswap /dev/$HD_swap
 mkfs.ext3 /dev/$HD_root 
 mount -t ext3 /dev/$HD_root /mnt
 mkdir /mnt/boot
 mount -t ext2 /dev/$HD_boot /mnt/boot
 mkdir /mnt/dev
 mount -o bind /dev /mnt/dev
}
extract_default()
{
 tar -x -p -j -f root.tar.bz2 -C /mnt
}
send_msg()
{
  $WGET $URL$1
}
#
# END MISC
#
case "$1" in
 start)
# Mount share with configs
mount -t nfs $SERVER:$CONFIG_PATH $MNT 
CONFIG=$MNT/$IP.conf
if [ ! -f $CONFIG ]; then
  echo Unable to load server config
  echo Terminate install with error
  reboot
  exit 0
fi
. $CONFIG
URL="https://$SERVER/manager/dsmgr?auth=$ID&func=ds.reinstall&sok=ok&complete=on"
if [ "$FIRST_START" = "NO" ]; then
  echo This is the second time we have booted for reinstall
  echo Treminate install with error
  send_msg '&error=second'
  reboot
  exit 0
fi
echo "FIRST_START=NO" >> $CONFIG
umount $MNT
# If server hard disk name is not set in CONFIG we need to detect it
HD=${HD:-empty}
if [ $HD = "empty" ]; then
  if [ -b /dev/hda ]; then
    HD=hda
  elif [ -b /dev/sda ]; then
    HD=sda
  else
    halt
  fi
else
  if [ ! -b /dev/$HD ]; then
    echo Hard disk device with this name not found
    echo Terminate install with error
    send_msg '&error=disk'
    reboot
  fi
fi
# Mount disk templates
mount -t nfs $SERVER:$TEMPLATE_PATH $MNT
if [ ! -f "$MNT/$IMAGE/install.4.sh" ]; then
  echo Install script for disk template not found
  echo Terminate install with error
  send_msg '&error=template'
  reboot
  exit 0
fi
# Default disk names
HD_boot=$HD"1"
HD_swap=$HD"2"
HD_root=$HD"3"
HD_root=$HD"3"
cd $MNT/$IMAGE
. install.4.sh
send_msg 
reboot
;;
esac
Was this helpful? Yes | No
Personal tools