歡迎您光臨本站 註冊首頁

pex無人守護安裝linux系統腳本

←手機掃碼閱讀     火星人 @ 2014-03-08 , reply:0

linux 系統安裝大體分為兩個階段
1,anaconda階段(anaconda程序藉助linux內核和initrd文件實現),也稱配置階段
在這個階段是安裝配置階段,配置語言,鍵盤,等信息.同時boot提示符下能夠向內核傳遞參數.
2,安裝階段.
安裝前腳本配置
安裝軟體包階段
安裝後腳本配置

.....................................................................................
pxe無人值守網路安裝redhat linux系統腳本
.....................................................................................
要實現上面的功能,我們需要配置DHCP服務 NFS服務 TFTP服務,具體原理網上很多 ,在這我只提供一個腳本和我在實現中遇到的故障

在執行這個腳本的時候要先配置好yum源,自己主機在172.16.8.0/24網段

#!/bin/bash
myip=`ifconfig | awk -F: '/inet addr/{print $2}' | grep -v "127.0.0.1" | cut -d' ' -f1 | cut -d'.' -f4`
[ ! -e /mnt/cdrom ] && mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
function setdhcp {
yum -y install dhcp
[ $? -eq 0 ] && "echo install ok ...................................."
mv /etc/dhcpd.conf /etc/dhcpd.conf.bak
cat >> /etc/dhcpd.conf << EOF
ddns-update-style interim;
ignore client-updates;
allow booting;
allow bootp;
next-server 172.16.8.$myip;
filename "pxelinux.0";
subnet 172.16.8.0 netmask 255.255.255.0 {

option routers 172.16.8.$myip;
option subnet-mask 255.255.255.0;
option domain-name-servers 172.16.8.$myip;
option routers 172.16.8.$myip;
option subnet-mask 255.255.255.0;
option domain-name "domain.org";


option domain-name-servers 172.16.8.$myip;
option time-offset -18000; # Eastern Standard Time
range 172.16.8.200 172.16.8.220;
default-lease-time 21600;
max-lease-time 43200;
}
EOF
[ $? -eq 0 ] && echo " dhcp.conf is ok ..........................................."
service dhcpd start
[ $? -eq 0 ] && echo -e "\033[32mthe server dhcp start is ok......\033[0m" || exit 10
chkconfig dhcpd on
sync
}

function settftp {
yum -y install tftp-server
[ $? -eq 0 ] && "echo install ok ...................................."
sed -i "s@disable[[:space:]]*= yes@disable = no@g" /etc/xinetd.d/tftp
service xinetd restart
mkdir /tftpboot
}

function setpxe {
cp /usr/lib/syslinux/pxelinux.0 /tftpboot
cp /mnt/cdrom/images/pxeboot/{vmlinuz,initrd.img} /tftpboot
cp /mnt/cdrom/isolinux/*.msg /tftpboot/
[ $? -eq 0 ] && "cp vmlinuz,initrd.img is ok ..............................."
mkdir /tftpboot/pxelinux.cfg
#cp /mnt/cdrom/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default####也可以直接cp,然後用sed修改部分參數
cat >> /tftpboot/pxelinux.cfg/default << EOF
default linux
prompt 1
timeout 60
display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
label linux
kernel vmlinuz
append ks=nfs:172.16.8.$myip:/iso/ks.cfg initrd=initrd.img
label text
kernel vmlinuz
append initrd=initrd.img text
label ks
kernel vmlinuz
append ks initrd=initrd.img
label local
localboot 1
label memtest86
kernel memtest


append -
EOF
chmod 755 /tftpboot/*
mkdir -pv /iso/install
cp /root/redhat5.4.iso /iso/install #################需要鏡像
echo "/iso *(ro,sync)" >> /etc/exports
service nfs restart
chkconfig nfs on
}


function setks {
#cp /root/anaconda-ks.cfg /iso/ks.cfg####也可以直接cp,然後用sed修改部分參數,感覺sed修改這些參數很麻煩所以就cat一個文件
if [ ! -e /iso/ks.cfg ];then
cat >> /iso/ks.cfg << EOF
text
nfs --server=172.16.8.$myip --dir=/iso/install
key --skip
lang en_US.UTF-8
keyboard us
xconfig --startxonboot --resolution 1024x768 --depth 16
network --device eth0 --bootproto dhcp
rootpw --iscrypted $1$.Nwkli1d$Yr7n8.Oa0w9gl/K3Xe21/1 #########需要換成你自己設置的密碼
firewall --disabled
authconfig --useshadow --enablemd5
selinux --enforcing
timezone --utc Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="rhgb quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
clearpart --all --initlabel
part /boot --fstype ext3 --size=100
part pv.100000 --size=40960
part swap --size=512
volgroup vol0 --pesize=32768 pv.100000
logvol / --fstype ext3 --name=root --vgname=vol0 --size=29984
logvol /home --fstype ext3 --name=home --vgname=vol0 --size=1984

%packages
@GNOME Desktop Environment
@X Window System
@Printing Support
@Development Tools
elinks
openssh
openssh-server
openssh-clients
vim-enhanced
samba-common
samba-client
gimp


gimp-data-extras
enscript
libcap
ntp
coreutils
elfutils
elfutils-libelf
gimp-print-plugin
gnome-icon-theme
gstreamer
gstreamer-tools
libgnomeprint22
libgnomeprintui22
libgsf
libIDL
libraw1394
nautilus-cd-burner
openmotif
pyorbit
startup-notification
ttmkfdir
firefox
mutt
dialog
EOF
chmod rx /iso/ks.cfg ######################修改許可權
else
echo "the file exit......................."
fi
}

setdhcp
settftp
setpxe
setks
.....................................................................................................................
說明 這個腳本有局限性,我隨後有時間會加以修改,需要注意和容易犯錯的地方我已經用##號備註,使用的時候可以根據自己的實際情況修改.

本文出自 「gabylinux.blog.51cto.com」 博客,請務必保留此出處http://gabylinux.blog.51cto.com/1593644/764088


[火星人 ] pex無人守護安裝linux系統腳本已經有631次圍觀

http://coctec.com/docs/linux/show-post-46840.html