定制centos6.5自动安装ISO光盘

一 ISO定制项清单

  1. 安装系统为centos6.5 (base server),安装方式为全新安装

  2. 使用ext4分区格式

  3. 安装前可以交互输入root密码,主机名,swap分区大小,之后安装过程自动化

  4. 关闭防火墙,selinux

  5. 网络为dhcp方式获取

  6. 时区为Asia/Shanghai

  7. 分区表类型为mbr

  8. 默认设置三个分区,boot分区200M,swap分区由用户指定,其余为根分区

  9. 更改软件包安装背景为自定义logo,更改欢迎信息

二 安装步骤

1、安装制作系统镜像所需要的工具

yum -y install anaconda repodata createrepo mkisofs rsync

 

2、创建光盘挂载目录、资源重构目录、自定义数据库目录

mkdir /mnt/cdrom (挂载光盘)
mkdir /data/ISO (ISO目录)
mkdir /data/ISO/mydata (需要封装的数据)

 

3、挂载CentOS系统光盘

mount -o loop /data/iso/CentOS-6.4-x86_64-bin-DVD1.iso /mnt/cdrom

 

4、拷贝定制ISO光盘所需的数据和文件

rsync -a --exclude=Packages/ /mnt/cdrom/ /data/ISO/ #--exclude=Packages/排除此目录
rm -fr /data/ISO/repodata
mkdir -p /data/ISO/{Packages,repodata} #创建yum仓库,软件包存放位置

 

5、拷贝定制的的软件包到ISO重构目录(/data/ISO/Packages)

#!/bin/bash 
cd /root
awk '/Installing/{print $2}' install.log | sed 's/^*://g' > package.txt 
PACKAGES='/mnt/cdrom/Packages'
PACKDIR='/root/package.txt'
NEW_PACKAGES='/data/ISO/Packages'
while read LINE 
do
cp ${PACKAGES}/${LINE}.rpm /${NEW_PACKAGES} || echo "$LINE don't cp......."
done < package.txt
rm -f package.txt

 

6、创建自响应文件 ks.cfg ,把此文件放在/data/ISO/isolinux/ks.cfg

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use CDROM installation media
cdrom
#interactive
# Root password
#rootpw --plaintext 123456
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
#text
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
network --onboot=yes --device=eth0 --bootproto=dhcp --noipv6
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone --isUtc Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel 
# Disk partitioning information
#part /boot --fstype="ext4" --size=200
#part swap --fstype="swap" --size=16384
#part / --fstype="ext4" --grow --size=1
%include /tmp/mydata.txt
%packages
@base
@console-internet
@core
@debugging
@directory-client
@hardware-monitoring
@java-platform
@large-systems
@network-file-system-client
@performance
@perl-runtime
@server-platform
@server-policy
@workstation-policy
pax
oddjob
sgpio
device-mapper-persistent-data
samba-winbind
certmonger
pam_krb5
krb5-workstation
perl-DBD-SQLite
%end
%pre
#!/bin/bash
exec < /dev/tty6 > /dev/tty6
chvt 6
clear
echo "######################################################################"
echo " Welcome to xxx OS , before install, we will set something"
echo "######################################################################"
echo -n "Please entrer the hostname:"
read hostn
hostname $hostn
echo -e "NETWORKING=yes\nHOSTNAME=$hostn" > /etc/sysconfig/network
echo -e "\n"
echo -n "Please input the root passwd:"
read -s Passwd
echo "rootpw --plaintext $Passwd" >> /tmp/mydata.txt
echo -e "\n"
echo -n "Please input the swap size(M):"
read Size
echo -e "part /boot --fstype="ext4" --size=200\npart swap --fstype="swap" --size=${Size}\npart / --fstype="ext4" --grow --size=1" >> /tmp/mydata.txt
exec < /dev/tty1 > /dev/tty1
chvt 1
%end

 

7、修改启动安装导向文件/data/ISO/isolinux/isolinux.cfg,下面为修改后内容

default vesamenu.c32 
#prompt 1 
timeout 50                               ##等待时间
display boot.msg
menu background splash.jpg 
menu title Welcome to use CentOS 6.4! 
menu color border 0 #ffffffff #00000000 
menu color sel 7 #ffffffff #ff000000 
menu color title 0 #ffffffff #00000000 
menu color tabmsg 0 #ffffffff #00000000 
menu color unsel 0 #ffffffff #00000000 
menu color hotsel 0 #ff000000 #ffffffff 
menu color hotkey 7 #ffffffff #ff000000 
menu color scrollbar 0 #ffffffff #00000000
label linux                              #用ks.cfg自响应方式安装
menu label ^Install PowerSoft OS
menu default 
kernel vmlinuz 
append ks=cdrom:/isolinux/ks.cfg initrd=initrd.img        #加载ks应答文件作为默认配置
label vesa 
menu label Install system with ^basic video driver 
kernel vmlinuz 
append initrd=initrd.img xdriver=vesa nomodeset 
label rescue 
menu label ^Rescue installed system 
kernel vmlinuz 
append initrd=initrd.img rescue 
label local
menu label Boot from ^local drive 
localboot 0xffff 
label memtest86 
menu label ^Memory test
kernel memtest 
append -

 

8、创建软件仓库

