CentOS 6.7定制自动安装

Posted KaShing

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS 6.7定制自动安装相关的知识,希望对你有一定的参考价值。

转载至http://luyafei.blog.51cto.com/1092421/1131532

测试环境:

VMware Workstation 8.0

CentOS 6.7 x86_64

1.安装所需的软件包:
[[email protected]host ~]# yum -y install createrepo mkisofs isomd5sum

2.根据当前系统已安装的软件包生成安装系统所需要的rpm列表
[[email protected]host ~]# awk ‘/Installing/{print $2}‘ install.log |sed ‘s/^[0-9]*://g‘ >/root/packages.list

3.建立定制所需要的目录并把除Packages目录以外的文件复制到新的系统目录

[[email protected]host ~]# mkdir  /mnt/cdrom
[[email protected]host ~]# mkdir -p /data/OS
[[email protected]host ~]# mount /dev/cdrom /mnt/cdrom/
[[email protected]host ~]# rsync -a --exclude=Packages /mnt/cdrom/ /data/OS/ 
[[email protected]host ~]# mkdir /data/OS/Packages

4.使用脚本自动复制所需要的RPM包到新建立的光盘目录中Packages

[[email protected]host ~]# vim cprpms.sh

 

    #!/bin/bash   
    SRC_RPMS=/mnt/cdrom/Packages      
    DST_RPMS=/data/OS/Packages      
    packages_list=/root/packages.list  
    number_of_packages=`cat $packages_list | wc -l`  
    i=1  
    while [ $i -le $number_of_packages ] ;  
     do  
        name=`head -n $i $packages_list | tail -n -1`  
             echo "cp $SRC_RPMS/$name* $DST_RPMS/"   
             cp $SRC_RPMS/$name* $DST_RPMS/          
        i=`expr $i + 1`  
    done 

 

 [[email protected]host ~]# sh cprpms.sh

5.配置kickstart脚本
[[email protected]host ~]# vim /data/OS/isolinux/ks.cfg

 

#platform=x86, AMD64, or Intel EM64T  
# Firewall configuration  
firewall --disabled  
# Install OS instead of upgrade  
install  
# Use CDROM installation media  
cdrom  
# Root password default is "redhat"  
rootpw --iscrypted $1$JJuQiyTA$fbBF2fBqHB1P5PpFNy5f.1
# System authorization information  
auth  --useshadow  --passalgo=md5 
# Use text mode install  
text  
firstboot --disable  
# System keyboard  
keyboard us  
# System language  
lang en_US  
# SELinux configuration  
selinux --disabled  
# Do not configure the X Window System  
skipx  
# Installation logging level  
logging --level=info 
# Reboot after installation  
reboot  
# System timezone  
timezone  Asia/Shanghai  
# Network information  
network  --bootproto=dhcp --device=eth0 --onboot=on –noipv6  
# System bootloader configuration  
bootloader --location=mbr 
# Clear the Master Boot Record  
zerombr  
# Partition clearing information  
clearpart --all --initlabel  
# Disk partitioning information  
ignoredisk --only-use=sda
part /boot --fstype="ext4" --size=1024 
part swap --recommended
part / --fstype="ext4" --grow --size=1 
%packages
@additional-devel
@base
@core
@debugging
@basic-desktop
@desktop-debugging
@desktop-platform
@desktop-platform-devel
@development
@directory-client
@eclipse
@emacs
@fonts
@general-desktop
@graphical-admin-tools
@graphics
@input-methods
@internet-browser
@java-platform
@legacy-x
@network-file-system-client
@performance
@perl-runtime
@print-client
@remote-desktop-clients
@server-platform
@server-platform-devel
@server-policy
@tex
@technical-writing
@virtualization
@virtualization-client
@virtualization-platform
@workstation-policy
@x11
libgcrypt-devel
libXinerama-devel
openmotif-devel
libXmu-devel
xorg-x11-proto-devel
startup-notification-devel
libgnomeui-devel
libbonobo-devel
junit
libXau-devel
libXrandr-devel
popt-devel
gnome-python2-desktop
libdrm-devel
libxslt-devel
libglade2-devel
gnutls-devel
mtools
pax
python-dmidecode
oddjob
wodim
sgpio
genisoimage
device-mapper-persistent-data
systemtap-client
abrt-gui
desktop-file-utils
ant
rpmdevtools
jpackage-utils
rpmlint
samba-winbind
certmonger
pam_krb5
krb5-workstation
netpbm-progs
openmotif
libXmu
libXp
perl-DBD-SQLite
libvirt-java
%end

 

 6.让系统从kickstart配置启动安装
[[email protected]host OS]# vim /data/OS/isolinux/isolinux.cfg   #备注这里需要给执行权限,才可以编辑,默认只读;

 

default ks
prompt 1
timeout 60
display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
label linux
kernel vmlinuz
append initrd=initrd.img
label text
kernel vmlinuz
append initrd=initrd.img text
label ks
kernel vmlinuz
append ks=cdrom:/isolinux/ks.cfg initrd=initrd.img
label local
localboot 1
label memtest86
kernel memtest
append -

 

 7.生成rpm包的依赖关系
[[email protected]host ~]# cd /data/OS/
[[email protected]host OS]# createrepo -g repodata/*-comps.xml /data/OS/
[[email protected]host OS]# declare -x discinfo=`head -1 .discinfo`
[[email protected]host OS]# createrepo -u "media://$discinfo" -g repodata/*-comps.xml /data/OS/

8.生成ISO镜像文件
[[email protected]host ~]# cd /data/OS/
[[email protected]host OS]# mkisofs -R -J -T -r -l -d -joliet-long -allow-multidot \
 -allow-leading-dots -no-bak -o /data/CentOS-6.7-x86_64.iso \
 -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot \
 -boot-load-size 4 -boot-info-table /data/OS

9.生成MD5校验码
[[email protected]host ~]# implantisomd5 /data/CentOS-6.3-x86_64.iso

10.测试

如果安装提示“unable to read group information from repositories。This is problem with the generation of your install tree.” 是没生产MD5效验码,也就是忘记执行博文的第9步操作;

 

以上是关于CentOS 6.7定制自动安装的主要内容,如果未能解决你的问题,请参考以下文章

centos 6.7安装mongodb

CentOS 6.7安装docker

Centos 6.7 安装jdk

CentOS 6.7 配置 yum 安装 Nginx

CentOS 6.7 配置 yum 安装 Nginx

初涉定制linux系统之——自动化安装Centos系统镜像制作