kickstart全自动安装Linux

    

    今天晚上在这里和大家分享一下如何利用kickstart全自动安装Linux,当然还有别的工具可以全自动的安装Linux,每个工具都有它自己的优点和缺点,选择一个适合你的就好了。


    需要的软件包:nfs*   dhcp*   tftp*


一、安装软件

    先把上面的三个软件包安装好

yum install nfs* -y
yum install dhcp* -y
yum install tftp* -y

二、拷贝光盘内容

    在根分区中建立一个目录

mkdir /redhatinstall

    挂载光盘,拷贝光盘内容到这个目录下

mount -o loop /dev/cdrom /media
cp -r /media/* /redhatinstall


三、配置nfs

    编辑 nfs 的共享配置文件

echo "/redhatinstall *(rw,sync)" >> /etc/exports

把我们刚刚拷贝近光盘的那个目录共享出去,*表示任何ip都可以mount这个目录。


四、配置dhcp服务器

[root@server ~]# cat /etc/dhcpd.conf 
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample  
#[root@server ~]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf 
cp: overwrite `/etc/dhcpd.conf‘? y
[root@server ~]#

    通过命令我们可以看到,dhcp的默认配置文件中没有内容,有一个提示说,我们可以参考 /usr/share/doc/dhcp*/dhcpd.conf.sample 这个示例文件。

    所以我们把这个文件拷贝过来,直接覆盖。

下面我们打开这个文件进行配置

      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 # 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 目录

[root@server ~]# cd /tftpboot/
[root@server tftpboot]# ls
linux-install
[root@server tftpboot]#

只有一个目录,这时候我们需要copy几个文件到这个 tftpboot目录下面

[root@server tftpboot]# cp /redhatinstall/images/pxeboot/{initrd.img,vmlinuz} .
[root@server tftpboot]# ls
initrd.img  linux-install  vmlinuz
[root@server tftpboot]#

接着再拷贝一个文件,就是刚刚我们在dhcpd.conf配置文件中配置的  pxelinux.0 文件。

[root@server tftpboot]# cp /usr/lib/syslinux/pxelinux.0 .
[root@server tftpboot]# ls
initrd.img  linux-install  pxelinux.0  vmlinuz
[root@server tftpboot]#

我们再建立一个目录,拷贝一个文件到这个目录下面:

[root@server pxelinux.cfg]# pwd
/tftpboot/pxelinux.cfg
[root@server pxelinux.cfg]# cp /redhatinstall/isolinux/isolinux.cfg default
[root@server pxelinux.cfg]# ls
default
[root@server pxelinux.cfg]# ll
total 4
-r-xr-xr-x 1 root root 366 Mar 29 22:39 default
[root@server pxelinux.cfg]# chmod 755 default 
[root@server pxelinux.cfg]# ll
total 4
-rwxr-xr-x 1 root root 366 Mar 29 22:39 default
[root@server pxelinux.cfg]#

记得修改权限,要不然我们没法编辑。接下来编辑这个文件 default

      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。

[root@server ~]# cp anaconda-ks.cfg /redhatinstall/ks.cfg
[root@server ~]# cd /redhatinstall/
[root@server redhatinstall]# ll ks.cfg 
-rw------- 1 root root 1107 Mar 29 22:44 ks.cfg
[root@server redhatinstall]#

把这个问价的权限改为 777。然后编辑这个文件,下面是我的配置信息,想要看看每个选项是什么意思的话,可以去这里看http://www.linuxidc.com/Linux/2013-07/87299.htm

      # 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

配置好这个文件后,我们把需要的服务都启动起来

[root@server redhatinstall]# 
[root@server redhatinstall]# service dhcpd restart
Starting dhcpd:                                            [  OK  ]
[root@server redhatinstall]# service xinetd restart
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]
[root@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  ]
[root@server redhatinstall]#

    全部OK,记得启动dhcp服务的时候,一定保证本机的ip是static的。

这个时候,我们新建一个虚拟机,让这个虚拟机和刚才我们配置好的服务器都用桥接模式,我们不挂载光盘,直接启动。就开始自动安装了。





本文出自 “专注Java,linux技术” 博客,请务必保留此出处http://wuqinglong.blog.51cto.com/9087037/1626259

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。