diff --git a/build_library/virtualbox_ovf.sh b/build_library/virtualbox_ovf.sh new file mode 100755 index 0000000000..ebbde4799c --- /dev/null +++ b/build_library/virtualbox_ovf.sh @@ -0,0 +1,267 @@ +#!/bin/bash + +# Mostly this just copies the below XML, but inserting random MAC address +# and UUID strings, and other options as appropriate. + +SCRIPT_ROOT=$(readlink -f $(dirname "$0")/..) +. "${SCRIPT_ROOT}/common.sh" || exit 1 + +DEFINE_string vm_name "CoreOS" "Name for this VM" +DEFINE_string disk_vmdk "" "Disk image to reference, only basename is used." +DEFINE_integer memory_size 1024 "Memory size in MB" + +# Parse command line +FLAGS "$@" || exit 1 +eval set -- "${FLAGS_ARGV}" + +# Die on any errors. +switch_to_strict_mode + +if [[ ! -e "${FLAGS_disk_vmdk}" ]]; then + echo "No such disk image '${FLAGS_disk_vmdk}'" >&2 + exit 1 +fi + +DISK_NAME=$(basename "${FLAGS_disk_vmdk}") +DISK_UUID=$(uuidgen) +DISK_SIZE_BYTES=$(qemu-img info -f vmdk "${FLAGS_disk_vmdk}" \ + | gawk 'match($0, /^virtual size:.*\(([0-9]+) bytes\)/, a) {print a[1]}') + +if [[ -z "${DISK_SIZE_BYTES}" ]]; then + echo "Unable to determine virtual size of ${FLAGS_disk_vmdk}" >&2 + exit 1 +fi + +# Generate random MAC addresses just as VirtualBox does, the format is +# their assigned prefix for the first 3 bytes followed by 3 random bytes. +VBOX_MAC_PREFIX=080027 +macgen() { + hexdump -n3 -e "\"${VBOX_MAC_PREFIX}%X\n\"" /dev/urandom +} + +# Date format as used in this file +datez() { + date -u "+%Y-%m-%dT%H:%M:%SZ" +} + +cat < + + + + + + List of the virtual disks used in the package + + + + Logical networks used in the package + + Logical network used by this appliance. + + + + A virtual machine + + The kind of installed guest operating system + Linux26_64 + Linux26_64 + + + Virtual hardware requirements for a virtual machine + + Virtual Hardware Family + 0 + ${FLAGS_vm_name} + virtualbox-2.2 + + + 1 virtual CPU + Number of virtual CPUs + 1 virtual CPU + 1 + 3 + 1 + + + MegaBytes + ${FLAGS_memory_size} MB of memory + Memory Size + ${FLAGS_memory_size} MB of memory + 2 + 4 + ${FLAGS_memory_size} + + + 0 + ideController0 + IDE Controller + ideController0 + 3 + PIIX4 + 5 + + + 1 + ideController1 + IDE Controller + ideController1 + 4 + PIIX4 + 5 + + + true + Ethernet adapter on 'NAT' + NAT + Ethernet adapter on 'NAT' + 5 + E1000 + 10 + + + 0 + disk1 + Disk Image + disk1 + /disk/vmdisk1 + 6 + 3 + 17 + + + + Complete VirtualBox machine configuration in VirtualBox format + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +EOF diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index dbeffd6dbc..d78f209b17 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -56,7 +56,8 @@ IMG_xen_HYBRID_MBR=1 IMG_xen_CONF_FORMAT=xl ## virtualbox -IMG_virtualbox_DISK_FORMAT=vdi +IMG_virtualbox_DISK_FORMAT=vmdk +IMG_virtualbox_CONF_FORMAT=ovf ## vagrant IMG_vagrant_DISK_FORMAT=vdi @@ -400,6 +401,28 @@ EOF VM_GENERATED_FILES+=( "${pygrub}" "${pvgrub}" "${VM_README}" ) } +_write_ovf_conf() { + local vm_mem="${1:-$(_get_vm_opt MEM)}" + local src_name=$(basename "$VM_SRC_IMG") + local dst_name=$(basename "$VM_DST_IMG") + local dst_dir=$(dirname "$VM_DST_IMG") + local ovf="${dst_dir}/$(_src_to_dst_name "${src_name}" ".ovf")" + + "${BUILD_LIBRARY_DIR}/virtualbox_ovf.sh" \ + --vm_name "$VM_NAME" \ + --disk_vmdk "$VM_DST_IMG" \ + --memory_size "$vm_mem" \ + > "$ovf" + + local ovf_name=$(basename "${ovf}") + cat > "${VM_README}" <