利用Oz工具制作openstack镜像

                     利用Oz工具制作openstack镜像

1、首先,安装oz工具:


安装epel源 (epel源里包含oz包)

rpm -ivh http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm


yum install -y oz libguestfs-tools


2、其次,创建一个TDL文件

我制作的是rhel6.3.tdl 的文件模板  #更多的模板格式在/root/oz-0.12.0/tests/tdl这个目录

<template>

<name>rhel63_x86_64</name>

<description>RedHat 6.3 x86_64 template</description>

<os>

<name>RHEL-6</name>

<version>3</version>

<arch>x86_64</arch>

<rootpw>root</rootpw>

<install type='iso'>

<iso>file:////usr/iso/rhel-server-6.3-x86_64-dvd.iso</iso>

</install>

</os>

<disk>

   <size>50</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  #上面四条命令是为了用此镜像建立虚拟机的时候,可以获得mac和IP。

sed -i '/^SELINUX=/s/enforcing/disabled/' /etc/selinux/config

</command>

</commands>

</template>

#其中上面模板中的iso的安装方式可以换成url安装,需要把配置改为下面的命令行

#iso安装的命令行

<install type='iso'>

<iso>file:////usr/iso/rhel-server-6.3-x86_64-dvd.iso</iso>

</install>

#url的安装命令行

<install type='url'>

<url>http://10.240.240.205/redhat-6.3/</url>

</install>

3、制作kickstart文件

  我已是rhel6.3.ks 的kickstart文件  #oz自带的ks模板在/root/oz-0.12.0/oz/auto目录中,我是用其中的RHEL6.auto进行修改的

install

text

key --skip

keyboard us

lang en_US.UTF-8

skipx

network --device eth0 --bootproto dhcp

rootpw root

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=20000

part swap  --fstype swap --size=8192

part /u01  --fstype ext4 --grow --size=200

reboot


%packages

@base

@core

@server-policy

authconfig

ipmitool

OpenIPMI

openssh-clients

net-snmp

%post


rm -rf /etc/yum.repos.d/*

cat >/etc/yum.repos.d/puppet.repo <<-EOF

[puppet]

name=rhel-server-6.3-x86_64

baseurl=http://10.0.0.233/OS/rhel-server-6.3-x86_64/

enabled=1

gpgcheck=0

priority=1


[core-0]

name=core-0

baseurl=http://10.0.3.91/cobbler/ks_mirror/rhel-server-6.3-x86_64

enabled=1

gpgcheck=0

priority=1



[core-1]

name=core-1

baseurl=http://10.0.3.91/cobbler/ks_mirror/rhel-server-6.3-x86_64/Server

enabled=1

gpgcheck=0

priority=1



[core-2]

name=core-2

baseurl=http://10.0.3.91/cobbler/ks_mirror/rhel-server-6.3-x86_64/ResilientStorage

enabled=1

gpgcheck=0

priority=1



[core-3]

name=core-3

baseurl=http://10.0.3.91/cobbler/ks_mirror/rhel-server-6.3-x86_64/ScalableFileSystem

enabled=1

gpgcheck=0

priority=1



[core-4]

name=core-4

baseurl=http://10.0.3.91/cobbler/ks_mirror/rhel-server-6.3-x86_64/LoadBalancer

enabled=1

gpgcheck=0

priority=1



[core-5]

name=core-5

baseurl=http://10.0.3.91/cobbler/ks_mirror/rhel-server-6.3-x86_64/HighAvailability

enabled=1

gpgcheck=0

priority=1


EOF



#ssh-keygen -f /root/.ssh/id_rsa -N jiayuan.com

ssh-keygen -f /root/.ssh/id_rsa -N ""

cat << EOF > /root/.ssh/authorized_keys 

ssh-dss AAAAB3NzaC1kc3MAAACBAOhEPU3K5V0+0arAJAOfJpndZICISJpBLsgxK+Jfh918zKI8h1/wa2BeNh3dRn61xcxYNlYmTOhnfebqOl9BUT5pFFG263msMx9OCImZzkL8iL/u0bMDxIebGg8HkbkBUUoN3dp/gaQmbhhib9ZrNe6u63cfrehwIEhoZ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sCeYt+P5RF1q5df2HvNWRx6RZnDEbtxwh5zATG63RxtWHCnpGhNgScuRWB1JnVcyZDPKlaPExwqCkR1OmB2fFoDhJgbVXPE/VPG9XlXFxWNpCqpDK3BSDuD2c/ggMNeqZo8toCyfbAqxb/jkg root@manager_network

ssh-dss AAAAB3NzaC1kc3MAAACBAJBa7KArcDrwytnrLbh8uWJw3pKKYNLZEhnT2+LuDUmBERFPH/VtM4rp50k3meYgxlRch/iyWSBLdIC/UeZlRZPSFinDIvGEvqKqN/r+shddZgQQZXRH2pYAP8Rb/xzj4pIPpc0V1LpEIk7LashFx/41nCJXhODnJLcPcuASwR/LAAAAFQCHViB2P3fR4ud/tYUPeSgeumbLgQAAAIBsDZo3eB3WaY9VbztVToMgqii+NsJfiJPrcdQDMOJmEgYGQ/L7BKJglfDoLMvY/rvaumKN6rE9gsPiiN4m3xnOkXaYYjOqYb2fMk3N7AfozpgMdtgfp/o9Cy0qh4keOgawpJQTxnQVr1Lc5sFAptGb4Mx19lSY4c2lFRjpRSUSIgAAAIAo/yT9iqm1dD6n9sD982FK77WgPCUZQKAb7EqYx4qA4W8+GafkvvQSPHJ/ogrA+xS9+W/Y7MCMbqLLKC+si6gbSuLOxORP1EYMHLUOkJ2jPOCwYyDt1p7ZnFXJ9LP+cWeehuyujp4r7xlazcpwBm+n1j24Q2p4uX6v7BCpt0MEXA== liutao@manager_network

EOF


#用kickstart制作镜像的优点是:可以按自己的方式分区、安装定制包、包括安装完后执行的脚本。

4、修改/etc/oz/oz.cfg的配置文件(可以不修改,我要把制作制格式改为qcow2,默认是raw,raw格式输出的文件太大,不支持压缩)

[paths]

output_dir = /home/oz-img   #修改成自己的输出路径

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

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

5、开始制作镜像

执行此命令 #oz-install -p -u -d3 -a rhel6.3.ks rhel6.3.tdl

6、就制作好的镜像进行压缩

  正常制作出来的是1--2个G的容量,可以用下面的命令进行压缩,压缩后只有几百M的容量方便上传

 #qemu-img convert -c /home/oz-img/rhel63_x86_64.qcow2  -O qcow2 /home/qcow2/rhel63_x86_64.qcow2


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