diff --git a/build_image b/build_image index 58f883a091..5a16c02295 100755 --- a/build_image +++ b/build_image @@ -198,7 +198,16 @@ fi # Generating AU generator zip file to run outside chroot generate_au_zip || echo "Failed generating AU zip file - ignoring Error..." -upload_image "${BUILD_DIR}/au-generator.zip" + +# Write out a version.txt file, this will be used by image_to_vm.sh +tee "${BUILD_DIR}/version.txt" <&2 + exit 1 +fi + +if [[ -z "${FLAGS_output_ovf}" ]]; then + echo "No ovf file path provided." >&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 +} + +# Used in both the ovf and Vagrantfile +PRIMARY_MAC=$(macgen) + +# Date format as used in ovf +datez() { + date -u "+%Y-%m-%dT%H:%M:%SZ" +} + +if [[ -n "${FLAGS_output_vagrant}" ]]; then + cat >"${FLAGS_output_vagrant}" <"${FLAGS_output_ovf}" < + + + + + + 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 852af5d15a..3f8573b0e4 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -9,6 +9,7 @@ VALID_IMG_TYPES=( ami qemu rackspace + vagrant virtualbox vmware xen @@ -37,7 +38,7 @@ IMG_DEFAULT_HYBRID_MBR=0 IMG_DEFAULT_OEM_PACKAGE= # Name of the target image format. -# May be raw, vdi (virtualbox), or vmdk (vmware) +# May be raw or vmdk (vmware, virtualbox) IMG_DEFAULT_DISK_FORMAT=raw # Name of the target config format, default is no config @@ -55,7 +56,13 @@ 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=vmdk +IMG_vagrant_CONF_FORMAT=vagrant +IMG_vagrant_OEM_PACKAGE=oem-vagrant ## vmware IMG_vmware_DISK_FORMAT=vmdk @@ -99,14 +106,7 @@ set_vm_paths() { VM_DST_IMG="${dst_dir}/${dst_name}" VM_TMP_DIR="${dst_dir}/${dst_name}.vmtmpdir" VM_TMP_IMG="${VM_TMP_DIR}/disk_image.bin" - - # If src_dir happens to be in the build directory figure out the version - # from the directory name and use it in the vm name for config files. - VM_NAME=$(_src_to_dst_name "${src_name}" "") - if [[ "${src_dir}" =~ /build/images/${BOARD}/\d+\.\d+\.[^/]*$ ]]; then - VM_NAME+="-$(basename ${src_dir})" - fi - + VM_NAME="$(_src_to_dst_name "${src_name}" "")-${COREOS_VERSION_STRING}" VM_UUID=$(uuidgen) VM_README="${dst_dir}/$(_src_to_dst_name "${src_name}" ".README")" } @@ -256,11 +256,6 @@ _write_raw_disk() { mv "$1" "$2" } -_write_vdi_disk() { - sudo VBoxManage convertdd "$1" "$2" - sudo chown $(id -un) "$2" -} - _write_vmdk_disk() { qemu-img convert -f raw "$1" -O vmdk "$2" } @@ -403,6 +398,64 @@ 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" \ + --output_ovf "$ovf" + + local ovf_name=$(basename "${ovf}") + cat > "${VM_README}" < "${VM_README}" <= 1.2 is required. Use something like the following to get started: +vagrant box add coreos path/to/$(basename "${box}") +vagrant init coreos +vagrant up +vagrant ssh + +You will get a warning about "No guest additions were detected...", +this is expected and should be ignored. SSH should work just dandy. +EOF + + # Replace list, not append, since we packaged up the disk image. + VM_GENERATED_FILES=( "${box}" "${VM_README}" ) +} + vm_cleanup() { info "Cleaning up temporary files" rm -rf "${VM_TMP_DIR}" diff --git a/image_to_vm.sh b/image_to_vm.sh index a91f20c9f3..3957b626ff 100755 --- a/image_to_vm.sh +++ b/image_to_vm.sh @@ -29,8 +29,6 @@ DEFINE_string adjust_part "" \ "Adjustments to apply to the partition table" DEFINE_string board "${DEFAULT_BOARD}" \ "Board for which the image was built" -DEFINE_boolean prod $FLAGS_FALSE \ - "Build prod image" # We default to TRUE so the buildbot gets its image. Note this is different # behavior from image_to_usb.sh @@ -88,6 +86,12 @@ fi FLAGS_from=`eval readlink -f $FLAGS_from` FLAGS_to=`eval readlink -f $FLAGS_to` +# If source includes version.txt switch to its version information +if [ -f "${FLAGS_from}/version.txt" ]; then + source "${FLAGS_from}/version.txt" + COREOS_VERSION_STRING="${COREOS_BUILD}.${COREOS_BRANCH}.${COREOS_PATCH}" +fi + if [ ${FLAGS_prod_image} -eq ${FLAGS_TRUE} ]; then set_vm_paths "${FLAGS_from}" "${FLAGS_to}" "${COREOS_PRODUCTION_IMAGE_NAME}" elif [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ]; then