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]#