根据业务定制自动安装CentOS
过几天机房要上架29台服务器,需要装系统。机器太多,想自动化安装,由于没测试机,实验都在虚拟机实现,为了能快点部署完,想了几套方案,毕竟早点部署完, 就可以回宿舍,不用去公司了。
大体操作是:找一个DVD,安装方式根据业务需要来(如:分区 安装包 语言等),这样在安装完,系统会创建一个自动安装系统cfg模版文件,在/root目录下。同时root目录下有一个install.log日志文件,里面记录了这个系统安装了什么包,等下就根据这个文件记录,从DVD光盘提取需要的包,重新封装成新镜像,然后把root目录下的自动安装文件复制到新镜像目录下,再做点小修改就可以了。 第一步:先挂载DVD镜像;[root@linuxso.com ~]# mount /dev/cdrom /mnt###我把镜像挂载到了/mnt目录下 第二步:创建一个目录 ,用来保存需要业务包 和封装新镜像的文件;
[root@linuxso.com ~]# mkdir -p iso/CentOS [root@linuxso.com ~]# awk '/Installing/{print $2}' install.log | sed 's/^[0-9]*://g' >package.txtpackage.txt 文件里保存的就是当前系统里安装的所有包; 第四步:根据package 内容,从DVD镜像提取需要的包,放到/root/iso/CentOS目录;
[root@linuxso.com ~]# cat cp.sh #!/bin/bash DVD='/mnt/CentOS' #DVD镜像存放包路径 PACKDIR='/root/package.txt' #记录的是现在系统里安装的所有包名 NEW_DVD='/root/iso/CentOS/' # 新镜像需要包的存放路径 while read LINE do cp ${DVD}/${LINE}*.rpm /${NEW_DVD} || echo "$LINE don't cp......." done < package.txt第五步:把镜像需要的其他文件也拷贝到iso目录下,这样就和挂载的DVD镜像没区别了,除了缺少某些包以外。
[root@linuxso.com ~]# cat anaconda-ks.cfg | grep -v "^#" install cdrom lang en_US.UTF-8 keyboard us network --device eth0 --bootproto static --ip 192.168.0.45 --netmask 255.255.255.0 --gateway 192.168.0.1 rootpw --iscrypted $1$cT7w.PYF$autqNIf5WqO0P.3CW5nru. firewall --enabled --port=22:tcp authconfig --enableshadow --enablemd5 selinux --enforcing timezone --utc Asia/Shanghai bootloader --location=mbr --driveorder=sda clearpart --linux part /boot --fstype ext3 --size=100 part swap --size=2000 part / --fstype ext3 --size=100 --grow %packages @linuxso.com ~]# cp anaconda-ks.cfg /root/iso#大家可以根据需求 再添加写脚本到这文件里 第七步:修改/root/iso/isolinux/isolinux.cfg
[root@linuxso.com ~]# vim /root/iso/isolinux/isolinux.cfg Default linux 修改成default linux ks=cdrom:/anaconda-ks.cfg保存就可以了 第八步:生成comps.xml文件
[root@linuxso.com ~]# cd /root/iso/ [root@linuxso.com ~]# mkisofs -o MyCentOS.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -T /root/iso/第十步:生成MD5验证码
[root@linuxso.com ~]# /usr/lib/anaconda-runtime/implantisomd5 new_MyCentOS.iso Inserting md5sum into iso image... md5 = 82cc70b16908bea468a2ce1c263dee9a Inserting fragment md5sums into iso image... fragmd5 = bdf4b332ccf4a6fafe883a4cff54527df985ac2ee71be3c6c66d51e3421c frags = 20 Setting supported flag to 0 [root@linuxso.com ~]#如果提示没这个命令,yum –y install anaconda-runtime 安装 以上内容参考http://liusy23.blog.51cto.com/1306558/280831