From 48bcbfff70c0e7629f7ece72f59aec3c67e8efb4 Mon Sep 17 00:00:00 2001 From: Kim Hagen Date: Mon, 18 Mar 2019 16:01:29 +0100 Subject: Add vmware ovf build procedure --- Makefile | 14 +- scripts/build-vmware-image | 172 ++++++++++++++++++--- scripts/template.ovf | 232 ++++++++++++++++++---------- tools/cloud-init/vmware/90_dpkg.cfg | 3 + tools/cloud-init/vmware/config.boot.default | 30 ++++ 5 files changed, 347 insertions(+), 104 deletions(-) create mode 100644 tools/cloud-init/vmware/90_dpkg.cfg create mode 100644 tools/cloud-init/vmware/config.boot.default diff --git a/Makefile b/Makefile index 17ee4e65..fb5d0e3a 100644 --- a/Makefile +++ b/Makefile @@ -57,10 +57,14 @@ vagrant-libvirt: .PHONY: vmware .ONESHELL: -vmware: +vmware: clean prepare @set -e - @scripts/check-vm-build-env - @scripts/build-vmware-image + @echo "It's not like I'm building this specially for you or anything!" + mkdir -p build/config/includes.chroot/etc/cloud/cloud.cfg.d + cp tools/cloud-init/vmware/90_dpkg.cfg build/config/includes.chroot/etc/cloud/cloud.cfg.d/ + cp -f tools/cloud-init/vmware/config.boot.default build/config/includes.chroot/opt/vyatta/etc/ + cd $(build_dir) + @../scripts/build-vmware-image .PHONY: hyperv .ONESHELL: @@ -140,6 +144,10 @@ clean: rm -f *.raw rm -f *.tar.gz rm -f *.qcow2 + rm -f *.mf + rm -f *.ovf + rm -f *.ova + rm -f *.vmdk .PHONY: purge purge: diff --git a/scripts/build-vmware-image b/scripts/build-vmware-image index 1730d7a3..5ad6615a 100755 --- a/scripts/build-vmware-image +++ b/scripts/build-vmware-image @@ -1,10 +1,8 @@ #!/bin/sh # -# Copyright (C) 2016 VyOS maintainers and contributors +# Copyright (C) 2019 VyOS maintainers and contributors # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 or later as -# published by the Free Software Foundation. +# This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 or later as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -16,7 +14,7 @@ # # File: build-vmware-image # Purpose: -# Build VyOS OVA and OVF for VMware. +# Build VyOS image for VMWARE. if [ ! $(which vmdk-convert) ]; then echo "Your system doesn't have vmdk-convert. Please install it from https://github.com/vmware/open-vmdk." @@ -32,32 +30,168 @@ else echo "Your system has ovftool." fi -export PACKER_BUILD_DIR=packer_build +lb bootstrap -DST_DIR=${PACKER_BUILD_DIR}/vmware -mkdir -p ${DST_DIR} +lb chroot +lb installer +lb binary_chroot +lb chroot_devpts install +lb chroot_proc install +lb chroot_selinuxfs install +lb chroot_sysfs install +lb chroot_hosts install +lb chroot_resolv install +lb chroot_hostname install +lb chroot_sysv-rc install +lb chroot_upstart install +lb chroot_apt install-binary +lb chroot_archives chroot install +lb binary_rootfs +lb binary_manifest +lb binary_package-lists +lb binary_linux-image +lb binary_memtest +lb binary_grub +lb binary_grub2 +lb binary_syslinux +lb binary_disk +lb binary_loadlin +lb binary_win32-loader +lb binary_includes +lb binary_hooks +lb binary_checksums -# Convert qcow2 image to VMDK -source_image=${PACKER_BUILD_DIR}/qemu/vyos_qemu_image.img -tmp_vmdk=${DST_DIR}/tmp.vmdk -vmdk=${DST_DIR}/vyos_vmware_image.vmdk -ovf=${DST_DIR}/vyos_vmware_image.ovf -qemu-img convert -f qcow2 ${source_image} -O vmdk -o adapter_type=lsilogic ${tmp_vmdk} -vmdk-convert ${tmp_vmdk} ${vmdk} +# get vyos build version +version=$(cat version) +dateymd=$(date +%Y%m%d) + +###################################### +### Prepare the HDD (format, ext.) ### +###################################### +PARTED=/sbin/parted +OUTPUT=disk.raw +OUTPUTVMDK=VyOS-"$dateymd".vmdk +IMAGE_SIZE=2 +qemu-img create -f raw ${OUTPUT} ${IMAGE_SIZE}G + +${PARTED} -s ${OUTPUT} mktable msdos +${PARTED} -s -a optimal ${OUTPUT} mkpart primary ext4 1Mi 100% +${PARTED} -s ${OUTPUT} set 1 boot on +RESULT_KPARTX=`kpartx -asv ${OUTPUT} 2>&1` + +if echo "${RESULT_KPARTX}" | grep "^add map" ; then + LOOP_DEVICE=$(echo ${RESULT_KPARTX} | cut -d" " -f3) + LOOPRAW_DEVICE=${LOOP_DEVICE%p*} + echo "kpartx mounted using: ${LOOP_DEVICE} via ${LOOPRAW_DEVICE}" +else + echo "It seems kpartx didn't mount the image correctly: exiting." + exit 1 +fi + +cleanup(){ + error=$? + [ ! -d "${MOUNT_DIR}" ] && return + if [ "$error" -gt 0 ]; then + echo + echo "Error $error" + else + echo "Finished." + fi + + set +e + + sync + umount -l ${MOUNT_DIR} + rmdir ${MOUNT_DIR} + + umount devpts-live + umount proc-live + umount sysfs-live + + dmsetup remove --deferred ${LOOP_DEVICE} + losetup -d /dev/${LOOPRAW_DEVICE} + exit $error +} +trap "cleanup" EXIT TERM INT + +mkfs.ext4 /dev/mapper/${LOOP_DEVICE} -L persistence +UUID=$(blkid -o value -s UUID /dev/mapper/${LOOP_DEVICE}) + +# No fsck because of X days without checks +tune2fs -i 0 /dev/mapper/${LOOP_DEVICE} + +MOUNT_DIR=`mktemp -d -t build-debimg.XXXXXX` +mount /dev/mapper/${LOOP_DEVICE} ${MOUNT_DIR} + +######################## +### Setting-up files ### +######################## +mkdir -p ${MOUNT_DIR}/boot/grub +mkdir -p ${MOUNT_DIR}/boot/"$version"/rw + +echo "/ union" > ${MOUNT_DIR}/persistence.conf +cp binary/live/filesystem.squashfs ${MOUNT_DIR}/boot/"$version"/"$version.squashfs" +cp binary/live/initrd.img ${MOUNT_DIR}/boot/"$version"/initrd.img +cp binary/live/vmlinuz ${MOUNT_DIR}/boot/"$version"/vmlinuz + +######################## +### Create grub menu ### +######################## +cat > ${MOUNT_DIR}/boot/grub/grub.cfg << EOF +set timeout=5 +set default=0 + +menuentry "VyOS (KVM console)" { + linux /boot/"$version"/vmlinuz boot=live quiet vyos-union=/boot/"$version" console=ttyS0,9600 console=tty0 systemd.show_status=true + initrd /boot/"$version"/initrd.img +} + +menuentry "Lost password change (KVM console)" { + linux /boot/"$version"/vmlinuz boot=live vyos-union=/boot/"$version" console=ttyS0,9600 console=tty0 systemd.show_status=true init=/opt/vyatta/sbin/standalone_root_pw_reset + initrd /boot/"$version"/initrd.img +} + +menuentry "VyOS $version (Serial console)" { + linux /boot/"$version"/vmlinuz boot=live vyos-union=/boot/"$version" console=tty0 console=ttyS0,9600n8d consoleblank=0 systemd.show_status=true + initrd /boot/"$version"/initrd.img +} + +menuentry "Lost password change $version (Serial console)" { + linux /boot/"$version"/vmlinuz boot=live vyos-union=/boot/"$version" console=tty0 console=ttyS0,9600n8d consoleblank=0 systemd.show_status=true init=/opt/vyatta/sbin/standalone_root_pw_reset + initrd /boot/"$version"/initrd.img +} +EOF + + +############################# +### Setting-up bootloader ### +############################# +grub-install --boot-directory ${MOUNT_DIR}/boot --force --no-floppy --skip-fs-probe /dev/${LOOPRAW_DEVICE} + +################### +### HOOK SCRIPT ### +################### +fstrim ${MOUNT_DIR} +sync + +qemu-img convert -f raw ${OUTPUT} -O vmdk -o adapter_type=lsilogic ${OUTPUTVMDK} +rm ${OUTPUT} + +vmdk=vyos_vmware_image.vmdk +ovf=vyos_vmware_image.ovf +vmdk-convert ${OUTPUTVMDK} ${vmdk} # Generate OVF echo 'Generating OVF file...' vmdk_file_size=$(du --bytes ${vmdk} | cut -f1) vmdk_populated_size=$(vmdk-convert -i ${vmdk} | jq .used) -version=$(cat build/version) -sed scripts/template.ovf \ +sed ../scripts/template.ovf \ -e "s/{{vmdk_file_size}}/${vmdk_file_size}/" \ -e "s/{{vmdk_populated_size}}/${vmdk_populated_size}/" \ -e "s/{{version}}/${version}/" \ > ${ovf} # Generate manifest file -cd ${DST_DIR} openssl sha1 *.vmdk *.ovf > vyos_vmware_image.mf # Convert the OVF to signed OVA... @@ -68,7 +202,9 @@ if [ ! -f ${private_key} ]; then exit 1 fi ovftool --privateKey=${PRIVATE_KEY_PATH} vyos_vmware_image.ovf vyos_vmware_image-signed.ova +#ovftool vyos_vmware_image.ovf vyos_vmware_image-signed.ova # Convert the OVF to signed OVF... echo 'Converting the OVF to signed OVF...' ovftool --privateKey=${PRIVATE_KEY_PATH} vyos_vmware_image.ovf vyos_vmware_image-signed.ovf +#ovftool vyos_vmware_image.ovf vyos_vmware_image-signed.ovf diff --git a/scripts/template.ovf b/scripts/template.ovf index f3624339..b8d3eddc 100644 --- a/scripts/template.ovf +++ b/scripts/template.ovf @@ -1,121 +1,187 @@ - - + + - - Virtual disk information - - + + List of profiles + + + Minimal hardware profile - 1 vCPU, 512 MB RAM + + + + Medium hardware profile - 4 vCPUs, 16 GB RAM + + + + Large hardware profile - 8 vCPUs, 32 GB RAM + + - The list of logical networks - - The VM Network network + List of logical networks used in the package + + Network 1 - + + Supported IP assignment schemes + + + Virtual disk information + + + A virtual machine - vyos - - The kind of installed guest operating system + + VyOS is a Linux-based network operating system that provides software-based network routing, firewall, and VPN functionality. + VyOS + VyOS maintainers and contributors + {{version}} + https://www.vyos.io + https://sentrium.io/ + + Appliance user Settings + + + The password for the appliance 'vyos' account. Passwords must be at least 8 characters in length. + + + + The public ssh key for the appliance 'vyos' account. + + Appliance IPv4 Network Settings + + + The host name for this virtual machine. + + + + The IPv4 address. Leave blank if DHCP is desired. + + + + The IPv4 netmask or prefix for this interface. Leave blank if DHCP is desired. + + + + Default gateway address. Leave blank if DHCP is desired. + + + + The domain name server IP Addresses for this VM (comma separated). Leave blank if DHCP is desired. + + + + NTP servers for this VM (comma separated). Leave blank if DHCP is desired. + + + + VM specific properties + + + + + VyOS + + + Guest Operating System + VyOS - - Virtual hardware requirements + + Virtual Hardware Requirements Virtual Hardware Family 0 - vyos - vmx-09 + vmx-11 - + hertz * 10^6 - Number of Virtual CPUs - 1 virtual CPU(s) - 1 + Number of virtual CPUs + 1 virtual CPU + 1 3 1 - - byte * 2^30 + + hertz * 10^6 + Number of virtual CPUs + 4 virtual CPUs + 1 + 3 + 4 + + + hertz * 10^6 + Number of virtual CPUs + 8 virtual CPUs + 1 + 3 + 8 + + + byte * 2^20 Memory Size - 1GB of memory - 2 + 512 MB of memory + 2 4 - 1 + 512 + + + byte * 2^20 + Memory Size + 16 GB of memory + 2 + 4 + 16384 + + + byte * 2^20 + Memory Size + 32 GB of memory + 2 + 4 + 32768 - 0 - SCSI Controller - scsiController0 - 3 + 0 + SCSI Controller 0 - LSI Logic + 3 lsilogic 6 - - 1 - IDE Controller - ideController1 - 4 - 5 - - - true - serial0 - 5 - 21 - - - - 0 - false - cdrom0 - 6 - 5 - 15 - 0 - disk0 + disk0 ovf:/disk/vmdisk1 - 7 + 4 3 17 - 2 + 1 true - VM Network - VmxNet3 ethernet adapter on "VM Network" - ethernet0 - 8 - VmxNet3 + Network 1 + Ethernet adapter on "Network 1" + 5 + vmxnet3 10 - - - false - video - 9 - 24 + + 0 + IDE Controller 0 + 6 + 5 - + + 0 false - vmci - 10 - vmware.vmci - 1 + CD/DVD Drive 1 + 7 + 6 + 15 - - - - - + - - VyOS is a Linux-based network operating system that provides software-based network routing, firewall, and VPN functionality. - VyOS - VyOS maintainers and contributors - {{version}} - - + diff --git a/tools/cloud-init/vmware/90_dpkg.cfg b/tools/cloud-init/vmware/90_dpkg.cfg new file mode 100644 index 00000000..f9c9cba0 --- /dev/null +++ b/tools/cloud-init/vmware/90_dpkg.cfg @@ -0,0 +1,3 @@ +# to update this file, run dpkg-reconfigure cloud-init +datasource_list: [ OVF ] +disable_vmware_customization: false diff --git a/tools/cloud-init/vmware/config.boot.default b/tools/cloud-init/vmware/config.boot.default new file mode 100644 index 00000000..8b7cdae5 --- /dev/null +++ b/tools/cloud-init/vmware/config.boot.default @@ -0,0 +1,30 @@ +system { + host-name vyos + login { + user vyos { + authentication { + encrypted-password $6$QxPS.uk6mfo$9QBSo8u1FkH16gMyAVhus6fU3LOzvLR9Z9.82m3tiHFAxTtIkhaZSWssSgzt4v4dGAL8rhVQxTg0oAG9/q11h/ + plaintext-password "" + } + level admin + } + } + syslog { + global { + facility all { + level info + } + facility protocols { + level debug + } + } + } + config-management { + commit-revisions 100 + } +} + +interfaces { + loopback lo { + } +} -- cgit v1.2.3