主要用途:
自动安装操作系统(swap分区交互输入),系统安装后并自动执行一些自定义脚本
以Rhel6.5x86_64光盘为例!
1、挂载光盘到/mnt下,拷贝内容到新建目录
1
2
3
|
mount
/dev/cdrom
/mnt
mkdir
/opt/iso
cp
-rT
/mnt
/opt/iso
|
2、修改isolinux.cfg文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
vim
/opt/iso/isolinux/isolinux
.cfg
default vesamenu.c32 改为 default linux
timeout 600 改为 timeout 30 3秒
label linux
menu label ^Install or upgrade an existing system
menu default
kernel vmlinuz
append initrd=initrd.img
改为:
label linux
menu label ^Install or upgrade an existing system
menu default
kernel vmlinuz
append initrd=initrd.img ks=cdrom:
/ks
.cfg
|
其中的ks.cfg位于/opt/iso/下,cdrom:/的路径就是/opt/iso
3、定义ks.cfg文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
firewall --disabled
#禁用防火墙
install
#新的安装
cdrom
#安装介质为cdrom
text
#文本安装
keyboard us
lang en_US.UTF-8
selinux --disabled
#禁用selinux
skipx
logging --level=info
rootpw --iscrypted $6$Mq
/o
.xHPh3L2wpJj$1IinnbXglCDM.ZyNVWocMHEsIlRc.oyU4In.1GTrRESIfa2Wb4IAVo8Xma3YHCirHXSyyM.Zt1VzXZyKCWAm00
authconfig --enableshadow --passalgo=sha512
#经过加密的密码 --iscrypted代表密码已经被加密,如rootpw 123456密码直接为123456
reboot
timezone Asia
/Shanghai
network --bootproto=static --device=eth0 --ip=10.0.1.1 --netmask=255.255.255.0 --onboot=on
network --bootproto=static --device=eth1 --onboot=on
bootloader --location=mbr
zerombr
clearpart --all
part
/boot
--fstype=
"ext4"
--size=200
#启动分区200M
#part swap --fstype="swap" --size=4096 #Swap注释,从配置文件读取(用户交互输入)
part / --fstype=
"ext4"
--grow --size=1
#剩余的空间全部给/
%include
/tmp/mydata
.txt
#包括用户输入的自定义的内容
%packages
#以下为默认安装的一些包
@base
@client-mgmt-tools
@console-internet
@core
@debugging
@directory-client
@hardware-monitoring
@java-platform
@large-systems
@network-
file
-system-client
@performance
@perl-runtime
@server-platform
@server-policy
@X Window System
@Desktop
@Graphics Creation Tools
@chinese-support
pax
python-dmidecode
oddjob
sgpio
device-mapper-persistent-data
samba-winbind
certmonger
pam_krb5
krb5-workstation
perl-DBD-SQLite
firefox
%pre
#安装前定义的脚本,切换到rry6终端,用于交互输入Swap分区
#!/bin/bash
exec
<
/dev/tty6
>
/dev/tty6
chvt 6
clear
echo
-n
"Please input the swap size(M)-32G(32768)-64G(65536)-Or-Other: "
read
Size
echo
-e
"part swap --fstype="
swap
" --size=${Size}"
>>
/tmp/mydata
.txt
exec
<
/dev/tty1
>
/dev/tty1
chvt 1
#
%post --nochroot
#从光盘拷贝文件到安装后的系统,光盘的/目录为/mnt/source/下,也就是/opt/iso下,/mnt/sysimage/为装完系统后的/目录
cp
/mnt/source/test
.
tar
.gz
/mnt/sysimage/opt/
#把光盘/opt/iso下的test.tar.gz 拷贝的安装后系统的/opt目录下
#
%post
#安装系统后要执行的命令,此处的/目录即为装完系统后的真实的/目录
sed
-i
'/^id/s/3/5/g'
/etc/inittab
#把系统启动级别改为5
cd
/opt
tar
-zxf
test
.
tar
.gz -C
/opt
#把/opt下的test.tar.gz解压到/opt
cd
/opt/test/123
#进入某目录,就相当于真实操作系统的命令
bash
/opt/test/123/test
.sh
#执行某目录下的脚本
%end
|
更多ks.cfg参数参考:
关于ks的生成可参考:利用Kickstart部署无人值守安装源服务器
1
2
3
|
rm
-f repodata/*.gz repodata/*.*.bz2 repodata/*.repomd.xml
declare
-x discinfo=`
head
-1 .discinfo`
createrepo -u media:
//
$discinfo -g repodata
/2a7e0c1da38a40e2961c0cec6acca8b8446d974b1fc055216ebde88bb4a19eb9-c6-x86_64-comps
.xml .
|
5、重新封装ISO
1
2
|
cd
/opt/iso
mkisofs
-R -l -r -T -no-emul-boot -J -c isolinux
/boot
.
cat
-b isolinux
/isolinux
.bin -o
/root/test
.iso -boot-load-size 4 -boot-info-table -no-bak .
|
把镜像重新封装到/root/test.iso,test.iso即为制作好的镜像,上边的参数不要修改,除非很清楚在干什么
主要有几个注意点:
1、光盘安装的时候,光盘的临时目录为/mnt/source/(把USB刻录为CD-ROM时,此目录为/mnt/stage2)
2、安装过程系统的目录为/mnt/sysimage/
如果定制的ISO过大(超过4G),将无法刻录到一般的光盘,可以刻录到U盘,把U盘做一个光盘来用
U盘需要量产,可以参考http://jingyan.baidu.com/article/20095761bd435ecb0721b4bb.html
用U盘来模拟CD-ROM会出现以下错误(iso在vmware中启动无问题)
报错一:
1
2
3
4
5
|
No driver
find
Unabled to
find
any devices of the
type
needed
for
this installation
type
.
Woulud you like to manually
select
your
device or use a driver Disk?
|
解决方法:
在从光盘启动后,快速按Esc键,输入"linux all-generic-ide irqpoll pci=nommconf“
报错二:
1
2
|
Unable to
read
group information from repositories. This
is a problem with the generation of your
install
tree
|
解决方法:
重置repodata,然后重新生成镜像
1
2
3
|
rm
-f repodata/*.gz repodata/*.*.bz2 repodata/*.repomd.xml
declare
-x discinfo=`
head
-1 .discinfo`
createrepo -u media:
//
$discinfo -g repodata
/2a7e0c1da38a40e2961c0cec6acca8b8446d974b1fc055216ebde88bb4a19eb9-c6-x86_64-comps
.xml .
|
本文转自Jacken_yang 51CTO博客,原文链接:http://blog.51cto.com/linuxnote/1834293,如需转载请自行联系原作者