cd /data/ISO
declare -x discinfo=$(head -1 .discinfo)
cp /mnt/cdrom/repodata/*-c6-x86_64-comps.xml repodata/c6-x86_64-comps.xml
createrepo -g repodata/c6-x86_64-comps.xml ./

 

9.修改光盘背景,文字等信息

9.1修改系统自动安装过程中显示的背景图片.修改光盘背景,文字等信息
#进入光盘images目录
cd /data/ISO/images/
#install.img镜像中包含了光盘安装过程中使用到的背景图片,挂载此img文件
mount -o loop -t squashfs install.img /mnt/install 
mkdir tmp
#挂载的install.img不能编辑,需要拷贝一份,修改后替换原install.img文件
rsync -av /mnt/install/ tmp/
#进入背景图片所在目录,选择需要修改的图片,并替换(主机图片尺寸,格式需要与原来的相同),图片位置为:tmp/install/usr/share/anaconda/pixmaps
#重新创建新的install.img
mksquashfs tmp/ install_v1.img -all-root
#替换install.img
cp tmp/install_v1.img install.img
9.2 修改安装过程中的欢迎语
mkdir /data/ISO/isolinux/tmp
#解压initrd.img镜像
xz -dc ../initrd.img | cpio -id
#修改欢迎语.buildstamp文件,把其中的CentOS替换为PowerSoft
vim .buildstamp
#创建新的initrd.img并替换
find . | cpio -c -o | xz -9 --format=lzma > ../initrd.img

 

10、重构系统,生成ISO镜像

mkisofs -o CentOS-6.5_64.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -T ISO/

 

11、用生成的ISO刻录光盘进行安装测试

virt-install -n centos6 -r 1024 -c CentOS-6.6_64.iso --disk path=centos6_v1.qcow2,device=disk,bus=virtio,size=5,format=qcow2 --vnc --vncport=5902 --vnclisten=0.0.0.0 -v

#这里使用KVM虚拟化测试ISO文件

 

12 ks.cfg文件解析

#更多ks.cfg配置选项,参考redhat文档:https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Installation_Guide/s1-kickstart2-options.html

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
#关闭防火墙
firewall --disabled

#install表示为全新安装系统
install
 
#使用的安装源为光盘
cdrom
 
#打开此选项,使用ks.cfg中的选项作为默认配置,但是允许用户手动修改每一项配置,用户需要手动点击下一步
#interactive

#设置root密码
#rootpw --plaintext 123456
 
#设置系统认证信息
auth  --useshadow  --passalgo=sha512
 
#打开此选项,表示安装过程使用纯文本模式,没有此选项为图形安装界面
#text
 
#键盘类型
keyboard us

#系统语言
lang en_US

#关闭selinux
selinux --disabled
 
#配置eth0网卡开机启动,使用dhcp获取IP信息,禁用ipv6
network --onboot=yes --device=eth0 --bootproto=dhcp --noipv6
 

#不配置x window
skipx
 
#设置安装过程中的错误记录等级为info
logging --level=info
 
#安装完成之后,重启系统(注:使用kvm虚拟机测试制作的ISO镜像时发现,安装完成之后是关机,不能重启)
reboot
 
#系统时区
timezone --isUtc Asia/Shanghai
 
#分区表类型为mbr
bootloader --location=mbr
 

#清楚主机原有mbr分区信息
zerombr
 
#初始化系统所有分区,执行全新安装
clearpart --all --initlabel 
 

#指定分区方式,boot分区200M,swap分区16G,其余全为主分区
#part /boot --fstype="ext4" --size=200
#part swap --fstype="swap" --size=16384
#part / --fstype="ext4" --grow --size=1
 
#加载额外的配置信息作为ks项
%include /tmp/mydata.txt
 
#安装软件包(base server)
%packages
@base
@console-internet
@core
@debugging
@directory-client
@hardware-monitoring
@java-platform
@large-systems
@network-file-system-client
@performance
@perl-runtime
@server-platform
@server-policy
@workstation-policy
pax
oddjob
sgpio
device-mapper-persistent-data
samba-winbind
certmonger
pam_krb5
krb5-workstation
perl-DBD-SQLite
%end
 
#安装前执行脚本
%pre
#!/bin/bash
#切换到终端6执行脚本,然后再切换会原终端1
exec < /dev/tty6 > /dev/tty6
chvt 6
clear
echo "######################################################################"
echo "     Welcome to xxx
echo "######################################################################"
#设置主机名
echo -n "Please entrer the hostname:"
read hostn
hostname $hostn
echo -e "NETWORKING=yes\nHOSTNAME=$hostn" > /etc/sysconfig/network
echo -e "\n"
#设置root密码
echo -n "Please input the root passwd:"
read -s Passwd
echo "rootpw --plaintext $Passwd" >> /tmp/mydata.txt
echo -e "\n"
#设置swap分区大小
echo -n "Please input the swap size(M):"
read Size
echo  -e "part /boot --fstype="ext4" --size=200\npart swap --fstype="swap" --size=${Size}\npart / --fstype="ext4" --grow --size=1" >> /tmp/mydata.txt
exec < /dev/tty1 > /dev/tty1
chvt 1
%end
posted @ 2015-02-26 18:39  jython.li  阅读(4383)  评论(0编辑  收藏  举报