测试环境:CentOS 5.5 x86_64
1.安装所需的软件包:
[root@localhost ~]# yum -y install createrepo mkisofs anaconda-runtime
2.生成安装系统所需要的rpm列表
[root@localhost ~]# awk '/Installing/{print $2}' install.log |sed 's/^[0-9]*://g' >/root/packages.list
3.建立定制所需要的目录
[root@localhost ~]# mkdir /mnt/cdrom
[root@localhost ~]# mkdir -p /data/OS
[root@localhost ~]# mount /dev/hdc /mnt/cdrom/
[root@localhost ~]# rsync -a --exclude=CentOS /mnt/cdrom/ /data/OS/
[root@localhost ~]# mkdir /data/OS/CentOS
4.使用脚本自动复制RPM包
[root@localhost ~]# vim cprpms.sh
- #!/bin/bash
- SRC_RPMS=/mnt/cdrom/CentOS
- DST_RPMS=/data/OS/CentOS
- packages_list=/root/packages.list
- number_of_packages=`cat $packages_list | wc -l`
- i=1
- while [ $i -le $number_of_packages ] ;
- do
- name=`head -n $i $packages_list | tail -n -1`
- echo "cp $SRC_RPMS/$name* $DST_RPMS/"
- cp $SRC_RPMS/$name* $DST_RPMS/
- i=`expr $i + 1`
- done
[root@localhost ~]# sh cprpms.sh
5.配置kickstart脚本
[root@localhost ~]# vim /data/OS/isolinux/ks.cfg
- #platform=x86, AMD64, or Intel EM64T
- # System authorization information
- auth --useshadow --enablemd5
- # System bootloader configuration
- bootloader --location=mbr
- # Clear the Master Boot Record
- zerombr
- # Partition clearing information
- clearpart --all --initlabel
- # Use text mode install
- text
- # Firewall configuration
- firewall --disabled
- # Run the Setup Agent on first boot
- firstboot --disable
- # System keyboard
- keyboard us
- # System language
- lang en_US
- # Installation logging level
- logging --level=info
- #Use CDROM installation media
- cdrom
- # Network information
- network --bootproto=dhcp --device=eth0 --onboot=on
- # Reboot after installation
- reboot
- #Root password default is “redhat”
- rootpw --iscrypted $1$36bsCbH1$UDJ6eCqPi2Nm1KsgajvHs1
- # SELinux configuration
- selinux --disabled
- # Do not configure the X Window System
- skipx
- # System timezone
- timezone --isUtc Asia/Shanghai
- # Install OS instead of upgrade
- install
- # Disk partitioning information
- part / --bytes-per-inode=4096 --fstype="ext3" --size=10000
- part swap --bytes-per-inode=4096 --size=2048
- part /data --bytes-per-inode=4096 --fstype="ext3" --grow --size=1
- part /boot --bytes-per-inode=4096 --fstype="ext3" --size=100
- %packages
- @base
- @development-libs
- @development-tools
- @core
- @text-internet
- @editors
- keyutils
- trousers
- fipscheck
- device-mapper-multipath
- imake
- ntp
6.让系统从kickstart配置启动安装
[root@localhost OS]# vim /data/OS/isolinux/isolinux.cfg
- default linux
- label linux
- kernel vmlinuz
- append ks=cdrom:/isolinux/ks.cfg initrdinitrd=initrd.img
7.生成rpm包的依赖关系
[root@localhost ~]# cd /data/OS/
[root@localhost OS]# createrepo -g repodata/comps.xml /data/OS/
[root@localhost OS]# declare -x discinfo=`head -1 .discinfo`
[root@localhost OS]# createrepo -u "media://$discinfo" -g repodata/comps.xml /data/OS/
8.生成ISO镜像文件
[root@localhost ~]# cd /data/OS/
[root@localhost OS]# mkisofs -R -J -T -r -l -d -joliet-long -allow-multidot \
> -allow-leading-dots -no-bak -o /data/CentOS-5.5-x86_64.iso \
> -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot \
> -boot-load-size 4 -boot-info-table /data/OS
9.生成MD5校验码
[root@localhost ~]# /usr/lib/anaconda-runtime/implantisomd5 /data/CentOS-5.5-x86_64.iso