|
今天晚上在这里和大家分享一下如何利用kickstart全自动安装Linux,当然还有别的工具可以全自动的安装Linux,每个工具都有它自己的优点和缺点,选择一个适合你的就好了。
需要的软件包:nfs* dhcp* tftp*
一、安装软件
先把上面的三个软件包安装好
1
2
3
| yum install nfs* -y
yum install dhcp* -y
yum install tftp* -y
|
二、拷贝光盘内容
在根分区中建立一个目录
挂载光盘,拷贝光盘内容到这个目录下
1
2
| mount -o loop /dev/cdrom /media
cp -r /media/* /redhatinstall
|
三、配置nfs
编辑 nfs 的共享配置文件
1
| echo "/redhatinstall *(rw,sync)" >> /etc/exports
|
把我们刚刚拷贝近光盘的那个目录共享出去,*表示任何ip都可以mount这个目录。
四、配置dhcp服务器
1
2
3
4
5
6
7
| [iyunv@server ~]# cat /etc/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
#[iyunv@server ~]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
cp: overwrite `/etc/dhcpd.conf'? y
[iyunv@server ~]#
|
通过命令我们可以看到,dhcp的默认配置文件中没有内容,有一个提示说,我们可以参考 /usr/share/doc/dhcp*/dhcpd.conf.sample 这个示例文件。
所以我们把这个文件拷贝过来,直接覆盖。
下面我们打开这个文件进行配置
1
2
3
4
5
6
7
8
9
10
11
12
13
| 1 ddns-update-style interim;
2 ignore client-updates;
3
4 subnet 192.168.21.0 netmask 255.255.255.0 {
5
6 option routers 192.168.21.1;
7 option subnet-mask 255.255.255.0;
8 range dynamic-bootp 192.168.21.100 192.168.21.200;
9 default-lease-time 21600;
10
11 next-server 192.168.21.10;
12 filename "pxelinux.0";
13 }
|
这是我的配置文件,其中 subnet 代表要分配ip所处的网段,option routers 表示默认网关,range dynamic-bootp 表示,分配ip的范围,next-server 表示要去那个ip服务器读取文件,filename表示读取哪个文件。
五、配置TFTP
修改文件 /etc/xinetd.d/tftp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| 1 # default: off
2 # description: The tftp server serves files using the trivial file transfer \
3 # protocol. The tftp protocol is often used to boot diskless \
4 # workstations, download configuration files to network-aware printers, \
5 # and to start the installation process for some operating systems.
6 service tftp
7 {
8 socket_type = dgram
9 protocol = udp
10 wait = yes
11 user = root
12 server = /usr/sbin/in.tftpd
13 server_args = -s /tftpboot
14 disable = yes
15 per_source = 11
16 cps = 100 2
17 flags = IPv4
18 }
|
把14行的disable的值改为 no。
然后进入 /tftpboot 目录
1
2
3
4
| [iyunv@server ~]# cd /tftpboot/
[iyunv@server tftpboot]# ls
linux-install
[iyunv@server tftpboot]#
|
只有一个目录,这时候我们需要copy几个文件到这个 tftpboot目录下面
1
2
3
4
| [iyunv@server tftpboot]# cp /redhatinstall/images/pxeboot/{initrd.img,vmlinuz} .
[iyunv@server tftpboot]# ls
initrd.img linux-install vmlinuz
[iyunv@server tftpboot]#
|
接着再拷贝一个文件,就是刚刚我们在dhcpd.conf配置文件中配置的 pxelinux.0 文件。
1
2
3
4
| [iyunv@server tftpboot]# cp /usr/lib/syslinux/pxelinux.0 .
[iyunv@server tftpboot]# ls
initrd.img linux-install pxelinux.0 vmlinuz
[iyunv@server tftpboot]#
|
我们再建立一个目录,拷贝一个文件到这个目录下面:
1
2
3
4
5
6
7
8
9
10
11
12
13
| [iyunv@server pxelinux.cfg]# pwd
/tftpboot/pxelinux.cfg
[iyunv@server pxelinux.cfg]# cp /redhatinstall/isolinux/isolinux.cfg default
[iyunv@server pxelinux.cfg]# ls
default
[iyunv@server pxelinux.cfg]# ll
total 4
-r-xr-xr-x 1 root root 366 Mar 29 22:39 default
[iyunv@server pxelinux.cfg]# chmod 755 default
[iyunv@server pxelinux.cfg]# ll
total 4
-rwxr-xr-x 1 root root 366 Mar 29 22:39 default
[iyunv@server pxelinux.cfg]#
|
记得修改权限,要不然我们没法编辑。接下来编辑这个文件 default
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
| 1 default linux
2 prompt 1
3 timeout 600
4 display boot.msg
5 F1 boot.msg
6 F2 options.msg
7 F3 general.msg
8 F4 param.msg
9 F5 rescue.msg
10 label linux
11 kernel linuz
12 append ks=nfs:192.168.21.10:/redhatinstall/ks.cfg initrd=initrd.img
13
14
15 #label linux
16 # kernel vmlinuz
17 # append initrd=initrd.img
18 label text
19 kernel vmlinuz
20 append initrd=initrd.img text
21 label ks
22 kernel vmlinuz
23 append ks initrd=initrd.img
24 label local
25 localboot 1
26 label memtest86
27 kernel memtest
28 append -
29
|
第10-12行是我自己添加进去的。ks=nfs:192.168.21.10:/redhatinstall/ks.cfg 表示我们读取nfs服务器上的ks.cfg 文件的路径。
六、拷贝ks.cfg文件
Linux系统安装完后我们可以在root的家目录下看到有一个 anaconda-ks.cfg 文件,我们把这个文件拷贝到 /redhatinstall 目录下面,并改名为 ks.cfg。
1
2
3
4
5
| [iyunv@server ~]# cp anaconda-ks.cfg /redhatinstall/ks.cfg
[iyunv@server ~]# cd /redhatinstall/
[iyunv@server redhatinstall]# ll ks.cfg
-rw------- 1 root root 1107 Mar 29 22:44 ks.cfg
[iyunv@server redhatinstall]#
|
把这个问价的权限改为 777。然后编辑这个文件,下面是我的配置信息,想要看看每个选项是什么意思的话,可以去这里看http://www.iyunv.com/Linux/2013-07/87299.htm
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
| # Kickstart file automatically generated by anaconda.
install
text
key --skip
lang en_US.UTF-8
keyboard us
xconfig --startxonboot
network --device eth0 --bootproto dhcp
rootpw oracle
firewall --diabled
authconfig --enableshadow --enablemd5
nfs --server=192.168.21.10 --dir=/redhatinstall
selinux --diabled
timezone --utc Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="rhgb quiet"
clearpart --linux
part /boot --fstype ext3 --size=200
part swap --size=3000
part / --fstype ext3 --size=100 --grow
%packages
@admin-tools
@base
@core
@dialup
@editors
@gnome-desktop
@graphical-internet
@graphics
@legacy-software-support
@printing
@system-tools
@text-internet
@base-x
kexec-tools
fipscheck
device-mapper-multipath
sgpio
emacs
libsane-hpaio
festival
audit
xorg-x11-utils
xorg-x11-server-Xnest
reboot
|
配置好这个文件后,我们把需要的服务都启动起来
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| [iyunv@server redhatinstall]#
[iyunv@server redhatinstall]# service dhcpd restart
Starting dhcpd: [ OK ]
[iyunv@server redhatinstall]# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
[iyunv@server redhatinstall]# service nfs restart
Shutting down NFS mountd: [FAILED]
Shutting down NFS daemon: [FAILED]
Shutting down NFS quotas: [FAILED]
Shutting down NFS services: [FAILED]
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
[iyunv@server redhatinstall]#
|
全部OK,记得启动dhcp服务的时候,一定保证本机的ip是static的。
这个时候,我们新建一个虚拟机,让这个虚拟机和刚才我们配置好的服务器都用桥接模式,我们不挂载光盘,直接启动。就开始自动安装了。
|
|