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
第 7 章 转换镜像格式
转换一种镜像格式到另一种通常是直接的。
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
[注意]
注意
-f format参数是可选的,如果忽略,qemu-img将尝试推断镜像格式。
当转换一个Windows系统的镜像文件时,需确保镜像内系统已安装好virtio驱动。否则,在你启动虚拟机时会由于缺少virtio驱动遇到蓝屏死机。另外避免这个问题的方法是按如下命令通过更新glance服务中镜像属性,但是这个方法会明显的降低磁盘性能。
$ glance image-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)。你仅仅需要修改
部分的内容。
centos64
CentOS-6
4
x86_64
http://mirror.rackspace.com/CentOS/6/isos/x86_64/CentOS-6.4-x86_64-bin-DVD1.iso
CHANGE THIS TO YOUR ROOT PASSWORD
CentOS 6.4 x86_64
http://download.fedoraproject.org/pub/epel/6/$basearch
no
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
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 -u centos64.tdl -x centos64-libvirt.xml
We need to start libertd before run this command.
And the following should be with url format in my testing.
http://mirror.rackspace.com/CentOS/6/isos/x86_64/CentOS-6.4-x86_64-bin-DVD1.iso
Waiting for centos64 to finish installing, 930/1200
Waiting for centos64 to finish installing, 920/1200
Waiting for centos64 to finish installing, 910/1200
Waiting for centos64 to finish installing, 900/1200
Cleaning up guest named centos64
Cleaning up after install
Traceback (most recent call last):
File "/usr/bin/oz-install", line 162, in
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("No disk 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.ppm for more detail
[root@cts-orch image]# ds -a
-bash: ds: command not found
[root@cts-orch image]# 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-orch image]# pwd
/root/image
[root@cts-orch image]# ls
centos64.tdl trusty-server-cloudimg-amd64-disk1.img
rhel6_ccache_1.tdl trusty-server-cloudimg-amd64-disk1.qcow2
[root@cts-orch image]# 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 for centos_65_x86_64 to finish installing, 980/1200
Waiting for centos_65_x86_64 to finish installing, 970/1200
Waiting for centos_65_x86_64 to finish installing, 960/1200
Waiting for centos_65_x86_64 to finish installing, 950/1200
Waiting for centos_65_x86_64 to finish installing, 940/1200
Waiting for centos_65_x86_64 to finish installing, 930/1200
Waiting for centos_65_x86_64 to finish installing, 920/1200
Waiting for centos_65_x86_64 to finish installing, 910/1200
Waiting for centos_65_x86_64 to finish installing, 900/1200
Cleaning up guest named centos_65_x86_64
Cleaning up after install
Traceback (most recent call last):
File "/usr/bin/oz-install", line 162, in
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("No disk 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-orch image]#