Skip to content

Instantly share code, notes, and snippets.

@shalk
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shalk/af4560420a0563bb2161 to your computer and use it in GitHub Desktop.
Save shalk/af4560420a0563bb2161 to your computer and use it in GitHub Desktop.
安装好一台suse11SP2,将iso,autoinst.xml 和susepxe.sh 上传到/root目录,修改脚本中开头的参数,再sh susepxe.sh 就建立PXE服务器,可以批量安装SUSE
#!/bin/bash
# prepare:
# a server installed suse 11 sp2
# ISO of suse
# autoinst.xml
# this script
# usage:
# modify this script's line between 18 ~ 26
# make this parameter correct
# description:
# this server is a dhcp(PXE) server and tftp server and vsftp srever
# dhcp use local_eth as dhcp enthernet interface
# other machines in the broadcast using pxe boot will use the autoinstfile and install suse paralel
# if you want paralel and automation ,you can modify the xml .
#
#
isofile='/root/SLES-11-SP2-DVD-x86_64-GM-DVD1.iso'
autoxmlfilename='my_autoinst.xml'
autoxml="/root/${autoxmlfilename}"
local_eth='br0'
local_ip='10.5.101.17'
local_netmask='255.255.255.0'
local_network='10.5.101.0'
local_range1='10.5.101.150'
local_range2='10.5.101.200'
mount_path="/media"
if [ ! -f $isofile ] ;then
echo $isofile is not exist!
fi
if [ ! -f $autoxml ] ;then
echo $autoxml is not exist!
fi
backup(){
local file1=$1
[ ! -f ${file1}.bak ] && cp -rf ${file1}{,.bak}
}
restore(){
local file1=$1
[ -f ${file1}.bak ] && cp -rf ${file1}{.bak,}
}
# mount iso
install(){
mkdir -p $mount_path
mount -t iso9660 -o loop $isofile $mount_path
cd ${mount_path}/suse/x86_64
#install rpm
rpm -ivh dhcp*
rpm -ivh syslinux*
rpm -ivh tftp*
rpm -ivh vsftpd*
#restore and bakcup
#modify dhcp
`restore /etc/dhcpd.conf`
`backup /etc/dhcpd.conf`
cat >> /etc/dhcpd.conf << EOF
default-lease-time 14400;
ddns-update-style none;
next-server $local_ip;
filename "pxelinux.0";
subnet $local_network netmask $local_netmask {
range $local_range1 $local_range2;
default-lease-time 14400;
max-lease-time 172800;
}
EOF
`restore /etc/sysconfig/dhcpd`
`backup /etc/sysconfig/dhcpd`
sed -i "s/DHCPD_INTERFACE=\"\"/DHCPD_INTERFACE=\"${local_eth}\"/" /etc/sysconfig/dhcpd
service dhcpd restart
#tftp
`restore /etc/xinetd.d/tftp`
`backup /etc/xinetd.d/tftp`
perl -p -i -e "s/yes/no/ if /disable/ " /etc/xinetd.d/tftp
service xinetd restart
# prepare tftp file
mkdir -p /tftpboot/
mkdir -p /tftpboot/pxelinux.cfg
cp -rf ${mount_path}/boot/x86_64/loader/initrd /tftpboot/
cp -rf ${mount_path}/boot/x86_64/loader/linux /tftpboot/
cp -rf /usr/share/syslinux/pxelinux.0 /tftpboot/
touch /tftpboot/pxelinux.cfg/default
> /tftpboot/pxelinux.cfg/default
cat >> /tftpboot/pxelinux.cfg/default <<EOF
default linux
lable linux
kernel linux
append initrd=initrd autoyast=ftp://${local_ip}/${autoxmlfilename} install=ftp://${local_ip}/suse/ splash=verbose showopts
EOF
mkdir -p /srv/ftp/
cp -rf $autoxml /srv/ftp/
cd /srv/ftp
mkdir suse -p
umount $mount_path
mount -t iso9660 -o loop $isofile /srv/ftp/suse/
service vsftpd restart
}
uninstall(){
service vsftpd stop
service dhcpd stop
}
install
@shalk
Copy link
Author

shalk commented Jul 29, 2014

停止PXE 操作,执行
service vsftpd stop
service dhcpd stop
umount /srv/ftp/suse/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment