定制CentOS 5.6精简的自动安装版
原创
©著作权归作者所有:来自51CTO博客作者navyaijm2012的原创作品,请联系作者获取转载授权,否则将追究法律责任
由于工作需要,要制定属于自己公司的系统,下面我把过程给大家分享一下,有什么缺陷大家给指点一下。
1.首先要找一台服务器安装要封装的系统对应的版本,这里我封装的CentOS5.6,安装过程中,在选择要安装的包的时候,要根据自己公司的需要选择。
2.安装制作发行版所需的基本软件包
yum –y install createrepo mkisofs
3.生成安装系统所需的rpm文件列表
awk '/Installing/{print $2}' install.log |sed 's/^[0-9]*://g' >/root/packages.list
4.创建定制工作目录
mkdir -p /mnt/cdrom
mkdir -p /data/OS
mount /dev/cdrom /mnt/cdrom
rsync -a --exclude=CentOS /mnt/cdrom/* /data/OS/
cp /mnt/cdrom/.discinfo /data/OS/
mkdir /data/OS/CentOS
5.复制精简后的RPM包
vi /data/cprmps.sh
#创建自动复制RPM包脚本
#!/bin/bash
DEBUG=0
CentOS_DVD=/mnt/cdrom
ALL_RPMS_DIR=/mnt/cdrom/CentOS #源光盘RPM包存放的目录
KOS_RPMS_DIR=/data/OS/CentOS #精简后RPM包存放的目录
packages_list=/root/packages.list #精简后的RPM包列表
number_of_packages=`cat $packages_list | wc -l`
i=1
while [ $i -le $number_of_packages ] ; do
line=`head -n $i $packages_list | tail -n -1`
name=`echo $line | awk '{print $1}'`
version=`echo $line | awk '{print $3}' | cut -f 2 -d :`
if [ $DEBUG -eq "1" ] ; then
echo $i: $line
echo $name
echo $version
fi
if [ $DEBUG -eq "1" ] ; then
ls $ALL_RPMS_DIR/$name-$version*
if [ $? -ne 0 ] ; then
echo "cp $ALL_RPMS_DIR/$name-$version* "
fi
else
echo "cp $ALL_RPMS_DIR/$name-$version* $KOS_RPMS_DIR/"
cp $ALL_RPMS_DIR/$name-$version* $KOS_RPMS_DIR/
# in case the copy failed
if [ $? -ne 0 ] ; then
echo "cp $ALL_RPMS_DIR/$name-$version* "
cp $ALL_RPMS_DIR/$name* $KOS_RPMS_DIR/
fi
fi
i=`expr $i + 1`
done
执行:
chmod +x cprpm.sh
./cprpm.sh
6.配置kickstart脚本
vi /data/OS/isolinux/ks.cfg
# Kickstart file automatically generated by anaconda.
#Install OS instead of upgrade
install
#Use text mode install
text
#Use CDROM installation media
cdrom
lang en_US.UTF-8
keyboard us
#Skip the X Configuration
skipx
#Network information
#root -- 1q2w3e
rootpw --iscrypted $1$UJlaGQFP$.Wf93SJYnar9yDIzS8YDr1
firewall --disabled
#System authorization information
authconfig --enableshadow --enablemd5
selinux --disabled
timezone --utc Asia/Shanghai
#System bootloader configuration
bootloader --location=mbr
#Clear the Master Boot Record
zerombr yes
# 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
#Partition clearing information
clearpart --linux
part /boot --fstype ext3 --size=100
part pv.7 --size=30000
part swap --size=10000
part pv.10 --size=100 --grow
volgroup VolGroupData pv.10
volgroup VolGroupRoot pv.7
logvol / --fstype ext3 --name=LogVolRoot --vgname=VolGroupRoot --size=29900
logvol /data/logs --fstype ext3 --name=LogVolLogs --vgname=VolGroupData --size=10000
logvol /data --fstype ext3 --name=LogVolData --vgname=VolGroupData --size=1 --grow
#--- Reboot the host after installation is done
reboot
%packages
@base
@core
@development-libs
@development-tools
@editors
@text-internet
keyutils
iscsi-initiator-utils
trousers
fipscheck
device-mapper-multipath
imake
%post
#vim syntax on
sed -i "8 s/^/alias vi='vim'/" /root/.bashrc 2>/dev/null
echo 'syntax on' > /root/.vimrc 2>/dev/null
#init_ssh
ssh_cf="/etc/ssh/sshd_config"
sed -i -e '74 s/^/#/' -i -e '76 s/^/#/' $ssh_cf
sed -i "s/#UseDNS yes/UseDNS no/" $ssh_cf
#client
sed -i -e '44 s/^/#/' -i -e '48 s/^/#/' $ssh_cf
# Remove the ISO File translation files
find / -name TRANS.TBL -exec rm {} \; /dev/null 2>/dev/null
# Remove some unneeded services
#--------------------------------------------------------------------------------
cat << EOF
+--------------------------------------------------------------+
| === Welcome to Tunoff services === |
+--------------------------------------------------------------+
EOF
#---------------------------------------------------------------------------------
for i in `ls /etc/rc3.d/S*`
do
CURSRV=`echo $i|cut -c 15-`
echo $CURSRV
case $CURSRV in
crond | irqbalance | microcode_ctl | network | random | sshd | syslog | local )
echo "Base services, Skip!"
;;
*)
echo "change $CURSRV to off"
chkconfig --level 235 $CURSRV off
service $CURSRV stop
;;
esac
done
# file descriptors
ulimit -HSn 65535
echo -ne "
* soft nofile 65536
* hard nofile 65536
" >>/etc/security/limits.conf
#set sysctl
true > /etc/sysctl.conf
cat >> /etc/sysctl.conf <<EOF
net.ipv4.ip_forward = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.tcp_syncookies = 1
net.core.somaxconn = 204800
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_fin_timeout = 5
net.ipv4.tcp_retries1 = 3
net.ipv4.tcp_retries2 = 3
net.ipv4.tcp_orphan_retries = 3
net.ipv4.tcp_keepalive_time = 60
net.ipv4.netfilter.ip_conntrack_max = 6553600
net.core.netdev_max_backlog = 8096
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 150000
EOF
/sbin/sysctl -p
#close ctrl+alt+del
sed -i "s/ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/#ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/" /etc/inittab
#set purview
chmod 600 /etc/passwd
chmod 600 /etc/shadow
chmod 600 /etc/group
chmod 600 /etc/gshadow
7.生成comps.xml
cd /data/OS
createrepo –g repodata/comps.xml /data/OS/
8.让系统从kickstart配置启动安装
vi /data/OS/isolinux/isolinux.cfg
default text
prompt 1
timeout 100
display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
label linux
kernel vmlinuz
append initrd=initrd.img
label text
kernel vmlinuz
append ks=cdrom:/isolinux/ks.cfg initrd=initrd.img
label ks
kernel vmlinuz
append ks initrd=initrd.img
label local
localboot 1
label memtest86
9.生成ISO文件
cd /data/OS
declare -x discinfo=`head -1 .discinfo`
createrepo -u "media://$discinfo" -g repodata/comps.xml /data/OS/
mkisofs -R -J -T -r -l -d -joliet-long -allow-multidot -allow-leading-dots -no-bak -o /data/kingsoft_navy_1.0.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table /data/OS
10.生成MD5检验码
/usr/bin/md5sum /data/kingsoft_navy_1.0.iso
到此,系统分装完成,谢谢。