Centos 6.4 kickstart 自动安装操作系统

Centos6.4 Kickstart 自动安装操作系统


准备工作:

挂载光盘:

# mount /dev/cdrom /media/

mount: block device /dev/sr0 is write-protected, mounting read-only

配置本地yum 源:

# cd /etc/yum.repos.d/

# mkdir repo

# ls

CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo repo

# mv CentOS-[^M]* repo

# vim CentOS-Media.repo

[c6-media]

name=CentOS-$releasever - Media

baseurl=file:///media

gpgcheck=1

enabled=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6


1.安装所需软件包

vsftpd 提供客户端安装时所需的操作系统文件

dhcp 为客气端提供IP地址

tftp-server 提供pxe已经文件的加载

syslinux 提供pxelinux.0 引导文件

system-config-kickstart 图形界面,提供ks文件的生成


# yum install -y vsftpd dhcp tftp-server system-config-kickstart syslinux


2.配置tftp-server

# cat /etc/xinetd.d/tftp

service tftp

{

disable = no

socket_type = dgram

protocol = udp

wait = yes

user = root

server = /usr/sbin/in.tftpd

server_args = -s /install/tftpboot

per_source = 11

cps = 100 2

flags = IPv4

}

# mkdir /install/tftpboot

# /etc/init.d/xinetd restart #重启xinetd服务,因为tftp-server受xinetd服务所管理

# chkconfig tftp on #开启tftp-server

# chkconfig xinetd on

3.配置dhcp Server

# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf

# vim /etc/dhcp/dhcpd.conf

ddns-update-style none; #关闭DDNS更新

default-lease-time 259200; #默认租约

max-lease-time 518400; #最大租约

subnet 192.168.7.0 netmask 255.255.255.0 { #要分配IP的网段

range 192.168.7.223 192.168.7.230; #要分配IP的范围

option subnet-mask 255.255.255.0; #子网掩码

option routers 192.168.7.1; #默认网关

option domain-name-servers 192.168.6.200; #DNS 服务器

next-server 192.168.7.222; #tftp-server服务器IP

filename "pxelinux.0"; #预启动文件pxelinux.0

}


启动dhcp服务

# service dhcpd start

Starting dhcpd: [ OK ]


4.配置vsftpd


# /etc/init.d/vsftpd restart

# chkconfig vsftpd on

# mkdir -p /var/ftp/install/centos6.4

将光盘制作成iso文件到本地,避免安装时从光盘读取文件(这样会很慢)。

# mkdir /install/

# dd if=/dev/cdrom of=/install/CentOS6_4.iso

将光盘挂载到/var/ftp/install/centos6.4

# mount -o loop /install/CentOS6_4.iso /var/ftp/install/centos6.4/

加入开机启动

# vim /etc/fstab

/install/CentOS6_4.iso /var/ftp/install/centos6.4 iso9660 defaults,loop 0 0


5.拷贝安装所需相关文件

# cp /usr/share/syslinux/menu.c32 /usr/share/syslinux/vesamenu.c32 /usr/share/syslinux/pxelinux.0 /install/tftpboot/

# mkdir /install/tftpboot/pxelinux.cfg

解释:

menu.c32 <==提供开机选单功能

pxelinux.0 <==开机管理程序

pxelinux.cfg <==开机选单设置

vesamenu.c32 <==图形界面选单

# mkdir -p /install/tftpboot/kernel/centos6.4

# cp /media/isolinux/vmlinuz /install/tftpboot/kernel/centos6.4

# cp /media/isolinux/initrd.img /install/tftpboot/kernel/centos6.4

# cp /media/isolinux/isolinux.cfg /install/tftpboot/pxelinux.cfg/default

解释:

vmlinuz: <==内核文件(kernel file);

initrd.img: <==开机过程中的核心内核模块组;

isolinux.cfg --> default:<== PXE开机选单的参考配置文件


6.设置开机选单

# vim /install/tftpboot/pxelinux.cfg/default

UI vesamenu.c32

TIMEOUT 300

DISPLAY ./boot.msg


MENU TITLE Welcome to PXE Server System


LABEL local

MENU LABEL Boot from local drive

MENU DEFAULT

localboot 0


LABEL network1

MENU LABEL Boot from PXE Server for Install CentOS 6.4

kernel ./kernel/centos6.4/vmlinuz

append initrd=./kernel/centos6.4/initrd.img


# vim /install/tftpboot/boot.msg

Welcome to PXE Server System.


The 1st menu can let you system goto hard disk menu.

The 2nd menu can goto interactive installation step.



7.生成ks.cfg文件

# mkdir -p /var/ftp/install/kickstart

# system-config-kickstart

# cat /var/ftp/install/kickstart/ks.cfg

#platform=x86, AMD64, or Intel EM64T

#version=DEVEL

# Firewall configuration

firewall --disabled

# Install OS instead of upgrade

install

# Use network installation

url --url="ftp://192.168.7.222/install/centos6.4"

# Root password

rootpw --iscrypted $1$diqzmtsG$8Yx12A/JVqZh7HoQGa9FO/

# System authorization information

auth --useshadow --passalgo=sha512

# Use text mode install

text

firstboot --disable

# System keyboard

keyboard us

# System language

lang en_US

# SELinux configuration

selinux --disabled

# Installation logging level

logging --level=info

# Reboot after installation

reboot

# System timezone

timezone --isUtc Africa/Abidjan

# System bootloader configuration

bootloader --location=mbr --md5pass="$1$toKu.eEZ$pkqnZY.psEMYA4L7spHs20"

# Clear the Master Boot Record

zerombr

# Partition clearing information

clearpart --all

# Disk partitioning information

part /boot --fstype="ext4" --size=200

part swap --fstype="swap" --size=2048

part / --fstype="ext4" --size=10000


%post

yum install -y vim

#!/bin/sh

mkdir -p /root/.ssh

chmod 700 /root/.ssh

chown root.root /root/.ssh

echo "你所要管理新安装客户端的公钥" >> /root/.ssh/authorized_keys

chmod 644 /root/.ssh/authorized_keys

chown root.root /root/.ssh/authorized_keys


%end


%packages

@basic-desktop

@chinese-support

%end


编辑default文件,指定ks文件

# vim /install/tftpboot/pxelinux.cfg/default

………………

append initrd=./kernel/centos6.4/initrd.img ks=ftp://192.168.7.222/install/kickstart/ks.cfg


8.测试,到此为止kickstart自动部署操作系统已经完成






你可能感兴趣的:(kickstart,kickstart,6.4,cnetos,自动安装操作系统)