diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/build-GCE-image | 165 | ||||
-rwxr-xr-x | scripts/build-azure-image | 151 | ||||
-rwxr-xr-x | scripts/build-hyperv-image | 32 | ||||
-rwxr-xr-x | scripts/build-oracle-image | 154 | ||||
-rwxr-xr-x | scripts/build-qemu-image | 34 | ||||
-rwxr-xr-x | scripts/build-vmware-image | 210 | ||||
-rw-r--r-- | scripts/packer-scripts/vmware.sh | 29 | ||||
-rw-r--r-- | scripts/packer.json | 61 | ||||
-rw-r--r-- | scripts/template.ovf | 223 | ||||
-rwxr-xr-x | scripts/vhd.py | 90 |
10 files changed, 0 insertions, 1149 deletions
diff --git a/scripts/build-GCE-image b/scripts/build-GCE-image deleted file mode 100755 index f9273874..00000000 --- a/scripts/build-GCE-image +++ /dev/null @@ -1,165 +0,0 @@ -#!/bin/sh -# -# Copyright (C) 2018 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 distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -# File: build-GCE-image -# Purpose: -# Build VyOS image for Google cloud. - -lb bootstrap - -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 - -# get vyos build version -version=$(cat version) -dateymd=$(date +%Y%m%d) - -###################################### -### Prepare the HDD (format, ext.) ### -###################################### -PARTED=/sbin/parted -OUTPUT=disk.raw -OUTPUTGZ=VyOS-"$dateymd".tar.gz -IMAGE_SIZE=10 -qemu-img create -f raw ${OUTPUT} ${IMAGE_SIZE}G - -LOOPNAME=`losetup -f` -LOOPMINOR=${LOOPNAME//[^0-9]} -if [ ! -e $LOOPNAME ]; then - mknod $LOOPNAME b 7 $LOOPMINOR -fi - -${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 - -serial --speed=38400 --unit=0 --word=8 --parity=no --stop=1 -terminal_input serial -terminal_output serial - -menuentry "VyOS $version (Serial console)" { - linux /boot/"$version"/vmlinuz boot=live vyos-union=/boot/"$version" console=tty0 console=ttyS0,38400n8d earlyprintk=ttyS0,38400 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,38400n8d earlyprintk=ttyS0,38400 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} -umount ${MOUNT_DIR} && { - tar -Sczf ${OUTPUTGZ} ${OUTPUT} - mount /dev/mapper/${LOOP_DEVICE} ${MOUNT_DIR} -} diff --git a/scripts/build-azure-image b/scripts/build-azure-image deleted file mode 100755 index 48590cb4..00000000 --- a/scripts/build-azure-image +++ /dev/null @@ -1,151 +0,0 @@ -#!/bin/sh -# -# Copyright (C) 2018 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 distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -# File: build-azure-image -# Purpose: -# Build VyOS image for Azure. - -lb bootstrap - -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 - -# get vyos build version -version=$(cat version) -dateymd=$(date +%Y%m%d) - -###################################### -### Prepare the HDD (format, ext.) ### -###################################### -PARTED=/sbin/parted -OUTPUT=VyOS-"$dateymd".vhd -IMAGE_SIZE=10 -qemu-img create ${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 $version (Serial console)" { - linux /boot/"$version"/vmlinuz boot=live quiet vyos-union=/boot/"$version" console=tty0 console=ttyS0,115200n8 earlyprintk=ttyS0,115200 consoleblank=0 systemd.show_status=true - initrd /boot/"$version"/initrd.img -} - -menuentry "Lost password change $version (Serial console)" { - linux /boot/"$version"/vmlinuz boot=live quiet vyos-union=/boot/"$version" console=tty0 console=ttyS0,115200n8 earlyprintk=ttyS0,115200 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} - -../scripts/vhd.py ${OUTPUT} diff --git a/scripts/build-hyperv-image b/scripts/build-hyperv-image deleted file mode 100755 index 40c0c828..00000000 --- a/scripts/build-hyperv-image +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh -# -# Copyright (C) 2016 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 distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -# File: build-hyperv-image -# Purpose: -# Build VyOS image for Hyper-V. - -export PACKER_BUILD_DIR=packer_build - -DST_DIR=${PACKER_BUILD_DIR}/hyperv -mkdir -p ${DST_DIR} - -# Convert raw image to VHD -source_image=${PACKER_BUILD_DIR}/qemu/vyos_qemu_image.img -vhd=${DST_DIR}/vyos_hyperv_image.vhd -qemu-img convert -f raw ${source_image} -O vpc ${vhd} -if [ "$?" = "0" ]; then - echo "Hyper-V image successfully created to ./${vhd}" -fi diff --git a/scripts/build-oracle-image b/scripts/build-oracle-image deleted file mode 100755 index e2066fc7..00000000 --- a/scripts/build-oracle-image +++ /dev/null @@ -1,154 +0,0 @@ -#!/bin/sh -# -# Copyright (C) 2018 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 distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -# File: build-oracle-image -# Purpose: -# Build VyOS image for Oracle cloud. - -lb bootstrap - -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 - -# get vyos build version -version=$(cat version) -dateymd=$(date +%Y%m%d) - -###################################### -### Prepare the HDD (format, ext.) ### -###################################### -PARTED=/sbin/parted -OUTPUT=disk.raw -OUTPUTQCOW2=VyOS-"$dateymd".qcow2 -IMAGE_SIZE=10 -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 $version (Serial console)" { - linux /boot/"$version"/vmlinuz boot=live vyos-union=/boot/"$version" console=tty0 console=ttyS0,38400n8d earlyprintk=ttyS0,38400 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,38400n8d earlyprintk=ttyS0,38400 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 -O qcow2 ${OUTPUT} ${OUTPUTQCOW2} -rm $OUTPUT diff --git a/scripts/build-qemu-image b/scripts/build-qemu-image deleted file mode 100755 index 349f4a5d..00000000 --- a/scripts/build-qemu-image +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh -# -# Copyright (C) 2016-2021 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 distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -# File: build-qemu-image -# Purpose: -# Build VyOS raw image for qemu. - -BUILD_DIR="$(scripts/query-json build/build-config.json build_dir)" -BUILD_ARCH="$(scripts/query-json build/build-config.json architecture)" -export VERSION="$(cat $BUILD_DIR/version)" - -export ISO_IMAGE="${BUILD_DIR}/live-image-$BUILD_ARCH.hybrid.iso" -export ISO_MD5_SUM="$(md5sum ${ISO_IMAGE} | awk '{print $1}')" -export PACKER_BUILD_DIR=packer_build -export PACKER_LOG_PATH="${PACKER_BUILD_DIR}/build.log" -export PACKER_LOG=1 - -mkdir -p "${PACKER_BUILD_DIR}" - -packer build -only=qemu-image scripts/packer.json -cp "${PACKER_BUILD_DIR}/qemu/vyos_qemu_image.img" "$BUILD_DIR/vyos-$VERSION-$BUILD_ARCH.qcow2" diff --git a/scripts/build-vmware-image b/scripts/build-vmware-image deleted file mode 100755 index e56ce137..00000000 --- a/scripts/build-vmware-image +++ /dev/null @@ -1,210 +0,0 @@ -#!/bin/sh -# -# 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 distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -# File: build-vmware-image -# Purpose: -# 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." - exit 1 -else - echo "Your system has vmdk-convert." -fi - -if [ ! $(which ovftool) ]; then - echo "Your system doesn't have ovftool. Please install it from https://www.vmware.com/support/developer/ovf/." - exit 1 -else - echo "Your system has ovftool." -fi - -lb bootstrap - -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 - -# 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,115200 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,115200 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,115200n8d 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,115200n8d 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) -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 -openssl sha1 *.vmdk *.ovf > vyos_vmware_image.mf - -# Convert the OVF to signed OVA... -echo 'Converting the OVF to signed OVA...' -private_key=${PRIVATE_KEY_PATH:-"../key/privatekey.pem"} -if [ ! -f ${private_key} ]; then - echo 'Please put your key to "key/privatekey.pem" in repository root, or set PRIVATE_KEY_PATH to environment variables.' - exit 1 -fi -ovftool --privateKey=${private_key} 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} vyos_vmware_image.ovf vyos_vmware_image-signed.ovf -#ovftool vyos_vmware_image.ovf vyos_vmware_image-signed.ovf diff --git a/scripts/packer-scripts/vmware.sh b/scripts/packer-scripts/vmware.sh deleted file mode 100644 index 60c4db7e..00000000 --- a/scripts/packer-scripts/vmware.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/vbash -source /opt/vyatta/etc/functions/script-template - -# Add Debian Jessie repository -set system package repository jessie url 'http://ftp.nl.debian.org/debian/' -set system package repository jessie distribution 'jessie' -set system package repository jessie components 'main contrib non-free' -commit -save - -# Install open-vm-tools -sudo apt-get update -sudo apt-get -y install open-vm-tools - -# Delete Debian Jessie repository -delete system package repository jessie -commit -save - -# Removing leftover leases and persistent rules -sudo rm -f /var/lib/dhcp3/* - -# Removing apt caches -sudo rm -rf /var/cache/apt/* - -# Removing hw-id -delete interfaces ethernet eth0 hw-id -commit -save diff --git a/scripts/packer.json b/scripts/packer.json deleted file mode 100644 index f1e49798..00000000 --- a/scripts/packer.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "variables": { - "iso_url": "{{env `ISO_IMAGE`}}", - "iso_checksum": "{{env `ISO_MD5_SUM`}}", - "output_directory": "{{env `PACKER_BUILD_DIR`}}" - }, - "builders": - [ - { - "name": "qemu-image", - "type": "qemu", - "iso_url": "{{user `iso_url`}}", - "iso_checksum": "md5:{{user `iso_checksum`}}", - "output_directory": "{{user `output_directory`}}/qemu", - "shutdown_command": "sudo halt -p", - "disk_size": 4096, - "format": "qcow2", - "headless": true, - "host_port_min": 2222, - "host_port_max": 2229, - "ssh_username": "vyos", - "ssh_password": "vyos", - "ssh_port": 22, - "ssh_wait_timeout": "300s", - "vm_name": "vyos_qemu_image.img", - "net_device": "virtio-net", - "disk_interface": "virtio", - "boot_wait": "5s", - "boot_command": - [ - "<enter><wait3m>", - "vyos<enter><wait5>", - "vyos<wait><enter><wait10>", - "install image<enter><wait5>", - "<enter><wait5>", - "<enter><wait5>", - "<enter><wait5>", - "Yes<enter><wait5>", - "<enter><wait10>", - "<enter><wait5>", - "<enter><wait5>", - "vyos<enter><wait5>", - "vyos<enter><wait10>", - "<enter><wait10><wait10>", - "reboot<enter><wait5>", - "Yes<enter><wait3m>", - "vyos<enter><wait5>", - "vyos<enter><wait10>", - "configure<enter><wait5>", - "set interface ethernet eth0 address dhcp<enter><wait5>", - "set service ssh<enter><wait5>", - "commit<enter><wait5>", - "save<enter><wait5>", - "delete interface ethernet eth0 hw-id<enter><wait5>", - "commit<enter><wait5>", - "save<enter><wait5>", - "exit<enter><wait5>" - ] - } - ] -} diff --git a/scripts/template.ovf b/scripts/template.ovf deleted file mode 100644 index 26d6cc62..00000000 --- a/scripts/template.ovf +++ /dev/null @@ -1,223 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ovf:Envelope xmlns="http://schemas.dmtf.org/ovf/envelope/1" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vmw="http://www.vmware.com/schema/ovf" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <References> - <File ovf:href="vyos_vmware_image.vmdk" ovf:id="file1" ovf:size="{{vmdk_file_size}}"/> - </References> - <ovf:NetworkSection> - <ovf:Info>The list of logical networks</ovf:Info> - <ovf:Network ovf:name="WAN"> - <ovf:Description>WAN network</ovf:Description> - </ovf:Network> - <ovf:Network ovf:name="LAN"> - <ovf:Description>LAN network</ovf:Description> - </ovf:Network> - </ovf:NetworkSection> - <DeploymentOptionSection> - <Info>List of profiles</Info> - <Configuration ovf:default="true" ovf:id="1CPU-512MB"> - <Label ovf:msgid="Small.label">Small</Label> - <Description ovf:msgid="Small.description">Minimal hardware profile - 1 vCPU, 512 MB RAM</Description> - </Configuration> - <Configuration ovf:id="4CPU-16GB"> - <Label ovf:msgid="Medium.label">Medium</Label> - <Description ovf:msgid="Medium.description">Medium hardware profile - 4 vCPUs, 16 GB RAM</Description> - </Configuration> - <Configuration ovf:id="8CPU-32GB"> - <Label ovf:msgid="Large.label">Large</Label> - <Description ovf:msgid="Large.description">Large hardware profile - 8 vCPUs, 32 GB RAM</Description> - </Configuration> - </DeploymentOptionSection> - <vmw:IpAssignmentSection ovf:required="false" vmw:protocols="IPv4 IPv6" vmw:schemes="ovfenv dhcp"> - <Info>Supported IP assignment schemes</Info> - </vmw:IpAssignmentSection> - <DiskSection> - <Info>Virtual disk information</Info> - <Disk ovf:capacity="10" ovf:capacityAllocationUnits="byte * 2^30" ovf:diskId="vmdisk1" ovf:fileRef="file1" ovf:format="http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized" ovf:populatedSize="{{vmdk_populated_size}}"/> - </DiskSection> - <VirtualSystem ovf:id="VyOS"> - <Info>A virtual machine</Info> - <ProductSection ovf:required="false"> - <Info>VyOS is a Linux-based network operating system that provides software-based network routing, firewall, and VPN functionality.</Info> - <Product>VyOS</Product> - <Vendor>Sentrium S.L.</Vendor> - <Version>{{version}}</Version> - <ProductUrl>https://www.vyos.io</ProductUrl> - <VendorUrl>https://sentrium.io/</VendorUrl> - <AppUrl/> - <Category>Appliance user Settings</Category> - <Property ovf:key="password" ovf:password="true" ovf:qualifiers="MinLen(8)" ovf:type="string" ovf:userConfigurable="true" ovf:value=""> - <Label ovf:msgid="Password.label">Password</Label> - <Description ovf:msgid="Password.description">The password for the appliance 'vyos' account. Passwords must be at least 8 characters in length.</Description> - </Property> - <Property ovf:key="public-keys" ovf:type="string" ovf:userConfigurable="true" ovf:value=""> - <Label>Public key</Label> - <Description>The public ssh key for the appliance 'vyos' account.</Description> - </Property> - <Category>Appliance IPv4 Network Settings (WAN interface)</Category> - <Property ovf:key="local-hostname" ovf:qualifiers="MinLen(0),MaxLen(65535)" ovf:type="string" ovf:userConfigurable="true" ovf:value=""> - <Label>Hostname</Label> - <Description>The host name for this virtual machine.</Description> - </Property> - <Property ovf:key="ip0" ovf:type="string" ovf:userConfigurable="true"> - <Label>Network IPv4 Address</Label> - <Description>The IPv4 address. Leave blank if DHCP is desired.</Description> - </Property> - <Property ovf:key="netmask0" ovf:type="string" ovf:userConfigurable="true"> - <Label>Network IPv4 Netmask</Label> - <Description>The IPv4 netmask or prefix for this interface. Leave blank if DHCP is desired.</Description> - </Property> - <Property ovf:key="gateway" ovf:type="string" ovf:userConfigurable="true"> - <Label>Default Gateway v4</Label> - <Description>Default gateway address. Leave blank if DHCP is desired.</Description> - </Property> - <Property ovf:key="DNS" ovf:type="string" ovf:userConfigurable="true"> - <Label>Domain Name Servers</Label> - <Description>The domain name server IP Addresses for this VM (comma separated). Leave blank if DHCP is desired.</Description> - </Property> - <Property ovf:key="NTP" ovf:type="string" ovf:userConfigurable="true"> - <Label>Domain Time Servers</Label> - <Description>NTP servers for this VM (comma separated). Leave blank if DHCP is desired.</Description> - </Property> - <Category>Appliance API Settings</Category> - <Property ovf:key="APIKEY" ovf:type="string" ovf:userConfigurable="true"> - <Label>API key</Label> - <Description>API key to access the VyOS api. If left blank the api wil not be enabled.</Description> - </Property> - <Property ovf:key="APIPORT" ovf:value="443" ovf:type="int" ovf:userConfigurable="true"> - <Label>API listening port</Label> - <Description>API port to listen on for calls. Leave blank to keep it default '443'.</Description> - </Property> - <Property ovf:key="APIDEBUG" ovf:value="false" ovf:type="boolean" ovf:userConfigurable="true"> - <Label>API debug logging</Label> - <Description>Enable API debug logging</Description> - </Property> - <Property ovf:key="user-data" ovf:type="string" ovf:userConfigurable="true" ovf:value=""> - <Label>Cloud-init User-Data</Label> - <Description>User-Data, encoded with base64.</Description> - </Property> - </ProductSection> - <ProductSection ovf:class="vm" ovf:required="false"> - <Info>VM specific properties</Info> - <Property ovf:key="vmname" ovf:type="string" ovf:value="VyOS"/> - </ProductSection> - <AnnotationSection> - <Info/> - <Annotation>VyOS</Annotation> - </AnnotationSection> - <OperatingSystemSection ovf:id="96" ovf:version="6" vmw:osType="debian8_64Guest"> - <Info>The operating system installed</Info> - <Description>Debian GNU/Linux 8 (64-bit)</Description> - </OperatingSystemSection> - <VirtualHardwareSection ovf:required="false" ovf:transport="com.vmware.guestInfo"> - <Info>Virtual Hardware Requirements</Info> - <System> - <vssd:ElementName>Virtual Hardware Family</vssd:ElementName> - <vssd:InstanceID>0</vssd:InstanceID> - <vssd:VirtualSystemType>vmx-11</vssd:VirtualSystemType> - </System> - <Item configuration="1CPU-512MB"> - <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits> - <rasd:Description>Number of virtual CPUs</rasd:Description> - <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1 virtual CPU</rasd:ElementName> - <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</rasd:InstanceID> - <rasd:ResourceType>3</rasd:ResourceType> - <rasd:VirtualQuantity>1</rasd:VirtualQuantity> - </Item> - <Item configuration="4CPU-16GB"> - <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits> - <rasd:Description>Number of virtual CPUs</rasd:Description> - <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">4 virtual CPUs</rasd:ElementName> - <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</rasd:InstanceID> - <rasd:ResourceType>3</rasd:ResourceType> - <rasd:VirtualQuantity>4</rasd:VirtualQuantity> - </Item> - <Item configuration="8CPU-32GB"> - <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits> - <rasd:Description>Number of virtual CPUs</rasd:Description> - <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">8 virtual CPUs</rasd:ElementName> - <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</rasd:InstanceID> - <rasd:ResourceType>3</rasd:ResourceType> - <rasd:VirtualQuantity>8</rasd:VirtualQuantity> - </Item> - <Item configuration="1CPU-512MB"> - <rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits> - <rasd:Description>Memory Size</rasd:Description> - <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">512 MB of memory</rasd:ElementName> - <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">2</rasd:InstanceID> - <rasd:Reservation>512</rasd:Reservation> - <rasd:ResourceType>4</rasd:ResourceType> - <rasd:VirtualQuantity>512</rasd:VirtualQuantity> - </Item> - <Item configuration="4CPU-16GB"> - <rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits> - <rasd:Description>Memory Size</rasd:Description> - <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">16 GB of memory</rasd:ElementName> - <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">2</rasd:InstanceID> - <rasd:Reservation>16384</rasd:Reservation> - <rasd:ResourceType>4</rasd:ResourceType> - <rasd:VirtualQuantity>16384</rasd:VirtualQuantity> - </Item> - <Item configuration="8CPU-32GB"> - <rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits> - <rasd:Description>Memory Size</rasd:Description> - <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">32 GB of memory</rasd:ElementName> - <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">2</rasd:InstanceID> - <rasd:Reservation>32768</rasd:Reservation> - <rasd:ResourceType>4</rasd:ResourceType> - <rasd:VirtualQuantity>32768</rasd:VirtualQuantity> - </Item> - <Item> - <rasd:Address xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">0</rasd:Address> - <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">SCSI Controller 0 - VMware Paravirtual SCSI</rasd:ElementName> - <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">3</rasd:InstanceID> - <rasd:ResourceSubType>VirtualSCSI</rasd:ResourceSubType> - <rasd:ResourceType>6</rasd:ResourceType> - </Item> - <Item> - <rasd:AddressOnParent>0</rasd:AddressOnParent> - <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">disk0</rasd:ElementName> - <rasd:HostResource>ovf:/disk/vmdisk1</rasd:HostResource> - <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">4</rasd:InstanceID> - <rasd:Parent>3</rasd:Parent> - <rasd:ResourceType>17</rasd:ResourceType> - </Item> - <Item> - <rasd:Address>0</rasd:Address> - <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">IDE Controller 0</rasd:ElementName> - <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">5</rasd:InstanceID> - <rasd:ResourceType>5</rasd:ResourceType> - </Item> - <Item> - <rasd:AddressOnParent>0</rasd:AddressOnParent> - <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation> - <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">CD/DVD Drive 1</rasd:ElementName> - <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">6</rasd:InstanceID> - <rasd:Parent>5</rasd:Parent> - <rasd:ResourceType>15</rasd:ResourceType> - </Item> - <ovf:Item> - <rasd:AddressOnParent>7</rasd:AddressOnParent> - <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation> - <rasd:Connection>WAN</rasd:Connection> - <rasd:Description>NIC representing WAN</rasd:Description> - <rasd:ElementName>WAN</rasd:ElementName> - <rasd:InstanceID>7</rasd:InstanceID> - <rasd:ResourceSubType>vmxnet3</rasd:ResourceSubType> - <rasd:ResourceType>10</rasd:ResourceType> - </ovf:Item> - <ovf:Item> - <rasd:AddressOnParent>8</rasd:AddressOnParent> - <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation> - <rasd:Connection>LAN</rasd:Connection> - <rasd:Description>NIC representing LAN</rasd:Description> - <rasd:ElementName>LAN</rasd:ElementName> - <rasd:InstanceID>8</rasd:InstanceID> - <rasd:ResourceSubType>vmxnet3</rasd:ResourceSubType> - <rasd:ResourceType>10</rasd:ResourceType> - </ovf:Item> - <vmw:Config ovf:required="false" vmw:key="cpuHotAddEnabled" vmw:value="true"/> - <vmw:Config ovf:required="false" vmw:key="memoryHotAddEnabled" vmw:value="true"/> - <vmw:ExtraConfig ovf:required="false" vmw:key="sched.mem.pin" vmw:value="TRUE"/> - </VirtualHardwareSection> - </VirtualSystem> -</ovf:Envelope> diff --git a/scripts/vhd.py b/scripts/vhd.py deleted file mode 100755 index 6a268924..00000000 --- a/scripts/vhd.py +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright: 2015 Bastian Blank -# License: MIT, see LICENSE.txt for details. - -import array -import struct -import time -import sys -import os - -from uuid import uuid4 - - -class VHDFooter: - _struct = struct.Struct('>8sLLQL4sL4sQQ4sLL16sB427x') - size = _struct.size - - vhd_timestamp_base = 946684800 - - def __init__(self, size, uuid=None, timestamp=None): - self.size = size - self.timestamp = timestamp or (int(time.time()) - self.vhd_timestamp_base) - self.uuid = uuid or uuid4() - - @staticmethod - def _checksum(msg): - return 0x100000000 + ~sum(array.array("B", msg)) - - def _pack_geometry(self): - sectors = self.size // 512 - - if sectors > 65535 * 16 * 255: - sectors = 65535 * 16 * 255 - - if sectors >= 65535 * 16 * 63: - sectorsPerTrack = 255 - heads = 16 - cylinderTimesHeads = sectors // sectorsPerTrack - - else: - sectorsPerTrack = 17 - cylinderTimesHeads = sectors // sectorsPerTrack - - heads = (cylinderTimesHeads + 1023) // 1024 - - if heads < 4: - heads = 4 - if cylinderTimesHeads >= (heads * 1024) or heads > 16: - sectorsPerTrack = 31 - heads = 16 - cylinderTimesHeads = sectors // sectorsPerTrack - if cylinderTimesHeads >= (heads * 1024): - sectorsPerTrack = 63 - heads = 16 - cylinderTimesHeads = sectors // sectorsPerTrack - - cylinders = cylinderTimesHeads // heads - - return struct.pack('>HBB', cylinders, heads, sectorsPerTrack) - - def _pack(self, checksum): - return self._struct.pack( - b'conectix', # Cookie - 0x00000002, # Features - 0x00010000, # File Format Version - 0xffffffffffffffff, # Data Offset - self.timestamp, # Time Stamp - b'qemu', # Creator Application - 0x00010000, # Creator Version - b'Wi2k', # Creator Host OS - self.size, # Original Size - self.size, # Current Size - self._pack_geometry(), # Disk Geometry - 2, # Disk Type - checksum, # Checksum - self.uuid.bytes, # Unique Id - 0, # Saved State - ) - - def pack(self): - c = self._checksum(self._pack(0)) - return self._pack(c) - -with open(sys.argv[1], 'rb+') as f: - f.seek(0, 2) - image_size = f.tell() - image_size_complete = image_size + VHDFooter.size - footer = VHDFooter(image_size) - f.write(footer.pack()) |