munki / munki

Managed software installation for macOS —

Home Page:https://www.munki.org/munki/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

startosinstall fails to run if SharedSupport.dmg cannot be mounted

miawri opened this issue · comments

If SharedSupport.dmg cannot be mounted and so the OS upgrade version cannot be retrieved from the com_apple_MobileAsset_MacSoftwareUpdate.xml file, munki adds the --applicationpath switch onto startosinstall by default which will fail for any modern version of the OS as below: -

Beginning os installer session

Nov 14 2022 08:51:02 +0000 Starting macOS upgrade...
Nov 14 2022 08:51:02 +0000 Mounting disk image Install macOS Ventura-13.0.1.dmg
Nov 14 2022 08:51:02 +0000 ERROR: Error: "hdiutil: attach failed - Resource busy" while mounting SharedSupport.dmg.
Nov 14 2022 08:51:04 +0000 WARNING: "--applicationpath" was deprecated in macOS 10.14, and has been removed completely in macOS 12.0.
Nov 14 2022 08:51:04 +0000 Please remove it from your invocation.
Nov 14 2022 08:51:06 +0000 Starting macOS install failed with return code 18
Nov 14 2022 08:51:06 +0000 ERROR: ------------------------------------------------------------------------------
Nov 14 2022 08:51:06 +0000 ERROR: WARNING: "--applicationpath" was deprecated in macOS 10.14, and has been removed completely in macOS 12.0.
Nov 14 2022 08:51:06 +0000 ERROR: Please remove it from your invocation.
Nov 14 2022 08:51:06 +0000 ERROR: ------------------------------------------------------------------------------
Nov 14 2022 08:51:06 +0000 ERROR: Error starting macOS install: startosinstall failed with return code 18
Nov 14 2022 08:51:06 +0000 ### Ending os installer session ###

Could the logic include a section so that if the the xml cannot be read, startosinstall defaults to the basic set of switches?

Thanks

Define "basic".
If we don't know what version we're installing, the required set of switches is unknown.
I suppose we can look at what version we're currently running and guess the new version is at least 1 major release higher.
PRs considered!

But I think the bigger problem is "why can't we mount SharedSupport.dmg?" I'd argue if we can't maybe we should error and not attempt to install macOS...

"I'd argue if we can't maybe we should error and not attempt to install macOS..."
-maybe, but would startosinstall have "just worked" regardless of the "resource busy" error from hdiutil? We don't know because munki is adding --applicationpath before it gets chance to try.

"I suppose we can look at what version we're currently running and guess the new version is at least 1 major release higher."
-I think that is the best thing for munki to do here. If the current OS version is 10.14 or above, does SharedSupport.dmg even need to be mounted?

" If the current OS version is 10.14 or above, does SharedSupport.dmg even need to be mounted?" Asked another way: if the current OS version is 10.14 or above, do we need to add any options to the startosinstall call? The answer is no, not currently, but of course Apple can change things in the future!

Here's my suggestion.

diff --git a/code/client/munkilib/osinstaller.py b/code/client/munkilib/osinstaller.py
index 09308962..f92ccf13 100644
--- a/code/client/munkilib/osinstaller.py
+++ b/code/client/munkilib/osinstaller.py
@@ -280,6 +280,9 @@ class StartOSInstallRunner(object):
             app_path, 'Contents/Resources/startosinstall')
 
         os_vers_to_install = get_os_version(app_path)
+        if not os_vers_to_install:
+            display.display_warning(
+                'Could not get OS version to install from application bundle.')
 
         # run startosinstall via subprocess
 
@@ -312,7 +315,7 @@ class StartOSInstallRunner(object):
                     '--rebootdelay', '300',
                     '--pidtosignal', str(os.getpid())])
 
-        if pkgutils.MunkiLooseVersion(
+        if os_vers_to_install and pkgutils.MunkiLooseVersion(
                 os_vers_to_install) < pkgutils.MunkiLooseVersion('10.14'):
             # --applicationpath option is _required_ in Sierra and early
             # releases of High Sierra. It became optional (or is ignored?) in
@@ -320,13 +323,13 @@ class StartOSInstallRunner(object):
             # so don't add this option when installing Mojave
             cmd.extend(['--applicationpath', app_path])
 
-        if pkgutils.MunkiLooseVersion(
+        if os_vers_to_install and pkgutils.MunkiLooseVersion(
                 os_vers_to_install) < pkgutils.MunkiLooseVersion('10.12.4'):
             # --volume option is _required_ prior to 10.12.4 installer
             # and must _not_ be included in 10.12.4+ installer's startosinstall
             cmd.extend(['--volume', '/'])
 
-        if pkgutils.MunkiLooseVersion(
+        if os_vers_to_install and pkgutils.MunkiLooseVersion(
                 os_vers_to_install) < pkgutils.MunkiLooseVersion('10.13.5'):
             # --nointeraction is an undocumented option that appears to be
             # not only no longer needed/useful but seems to trigger some issues

Looks good!