写了一个脚本(见下面的链接),利用kickstart文件 + 脚本来生成自动安装的ISO, 基于CentOS 6的,在CentOS 6.2下测试没问题,估计CentOS 6.*都没什么问题
免费下载地址在 http://linux.linuxidc.com/
用户名与密码都是www.linuxidc.com
具体下载目录在 /2012年资料/3月/30日/Shell脚本+Kickstart文件定制CentOS 6/
这个脚本的最大的特点就是不需要CentOS的官方原版ISO镜像,所有需要的文件都是通过网络下载,有的是从sohu的镜像源,有的是163的(分散压力,呵呵) 这样做的还有一个好处就是安装的rpm包都是最新的,进入系统之后,不需要yum -y update了 (适合有洁癖的人)
然后,rpm包都是通过yum安装,这里我安装了一个yum的插件,达到只下载不安装的目的,另外就是用yum的时候,还指定了一个–installroot的参数,让yum不去读本机的数据库,如果不加这个参数,就不能顺利的下载本机已经安装过的包
ks.cfg是用system-config-kickstart生成的kickstart配置文件,如果没有这个命令,就yum -y install system-config-kickstart来安装一下就行,也可以通过修改本地/root目录下的ananconda-ks.cfg,但需要注意的是这个文件里面有一行需要注释掉或者删除掉
repo –name=”CentOS” –baseurl=cdrom:sr0 –cost=100
如果不注释,安装的时候,ananconda会找这个yum源
650) this.width=650;” border=0>
下面贴出脚本
- #!/bin/bash
- if [ ! -e /root/xiaosu.cfg ];then
- echo “you must put the kickstart file named xiaosu.cfg to /root/”
- exit 1
- fi
- yum -y install yum-plugin-downloadonly createrepo genisoimage
- mv /etc/yum.repos.d/ /etc/yum.repos.d.bak
- mkdir /etc/yum.repos.d
- cat >/etc/yum.repos.d/suzezhi.repo << EOF
- [suzezhi-base]
- name=CentOS-$releasever – Base – 163.com
- baseurl=http://mirrors.163.com/centos/6/os/x86_64/
- gpgcheck=1
- gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
- [suzezhi-updates]
- name=CentOS-$releasever – Updates – 163.com
- baseurl=http://mirrors.163.com/centos/6/updates/x86_64/
- gpgcheck=1
- gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
- #additional packages that may be useful
- [suzezhi-extras]
- name=CentOS-$releasever – Extras – 163.com
- baseurl=http://mirrors.163.com/centos/6/extras/x86_64/
- gpgcheck=1
- gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
- #additional packages that extend functionality of existing packages
- [suzezhi-centosplus]
- name=CentOS-$releasever – Plus – 163.com
- baseurl=http://mirrors.163.com/centos/6/centosplus/x86_64/
- gpgcheck=1
- gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
- #contrib – packages by Centos Users
- [suzezhi-contrib]
- name=CentOS-$releasever – Contrib – 163.com
- baseurl=http://mirrors.163.com/centos/6/contrib/x86_64/
- gpgcheck=1
- gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
- EOF
- mkdir -p /tmp/suzezhi/temp
- cd /tmp/suzezhi/temp
- wget -r –no-parent -c –cut-dirs=4 –reject=gz –exclude-directories=centos/6/os/x86_64/Packages http://mirrors.sohu.com/centos/6/os/x86_64/
- find . -name index.html -exec rm -f {} \;
- cat >> /tmp/suzezhi/temp/yum.conf <<EOF
- [main]
- cachedir=/var/cache/Packages
- keepcache=0
- debuglevel=2
- logfile=/var/log/yum.log
- exactarch=1
- obsoletes=1
- gpgcheck=1
- plugins=1
- installonly_limit=5
- bugtracker_url=http://bugs.centos.org/set_project.php?project_id=16&ref=http://bugs.centos.org/bug_report_page.php?category=yum
- distroverpkg=centos-release
- EOF
- for i in $(awk ‘/^%packages$/,/^%end$/’ /root/xiaosu.cfg |grep -v -E ‘%end|%packages’); do
- yum –installroot=/tmp/suzezhi/test -c yum.conf –downloadonly –downloaddir=/tmp/suzezhi/Packages -y install $i
- done
- rm -rf /etc/yum.repos.d
- mv /etc/yum.repos.d.bak /etc/yum.repos.d
- cd /tmp/suzezhi/
- mv Packages/ /tmp/suzezhi/temp/mirrors.sohu.com/
- cd /tmp/suzezhi/temp/mirrors.sohu.com
- cat > .discinfo << EOF
- 1333560292.885204
- 6
- x86_64
- 1
- EOF
- cat > .treeinfo << EOF
- [general]
- family = CentOS
- timestamp = 1333560005.81
- variant =
- totaldiscs = 1
- version = 6
- discnum = 1
- packagedir = Packages
- arch = x86_64
- [images-x86_64]
- kernel = images/pxeboot/vmlinuz
- initrd = images/pxeboot/initrd.img
- [images-xen]
- kernel = images/pxeboot/vmlinuz
- initrd = images/pxeboot/initrd.img
- [stage2]
- mainimage = images/install.img
- EOF
- cp /root/xiaosu.cfg .
- sed -i “/menu default/d” isolinux/isolinux.cfg
- cat >> isolinux/isolinux.cfg << EOF
- label auto
- menu label ^Auto install an system
- menu default
- kernel vmlinuz
- append ks=cdrom:/xiaosu.cfg initrdinitrd=initrd.img
- EOF
- mv repodata/*-comps.xml .
- rm -f repodata/*
- mv *-comps.xml repodata
- createrepo -d –unique-md-filenames -g repodata/*-comps.xml .
- cd ..
- mkisofs -R -J -T -r -l -d -joliet-long -allow-multidot -allow-leading-dots -no-bak -o /root/xiaosu.iso -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table mirrors.sohu.com/
- rm -rf /tmp/suzezhi
下面解释一下大概的意思
先检测 /root目录下面有没有文件名为xiaosu.cfg的kickstart配置文件
然后安装制作ISO包和yum的插件还有创建yum源数据库的包
备份原来的yum配置文件
将163的源写入配置文件
创建目录
用wget从sohu的镜像源上下载ISO文件中必须的一些文件(比如initrd文件,install.img)
生成一个临时的yum配置文件
从kickstart配置文件中读取需要安装的包,然后用一个for循环遍历安装
恢复原来的配置文件
生成ISO中必须的文本文件.treeinfo 和 .discinfo
将kickstart的配置文件复制到光盘目录
用sed取消掉原来的默认选项 然后追加一个自动安装的选项(如刚才那个图片所示,开机之后,自动将光标停留在自动安装的选项上)
重新生成yum源的数据库
生成ISO文件,并放到/root目录下
再贴一下xiaosu.cfg
- #platform=x86, AMD64, 或 Intel EM64T
- #version=DEVEL
- # Firewall configuration
- firewall –disabled
- # Install OS instead of upgrade
- install
- # Use CDROM installation media
- cdrom
- # Root password
- rootpw –iscrypted $1$oSWcILwo$7OFkCcL9u6jvQxFeavj5V0
- # System authorization information
- auth –useshadow –passalgo=sha512
- # Use graphical install
- graphical
- firstboot –disable
- # System keyboard
- keyboard us
- # System language
- lang en_US
- # SELinux configuration
- selinux –disabled
- # Installation logging level
- logging –level=info
- # Reboot after installation
- reboot
- # System timezone
- timezone Asia/Shanghai
- # Network information
- network –bootproto=dhcp –device=eth0 –onboot=on
- zerombr
- # System bootloader configuration
- bootloader –location=mbr
- # Partition clearing information
- clearpart –all
- # Disk partitioning information
- part / –fstype=“ext4” –ondisk=sda –size=10000
- part /boot –fstype=“ext4” –ondisk=sda –size=100
- part swap –fstype=“swap” –ondisk=sda –size=1000
- %packages
- @base
- @client-mgmt-tools
- @chinese-support
- @core
- @basic-desktop
- @desktop-platform
- @fonts
- @general-desktop
- @graphical-admin-tools
- @input-methods
- @internet-applications
- @internet-browser
- @java-platform
- @legacy-x
- @server-platform
- @server-policy
- @x11
- mtools
- pax
- oddjob
- sgpio
- wodim
- abrt-gui
- certmonger
- pam_krb5
- krb5-workstation
- libXmu
- %end