OZ制作OpenStack镜像

OZ制作OpenStack镜像


用OZ制作Openstack的镜像,RHEL6.4系统。


安装oz


yum -y  install oz


配置Oz,默认Oz是使用raw格式,我们使用qcow2格式

vim /etc/oz/oz.cfg


[paths]
output_dir = /var/lib/libvirt/images
data_dir = /var/lib/oz
screenshot_dir = /var/lib/oz/screenshots
[libvirt]
uri = qemu:///system
#image_type = raw
image_type = qcow2
# type = kvm
bridge_name = virbr0
# cpus = 1
# memory = 1024
[cache]
original_media = yes
modified_media = no
jeos = no
[icicle]
safe_generation = no


Oz内置了各个操作系统的自动化安装模板,路径在/usr/lib/python2.6/site-packages/oz/auto


建立TDL模板文件,及修改RHEL6.auto文件


RHEL6.tdl:

<template>
  <name>RHEL6.4</name>
  <os>
    <name>RHEL-6</name>
    <version>4</version>
    <arch>x86_64</arch>
    <install type='iso'>
      <iso>file:///home/rhel-server-6.4-x86_64-dvd.iso</iso>
    </install>
    <rootpw>root</rootpw>
  </os>
  <description>RHEL 6.4 x86_64</description>
  <repositories>
    <repository name='repo1'>
      <url>http://http://mirrors.yun-idc.com/epel/6/x86_64</url>
      <signed>no</signed>
    </repository>
    <repository name='repo2'>
      <url>http://ftp.sjtu.edu.cn/centos/6/os/x86_64</url>
      <signed>no</signed>
    </repository>
    <repository name='repo3'>
      <url>http://mirrors.kernel.org/centos/6/os/x86_64</url>
      <signed>no</signed>
    </repository>
    <repository name='repo4'>
      <url>http://mirrors.kernel.org/centos/6/updates/x86_64</url>
      <signed>no</signed>
    </repository>
    <repository name='repo5'>
      <url>http://mirrors.kernel.org/fedora-epel/6/x86_64</url>
      <signed>no</signed>
    </repository>
    <repository name='repo6'>
      <url>http://repos.fedorapeople.org/repos/openstack/cloud-init/epel-6</url>
      <signed>no</signed>
    </repository>
  </repositories>
  <packages>
    <package name='epel-release'/>
    <package name='cloud-utils'/>
    <package name='cloud-init'/>
    <package name='vnc'/>
    <package name='vnc-server'/>
  </packages>
  <commands>
    <command name='post'>
sed -i '/^HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-eth0
echo "NOZEROCONF=yes" >> /etc/sysconfig/network
echo "dns-nameservers 192.168.244.1" >> /etc/sysconfig/network
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
echo -n > /etc/udev/rules.d/70-persistent-net.rules
echo -n > /lib/udev/rules.d/75-persistent-net-generator.rules
sed -i 's/disable_root: 1/disable_root: 0/g' /etc/cloud/cloud.cfg
sed -i 's/ssh_pwauth:   0/ssh_pwauth:   1/g' /etc/cloud/cloud.cfg
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
service sshd restart
iptables -A INPUT -p tcp --dport 5000:6000 -j ACCEPT
    </command>
  </commands>
</template>

RHEL6.auto:


install
text
key --skip
keyboard us
lang en_US.UTF-8
skipx
network --device eth0 --bootproto dhcp
rootpw %ROOTPW%
firewall --disabled
authconfig --enableshadow --enablemd5
selinux --permissive
timezone --utc America/New_York
bootloader --location=mbr --append="console=tty0 console=ttyS0,115200"
zerombr yes
clearpart --all
part /boot --fstype ext4 --size=200
part pv.2 --size=1 --grow
volgroup VolGroup00 --pesize=32768 pv.2
logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=768 --grow --maxsize=1536
logvol / --fstype ext4 --name=LogVol00 --vgname=VolGroup00 --size=1024 --grow
reboot
%packages
@base
%post

默认只安装base包,可以自定配置如下:


.
.
.
reboot
%packages --ignoremissing
@base
@basic-desktop
@chinese-support
@desktop-platform
@desktop-platform-devel
@development
@general-desktop
@graphical-admin-tools
@input-methods
@internet-browser
@java-platform
@gnome-desktop
@network-tools
@remote-desktop-clients
@server-platform
@server-platform-devel
@x11
%post


通过oz-install生成镜像


oz-install -d3 -u RHEL6.tdl


镜像创建完后,会保存在 /var/lib/libvirt/images ,对image进行压缩


qemu-img convert -c /var/lib/libvirt/images/RHEL6.4.qcow2 -O qcow2 /root/RHEL6.4.qcow2


然后就可以使用建好的镜像了。

你可能感兴趣的:(镜像,openstack,RHEL,oz)