From 24ee4b8c4d3fc83fd1798c01c62a882dd975eff1 Mon Sep 17 00:00:00 2001 From: John Chittum Date: Fri, 16 Oct 2020 13:43:26 -0500 Subject: [PATCH] vmtools version in vmdk header (LP: #1893898) LP: #1893898 describes missing vmtools version from the vmdk headers. The version should be added as ddb.toolsVersion = "2147483647" however the sed was no longer replacing a ddb.comment field with the tools version. Rather than subbing ddb.comment with toolsVersion, this commit deletes ddb.comment (which the comment mentions could cause errors), and adds the correct value. There was no visibility into the descriptor during hook creation, so debug statements were added. This allows us to quickly verify in the logs that bad statements are removed (the possibly offending commetns), as well as ensuring that the toolsVersion is added --- debian/changelog | 4 ++++ live-build/functions | 44 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/debian/changelog b/debian/changelog index 93e2b1a2..bc319f9a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,10 @@ livecd-rootfs (2.693) groovy; urgency=medium livecd-rootfs (2.692) groovy; urgency=medium + [ John Chittum ] + * Ensure vmtools version entered into vmdk header (LP: #1893898) + + [ Łukasz 'sil2100' Zemczak ] * Create a 1GB swapfile for the raspi desktop images. -- Łukasz 'sil2100' Zemczak Thu, 15 Oct 2020 11:23:47 +0200 diff --git a/live-build/functions b/live-build/functions index e4b90425..830a0549 100644 --- a/live-build/functions +++ b/live-build/functions @@ -237,6 +237,12 @@ modify_vmdk_header() { # Extract the vmdk header for manipulation dd if="${vmdk_name}" of="${descriptor}" bs=1 skip=512 count=1024 + # cat header so we are aware of the original descriptor for debugging + cat $descriptor + + # trim null bytes to treat as standard text file + tr -d '\000' < $descriptor > $newdescriptor + # The sed lines below is where the magic is. Specifically: # ddb.toolsVersion: sets the open-vm-tools so that VMware shows # the tooling as current @@ -248,15 +254,37 @@ modify_vmdk_header() { # remove the comments from vmdk-stream-converter which causes # VirtualBox and others to fail VMDK validation - sed -e 's|# Description file.*|# Disk DescriptorFile|' \ - -e '/# Believe this is random*/d' \ - -e '/# Indicates no parent/d' \ - -e '/# The Disk Data Base/d' \ - -e 's|ddb.comment.*|ddb.toolsVersion = "2147483647"|' \ - "${descriptor}" > "${newdescriptor}" + sed -i -e 's|# Description file.*|# Disk DescriptorFile|' \ + -e '/# Believe this is random*/d' \ + -e '/# Indicates no parent/d' \ + -e '/# The Disk Data Base/d' \ + -e '/ddb.comment*/d' \ + $newdescriptor + + # grep for removal of the ddb.comment line to ensure removal + if grep -q "ddb.comment" $newdescriptor; then + echo "ddb.comment exists and will cause Virtualbox failures"; exit 1 + fi + + # add newline to newdescriptor + echo "" >> $newdescriptor + + # add tools version + echo -n 'ddb.toolsVersion = "2147483647"' >> $newdescriptor + + # check ddb.toolsVersion in descriptor, otherwise image will fail + grep -q 'ddb.toolsVersion' $newdescriptor || { + echo 'failed to write version. Descriptor invalid'; exit 1; + } + + # diff original descriptor and new descriptor for debugging + diff --text $descriptor $newdescriptor | cat + + # reset newdescriptor to be 1024 + truncate --no-create --size=1K $newdescriptor - # The header is cannot be bigger than 1024 - expr $(stat --format=%s ${newdescriptor}) \< 1024 > /dev/null 2>&1 || { + # The header must be 1024 or less + expr $(stat --format=%s ${newdescriptor}) \< 1025 > /dev/null 2>&1 || { echo "descriptor is too large, VMDK will be invalid!"; exit 1; } # Overwrite the vmdk header with our new, modified one