寫了一個腳本(見下面的鏈接),利用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