vmware / open-vmdk

Apache License 2.0
115 stars 46 forks source link

Introduction

Open VMDK is an assistant tool for creating Open Virtual Appliance (OVA). An OVA is a tar archive file with Open Virtualization Format (OVF) files inside, which is composed of an OVF descriptor with extension .ovf, one or more virtual machine disk image files with extension .vmdk, and a manifest file with extension .mf.

This tool consists of two parts:

vmdk-convert

OVA files require stream optimized disk image files (.vmdk) so that they can be easily streamed over a network link. vmdk-convert can convert raw disk images, and flat or sparse vmdk images to the stream optimized disk image format.

ova-compose

The OVF file that will be embedded can be generated using ova-compose from a simple yaml config file.

ova-compose will then create the final OVA from the OVF file, the vmdk images and a manifest (a file that contains checksums of the other files).

There is also the legacy tool mkova.sh that generates OVF files from templates.

Specifications

The VMDK format specification can be downloaded at https://www.vmware.com/app/vmdk/?src=vmdk (pdf).

The OVF/OVA specification can be found at https://www.dmtf.org/standards/ovf

Getting Started

Installation

Clone the repository, like git clone https://github.com/vmware/open-vmdk.

Alternatively, download and extract it:

curl -O https://github.com/vmware/open-vmdk/archive/master.tar.gz
tar zxf master.tar.gz

or if you prefer wget and zip:

$ wget https://github.com/vmware/open-vmdk/archive/master.zip
$ unzip master.zip

Run below commands to build and install:

$ cd open-vmdk-master
$ make
$ make install

You can change the prefix with PREFIX (default is usr) or the installation directory with DESTDIR for packaging, for example:

$ make DESTDIR=/tmp/open-vmdk install

Usage

open-vmdk basically has two parts:

There is also a legacy tool mkova.sh that uses OVF templates. This is less flexible than ova-compose and will be deprecated.

New VM

vmdk-convert can process raw disk images to streamable vmdk images. For example (as root):

dd if=/dev/zero of=testvm.img bs=1M count=4096
LOOP_DEVICE=$(losetup --show -f testvm.img)
... format disk to loop device and install OS into image ...
losetup -d $LOOP_DEVICE
vmdk-convert testvm.img testvm.vmdk

Set the VMware Tools version

Set the VMware Tools version installed in your VM disk by adding the -t option. The tools version is a number calculated from the version string x.y.z using the formulae 1024*x + 32*y + z. So for example for the version 12.1.5 the number would be 1024 * 12 + 1 * 32 + 5 = 12325.

$ vmdk-convert -t 12325 testvm-flat.vmdk disk1.vmdk

This will set ddb.toolsVersion to 12325 in the metadata of disk1.vmdk. By default, the ddb.toolsVersion will be set to 2147483647 (MAXINT, or 2^31-1). See https://packages.vmware.com/tools/versions for all released VMware Tools versions. See https://kb.vmware.com/s/article/83068 for instructions to add ddb.toolsVersion to an exiting OVF/OVA template.

Existing VM

Below example shows how to create an Open Virtual Appliance (OVA) from vSphere virtual machine. Presume the virtual machine's name is testvm, and virtual machine files include:

testvm-312d29db.hlog
testvm-flat.vmdk
testvm.nvram
testvm.vmdk
testvm.vmsd
testvm.vmx
vmware.log
  1. Copy testvm folder to TESTSVM_PATH on the machine where you have open-vmdk installed.
  2. Convert vmfs raw data extent file of the VM to OVF streaming format.
    $ cd $TESTSVM_PATH
    $ vmdk-convert testvm-flat.vmdk

    After converting, a new vmdk file dst.vmdk will be created under $TESTSVM_PATH folder. Or, you can specify the new vmdk file name by running

    $ vmdk-convert testvm-flat.vmdk disk1.vmdk

Create an OVA with ova-compose

Config File

system:
    name: example
    type: vmx-17
    os_vmw: other4xLinux64Guest
    firmware: efi
    secure_boot: true
    default_configuration: grande

networks:
    vm_network:
        name: "VM Network"
        description: "The VM Network network"

