定制基于kickstart的Red Hat Enterprise Linux自动安装光盘
作者:Fang Yunlin
email: cst05001@gmail.com
msn: cst05001@hotmail.com
blog:
http://blog.afang.org
版权: GPL + 转载请注明出处
版本: 0.99
目标描述
以Red Hat Enterprise Linux 5 update 3为基础,定制一张DVD光盘。此光盘具有自动安装功
能,安装过程不用任何交互式操作。被安装的系统包含QQ for Linux,Adobe Reader,Adobe
Flash Player,EPEL软件仓库,并进行一些预先配置。
操作步骤
相关资源
QQ for Linux
http://im.qq.com/
EPEL
https://fedoraproject.org/wiki/EPEL
Adobe Reader
http://get.adobe.com/reader/?promoid=BUIGO
如果连软件都找不到,就不用往下看了……
建个文件夹,把我们需要的资源放到一起。
[root@dhcp-0-104 custom-iso]# pwd
/var/custom-iso
[root@dhcp-0-104 custom-iso]# tree
.
`-- source
`-- custom
`-- rpms
|-- AdobeReader_chs-8.1.5-1.i486.rpm
|-- epel-release-5-3.noarch.rpm
|-- flash-plugin-10.0.22.87-release.i386.rpm
`-- linuxqq-v1.0.2-beta1.i386.rpm
3 directories, 4 files
[root@dhcp-0-104 custom-iso]#
我们把RHEL的DVD安装光盘里面的所有内容拷贝到指定目录下
[root@dhcp-0-104 custom-iso]# mount -o loop,ro /data/iso/rhel-server-5.3-i386-
dvd.iso /data/tree/rhel-5.3-server/
[root@dhcp-0-104 custom-iso]# cp -r /data/tree/rhel-5.3-server/* /var/customiso/
source/
[root@dhcp-0-104 custom-iso]# cp -r /data/tree/rhel-5.3-server/.discinfo
/var/custom-iso/source/
[root@dhcp-0-104 custom-iso]# cp -r /data/tree/rhel-5.3-server/.treeinfo
/var/custom-iso/source/
[root@dhcp-0-104 custom-iso]# ls -a source/
. RELEASE-NOTES-kn.html RELEASE-NOTES-U2-kn.html
.. RELEASE-NOTES-ko.html RELEASE-NOTES-U2-ko.html
Cluster RELEASE-NOTES-ml.html RELEASE-NOTES-U2-ml.html
ClusterStorage RELEASE-NOTES-mr.html RELEASE-NOTES-U2-mr.html
custom RELEASE-NOTES-or.html RELEASE-NOTES-U2-or.html
.discinfo RELEASE-NOTES-pa.html RELEASE-NOTES-U2-pa.html
EULA RELEASE-NOTES-pt_BR.html RELEASE-NOTES-U2-
pt_BR.html
eula.en_US RELEASE-NOTES-ru.html RELEASE-NOTES-U2-ru.html
GPL RELEASE-NOTES-si.html RELEASE-NOTES-U2-si.html
p_w_picpaths RELEASE-NOTES-ta.html RELEASE-NOTES-U2-ta.html
isolinux RELEASE-NOTES-te.html RELEASE-NOTES-U2-te.html
README-as.html RELEASE-NOTES-U1-as.html RELEASE-NOTES-U2-
zh_CN.html
README-bn.html RELEASE-NOTES-U1-bn.html RELEASE-NOTES-U2-
zh_TW.html
README-de.html RELEASE-NOTES-U1-de.html RELEASE-NOTES-U3-as.html
README-en RELEASE-NOTES-U1-en RELEASE-NOTES-U3-bn.html
README-en.html RELEASE-NOTES-U1-en.html RELEASE-NOTES-U3-de.html
README-es.html RELEASE-NOTES-U1-es.html RELEASE-NOTES-U3-en
README-fr.html RELEASE-NOTES-U1-fr.html RELEASE-NOTES-U3-en.html
README-gu.html RELEASE-NOTES-U1-gu.html RELEASE-NOTES-U3-es.html
README-hi.html RELEASE-NOTES-U1-hi.html RELEASE-NOTES-U3-fr.html
README-it.html RELEASE-NOTES-U1-it.html RELEASE-NOTES-U3-gu.html
README-ja.html RELEASE-NOTES-U1-ja.html RELEASE-NOTES-U3-hi.html
README-kn.html RELEASE-NOTES-U1-kn.html RELEASE-NOTES-U3-it.html
README-ko.html RELEASE-NOTES-U1-ko.html RELEASE-NOTES-U3-ja.html
README-ml.html RELEASE-NOTES-U1-ml.html RELEASE-NOTES-U3-kn.html
README-mr.html RELEASE-NOTES-U1-mr.html RELEASE-NOTES-U3-ko.html
README-or.html RELEASE-NOTES-U1-or.html RELEASE-NOTES-U3-ml.html
README-pa.html RELEASE-NOTES-U1-pa.html RELEASE-NOTES-U3-mr.html
README-pt_BR.html RELEASE-NOTES-U1-pt_BR.html RELEASE-NOTES-U3-or.html
README-ru.html RELEASE-NOTES-U1-ru.html RELEASE-NOTES-U3-pa.html
README-si.html RELEASE-NOTES-U1-si.html RELEASE-NOTES-U3-
pt_BR.html
README-ta.html RELEASE-NOTES-U1-ta.html RELEASE-NOTES-U3-ru.html
README-te.html RELEASE-NOTES-U1-te.html RELEASE-NOTES-U3-si.html
README-zh_CN.html RELEASE-NOTES-U1-zh_CN.html RELEASE-NOTES-U3-ta.html
README-zh_TW.html RELEASE-NOTES-U1-zh_TW.html RELEASE-NOTES-U3-te.html
RELEASE-NOTES-as.html RELEASE-NOTES-U2-as.html RELEASE-NOTES-U3-
zh_CN.html
RELEASE-NOTES-bn.html RELEASE-NOTES-U2-bn.html RELEASE-NOTES-U3-
zh_TW.html
RELEASE-NOTES-de.html RELEASE-NOTES-U2-de.html RELEASE-NOTES-zh_CN.html
RELEASE-NOTES-en RELEASE-NOTES-U2-en RELEASE-NOTES-zh_TW.html
RELEASE-NOTES-en.html RELEASE-NOTES-U2-en.html RPM-GPG-KEY-redhat-beta
RELEASE-NOTES-es.html RELEASE-NOTES-U2-es.html RPM-GPG-KEY-redhat-release
RELEASE-NOTES-fr.html RELEASE-NOTES-U2-fr.html Server
RELEASE-NOTES-gu.html RELEASE-NOTES-U2-gu.html TRANS.TBL
RELEASE-NOTES-hi.html RELEASE-NOTES-U2-hi.html .treeinfo
RELEASE-NOTES-it.html RELEASE-NOTES-U2-it.html VT
RELEASE-NOTES-ja.html RELEASE-NOTES-U2-ja.html
[root@dhcp-0-104 custom-iso]#
上面的目录结构记住了。
其中.discinfo特别重要。RHEL的安装程序anaconda辨认光盘是否为合法安装光盘,看的就是
这个文件!里面的内容是
[root@dhcp-0-104 source]# cat .discinfo
1231281587.615363
Red Hat Enterprise Linux Server 5.3
i386
1,2,3,4,5
Server/base
Server/RPMS
Server/pixmaps
[root@dhcp-0-104 source]#
值得一提的是Red Hat Enterprise Linux Server 5.3 声明了操作系统的版本,
1,2,3,4,5 表示DVD光盘包含了哪几张CD的内容。(知道如何用CD安装盘合成DVD安装盘了
吧。)
如果这个隐藏文件没有拷过来,安装程序会认为安装光盘没有准备好,报没有安装介质的错
误。
配置kickstart配置文件。RHEL有个配置工具叫做system-config-kickstart,默认没有安装,大家
可以安装一下。
通常情况下为了减少劳动量,大家可以用安装后自动生成的/root/anaconda-ks.cfg作为模板来修
改。
[root@dhcp-0-104 source]# cp /root/anaconda-ks.cfg custom/ks.cfg
运行system-config-kickstart,读取/var/custom-iso/source/custom/ks.cfg,按照自己需求修改吧。
改完记得保存回去。
这个是我修改后的配置
[root@dhcp-0-104 source]# cat custom/ks.cfg
#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth --useshadow --enablemd5
# System bootloader configuration
bootloader --append="rhgb quiet" --location=mbr --driveorder=xvda
# Partition clearing information
clearpart --linux --initlabel
# Use text mode install
text
# Firewall configuration
firewall --disabled
# Run the Setup Agent on first boot
firstboot --disable
key 1234123412341234(这里是Red Hat提供的16位订阅号)
# 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
rootpw --iscrypted $1$A/6ze7v3$yUFTi/hWtYEh1RTDULOfW/
# SELinux configuration
selinux --disabled
# System timezone
timezone Asia/Shanghai
# Install OS instead of upgrade
install
# X Window System configuration information
xconfig --defaultdesktop=GNOME --depth=32 --resolution=800x600 --startxonboot
# Disk partitioning information
part /boot --bytes-per-inode=4096 --fstype="ext3" --size=100
part swap --bytes-per-inode=4096 --size=512
part / --bytes-per-inode=4096 --fstype="ext3" --grow --size=100
%pre
mkdir /tmp/custom_rpms
cp /mnt/source/custom/rpms/*.rpm /tmp/custom_rpms
%post --nochroot
rpm -ivh --root=/mnt/sysp_w_picpath /tmp/custom_rpms/*.rpm
mkdir /mnt/sysp_w_picpath/root/{Documents,Music,Pictures,Videos,Download}
%packages
@gnome-desktop
@base
@development-libs
@core
@sound-and-video
@chinese-support
@japanese-support
@korean-support
@admin-tools
@base-x
@development-tools
@clustering
@java
@web-server
@system-tools
@legacy-software-support
@printing
@text-internet
@graphical-internet
@cluster-storage
@dialup
@smb-server
@graphics
@office
@editors
@ftp-server
@games
emacs
kexec-tools
fipscheck
device-mapper-multipath
xorg-x11-utils
xorg-x11-server-Xnest
libsane-hpaio
[root@dhcp-0-104 source]#
其中Pre-installation script是在安装过程开始前执行的脚本,Post-installiation script是安装过程结
束后执行的脚本。因为在安装过程结束后,安装程序会卸载掉光驱。所以我在安装前把自己添
加的安装包现拷了出来。等待安装结束后再到指定目录去安装。这里涉及到一个chroot的问
题。这个问题我们以后再讨论。
配置anaconda安装程序,指定读取kickstart安装配置。这个配置文件属性是不可写的。用vim
的同志记得退出时候要用:x!命令强制保存退出。
[root@dhcp-0-104 source]# pwd
/var/custom-iso/source
[root@dhcp-0-104 source]# vim isolinux/isolinux.cfg
[root@dhcp-0-104 source]#
这个是修改后的配置
[root@dhcp-0-104 source]# cat isolinux/isolinux.cfg
default ks
prompt 1
timeout 10
display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
label linux
kernel vmlinuz
append initrd=initrd.img
label text
kernel vmlinuz
append initrd=initrd.img text
label ks
kernel vmlinuz
append ks ks=cdrom:/custom/ks.cfg initrd=initrd.img
label local
localboot 1
label memtest86
kernel memtest
append -
[root@dhcp-0-104 source]#
最后只要把安装树转换成可启动iso,刻录之就可以用了。
命令如下
[root@dhcp-0-104 source]# mkisofs -R -b isolinux/isolinux.bin -c
isolinux/boot.cat -V RHEL-5.3-custom -no-emul-boot -boot-load-size 4 -bootinfo-
table -o ../RHEL-5.3-custom.iso .
其实上面这条命令是在网上看到的。我对参数也是不甚了解。只能狭隘的解释一下。
-R 参数开启Rock Ridge protocol支持。这个协议可以让iso9660支持一些linux文件系统的特
性,否则一些特殊文件名的文件无法压制进iso镜像里面,比如说隐藏文件(不是很确定,我
这里实验是这样)。
-V 参数其实就是系统显示的光盘名,类似卷标。
-no-emul-boot 是声明这个iso为非虚拟iso(我不是很理解这个“虚拟”的意思),这样系统启动
后加载光盘不会去加载某些"虚拟光盘"方面的特性,这样有助于提高光盘的性能(个人理
解)。
-boot-load-size no-emulation格式的iso,默认情况下一个逻辑扇区的大小是512 byte。同时,默
认情况下,系统会读取整个引导程序。如果不指定默认读出的引导程序地址不超过4个逻辑扇
区,在一些BIOS上会出错。
-boot-info-table 如果指定这个参数,在压制iso文件的时候,会在引导程序的源文件第8个偏移
量开始打入56byte的引导信息(这个信息是干什么用的,我不知道)。所以,请保证被引导程
序有备份。
-b 指定引导程序
-c 如果有的话,引导程序会给烧到这个文件里面指定的位置。
最后只要把iso烧录到光盘里面就可以了。
[root@dhcp-0-104 source]# dvdrecord ../RHEL-5.3-custom.iso