在 ESXi 上导出虚拟机的时候,vSphere Web 端只能导出 ovf 格式的虚拟机,无法导出 OVA 格式的,使用 vSphere client 能导出这两种格式。看来一哈官方文档和标准手册,才明白。其实 OVA 是 ovf 的打包文件,导入 ova 格式的时候会自动解包出虚拟机的元数据信息。
OVF
The OVF descriptor contains the metadata about the OVF package. This is an extensible XML document for encoding information, such as product details, virtual hardware requirements, and licensing.
根据 Open Virtualization Format
的标准手册 Open Virtualization Format Specification 的描述,OVF 包含以下文件。确切地来讲 OVF 不是单个文件,而是一个未打包成一个文件的包? 虽然这样讲不太严格😂。打包成一个文件就时 OVA 而已。
- one OVF descriptor with extension .ovf
描述符用于指定服务对虚拟硬件的要求,并且还包括其他信息,例如虚拟磁盘的说明、服务本身、来宾操作系统、许可协议 (EULA)、在设备中启动和停止 VM 的说明以及服务安装说明。描述符文件的扩展名为 .ovf 。
- zero or one OVF manifest with extension .mf
清单文件是软件包中每个文件的 SHA-1 摘要,可以用来检测任何损坏,以验证软件包的内容。清单文件的扩展名为 .mf 。
- zero or one OVF certificate with extension .cert
签名是用软件包所含 X.509 证书中的公钥进行签名的清单文件摘要,用于对软件包作者进行验证。签名文件的扩展名为 .cert 。
- zero or more disk image files
OVF 不指定磁盘映像格式。OVF 包中包含组成虚拟磁盘的文件(格式由导出虚拟磁盘所用的虚拟化产品定义)。XenServer 生成的 OVF 包具有动态 VHD 格式的磁盘映像;VMware 产品和 Virtual Box 生成的 OVF 包具有流技术优化 VMDK 格式的虚拟磁盘。
- zero or more additional resource files, such as ISO images
.mf
An OVF package may have a manifest file containing the SHA digests of individual files in the package.OVF packages authored according to this version of the specification shall use SHA256 digests. The manifest file shall have an extension .mf and the same base name as the .ovf file and be a sibling of the .ovf file. If the manifest file is present, a consumer of the OVF package should verify the digests in the manifest file in the OVF package by computing the actual SHA digests and comparing them with the digests listed in the manifest file. The manifest file shall contain SHA digests for all distinct files referenced in the References element of the OVF descriptor and for no other files.
翻译一哈
一个 OVF 包可能会有一个
file | usage | need |
---|---|---|
one OVF descriptor with extension .ovf | 虚拟机配置信息 | 必须 |
zero or one OVF manifest with extension .mf | SHA256 | 非必须 |
zero or one OVF certificate with extension .cert | 验证证书 | 非必须 |
zero or more disk image files | 虚拟机磁盘 | 非必须 |
zero or more additional resource files, such as ISO images | 其他资源 | 非必须 |
下面看一个 ovf 文件的示例 ,可以看出 ovf 是 xml 格式的,描述了虚拟机的配置信息、元数据信息
1 |
|
下面是 mf 文件信息
1 | SHA256(Alpine-240.ovf)= 3d5b06e6741da7919e33775fb2c1b3e77968b4d7b020f4055a8a401f1127be29 |
在导入 ovf 格式的虚拟机文件时,会解析这个ovf 文件,通过这个文件里描述的设备信息自动创建新的虚拟机。
OVA
根据官方的描述
An OVF package can be stored as either a single compressed file (.ova) or a set of files
An OVF package may be stored as a compressed OVF package or as a set of files in a directory structure. A compressed OVF package is stored as single file. The file extension is .ova (open virtual appliance or application).
In addition, the entries shall be in one of the following orders inside the OVF package:
- 1) OVF descriptor
- 2) The remaining files shall be in the same order as listed in the References section
or
- 1) OVF descriptor
- 2) OVF manifest
- 3) OVF certificate
or
- 1) OVF descriptor
- 2) The intermediate files shall be in the same order as listed in the References section
- 3) OVF manifest
- 4) OVF certificate
需要注意的是,OVA 单个文件里打包了 OVF 所有的文件,文件是有顺序的,第一个一定要是 OVF 描述文件,即导出虚拟机时的那个 .ovf 后缀的文件
使用场景
OVF 包包含一系列未压缩的文件,对于需要访问文件中各个磁盘映像的用户而言较为方便,而 OVA 包只是一个大型文件。尽管您可以压缩此文件,但它不像一系列文件(如 OVF)那样灵活。
OVA 更适用于适合只使用一个文件的特定应用场合(例如创建用于 Web 下载的软件包),这种情况下软件包更易于处理。与 OVF 相比,导出和导入 OVA 包所需的时间更长。
转换
OVA 转 OVF 很简单,使用 tar 解包就行
比如任意解包一个 OVA 文件后会出来 ovf vmdk mf
这三个文件,而且解包出来的顺序也是和 OVA 标准定义的那样,第一个必须未 .ovf 文件。这里我讲的是解包而不是解压,是因为 OVA 和 OVF 里包含的文件,最大的就是磁盘文件,而磁盘文件在导出的时候虚拟机已经进行了压缩,你可以使用 df 命令看看磁盘占用的空间,以及导出的磁盘占用的空间,你就会发现导出的磁盘文件大小远小于系统占用的空间。
1 | tar -xvf Ubuntu1804.ova |
OVF 转 OVA
按照 OVA 标准的格式,按顺序打包 OVF 包里的文件就行,注意 .ovf 文件一定要在第一个
1 | tar -cf OP.ova Ubuntu1804.ovf Ubuntu1804-disk1.vmdk Ubuntu1804.mf |
OVA = tar OVF ?
我们把 OVA 解包出来,再打包回去,两者文件是否一样呢?
看一下两者的 sha256sum 信息就可以了,结果证明是不一样的
1 | e6b0f08dc80ef6509cd547b87d8fe9373069d6758b86f3cbb43e804a3c9b7e7d Ubuntu1804.ova |
两者导入虚拟机后没有任何差别,都可以导进去,都能开机和使用,但新生成的 OVA 文件元数据信息是不一样的。
使用 less 命令看一下两者的文件头
原来的 OVA 文件头
1 | Ubuntu1804.ovf^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ |
新生成的 OVA 文件头
1 | Ubuntu1804.ovf^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ |
第一眼看到 644 755 777
就发现,这一定是文件的权限,其中还有文件所属用户,原来的是 VMware 用户,而新生成的是我本地的用户。
刨根到底,去看一哈 tar 包的定义Basic Tar Format tar 包就是由一个个文件顺序排列而成,每个文件由两部分组成:文件头和文件内容。就像下面这样
1 | |文件头|文件内容|--|文件头|文件内容|--|文件头|文件内容|--|文件头|文件内容| |
我们从 OVA 解包出来后,文件头的内容就会更改为我们本机的内容,而不再是原有的文件所主。
文件头的定义在
1 |
|
收获
通过阅读官方标准手册对 OVF 和 OVA 有两个更深刻的了解,对 tar 包的格式和 Unix 文件头初次了解。这么好的资料准备有空翻译几个关键的章节来水一篇博客😂