您的位置:首页 > 运维架构

Openstack Generate image

2016-03-14 16:10 232 查看
image:
http://docs.openstack.org/zh_CN/image-guide/content/ch_obtaining_images.html

oz只做cloud镜像:ios--》qcow2
http://www.chenshake.com/oz-making-centos-mirror/

https://github.com/rackerjoe/oz-image-build/tree/master/templates

转换镜像格式

转换一种镜像格式到另一种通常是直接的。

qemu-img 转换:raw, qcow2, qed, vdi, vmdk, vhd

qemu-img convert命令可以转换多种格式的镜像文件,包括qcow2, qed, raw, vdi, vhd, and vmdk.。

表 7.1. qemu-img格式字符列表
镜像格式 qemu-img参数
QCOW2 (KVM,Xen) qcow2
QED(KVM) qed
raw raw
VDI(VirtualBox) vdi
VHD(Hyper-V) vpc
VMDK(VMware) vmdk
这个示例将转换换一个裸格式镜像文件centos7.img 到qcow2镜像文件。

$ qemu-img convert-f raw -O qcow2 centos7.img centos7.qcow2
运行以下命令转换 VMDK镜像文件到裸格式镜像文件,

$ qemu-img convert-f vmdk -O raw centos7.vmdk centos7.img
运行以下命令转换 VMDK镜像文件到qcow2镜像文件,

$ qemu-img convert-f vmdk -O qcow2 centos7.vmdk centos7.qcow2
[注意] 注意
-fformat参数是可选的,如果忽略,qemu-img将尝试推断镜像格式。

当转换一个Windows系统的镜像文件时,需确保镜像内系统已安装好virtio驱动。否则,在你启动虚拟机时会由于缺少virtio驱动遇到蓝屏死机。另外避免这个问题的方法是按如下命令通过更新glance服务中镜像属性,但是这个方法会明显的降低磁盘性能。

$ glanceimage-update --property hw_disk_bus='ide' image_id
VBoxManage: VDI (VirtualBox) 转换为 raw

如果你使用 VirtualBox创建了一个 VDI 镜像,你可以使用VirtualBox附带的 VBoxManage 工具转换它为raw格式,在 Mac OS X和Linux上,VirtualBox 默认存放镜像在 ~/VirtualBox VMs/ 目录,以下示例在当前目录中从一个VirtualBox VDI镜像创建一个 raw镜像。

$ VBoxManage clonehd~/VirtualBox\ VMs/fedora21.vdi fedora21.img --format raw

Oz

Oz是一个自动化创建镜像文件的命令行工具。它是一个和 KVM 进行交互完成整个虚拟机镜像安装过程的 Python 程序。它使用操作系统支持的一系列预定义的kickstart (红帽系)文件或 preseed 文件 (Debian 系),并且他也用于创建微软 Windows 镜像。在 Fedora 上,使用yum 安装 Oz:

# yum install oz
[注意] 注意
在本文档编写时,没有针对 Ubuntu的 Oz 安装包,因此你需要从源代码安装或者编译自己的.deb文件包。

完整的 Oz 示例已经超出本文档范围,但是我们提供一个示例。你可以在 GitHub rackerjoe/oz-image-build/templates.查找到额外的 Oz模板文件。下面演示了使用 Oz 如何创建 CentOS 6.4 镜像。

使用以下内容创建模板文件(我们叫做centos64.tdl)。你仅仅需要修改 <rootpw> 部分的内容。

<template>
<name>centos64</name>
<os>
<name>CentOS-6</name>
<version>4</version>
<arch>x86_64</arch>
<install type='iso'>
<iso>http://mirror.rackspace.com/CentOS/6/isos/x86_64/CentOS-6.4-x86_64-bin-DVD1.iso</iso>
</install>
<rootpw>CHANGE THIS TO YOUR ROOTPASSWORD</rootpw>
</os>
<description>CentOS 6.4x86_64</description>
<repositories>
<repository name='epel-6'>
<url>http://download.fedoraproject.org/pub/epel/6/$basearch</url>
<signed>no</signed>
</repository>
</repositories>
<packages>
<package name='epel-release'/>
<package name='cloud-utils'/>
<package name='cloud-init'/>
</packages>
<commands>
<command name='update'>
yum -y update
yum clean all
sed -i '/^HWADDR/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
</command>
</commands>
</template>
Oz 模板指定了 Centos 6.4安装 ISO 的下载位置。 Oz 使用版本信息确认了使用哪一个 kickstart 文件。在这个示例中,是 RHEL6.auto 。它添加 EPEL软件库,并且安装在 packages 字段指定的 epel-release, cloud-utils, 以及 cloud-init 包。

