1.下载需要的软件包
使用downloadonly命令下载需要的软件包(只下载不安装),将软件包保存到/rpm目录下:
[root@localhost ~]# mkdir -p /rpm
[root@localhost ~]# yum -y install yum-downloadonly
[root@localhost ~]# yum install –downloadonly –downloaddir=/rpm ntp net-snmp net-snmp-devel net-snmp-utils php-snmp expect mysql-devel mysql-server gcc-c++ make wget kvm libvirt python-virtinst scons ruby-devel ruby-docs ruby-ri flex bison xmlrpc-c-devel
2.挂载光盘将原光盘镜像内容同步
[root@localhost ~]# yum -y install createrepo mkisofs rsync
[root@localhost ~]# mkdir -p /data/OS
[root@localhost ~]# mkdir -p /mnt/cdrom
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom
[root@localhost ~]# rsync -a /mnt/cdrom/* /data/OS/
[root@localhost ~]# cp /mnt/cdrom/.discinfo /data/OS/
3.将下载的软件包copy到Packages目录下
[root@localhost ~]#cp /mfs/* /data/OS/Packages/
4.配置kickstart脚本
[root@localhost ~]#vi /data/OS/isolinux/ks.cfg
# Kickstart file automatically generated by anaconda.
#version=DEVEL
# Install OS instead of upgrade
install
# Use CDROM installation media
cdrom
# Install OS language
lang zh_CN.UTF-8
# Keyboardlanguage
keyboard us
# Install OS Network
network –onboot no –bootproto dhcp –hostname=ezCloud –noipv6
# Root password default is “ezcloud”
rootpw ezcloud
# Firewall configuration
firewall –disabled
# Firewall configuration
authconfig –enableshadow –passalgo=sha512
# Skip xwindows
skipx
# Selinuxconfiguration
selinux –disabled
# Timezone config
timezone –utc Asia/Shanghai
bootloader –location=mbr
# Clear disk part
clearpart –all –initlabel
# Disk Partition information
part /boot –fstype=ext4 –size=200
part / –fstype=ext4 –size=10240
part swap –size=2048
part /data –fstype=ext4 –grow –size=200
#repo –name=”CentOS” –baseurl=cdrom:sr0 –cost=100
reboot
%packages –nobase
@core
ntp
vixie-cron
net-snmp-devel
net-snmp-utils
php-snmp
expect
mysql-devel
mysql-server
gcc-c++
make
wget
kvm
libvirt
python-virtinst
scons
ruby-devel
ruby-docs
ruby-ri
flex
bison
xmlrpc-c-devel
puppet-server
%end
5.系统从kickstart启动配置
[root@localhost ~]# vi /data/OS/isolinux/isolinux.cfg
default linux
label linux
kernel vmlinuz
append ks=cdrom:/isolinux/ks.cfg initrd=initrd.img
6.生成rpm包的依赖关系
[root@localhost ~]# cd /data/OS/
[root@localhost OS]# createrepo -g repodata/*minimal-x86_64.xml /data/OS/
[root@localhost OS]# declare -x discinfo=`head -1 .discinfo`
[root@localhost OS]# createrepo -u “media://$discinfo” -g repodata/*minimal-x86_64.xml /data/OS/
7.生成ISO镜像文件
[root@localhost OS]# mkisofs -R -J -T -r -l -d -joliet-long -allow-multidot -allow-leading-dots -no-bak -o /data/CentOS-6.3-x86_64.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table /data/OS
8.生成MD5校验码
[root@localhost OS]# /usr/bin/md5sum /data/CentOS-6.3-x86_64.iso
02601a627d6fd0a021c6876806d884bd /data/CentOS-6.3-x86_64.iso
[root@localhost OS]#
总结:
问题1:
yum下载需要的软件包时尽量精简,确认需要下载的软件包名字正确,安全起见,最好逐个下载。
问题2:
生成镜像安装时可能出现如下提示:
“有些您选择要安装的软件包缺少相依性………….”
问题在于第一步下载的软件包中,被依赖的软件包也有依赖关系,而这些依赖包在批量yum时不会被下载。
解决办法:
1.mkdir -p /rpmsec
2.yum install –downloadonly –downloaddir=/rpmsec 图片中的软件包;
3.把这些包也放到Packages目录下,cp /rpmsec/* /data/OS/Packages/
4.重做步骤6-8;