Gabarits de DSmanager

De ISPWiki.

Comment créer des gabarits disque trouvez dans l'article [1]

Sommaire

Linux

CentOS

Créez un gabarit disque

  • Téléchargez netinstall;
  • Mets le noyau 'initrd' dedans TFTP.
  • Installez la version minimale (new interface network cards are not supported; choose another hardware).
  • Séparez le disque dur manuellement.
  • Personnalisez les interfaces. Vous devez l'accepter au lieu de faire manuellement. La configuration de l'interface est située dans /etc/sysconfig/networking/devices/ifcfg-*.
  • Pour ne pas utiliser chkconfig, désactivez tous les services hors mcstrans, network, portmap, sshd et syslog.
  • Puis, allez à RecoveryMode et y faitez le montage de la partition root.
  • Ecrivez les suivants:
rm -f /mnt/var/log/*
rm -f /mnt/root/.bash_history
  • et les modules à nouveau parce que on n'en a plus besoin:
rm -rf /mnt/lib/modules/*
  • Désactivez SELinux - spécifiez le suivant dans /mnt/etc/selinux/config:
SELINUX=disabled
  • Archivez:
tar -cpjf root.tar.bz2 /mnt/*
  • ensuite, placez dans le gabarit.

Configurez le noyau

  • Il est à noter que vous n'avez plus besoin 'initrd':
#CONFIG_BLK_DEV_INITRD is not set

Si vous démarrez le même noyau via réseau, les suivants ne sont plus demandés:

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

Ensuite, archivez les modules et placez-les dans le gabarit.

Il faut avoir un gabarit grub.conf:

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

Gabarits suivants:

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


Ajoutez les suivants dans install.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 #и замести следы

Script d'installation:

#!/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.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.sh
send_msg 
reboot
;;
esac
Cet article vous a-t-il été utile? Oui | Non
Outils personnels