Pino Toscano
2018-Nov-16 12:57 UTC
[Libguestfs] [PATCH 0/2] v2v: uninstall the VMware Tools from Windows guests
It seems newer versions of VMware Tools for Windows can be uninstalled also when the guest does not run on VMware anymore. Hence, attempt to uninstall them during a conversion, reusing the same code already used to uninstall Parallel Tools. This was tested with the following Windows guests: - Windows 2008r2 - Windows 2012r2 - Windows 2016 - Windows 7 - Windows 8 - Windows 10 Pino Toscano (2): v2v: windows: factor uninstall commands search v2v: windows: uninstall VMware Tools v2v/convert_windows.ml | 62 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 11 deletions(-) -- 2.17.2
Pino Toscano
2018-Nov-16 12:57 UTC
[Libguestfs] [PATCH 1/2] v2v: windows: factor uninstall commands search
Turn the code for 'prltools_uninsts' into an helper function 'unistallation_commands', so that can be used also for other applications installed. --- v2v/convert_windows.ml | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml index d651b2337..8740afd1c 100644 --- a/v2v/convert_windows.ml +++ b/v2v/convert_windows.ml @@ -124,8 +124,10 @@ let convert (g : G.guestfs) inspect source output rcaps Not_found -> None ) in - (* Locate and retrieve all uninstallation commands for Parallels Tools *) - let prltools_uninsts + (* Locate and retrieve all the uninstallation commands for installed + * applications. + *) + let unistallation_commands pretty_name matchfn extra_uninstall_string let uninsts = ref [] in Registry.with_hive_readonly g inspect.i_windows_software_hive @@ -146,25 +148,25 @@ let convert (g : G.guestfs) inspect source output rcaps raise Not_found; let dispname = g#hivex_value_string valueh in - if String.find dispname "Parallels Tools" = -1 && - String.find dispname "Virtuozzo Tools" = -1 then + if not (matchfn dispname) then raise Not_found; let uninstval = "UninstallString" in let valueh = g#hivex_node_get_value uninstnode uninstval in if valueh = 0L then ( let name = g#hivex_node_name uninstnode in - warning (f_"cannot uninstall Parallels Tools: registry key ‘HKLM\\SOFTWARE\\%s\\%s’ with DisplayName ‘%s’ doesn't contain value ‘%s’") - (String.concat "\\" path) name dispname uninstval; + warning (f_"cannot uninstall %s: registry key ‘HKLM\\SOFTWARE\\%s\\%s’ with DisplayName ‘%s’ doesn't contain value ‘%s’") + pretty_name (String.concat "\\" path) name dispname uninstval; raise Not_found ); let uninst = (g#hivex_value_string valueh) ^ " /quiet /norestart /l*v+ \"%~dpn0.log\"" ^ - " REBOOT=ReallySuppress REMOVE=ALL" ^ - (* without these custom Parallels-specific MSI properties the - * uninstaller still shows a no-way-out reboot dialog *) - " PREVENT_REBOOT=Yes LAUNCHED_BY_SETUP_EXE=Yes" in + " REBOOT=ReallySuppress REMOVE=ALL" in + let uninst + match extra_uninstall_string with + | None -> uninst + | Some s -> uninst ^ " " ^ s in List.push_front uninst uninsts with @@ -177,6 +179,19 @@ let convert (g : G.guestfs) inspect source output rcaps !uninsts in + (* Locate and retrieve all uninstallation commands for Parallels Tools. *) + let prltools_uninsts + let matchfn s + String.find s "Parallels Tools" != -1 || + String.find s "Virtuozzo Tools" != -1 + in + (* Without these custom Parallels-specific MSI properties the + * uninstaller still shows a no-way-out reboot dialog. + *) + let extra_uninstall_string + Some "PREVENT_REBOOT=Yes LAUNCHED_BY_SETUP_EXE=Yes" in + unistallation_commands "Parallels Tools" matchfn extra_uninstall_string in + (*----------------------------------------------------------------------*) (* Perform the conversion of the Windows guest. *) -- 2.17.2
Pino Toscano
2018-Nov-16 12:57 UTC
[Libguestfs] [PATCH 2/2] v2v: windows: uninstall VMware Tools
It looks like VMware Tools support their unattended uninstallation even after the guest is not running anymore on VMware. --- v2v/convert_windows.ml | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml index 8740afd1c..2d2b6adfe 100644 --- a/v2v/convert_windows.ml +++ b/v2v/convert_windows.ml @@ -192,6 +192,13 @@ let convert (g : G.guestfs) inspect source output rcaps Some "PREVENT_REBOOT=Yes LAUNCHED_BY_SETUP_EXE=Yes" in unistallation_commands "Parallels Tools" matchfn extra_uninstall_string in + (* Locate and retrieve all uninstallation commands for VMware Tools. *) + let vmwaretools_uninst + let matchfn s + String.find s "VMware Tools" != -1 + in + unistallation_commands "VMware Tools" matchfn None in + (*----------------------------------------------------------------------*) (* Perform the conversion of the Windows guest. *) @@ -277,7 +284,8 @@ let convert (g : G.guestfs) inspect source output rcaps configure_vmdp tool_path; unconfigure_xenpv (); - unconfigure_prltools () + unconfigure_prltools (); + unconfigure_vmwaretools () (* [set_reg_val_dword_1 path name] creates a registry key * called [name = dword:1] in the registry [path]. @@ -430,6 +438,23 @@ if errorlevel 3010 exit /b 0 "uninstall Parallels tools" fb_script ) prltools_uninsts + and unconfigure_vmwaretools () + List.iter ( + fun uninst -> + let fb_script = "\ +@echo off + +echo uninstalling VMware Tools +" ^ uninst ^ +(* ERROR_SUCCESS_REBOOT_REQUIRED == 3010 is OK too *) +" +if errorlevel 3010 exit /b 0 +" in + + Firstboot.add_firstboot_script g inspect.i_root + "uninstall VMware Tools" fb_script + ) vmwaretools_uninst + and update_system_hive reg (* Update the SYSTEM hive. When this function is called the hive has * already been opened as a hivex handle inside guestfs. -- 2.17.2
Richard W.M. Jones
2018-Nov-16 16:30 UTC
Re: [Libguestfs] [PATCH 1/2] v2v: windows: factor uninstall commands search
On Fri, Nov 16, 2018 at 01:57:19PM +0100, Pino Toscano wrote:> Turn the code for 'prltools_uninsts' into an helper function > 'unistallation_commands', so that can be used also for other > applications installed. > --- > v2v/convert_windows.ml | 35 +++++++++++++++++++++++++---------- > 1 file changed, 25 insertions(+), 10 deletions(-) > > diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml > index d651b2337..8740afd1c 100644 > --- a/v2v/convert_windows.ml > +++ b/v2v/convert_windows.ml > @@ -124,8 +124,10 @@ let convert (g : G.guestfs) inspect source output rcaps > Not_found -> None > ) in > > - (* Locate and retrieve all uninstallation commands for Parallels Tools *) > - let prltools_uninsts > + (* Locate and retrieve all the uninstallation commands for installed > + * applications. > + *) > + let unistallation_commands pretty_name matchfn extra_uninstall_string > let uninsts = ref [] in > > Registry.with_hive_readonly g inspect.i_windows_software_hive > @@ -146,25 +148,25 @@ let convert (g : G.guestfs) inspect source output rcaps > raise Not_found; > > let dispname = g#hivex_value_string valueh in > - if String.find dispname "Parallels Tools" = -1 && > - String.find dispname "Virtuozzo Tools" = -1 then > + if not (matchfn dispname) then > raise Not_found; > > let uninstval = "UninstallString" in > let valueh = g#hivex_node_get_value uninstnode uninstval in > if valueh = 0L then ( > let name = g#hivex_node_name uninstnode in > - warning (f_"cannot uninstall Parallels Tools: registry key ‘HKLM\\SOFTWARE\\%s\\%s’ with DisplayName ‘%s’ doesn't contain value ‘%s’") > - (String.concat "\\" path) name dispname uninstval; > + warning (f_"cannot uninstall %s: registry key ‘HKLM\\SOFTWARE\\%s\\%s’ with DisplayName ‘%s’ doesn't contain value ‘%s’") > + pretty_name (String.concat "\\" path) name dispname uninstval; > raise Not_found > ); > > let uninst = (g#hivex_value_string valueh) ^ > " /quiet /norestart /l*v+ \"%~dpn0.log\"" ^ > - " REBOOT=ReallySuppress REMOVE=ALL" ^ > - (* without these custom Parallels-specific MSI properties the > - * uninstaller still shows a no-way-out reboot dialog *) > - " PREVENT_REBOOT=Yes LAUNCHED_BY_SETUP_EXE=Yes" in > + " REBOOT=ReallySuppress REMOVE=ALL" in > + let uninst > + match extra_uninstall_string with > + | None -> uninst > + | Some s -> uninst ^ " " ^ s in > > List.push_front uninst uninsts > with > @@ -177,6 +179,19 @@ let convert (g : G.guestfs) inspect source output rcaps > !uninsts > in > > + (* Locate and retrieve all uninstallation commands for Parallels Tools. *) > + let prltools_uninsts > + let matchfn s > + String.find s "Parallels Tools" != -1 || > + String.find s "Virtuozzo Tools" != -1 > + in > + (* Without these custom Parallels-specific MSI properties the > + * uninstaller still shows a no-way-out reboot dialog. > + *) > + let extra_uninstall_string > + Some "PREVENT_REBOOT=Yes LAUNCHED_BY_SETUP_EXE=Yes" in > + unistallation_commands "Parallels Tools" matchfn extra_uninstall_string in > + > (*----------------------------------------------------------------------*) > (* Perform the conversion of the Windows guest. *)Looks like a straightforward refactoring, so ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat people.redhat.com/~rjones Read my programming and virtualization blog: rwmj.wordpress.com virt-builder quickly builds VMs from scratch libguestfs.org/virt-builder.1.html
Richard W.M. Jones
2018-Nov-16 16:31 UTC
Re: [Libguestfs] [PATCH 2/2] v2v: windows: uninstall VMware Tools
On Fri, Nov 16, 2018 at 01:57:20PM +0100, Pino Toscano wrote:> It looks like VMware Tools support their unattended uninstallation even > after the guest is not running anymore on VMware. > --- > v2v/convert_windows.ml | 27 ++++++++++++++++++++++++++- > 1 file changed, 26 insertions(+), 1 deletion(-) > > diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml > index 8740afd1c..2d2b6adfe 100644 > --- a/v2v/convert_windows.ml > +++ b/v2v/convert_windows.ml > @@ -192,6 +192,13 @@ let convert (g : G.guestfs) inspect source output rcaps > Some "PREVENT_REBOOT=Yes LAUNCHED_BY_SETUP_EXE=Yes" in > unistallation_commands "Parallels Tools" matchfn extra_uninstall_string in > > + (* Locate and retrieve all uninstallation commands for VMware Tools. *) > + let vmwaretools_uninst > + let matchfn s > + String.find s "VMware Tools" != -1 > + in > + unistallation_commands "VMware Tools" matchfn None in > + > (*----------------------------------------------------------------------*) > (* Perform the conversion of the Windows guest. *) > > @@ -277,7 +284,8 @@ let convert (g : G.guestfs) inspect source output rcaps > configure_vmdp tool_path; > > unconfigure_xenpv (); > - unconfigure_prltools () > + unconfigure_prltools (); > + unconfigure_vmwaretools () > > (* [set_reg_val_dword_1 path name] creates a registry key > * called [name = dword:1] in the registry [path]. > @@ -430,6 +438,23 @@ if errorlevel 3010 exit /b 0 > "uninstall Parallels tools" fb_script > ) prltools_uninsts > > + and unconfigure_vmwaretools () > + List.iter ( > + fun uninst -> > + let fb_script = "\ > +@echo off > + > +echo uninstalling VMware Tools > +" ^ uninst ^ > +(* ERROR_SUCCESS_REBOOT_REQUIRED == 3010 is OK too *) > +" > +if errorlevel 3010 exit /b 0 > +" in > + > + Firstboot.add_firstboot_script g inspect.i_root > + "uninstall VMware Tools" fb_script > + ) vmwaretools_uninst > + > and update_system_hive reg > (* Update the SYSTEM hive. When this function is called the hive has > * already been opened as a hivex handle inside guestfs.ACK Rich. -- Richard Jones, Virtualization Group, Red Hat people.redhat.com/~rjones Read my programming and virtualization blog: rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. people.redhat.com/~rjones/virt-top
Maybe Matching Threads
- [PATCH 1/2] v2v: windows: factor uninstall commands search
- [PATCH 0/2] v2v: uninstall the VMware Tools from Windows guests
- [PATCH] convert_windows: uninstall Parallels Tools on first boot
- [PATCH] v2v: windows: install QEMU Guest Agent MSI
- Re: [PATCH 2/2] v2v:windows: prevent conflicts with PnP on firstboot