关于CentOS5.X的系统定制,网上有不少很好的资料,但本人在实践6.X系统定制的时候,遇到问题不少,此文是对本次系统定制的一个总结,大家多多交流。
CentOS 6.2 X86_64有两张DVD,第二张DVD也用得到,所以定制光盘的时候,需要把两张光盘都下载到本地。
系统环境
vm7.14+CentOS 6.2_86_64系统
首先给虚拟机建立2个光驱,用CentOS6.2安装系统,当然也可以不用安装系统这个CentOS6.2系统,在其他5.X版本上制作也一样,但推荐安装,CentOS6.X图形化安装需要700M内存,之前我设置的是400M,直接进入text安装,且无法手动分区,此为系统bug,安装之后可以得到anaconda-ks.cfg,当然也可以用system-config-kickstart工具制作,关于ks制作,此处不讲解,附上我的ks文件内容:
ks.cfg文件内容(ks文件决定需要复制哪些文件包)
- # Kickstart file automatically generated by anaconda.
-
- #version=DEVEL
- install
- text
- cdrom
- lang en_US.UTF-8
- keyboard us
- skipx
- network –onboot yes –device eth0 –bootproto static –ip 192.168.16.154 –netmask 255.255.255.0 –gateway 192.168.16.1 –noipv6 –nameserver 114.114.114.114
- rootpw itnihao
- firewall –service=ssh –port=9090:tcp
- authconfig –enableshadow –passalgo=sha512
- selinux –enforcing
- timezone –utc Asia/Chongqing
- bootloader –location=mbr –driveorder=sda –append=” rhgb crashkernel=auto 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 –none
- clearpart –all –initlabel
- part /boot –fstype=ext4 –size=2000
- part /var –fstype=ext4 –size=100000
- part swap –size=5000
- part / –fstype=ext4 –grow –size=200
-
- reboot
- #repo –name=“CentOS” –baseurl=cdrom:sr0 –cost=100
-
- %packages –nobase
- @base
- @chinese-support
- @client-mgmt-tools
- @core
- @development
- @legacy-unix
- @network-file-system-client
- @network-tools
- @php
- @performance
- @perl-runtime
- @system-management-snmp
- @server-policy
- @system-admin-tools
- @web-server
- sgpio
- imake
- tcp_wrappers
- iptraf
- php-mysql
- perl-DBD-SQLite
- rrdtool
- crypto-utils
- perl-Cache-Memcached
- perl-CGI-Session
- perl-CGI
- lrzsz
- bind
- bind-chroot
- bind-devel
- mysql
- perl-DBD-MySQL
- mysql-server
- mysql-devel
- createrepo
- python-devel
- -vconfig
- -rng-tools
- -readahead
- -prelink
- -rfkill
- -pinfo
- -rdate
- -words
- -pm-utils
- -pcmciautils
- -usbutils
- -samba-client
- -nfs4-acl-tools
- -nfs-utils
- -cifs-utils
- -webalizer
- -httpd-manual
- zlib-devel
- openssl-devel
- openssl-perl
- openssl098e
- %post –nochroot #在没有切换到安装后系统的时候运行的命令,用于在光盘拷贝文件到系统
- cp /mnt/source/Packages/conf/settings.sh /mnt/sysimage/tmp/
- mv /mnt/sysimage/etc/httpd/conf/httpd.conf /mnt/sysimage/etc/httpd/conf/httpd.conf.back
- mv /mnt/sysimage/etc/snmp/snmpd.conf /mnt/sysimage/etc/snmp/snmpd.conf.back
- cp /mnt/source/Packages/conf/httpd.conf /mnt/sysimage/etc/httpd/conf/httpd.conf
- cp /mnt/source/Packages/conf/snmpd.conf /mnt/sysimage/etc/snmp/snmpd.conf
- cp /mnt/source/Packages/cacti.tar.gz /mnt/sysimage/tmp
- %post #进入安装后的系统
- /tmp/settings.sh
- cd /tmp
- tar zxvf cacti.tar.gz -C /var/www/html
- service mysqld restart
- mysqladmin -uroot password itnihao
- mysql -uroot -pitnihao -e “create database cacti;”
- mysql -uroot -pitnihao -D cacti -e “source /var/www/html/cacti/cacti.sql”
- mysql -uroot -pitnihao -e “grant all privileges on cacti.* to cacti@localhost identified by ‘cacti’;”
- mysql -uroot -pitnihao -e “flush privileges;”
- #mysql -ucacti -pcacti -D cacti</var/www/html/cacti/cacti.sql
- sed -i “s/cactiuser/cacti/g” /var/www/html/cacti/include/config.php
- chmod 777 -R /var/www/html/cacti/rra /var/www/html/cacti/log
- #sntp -P no -r pool.ntp.org
- #hwclock -w
- /usr/sbin/eject
- rm /tmp/*
- %end
#复制系统安装文件到定制的系统目录
- mkdir /mnt/cd{1,2}
mkdir /home/centos/Packages -p
mkdir /home/source
mount /dev/cdrom /mnt/cd1
mount /dev/cdrom1 /mnt/cd2
mount /dev/cdrom /mnt/cd1
mount /dev/cdrom1 /mnt/cd2
awk -F “Installing” ‘{print $2}’ ~/install.log |sed -e ‘/^$/d’ -e ‘s/^ //g’ >/home/source/packges.list
for packges in `cat /home/source/packges.list`
- do
- cp /mnt/cd1/Packages/$packges* /home/centos/Packages
- [ $? != 0 ] && echo “copy $packges is faied!”
- done
-
- rsync -a –exclude=Packages /mnt/cd1/ /home/centos
- rm -rf /home/centos/repodata
- cd /home/centos
- createrepo /home/centos/ #重新生成repodata文件
- createrepo -g repodata/repomd.xml /home/centos #创建组文件,此处似乎有bug,需经过以下处理
附件中有我的packges.list文件列表
前面的内容,百度都能搜到,下面内容是成功的关键所在
vim repodata/repomd.xml
原文件为
- </data>
- <data type=“group_gz”>
- <location href=“repodata/repomd.xml.gz”/>
- <checksum type=“sha256”>76f27114ff5588340a0b175f382a6c32185f94b36fc3495b8ae03db5724a943f</checksum>
- <open-checksum type=“sha256”>ae80d0c6948e128556f79d5b8b69b030899f5a825ada4a0779c29f5f94b9d912</open-checksum>
- <timestamp>1335105744</timestamp>
- </data>
- <data type=“group”>
- <location href=“repodata/repomd.xml”/>
- <checksum type=“sha256”>ae80d0c6948e128556f79d5b8b69b030899f5a825ada4a0779c29f5f94b9d912</checksum>
- <timestamp>1335105744</timestamp>
- </data>
- </repomd>
修改为
- <data type=“group_gz”>
- <location xml:base=“media://1323560292.885204#1” href=”repodata/bedb7dc8fdf920deffbdc5a70ea0d6d77255656556184f5e996e8a88a
- 63d145c-c6-x86_64-comps.xml.gz”/>
- <checksum type=“sha256”>bedb7dc8fdf920deffbdc5a70ea0d6d77255656556184f5e996e8a88a63d145c</checksum>
- <open-checksum type=“sha256”>3a27232698a261aa4022fd270797a3006aa8b8a346cbd6a31fae1466c724d098</open-checksum>
- <timestamp>1324003565</timestamp>
- </data>
- <data type=“group”>
- <location xml:base=“media://1323560292.885204#1” href=”repodata/3a27232698a261aa4022fd270797a3006aa8b8a346cbd6a31fae1466c
- 724d098-c6-x86_64-comps.xml”/>
- <checksum type=“sha256”>3a27232698a261aa4022fd270797a3006aa8b8a346cbd6a31fae1466c724d098</checksum>
- <timestamp>1324003565</timestamp>
- </data>
不修改上面的group,安装的时候会提示无法找到group组里面的包,如core组件无法安装,导致系统无法安装,附图
将ks.cfg文件复制到
- cp ks.cfg /home/CentOS/isolinux/ks.cfg
- #此处的ks.cfg可以自己制作,也可以用我上面的 关于ks文件中的自定义脚本和文件如下所示
ls /home/centos/Packages/conf/
httpd.conf settings.sh snmpd.conf
修改isolinux.cfg ,此文件是光盘启动的自动应答第一步
- cat /home/centos/isolinux/isolinux.cfg
- default auto
- timeout 600
- label auto
- kernel vmlinuz
- append ks=cdrom:/isolinux/ks.cfg initrdinitrd=initrd.img
- #default vesamenu.c32
- #prompt 1
- display boot.msg
经过以上处理,系统可以成功定制,下面是对文件打包
- mkisofs -o itnihaoOS.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -T /home/centos
总结一下,其实对系统简单的定制不是很难,难的是需要反复验证,反复测试,以上的内容经过测试完全可以使用.