=======制作基于原系统的自动安装CentOS镜像==========<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
说明:CentOS镜像有3.7G左右,而我们制作的CentOS镜像仅有1G左右,大大节省了空间,而且是自动安装。
需要有一个已经安装好的CentOS系统,如果用的是redhat系统,有可能会出错。
1.
挂载光盘:mount /dev/cdrom /media/cdrom
2.
在/root目录下创建iso目录:mkdir iso,并在iso目录下创建CentOS目录:mkdir –pv iso/CentOS
3.
在/root/install.log下有以Installing开头的软件包是我们安装系统所需要的软件包,使用命令把它们提取出来,把以数字开头的软件包前面的数字去掉,放到文件package.txt中:awk ‘/^Installing/{print$2}’ install.log | sed ’s/【0-9】*://g >package.txt
4.
编写一个脚本,能自动下载我们所需要的软件包到/root/iso/CentOS:
vim cp.sh:
#!/bin/bash
#cp.sh
FILE=’/root/package’
SOU_FILE=’/media/cdrom/CentOS’
DES_FILE=’/root/iso/CentOS’
while read LINE
do
cp $SOU_FILE/$LINE.rpm $DES_FILE || echo “The $LINE don’t’s cp…” >>error.txt
done <$FILE
5.
使用bash –n cp.sh检测脚本的语法错误
6.
bash -x cp.sh 执行脚本,执行之后查看error.txt文本查看是否有未拷贝的数据包
7.
切换到/media/cdrom下,拷贝其下的.discinfo, p_w_picpaths, isolinux, EULA, repodata, RPM-GPG-KEY-CentOS-5, .treeinfo到/root/iso下:cp –r .discinfo p_w_picpaths isolinux EULA repodata RPM-GPG-KEY-CentOS-5 .treeinfo /root/iso
8.
编辑/root/iso/isolinux/isolinux.cfg: vim /root/iso/isolinux/isolinux.cfg
指定kickstart文件,只用修改default linux -à default linux ks=cdrom:/ks.cfg,保存退出
9.
cp anaconda-ks.cfg /root/iso/ks.cfg,并修改其为:
# Kickstart file automatically generated by anaconda.
text
cdrom
lang en_us
keyboard --skip
network --device eth0 --bootproto dhcp
rootpw redhat
firewall --disable
authconfig --enableshadow --enablemd5
selinux --disable
timezone --utc Asia/Shanghai
bootloader --location=mbr --driveorder=sda
# 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 --linux --drives=sda
part /boot --fstype ext3 --size=100 --ondisk=sda
part pv.2 --size=0 --grow --ondisk=sda
volgroup VolGroup00 --pesize=32768 pv.2
logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=512 --grow --maxsize=1024
logvol / --fstype ext3 --name=LogVol00 --vgname=VolGroup00 --size=1024 --grow
bootloader
reboot
%packages
@base
@core
@development-tools
@dialup
@editors
@text-internet
keyutils
trousers
fipscheck
device-mapper-multipath
imake
保存退出。
10.
制作iso镜像: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 iso/
11.
把制作好的镜像导出,重新安装一个镜像指向刚刚做好的镜像的虚拟机,启动即可完成。
转载于:https://blog.51cto.com/liusy23/280831