1、安装软件包
# rpm -ivh http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
# yum install -y oz libguestfs-tools
2、修改配置文件(默认即可)
需要注意的是,制作出来的镜像,不管是raw格式还是qcow2格式,都是不经过压缩的,具体往下看
# cat /etc/oz/oz.cfg
[paths]
output_dir = /var/lib/libvirt/images
data_dir = /var/lib/oz
screenshot_dir = /var/lib/oz/screenshots
# sshprivkey = /etc/oz/id_rsa-icicle-gen
[libvirt]
uri = qemu:///system
image_type = qcow2
#image_type = raw
# type = kvm
# bridge_name = virbr0
# cpus = 1
# memory = 1024
[cache]
original_media = yes
modified_media = no
jeos = no
[icicle]
safe_generation = no
3、定义tdl文件
cat centos6.6.ks
<template>
<name>centos66_x86_64</name>
<description>Centos 6.6 x86_64 template</description>
<os>
<name>CentOS-6</name>
<version>6</version>
<arch>x86_64</arch>
<rootpw>root</rootpw>
<install type='iso'>
<iso>file:/iso/CentOS-6.6-x86_64-bin-DVD1.iso</iso>
</install>
</os>
<disk>
<size>20</size>
</disk>
<commands>
<command name='update'>
sed -i '/^HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i '/^UUID/d' /etc/sysconfig/network-scripts/ifcfg-eth0
echo -n > /etc/udev/rules.d/70-persistent-net.rules
echo -n > /lib/udev/rules.d/75-persistent-net-generator.rules
sed -i '/^SELINUX=/s/enforcing/disabled/' /etc/selinux/config
</command>
</commands>
</template>
4、定义ks文件
# cat centos_6.6.tdl
install
text
key --skip
keyboard us
lang en_US.UTF-8
skipx
network --device eth0 --bootproto dhcp
rootpw hscloud
firewall --disabled
authconfig --enableshadow --enablemd5
selinux --disabled
timezone --utc Asia/Shanghai
bootloader --location=mbr --append="console=tty0 console=ttyS0,115200"
zerombr yes
clearpart --all
part /boot --fstype ext4 --size=500
part / --fstype ext4 --size=15000
part swap --fstype swap --size=4096
reboot
%packages
@base
@core
%post
EOF
5、开始制作
# oz-install -p -u -d3 -a centos6.6.ks centos_6.6.tdl
6、镜像对比
qcow2
# qemu-img info centos66_x86_64.qcow2
image: centos66_x86_64.qcow2
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 1.5G
cluster_size: 65536
raw
# qemu-img info centos66_x86_64_raw.dsk
image: centos66_x86_64_raw.dsk
file format: raw
virtual size: 20G (21474836480 bytes)
disk size: 1.5G