在 Oz使用kickstart文件完成系统初始安装后,它通过更新镜像内容来定制镜像文件。定制的过程它通过 在XML 文件中的 command字段也删除任何关于eth0设备的信息。

运行:

# oz-install -d3 -ucentos64.tdl -x centos64-libvirt.xml

We need to startlibertd before run this command.
And the followingshould be with url format in my testing.
<iso>http://mirror.rackspace.com/CentOS/6/isos/x86_64/CentOS-6.4-x86_64-bin-DVD1.iso</iso>

Waiting for centos64 to finish installing,930/1200
Waiting for centos64to finish installing, 920/1200
Waiting for centos64to finish installing, 910/1200
Waiting for centos64to finish installing, 900/1200
Cleaning up guestnamed centos64
Cleaning up afterinstall
Traceback (mostrecent call last):
File "/usr/bin/oz-install", line162, in <module>
libvirt_xml = guest.install(timeout,force_download)
File"/usr/lib/python2.7/site-packages/oz/RedHat.py", line 705, in install
self.initrdfname, self.cmdline)
File"/usr/lib/python2.7/site-packages/oz/Guest.py", line 1699, in_do_install
self._wait_for_install_finish(dom, timeout)
File"/usr/lib/python2.7/site-packages/oz/Guest.py", line 817, in_wait_for_install_finish
raise oz.OzException.OzException("Nodisk activity in %d seconds, failing. %s" % (inactivity_timeout, screenshot_text))
oz.OzException.OzException:No disk activity in 300 seconds, failing. Check screenshot at /var/lib/oz/screenshots/centos64-1452672389.96.ppmfor more detail
[root@cts-orchimage]# ds -a
-bash: ds: commandnot found
[root@cts-orchimage]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 12G 29G 28% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 25M 1.9G 2% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
[root@cts-orchimage]# pwd
/root/image
[root@cts-orchimage]# ls
centos64.tdl trusty-server-cloudimg-amd64-disk1.img
rhel6_ccache_1.tdl trusty-server-cloudimg-amd64-disk1.qcow2
[root@cts-orchimage]# find / -name images
/root/kilo/neutron-7.0.0/doc/source/devref/images
/root/kilo/neutron-7.0.0/.venv/lib/python2.7/site-packages/pecan/scaffolds/base/public/images
/root/openstack_src/nova/doc/api_samples/images
/root/openstack_src/nova/doc/source/images
/root/openstack_src/nova/nova/tests/functional/api_sample_tests/api_samples/images
/root/openstack_src/neutron/doc/source/devref/images
/var/lib/libvirt/images
/usr/share/wallpapers/CentOS7/contents/images
/usr/share/emacs/24.3/etc/images
/usr/share/httpd/noindex/images

Waiting forcentos_65_x86_64 to finish installing, 980/1200
Waiting forcentos_65_x86_64 to finish installing, 970/1200
Waiting forcentos_65_x86_64 to finish installing, 960/1200
Waiting forcentos_65_x86_64 to finish installing, 950/1200
Waiting forcentos_65_x86_64 to finish installing, 940/1200
Waiting forcentos_65_x86_64 to finish installing, 930/1200
Waiting forcentos_65_x86_64 to finish installing, 920/1200
Waiting forcentos_65_x86_64 to finish installing, 910/1200
Waiting forcentos_65_x86_64 to finish installing, 900/1200
Cleaning up guestnamed centos_65_x86_64
Cleaning up afterinstall
Traceback (mostrecent call last):
File "/usr/bin/oz-install", line162, in <module>
libvirt_xml = guest.install(timeout,force_download)
File"/usr/lib/python2.7/site-packages/oz/RedHat.py", line 705, in install
self.initrdfname, self.cmdline)
File"/usr/lib/python2.7/site-packages/oz/Guest.py", line 1699, in_do_install
self._wait_for_install_finish(dom, timeout)
File"/usr/lib/python2.7/site-packages/oz/Guest.py", line 817, in_wait_for_install_finish
raise oz.OzException.OzException("Nodisk activity in %d seconds, failing. %s" % (inactivity_timeout, screenshot_text))
oz.OzException.OzException:No disk activity in 300 seconds, failing. Check screenshot at/var/lib/oz/screenshots/centos_65_x86_64-1452691952.46.ppm for more detail
[root@cts-orchimage]#
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: