From 56862cd9b870cb1d1e52bdbd5d035057fe87c431 Mon Sep 17 00:00:00 2001 From: John Chittum Date: Tue, 10 Nov 2020 12:50:32 -0600 Subject: [PATCH 1/3] Backport vmtools version in vmdk (LP: #1893898) Backport 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 comments), as well as ensuring that the toolsVersion is added --- live-build/functions | 47 ++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/live-build/functions b/live-build/functions index 17e42cd7..2771a521 100644 --- a/live-build/functions +++ b/live-build/functions @@ -242,28 +242,33 @@ modify_vmdk_header() { # Extract the vmdk header for manipulation dd if="${vmdk_name}" of="${descriptor}" bs=1 skip=512 count=1024 + echo "Cat'ing original vmdk disk descriptor to console for debugging." + # cat header so we are aware of the original descriptor for debugging + cat $descriptor - # 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 - # ddb.virtualHWVersion: set the version to 7, which covers most - # current versions of VMware - # createType: make sure its set to stream Optimized - # remove the vmdk-stream-converter comment and replace with - # # Disk DescriptorFile. This is needed for Virtualbox - # 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}" - - # The header is cannot be bigger than 1024 - expr $(stat --format=%s ${newdescriptor}) \< 1024 > /dev/null 2>&1 || { - echo "descriptor is too large, VMDK will be invalid!"; exit 1; } + # trim null bytes to treat as standard text file + tr -d '\000' < $descriptor > $newdescriptor + + # add newline to newdescriptor + echo "" >> $newdescriptor + + # add required tools version + echo -n 'ddb.toolsVersion = "2147483647"' >> $newdescriptor + + # diff original descriptor and new descriptor for debugging + # diff exits 1 if difference. pipefail not set so piping diff + # to cat prints diff and swallows exit 1 + echo "Printing diff of original and new descriptors." + diff --text $descriptor $newdescriptor | cat + + # The header must be 1024 or less before padding + if ! expr $(stat --format=%s ${newdescriptor}) \< 1025 > /dev/null 2>&1; then + echo "descriptor is too large, VMDK will be invalid!"; + exit 1 + fi + + # reset newdescriptor to be 1024 + truncate --no-create --size=1K $newdescriptor # Overwrite the vmdk header with our new, modified one dd conv=notrunc,nocreat \ From c56c2475e4f9c86606c8e30d3d4f5c4b0d54fee8 Mon Sep 17 00:00:00 2001 From: John Chittum Date: Mon, 16 Nov 2020 09:18:14 -0600 Subject: [PATCH 2/3] Update changelog Open release and add information --- debian/changelog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debian/changelog b/debian/changelog index 4d1865fd..5600583f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +livecd-rootfs (2.664.9) UNRELEASED; urgency=medium + + * Backport Ensure toolsVersion set in vmdk header (LP: #1893898) + + -- John Chittum Mon, 16 Nov 2020 08:57:16 -0600 + livecd-rootfs (2.664.8) focal; urgency=medium Backport snap-preseed work from groovy to focal LP: #1896755 From c5cea219f4c3ce7a4f9160ec130af6da0f1423c7 Mon Sep 17 00:00:00 2001 From: John Chittum Date: Tue, 17 Nov 2020 14:54:54 -0600 Subject: [PATCH 3/3] re-add sed command Older version of vmdk-stream-converter has an incorrect header. The original sed command replaced the incorrect "Description File" comment with the correct "Disk DescriptorFile". --- live-build/functions | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/live-build/functions b/live-build/functions index 2771a521..d69adddd 100644 --- a/live-build/functions +++ b/live-build/functions @@ -249,12 +249,25 @@ modify_vmdk_header() { # trim null bytes to treat as standard text file tr -d '\000' < $descriptor > $newdescriptor + # remove the vmdk-stream-converter comment and replace with + # # Disk DescriptorFile. This is needed for Virtualbox + # remove the comments from vmdk-stream-converter which causes + # VirtualBox and others to fail VMDK validation + 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' \ + ${newdescriptor} + # add newline to newdescriptor echo "" >> $newdescriptor # add required tools version echo -n 'ddb.toolsVersion = "2147483647"' >> $newdescriptor + echo "Cat'ing modified descriptor for debugging." + cat $newdescriptor + # diff original descriptor and new descriptor for debugging # diff exits 1 if difference. pipefail not set so piping diff # to cat prints diff and swallows exit 1