# rpm -ivh http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
# yum install -y oz libguestfs-tools
# rpm -qa | grep oz
# rpm -ql oz-0.12.0-2.el6.noarch
/usr/lib/python2.6/site-packages/oz/auto 各操作系统自动化安装模板所在目录
/usr/share/doc/oz-0.12.0/examples tdl配置模板所在目录
# 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 = raw #raw输出的结果文件太大,不支持压缩
image_type = qcow2 #修改镜像类型为qcow2,支持压缩,1-2G文件能压缩到几百兆
# type = kvm
# bridge_name = virbr0
# cpus = 1
# memory = 1024
[cache]
original_media = yes
modified_media = no
jeos = no
[icicle]
safe_generation = no
更多参考例子:https://github.com/rcbops/oz-image-build/tree/master/templates
从tdl文件安装支持两种格式:一种是iso,另一种是url,它们之间的差异是:采用iso类型时oz需要能够获取源镜像文件;URL类型则是从远程服务器(如cobbler服务器上)获取iso解压后的文件。例如:
#iso类型配置
<install type=‘iso‘>
<iso>file:////opt/rhel-server-6.5-x86_64-dvd.iso</iso>
</install>
或者:
<install type=‘iso‘>
<iso>ftp://kickstart.rackspace.com/isos/redhat/6.5/rhel-server-6.5-x86_64-dvd.iso</iso>
</install>
或者:
<installtype=‘iso‘>
<iso>http://mirror.rackspace.com/CentOS/6/isos/x86_64/CentOS-6.5-x86_64-bin-DVD1.iso</iso>
</install>
#url类型配置
<install type=‘url‘>
<url>http://mirror.rackspace.com/centos/6/os/x86_64/</url>
</install>
我创建的tdl文件(ISO类型– 注意下面的文件内容要满足xml文件格式,否则会报错):
# cat rhel6.5.tdl
<template>
<name>rhel6.5_x86_64</name>
<description>RedHat 6.5 x86_64 template</description>
<os>
<name>RHEL-6</name>
<version>5</version>
<arch>x86_64</arch>
<rootpw>linuxblind</rootpw>
<install type=‘iso‘>
<iso>file:////var/oz/ios/rhel-server-6.5-x86_64-dvd.iso</iso>
</install>
</os>
<disk>
<size>20</size>
</disk>
<commands>
<command name=‘console‘>
sed -i ‘s/ rhgb//g‘ /boot/grub/grub.conf
sed -i ‘s/ quiet//g‘ /boot/grub/grub.conf
</command>
<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>
更多参考例子:https://github.com/clalancette/oz/blob/master/oz/auto/
我创建的ks文件(这里采用RHEL6.auto作为模板):
# cat rhel6.5.ks
install
text
key --skip
keyboard us
lang en_US.UTF-8
skipx
network --device eth0 --bootproto dhcp
#network --device eth1 --bootproto dhcp
rootpw linuxblind
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=200
part / --fstype ext4 --size=10000
part swap --fstype swap --size=2048
part /var --fstype ext4 --grow --size=200
reboot
%packages
@core
@server-policy
%post
说明:用kickstart文件制作的镜像优点:支持自定义分区、定制安装包和自定义脚本等
# oz-install -p -u -d3 -a rhel6.5.ks rhel6.5.tdl
镜像创建完成后,会保存在/var/lib/libvirt/images/下,使用下面的语句压缩镜像,方便上传
# qemu-img convert -c/var/lib/libvirt/images/rhel6.5_x86_64.qcow2 -O qcow2 /opt/rhel6.5_x86_64.qcow2
如果生成的是raw格式,可以使用下面的语句转换成qcow2格式
# qemu-img convert/var/lib/libvirt/images/rhel6.5_x86_64.dsk -O qcow2 /opt/rhel6.5_x86_64.qcow2
压缩比:
# du -sh /opt/rhel6.5_x86_64.qcow2
399M rhel6.5_x86_64.qcow2
# du -sh /var/lib/libvirt/images/rhel6.5_x86_64.qcow2
1.6G /var/lib/libvirt/images/rhel6.5_x86_64.qcow2
问题1:使用# oz-install -p -u -d3 -a rhel6.5.ks rhel6.5.tdl 安装时提示下面的错误
raise oz.OzException.OzException("Nodisk activity in %d seconds, failing. %s" % (inactivity_timeout, screenshot_text))
oz.OzException.OzException: No diskactivity in 300 seconds, failing. Checkscreenshot at /var/lib/oz/screenshots/rhel6.5_x86_64-1432621714.18.ppm for moredetail
解决办法:检查ks文件是否有误,通常都是由于ks文件引起的
问题2:
oz.OzException.OzException: UnsupportedRHEl-6 update 5
解决办法:
修改rhel6.5.tdl文件,将<name>RHEl-6</name> 修改为<name>RHEL-6</name>
查看支持哪些参阅:https://github.com/clalancette/oz/blob/master/oz/GuestFactory.py
本文出自 “linuxblind开放空间” 博客,请务必保留此出处http://linuxblind.blog.51cto.com/7616603/1655550
原文地址:http://linuxblind.blog.51cto.com/7616603/1655550