Skip to content

Commit 23ae9aa

Browse files
committed
internal/worker/scripts: Add logging to hivex shell scripts
Signed-off-by: Max Asnaashari <max.asna@futurfusion.io>
1 parent e66c73e commit 23ae9aa

4 files changed

Lines changed: 28 additions & 0 deletions

File tree

internal/worker/scripts/hivex-assign-netcfg.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ hive_dir="${mount_dir}/Windows/System32/config/SYSTEM"
77
old_guid_file="${mount_dir}/migration_manager_old_guids"
88
nics_file="${mount_dir}/migration_manager_nics"
99

10+
echo "Setting up first-boot network reassignment script"
11+
1012
# Just exit if no MACs provided.
1113
if [ 0 = ${#} ]; then
14+
echo "No MACs supplied, exiting"
1215
exit 0
1316
fi
1417

@@ -21,6 +24,8 @@ fi
2124

2225
control_set="$(printf "ControlSet%03d" "${control_set_num}")"
2326

27+
echo "Using control set ${control_set}"
28+
2429
# Record each mapping of MAC to InstanceGUID because we can't tell which NIC is which after booting. (And also reading networksetup2 requires elevated privileges).
2530
# shellcheck disable=1003
2631
hivexregedit --export --prefix 'hklm\system' "${hive_dir}" "${control_set}\control\networksetup2\interfaces" --max-depth 3 \
@@ -32,18 +37,22 @@ hivexregedit --export --prefix 'hklm\system' "${hive_dir}" "${control_set}\contr
3237

3338
# If we can't find any MACs, then exit.
3439
if [ "$(wc -l /tmp/macs_to_guids)" = 0 ]; then
40+
echo "No GUID records found, exiting"
3541
exit 0
3642
fi
3743

3844
# Remove the state files in case they exist.
3945
rm -rf "${old_guid_file}" "${nics_file}"
4046

4147
for mac in "${@}" ; do
48+
echo " Checking mac ${mac}"
49+
4250
# Grab the previous GUID for this MAC.
4351
mac="$(printf "%s" "${mac}" | tr '[:upper:]' '[:lower:]')"
4452
mapping="$(grep "^${mac}" -B1 --no-group-separator /tmp/macs_to_guids | head -2)"
4553

4654
if [ -z "${mapping}" ] ; then
55+
echo " Mac ${mac} not found in GUID mappings"
4756
continue
4857
fi
4958

@@ -52,9 +61,12 @@ for mac in "${@}" ; do
5261
mac="$(printf "%s" "${mac}" | tr '[:lower:]' '[:upper:]' | sed -e 's/:/-/g')"
5362

5463
if [ -z "${old_guid}" ] || [ -z "${mac}" ]; then
64+
echo " Unexpected GUID mapping format: ${mapping}"
5565
exit 1
5666
fi
5767

68+
echo " MAC: ${mac} GUID: ${old_guid}"
69+
5870
echo "${old_guid}" >> "${old_guid_file}"
5971
echo "${mac}" >> "${nics_file}"
6072
done

internal/worker/scripts/hivex-cpu-hotplug-compat.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
set -e
44

5+
echo "Running Windows CPU-hotplug compatibility patches"
6+
57
mount_dir="/run/mount/win_main"
68
hive_dir="${mount_dir}/Windows/System32/config"
79

@@ -13,14 +15,20 @@ remove_key="$(hivexregedit --export --prefix 'hklm\system' "${hive_dir}/SYSTEM"
1315
# Only perform the ACPI removal if the key is found.
1416
# See: https://forum.proxmox.com/threads/windows-2016-cpu-hot-plug-support.42302/
1517
if [ -n "${remove_key}" ]; then
18+
echo "Removing invalid ACPI hidinterrupt.inf entry"
1619
cat << EOF | hivexregedit --merge --prefix 'HKLM\SYSTEM' "${hive_dir}/SYSTEM"
1720
[-DriverDatabase\DeviceIds\ACPI\ACPI0010]
1821
1922
${remove_key}
2023
2124
EOF
25+
else
26+
echo "Invalid ACPI hidinterrupt.inf entry not found, assuming Windows is patched"
2227
fi
2328

29+
30+
echo "Disabling VBS auto-start"
31+
2432
# Disable Virtualization Based Security.
2533
cat << EOF | hivexregedit --merge --prefix 'HKLM\SYSTEM' "${hive_dir}/SYSTEM"
2634
[ControlSet001\Control]

internal/worker/scripts/hivex-disable-vm-tools.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ set -e
55
mount_dir="/run/mount/win_main"
66
hive_dir="${mount_dir}/Windows/System32/config"
77

8+
echo "Cleaning up VMware tools"
9+
810
# No VMware tools, nothing to do.
911
if ! test -e "${mount_dir}/Program Files/VMware/VMware Tools" ; then
1012
echo "VMware tools were not found"
@@ -327,3 +329,5 @@ rm -rf "${mount_dir}/ProgramData/VMware/VMware Tools"
327329
rm -rf "${mount_dir}/ProgramData/VMware/VMware VGAuth"
328330
rm -rf "${mount_dir}/Program Files/Common Files/VMware/Drivers"
329331
rm -rf "${mount_dir}/Program Files/Common Files/VMware/InstallerCache"
332+
333+
echo "VMware Tools successfully cleaned up"

internal/worker/scripts/hivex-first-boot.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ set -e
55
mount_dir="/run/mount/win_main"
66
hive_dir="${mount_dir}/Windows/System32/config/SYSTEM"
77

8+
echo "Setting up first-boot service"
9+
810
# Get the current control set before it's loaded.
911
control_set_num="$(hivexregedit --export --prefix='HKEY_LOCAL_MACHINE\SYSTEM' "${hive_dir}" 'Select' | grep -io '^"Current"=dword:[0-9a-f]*' | cut -d':' -f2 | sed -e 's/^0*//')"
1012

@@ -14,6 +16,8 @@ fi
1416

1517
control_set="$(printf "ControlSet%03d" "${control_set_num}")"
1618

19+
echo "Using control set ${control_set}"
20+
1721
# Create a service that runs before any user boots. For some reason, we can't run powershell.exe directly here, it has to be called from cmd.exe.
1822
cat << EOF | hivexregedit --merge --prefix 'HKEY_LOCAL_MACHINE\SYSTEM' "${hive_dir}"
1923
[${control_set}\Services\MigrationManagerFirstBoot]

0 commit comments

Comments
 (0)