将CentOS重新打包成一个新ISO,可以自动分区、选择原件包,快速安装系统。
1.挂载光驱,创建临时目录
mount /dev/cdrom /mnt/cdrom
mkdir -p /root/iso/CentOS
2.使用cp.sh脚本提取需要的RPM包,正常安装好操作系统在/root目录下会有install.log文件,这个就是操作系统安装RPM包的记录,我们从这些记录中,将所需的RPM包从/mnt/cdrom/Packages中复制到/root/iso/CentOS里面去
#!/bin/bash
cd /root
awk ‘/Installing/{print $2}‘ install.log | sed ‘s/^[0-9]*://g‘ >package.txt
DVD=‘/mnt/cdrom/Packages‘
PACKDIR=‘/root/package.txt‘
NEW_DVD=‘/root/iso/CentOS/‘
while read LINE
do
cp ${DVD}/${LINE}*.rpm /${NEW_DVD} || echo "$LINE don‘t cp......."
done < package.txt
3.把原镜像除了Packages目录外的文件全部复制至/root/iso目录下
rsync -a --exclude=Packages /mnt/cdrom/ /root/iso
4.把/root目录下的anaconda-ks.cfg复制至/root/iso目录下,并根据自己实际需要修改安装要求
#version=DEVEL
install
text
cdrom
lang en_US.UTF-8
keyboard us
network --onboot no --device em1 --bootproto dhcp --noipv6
network --onboot no --device em2 --bootproto dhcp --noipv6
rootpw 123456 ----默认密码
firewall --disabled ----关闭防火墙
authconfig --enableshadow --passalgo=sha512
selinux --disabled ----禁用selinux
timezone --utc Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
#clearpart --none
clearpart --all --initlabel
zerombr
part /boot --fstype=ext4 --size=200
part swap --size=32000
part pv.008003 --grow --size=200
ignoredisk --only-use=sda
volgroup volGroup00 --pesize=4096 pv.008003
logvol / --fstype=ext4 --name=LogVol00 --vgname=volGroup00 --size=200000
logvol /data --fstype=ext4 --name=LogVol01 --vgname=volGroup00 --size=1655232
reboot
#repo --name="CentOS" --baseurl=cdrom:sr0 --cost=100
%packages
@chinese-support
@core
@server-policy
%end
5.让ISO按照anaconda-ks.cfg文件来执行安装
vi /root/iso/isolinux/isolinux.cfg
Default vesamenu.c32 修改成 default linux ks=cdrom:/anaconda-ks.cfg
6.使用repo.sh脚本重新生成repo文件
#!/bin/bash
ISO_DIR=/root/iso
cd ${ISO_DIR}
declare -x discinfo=$(head -1 .discinfo)
mv ${ISO_DIR}/repodata/*x86_64-comps.xml ${ISO_DIR}/repodata/c6-x86_64-comps.xml
createrepo -g ${ISO_DIR}/repodata/c6-x86_64-comps.xml ${ISO_DIR}
#createrepo -u "media://$discinfo" -g ${ISO_DIR}/repodata/c6-x86_64-comps.xml ${ISO_DIR}
mv ${ISO_DIR}/repodata/*x86_64-comps.xml ${ISO_DIR}/repodata/c6-x86_64-comps.xml
createrepo -u "media://$discinfo" -g ${ISO_DIR}/repodata/*c6-x86_64-comps.xml ${ISO_DIR}
7.制作ISO
yum -y install mkisofs
mkisofs -o MyCentOS.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -T /root/iso/
执行命令后会在当前目录生成一MyCentOS.iso文件,这样一个定制版的CentOS就出来了。
**参考界面**
http://kling.blog.51cto.com/3320545/1249962
http://lihuipeng.blog.51cto.com/3064864/759122
原文地址:http://987146971.blog.51cto.com/5230841/1585839