hardware:
    cpus: 2
    memory: 2048
    sata1:
        type: sata_controller
    scsi1:
        type: scsi_controller
    cdrom1:
        type: cd_drive
        parent: sata1
    rootdisk:
        type: hard_disk
        parent: scsi1
        disk_image: example.vmdk
    usb1:
        type: usb_controller
    ethernet1:
        type: ethernet
        subtype: VmxNet3
        network: vm_network
    videocard1:
        type: video_card
    vmci1:
        type: vmci

configurations:
    tall:
        label: Tall
        description: too little for the money
    grande:
        label: Grande
        description: just right
    venti:
        label: Venti
        description: too much

environment:
    transports:
        - com.vmware.guestInfo
        - iso
    categories:
        email: Email Settings
    properties:
        guestinfo.admin.email:
            value: admin@company.org
            user_configurable: true
            type: string
            description: "The Admin's email address"
            label: "Email Address"
            category: email

extra_configs:
    feature.enabled:
        required: false
        value: true
    log.rotateSize:
        value: 2048000

product:
    product: An Example VM
    vendor: A Company Inc.

annotation:
    text: the password is top secret

eula:
    file: eula.txt

The config file has 3 mandatory and 4 optional sections. system, networks and hardware are mandatory.

These sections are optional:

Parameters

Values can be filled in with parameters from the command line. This makes the yaml file reusable for different VMs. For example, the hard disk can be set via command line:

    rootdisk:
        type: hard_disk
        parent: scsi1
        disk_image: !param rootdisk

When invoking ova-compose (see below) the value can be set with --param rootdisk=example.vmdk.

Default values can also be set in case ova-compose is invoked without the parameter. Example:

hardware:
    cpus: !param cpus=2
    memory: !param memory=2048

In this case, setting the parameters cpus and memory will be optional.

If ova-compose is invoked without setting a parameter for which no default is set, it will throw an error.

Usage

ova-compose -i|--input_file <input_file> -o|--output_file <output_file> [ --format <format> ] [[--param <key=value>] ...] [-q] Options:

Example:

$ ova-compose.py -i minimal.yaml -o minimal.ova
creating 'minimal.ova' with format 'ova' from 'minimal.yaml'
done.

Create an OVA - Legacy (mkova.sh)

Hardware Options

By default, the OVA will be created with 2 CPUs and 1024 MB memory. For VMs with hardware version 11 or later, the default OVA firmware is efi. These defaults can be changed with options to mkova.sh:

These settings can also be set with the environment variables NUM_CPUS, MEM_SIZE and FIRMWARE, for example in the configuration file (see below).

For hardware versions 7 and 10 only bios is supported as firmware.

Selecting the Template

The template is an OVF file with place holders and provides settings for a pre-configured VM. It will be used to create the final OVF. The template file can be selected in two ways - either directly with the --template option, or by using the --hw option to specify the hardware version.

By default, the latest available template will be used.

Example: run mkova.sh to create OVA with specific hardware version (20):

$ mkova.sh --num-cpus 4 --mem-size 4096 --firmware bios --hw 20 ova_name disk1.vmdk

Note that templates do not exist for every possible hardware version.

Example: run mkova.sh to create OVA with a specific template:

$ mkova.sh --num-cpus 4 --mem-size 4096 --firmware bios --template /usr/share/open-vmdk/template-hw20.ovf ova_name disk1.vmdk

Where,

Create OVF File in Directory

Optionally, when the --ovf option is used, mkova.sh skips creating the OVA file and just creates a directory with the files that would be have been packed into the OVA. The directory will be created in the current directory with the supplied OVA name.

Multiple Disks

You can add multiple disks by adding them to the command line, for example:

$ mkova.sh ova_name path_to_ovf_template disk1.vmdk disk2.vmdk disk3.vmdk

Multiple disks are only supported to be attached to one SCSI controller, and at most 15 disks can be added in one OVA.

When mkova.sh completes, you should see the final OVA under the current directory.

Configuration File

mkova.sh will look for a configuration file at /etc/open-vmdk.conf. This is a simple shell script that can be used to set default values.