Work-around Root Volume unmounting

This commit is contained in:
Mykola Grymalyuk
2022-04-13 16:21:02 -06:00
parent 945ba18652
commit 42c4ed17bc
3 changed files with 43 additions and 5 deletions

View File

@@ -1,6 +1,8 @@
import sys
from resources import defaults, build, utilities, validation, sys_patch, sys_patch_auto
from data import model_array
import threading
import time
# Generic building args
class arguments:
@@ -101,7 +103,16 @@ If you plan to create the USB for another machine, please select the "Change Mod
print("- Set Mojave/Catalina root patch configuration")
settings.moj_cat_accel = True
print("- Set System Volume patching")
sys_patch.PatchSysVolume(settings.custom_model or settings.computer.real_model, settings, None).start_patch()
if "Library/InstallerSandboxes/" in str(self.constants.payload_path):
print("- Running from Installer Sandbox")
thread = threading.Thread(target=sys_patch.PatchSysVolume(settings.custom_model or settings.computer.real_model, settings, None).start_patch)
thread.start()
while thread.is_alive():
utilities.block_os_updaters()
time.sleep(1)
else:
sys_patch.PatchSysVolume(settings.custom_model or settings.computer.real_model, settings, None).start_patch()
elif self.args.unpatch_sys_vol:
print("- Set System Volume unpatching")
sys_patch.PatchSysVolume(settings.custom_model or settings.computer.real_model, settings, None).start_unpatch()

View File

@@ -241,9 +241,13 @@ class PatchSysVolume:
else:
result = utilities.elevated(["kextcache", "-i", f"{self.mount_location}/"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# kextcache always returns 0, even if it fails
# Check the output for 'KernelCache ID' to see if the cache was successfully rebuilt
if result.returncode != 0 or (self.constants.detected_os < os_data.os_data.catalina and "KernelCache ID" not in result.stdout.decode()):
# kextcache notes:
# - kextcache always returns 0, even if it fails
# - Check the output for 'KernelCache ID' to see if the cache was successfully rebuilt
# kmutil notes:
# - kmutil will return 71 on failure to build KCs
# - kmutil will sometimes have a stroke and return a negative value even if it succeeds
if result.returncode > 0 or (self.constants.detected_os < os_data.os_data.catalina and "KernelCache ID" not in result.stdout.decode()):
self.success_status = False
print("- Unable to build new kernel cache")
print(f"\nReason for Patch Failure({result.returncode}):")
@@ -254,7 +258,7 @@ class PatchSysVolume:
input("Press [ENTER] to continue")
else:
self.success_status = True
print("- Successfully built new kernel cache")
print(f"- Successfully built new kernel cache({result.returncode})")
if self.root_supports_snapshot is True:
print("- Creating new APFS snapshot")
bless = utilities.elevated(

View File

@@ -410,6 +410,29 @@ def monitor_disk_output(disk):
output = output[-2]
return output
def block_os_updaters():
# Disables any processes that would be likely to mess with
# the root volume while we're working with it.
bad_processes = [
"softwareupdate",
"SoftwareUpdate",
"Software Update",
"MobileSoftwareUpdate",
]
output = subprocess.check_output(["ps", "-ax"])
lines = output.splitlines()
for line in lines:
entry = line.split()
pid = entry[0]
process_name = entry[3].decode()
for process in bad_processes:
if process in process_name:
if pid != "":
print(f"Killing PID: {pid}")
print(f"Process: {process_name}")
subprocess.run(["kill", "-9", pid])
def check_boot_mode():
# Check whether we're in Safe Mode or not
sys_plist = plistlib.loads(subprocess.run(["system_profiler", "SPSoftwareDataType"], stdout=subprocess.PIPE).stdout)