Menu

Legacy boot

Startergo
2024-03-01
2024-05-24
  • Startergo

    Startergo - 2024-03-01

    Great application! Any options or intentions to include legacy boot?

     
    • Serhii

      Serhii - 2024-03-02

      Unfortunately no.

       
  • Startergo

    Startergo - 2024-03-01

    By the way the application crashes:

    Crash report
    -------------------------------------
    Translated Report (Full Report Below)
    -------------------------------------
    
    Process:               Windows Install [62330]
    Path:                  /private/var/folders/*/Windows Install.app/Contents/MacOS/Windows Install
    Identifier:            org.SerhiiHalan.WindowsInstall
    Version:               6.1.0 (6.1.0)
    Code Type:             X86-64 (Native)
    Parent Process:        launchd [1]
    User ID:               501
    
    Date/Time:             2024-03-01 20:03:54.2160 +0300
    OS Version:            macOS 14.3.1 (23D60)
    Report Version:        12
    Bridge OS Version:     8.3 (21P3049)
    Anonymous UUID:        95941D1C-B79A-7E2B-6F89-AF18B17DC1E7
    
    Sleep/Wake UUID:       A9EDCF0D-110C-4030-938A-8EA3583FB5DE
    
    Time Awake Since Boot: 74000 seconds
    Time Since Wake:       984 seconds
    
    System Integrity Protection: enabled
    
    Crashed Thread:        0
    
    Exception Type:        EXC_CRASH (SIGABRT)
    Exception Codes:       0x0000000000000000, 0x0000000000000000
    
    Termination Reason:    Namespace DYLD, Code 1 Library missing
    Library not loaded: @rpath/Sparkle.framework/Versions/B/Sparkle
    Referenced from: <CCE4B67A-4D3E-399F-AF80-B86CD2C589E2> /private/var/folders/*/Windows Install.app/Contents/MacOS/Windows Install
    Reason: tried: '/private/var/folders/3_/70vmt3s91gn6812rcpl3rx7m0000gn/T/AppTranslocation/AF21E708-A893-4682-AD48-36DA639B229E/d/Windows Install.app/Contents/Frameworks/Sparkle.framework/Versions/B/Sparkle' (code signature in <D90B5CB2-08C0-3C48-9826-3C50FADFBD88> '/private/var/folders/3_/70vmt3s91gn6812rcpl3rx7m0000gn/T/AppTranslocation/AF21E708-A893-4682-AD48-36DA639B229E/d/Windows Install.app/Contents/Frameworks/Sparkle.framework/Versions/B/Sparkle' not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs), '/private/var/folders/3_/70vmt3s91gn6812rcpl3rx7m0000gn/T/AppTranslocation/AF21E708-A893-4682-AD48-36DA639B229E/d/Windows Install.app/Contents/Frameworks/Sparkle.framework/Ver
    (terminated at launch; ignore backtrace)
    
    Thread 0 Crashed:
    0   dyld                                0x7ff80e82388e __abort_with_payload + 10
    1   dyld                                0x7ff80e83dd95 abort_with_payload_wrapper_internal + 82
    2   dyld                                0x7ff80e83ddc7 abort_with_payload + 9
    3   dyld                                0x7ff80e7bf13b dyld4::halt(char const*, dyld4::StructuredError const*) + 335
    4   dyld                                0x7ff80e7bc525 dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 4137
    5   dyld                                0x7ff80e7bb31f start + 1839
    
    
    Thread 0 crashed with X86 Thread State (64-bit):
      rax: 0x0000000002000209  rbx: 0x0000000000000001  rcx: 0x00007ff7b80d6418  rdx: 0x00007ff7b80d6880
      rdi: 0x0000000000000006  rsi: 0x0000000000000001  rbp: 0x00007ff7b80d6460  rsp: 0x00007ff7b80d6418
       r8: 0x00007ff7b80d6480   r9: 0x0000000000000000  r10: 0x00000000000000e4  r11: 0x0000000000000246
      r12: 0x0000000000000000  r13: 0x00007ff7b80d6880  r14: 0x0000000000000006  r15: 0x00000000000000e4
      rip: 0x00007ff80e82388e  rfl: 0x0000000000000246  cr2: 0x0000000000000000
    
    Logical CPU:     0
    Error Code:      0x02000209 
    Trap Number:     133
    
    
    Binary Images:
           0x107e28000 -        0x107e37fff org.SerhiiHalan.WindowsInstall (6.1.0) <cce4b67a-4d3e-399f-af80-b86cd2c589e2> /private/var/folders/*/Windows Install.app/Contents/MacOS/Windows Install
        0x7ff80e7b5000 -     0x7ff80e8513ff dyld (*) <01ae3ae3-f6ca-34d1-a2f8-462ede5fa818> /usr/lib/dyld
                   0x0 - 0xffffffffffffffff ??? (*) <00000000-0000-0000-0000-000000000000> ???
    
    External Modification Summary:
      Calls made by other processes targeting this process:
        task_for_pid: 0
        thread_create: 0
        thread_set_state: 0
      Calls made by this process:
        task_for_pid: 0
        thread_create: 0
        thread_set_state: 0
      Calls made by all processes on this machine:
        task_for_pid: 0
        thread_create: 0
        thread_set_state: 0
    
    VM Region Summary:
    ReadOnly portion of Libraries: Total=181.9M resident=0K(0%) swapped_out_or_unallocated=181.9M(100%)
    Writable regions: Total=12.3M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=12.3M(100%)
    
                                    VIRTUAL   REGION 
    REGION TYPE                        SIZE    COUNT (non-coalesced) 
    ===========                     =======  ======= 
    STACK GUARD                       56.0M        1 
    Stack                             8192K        1 
    VM_ALLOCATE                          8K        2 
    __DATA                              27K        2 
    __DATA_CONST                        20K        1 
    __DATA_DIRTY                         7K        1 
    __LINKEDIT                       181.2M        3 
    __TEXT                             692K        2 
    dyld private memory               4360K        4 
    shared memory                        4K        1 
    ===========                     =======  ======= 
    TOTAL                            250.2M       18 
    
    
    
    -----------
    Full Report
    -----------
    
    {"app_name":"Windows Install","timestamp":"2024-03-01 20:03:54.00 +0300","app_version":"6.1.0","slice_uuid":"cce4b67a-4d3e-399f-af80-b86cd2c589e2","build_version":"6.1.0","platform":1,"bundleID":"org.SerhiiHalan.WindowsInstall","share_with_app_devs":0,"is_first_party":0,"bug_type":"309","os_version":"macOS 14.3.1 (23D60)","roots_installed":0,"name":"Windows Install","incident_id":"3BE87E9D-8101-4D56-A0DC-F1CC4C23FD01"}
    {
      "uptime" : 74000,
      "procRole" : "Default",
      "version" : 2,
      "userID" : 501,
      "deployVersion" : 210,
      "modelCode" : "MacBookPro15,1",
      "coalitionID" : 10245,
      "osVersion" : {
        "train" : "macOS 14.3.1",
        "build" : "23D60",
        "releaseType" : "User"
      },
      "captureTime" : "2024-03-01 20:03:54.2160 +0300",
      "codeSigningMonitor" : 0,
      "incident" : "3BE87E9D-8101-4D56-A0DC-F1CC4C23FD01",
      "pid" : 62330,
      "cpuType" : "X86-64",
      "roots_installed" : 0,
      "bug_type" : "309",
      "procLaunch" : "2024-03-01 20:03:54.1898 +0300",
      "procStartAbsTime" : 74661898828137,
      "procExitAbsTime" : 74661924746932,
      "procName" : "Windows Install",
      "procPath" : "\/private\/var\/folders\/*\/Windows Install.app\/Contents\/MacOS\/Windows Install",
      "bundleInfo" : {"CFBundleShortVersionString":"6.1.0","CFBundleVersion":"6.1.0","CFBundleIdentifier":"org.SerhiiHalan.WindowsInstall"},
      "storeInfo" : {"deviceIdentifierForVendor":"4E2DA131-2B2B-57B1-878D-59C201E4EAC2","thirdParty":true},
      "parentProc" : "launchd",
      "parentPid" : 1,
      "coalitionName" : "org.SerhiiHalan.WindowsInstall",
      "crashReporterKey" : "95941D1C-B79A-7E2B-6F89-AF18B17DC1E7",
      "codeSigningID" : "org.SerhiiHalan.WindowsInstall",
      "codeSigningTeamID" : "",
      "codeSigningFlags" : 570503953,
      "codeSigningValidationCategory" : 10,
      "codeSigningTrustLevel" : 4294967295,
      "wakeTime" : 984,
      "bridgeVersion" : {"build":"21P3049","train":"8.3"},
      "sleepWakeUUID" : "A9EDCF0D-110C-4030-938A-8EA3583FB5DE",
      "sip" : "enabled",
      "exception" : {"codes":"0x0000000000000000, 0x0000000000000000","rawCodes":[0,0],"type":"EXC_CRASH","signal":"SIGABRT"},
      "termination" : {"code":1,"flags":518,"namespace":"DYLD","indicator":"Library missing","details":["(terminated at launch; ignore backtrace)"],"reasons":["Library not loaded: @rpath\/Sparkle.framework\/Versions\/B\/Sparkle","Referenced from: <CCE4B67A-4D3E-399F-AF80-B86CD2C589E2> \/private\/var\/folders\/*\/Windows Install.app\/Contents\/MacOS\/Windows Install","Reason: tried: '\/private\/var\/folders\/3_\/70vmt3s91gn6812rcpl3rx7m0000gn\/T\/AppTranslocation\/AF21E708-A893-4682-AD48-36DA639B229E\/d\/Windows Install.app\/Contents\/Frameworks\/Sparkle.framework\/Versions\/B\/Sparkle' (code signature in <D90B5CB2-08C0-3C48-9826-3C50FADFBD88> '\/private\/var\/folders\/3_\/70vmt3s91gn6812rcpl3rx7m0000gn\/T\/AppTranslocation\/AF21E708-A893-4682-AD48-36DA639B229E\/d\/Windows Install.app\/Contents\/Frameworks\/Sparkle.framework\/Versions\/B\/Sparkle' not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs), '\/private\/var\/folders\/3_\/70vmt3s91gn6812rcpl3rx7m0000gn\/T\/AppTranslocation\/AF21E708-A893-4682-AD48-36DA639B229E\/d\/Windows Install.app\/Contents\/Frameworks\/Sparkle.framework\/Ver"]},
      "extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0},
      "faultingThread" : 0,
      "threads" : [{"triggered":true,"id":1124165,"threadState":{"r13":{"value":140701921536128},"rax":{"value":33554953},"rflags":{"value":582},"cpu":{"value":0},"r14":{"value":6},"rsi":{"value":1},"r8":{"value":140701921535104},"cr2":{"value":0},"rdx":{"value":140701921536128},"r10":{"value":228},"r9":{"value":0},"r15":{"value":228},"rbx":{"value":1},"trap":{"value":133},"err":{"value":33554953},"r11":{"value":582},"rip":{"value":140703372032142,"matchesCrashFrame":1},"rbp":{"value":140701921535072},"rsp":{"value":140701921535000},"r12":{"value":0},"rcx":{"value":140701921535000},"flavor":"x86_THREAD_STATE","rdi":{"value":6}},"frames":[{"imageOffset":452750,"symbol":"__abort_with_payload","symbolLocation":10,"imageIndex":1},{"imageOffset":560533,"symbol":"abort_with_payload_wrapper_internal","symbolLocation":82,"imageIndex":1},{"imageOffset":560583,"symbol":"abort_with_payload","symbolLocation":9,"imageIndex":1},{"imageOffset":41275,"symbol":"dyld4::halt(char const*, dyld4::StructuredError const*)","symbolLocation":335,"imageIndex":1},{"imageOffset":29989,"symbol":"dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*)","symbolLocation":4137,"imageIndex":1},{"imageOffset":25375,"symbol":"start","symbolLocation":1839,"imageIndex":1}]}],
      "usedImages" : [
      {
        "source" : "P",
        "arch" : "x86_64",
        "base" : 4427251712,
        "CFBundleShortVersionString" : "6.1.0",
        "CFBundleIdentifier" : "org.SerhiiHalan.WindowsInstall",
        "size" : 65536,
        "uuid" : "cce4b67a-4d3e-399f-af80-b86cd2c589e2",
        "path" : "\/private\/var\/folders\/*\/Windows Install.app\/Contents\/MacOS\/Windows Install",
        "name" : "Windows Install",
        "CFBundleVersion" : "6.1.0"
      },
      {
        "source" : "P",
        "arch" : "x86_64",
        "base" : 140703371579392,
        "size" : 640000,
        "uuid" : "01ae3ae3-f6ca-34d1-a2f8-462ede5fa818",
        "path" : "\/usr\/lib\/dyld",
        "name" : "dyld"
      },
      {
        "size" : 0,
        "source" : "A",
        "base" : 0,
        "uuid" : "00000000-0000-0000-0000-000000000000"
      }
    ],
      "sharedCache" : {
      "base" : 140703370883072,
      "size" : 25769803776,
      "uuid" : "812473cc-f3ee-3c27-a996-84e3ebdc0dc8"
    },
      "vmSummary" : "ReadOnly portion of Libraries: Total=181.9M resident=0K(0%) swapped_out_or_unallocated=181.9M(100%)\nWritable regions: Total=12.3M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=12.3M(100%)\n\n                                VIRTUAL   REGION \nREGION TYPE                        SIZE    COUNT (non-coalesced) \n===========                     =======  ======= \nSTACK GUARD                       56.0M        1 \nStack                             8192K        1 \nVM_ALLOCATE                          8K        2 \n__DATA                              27K        2 \n__DATA_CONST                        20K        1 \n__DATA_DIRTY                         7K        1 \n__LINKEDIT                       181.2M        3 \n__TEXT                             692K        2 \ndyld private memory               4360K        4 \nshared memory                        4K        1 \n===========                     =======  ======= \nTOTAL                            250.2M       18 \n",
      "legacyInfo" : {
      "threadTriggered" : {
    
      }
    },
      "logWritingSignature" : "4f61377e997645917edb93c6319d9ced020bdc28",
      "trialInfo" : {
      "rollouts" : [
        {
          "rolloutId" : "63508950b3714d3622fc77f7",
          "factorPackIds" : {
            "SIRI_MEMORY_SYNC_CONFIG" : "6526e111d0c9ce2f459b54a8"
          },
          "deploymentId" : 240000014
        },
        {
          "rolloutId" : "5f72dc58705eff005a46b3a9",
          "factorPackIds" : {
    
          },
          "deploymentId" : 240000015
        }
      ],
      "experiments" : [
    
      ]
    }
    }
    
    Model: MacBookPro15,1, BootROM 2020.80.5.0.1 (iBridge: 21.16.3049.0.0,0), 6 processors, 6-Core Intel Core i7, 2.6 GHz, 32 GB, SMC 
    Graphics: Intel UHD Graphics 630, Intel UHD Graphics 630, Built-In
    Display: Color LCD, 2880 x 1800 Retina, Main, MirrorOff, Online
    Graphics: Radeon Pro 560X, Radeon Pro 560X, PCIe, 4 GB
    Memory Module: BANK 0/ChannelA-DIMM0, 16 GB, DDR4, 2400 MHz, Micron, 16ATS2G64HZ-2G6B1
    Memory Module: BANK 2/ChannelB-DIMM0, 16 GB, DDR4, 2400 MHz, Micron, 16ATS2G64HZ-2G6B1
    AirPort: spairport_wireless_card_type_wifi (0x14E4, 0x7BF), wl0: Jul 10 2023 12:30:19 version 9.30.503.0.32.5.92 FWID 01-88a8883
    AirPort: 
    Bluetooth: Version (null), 0 services, 0 devices, 0 incoming serial ports
    Network Service: Thunderbolt Bridge, Ethernet, bridge0
    Network Service: Wi-Fi, AirPort, en0
    Network Service: Tailscale Tunnel, VPN (io.tailscale.ipn.macos), utun4
    USB Device: USB31Bus
    USB Device: T2Bus
    USB Device: Touch Bar Backlight
    USB Device: Touch Bar Display
    USB Device: Apple Internal Keyboard / Trackpad
    USB Device: Headset
    USB Device: Ambient Light Sensor
    USB Device: FaceTime HD Camera (Built-in)
    USB Device: Apple T2 Controller
    Thunderbolt Bus: MacBook Pro, Apple Inc., 47.5
    Thunderbolt Bus: MacBook Pro, Apple Inc., 47.5
    
     
    👍
    1
  • Startergo

    Startergo - 2024-03-01

    Previous version works

     
  • Serhii

    Serhii - 2024-03-01

    Thanks for the feedback and report. Corrected, download again.

     
  • Startergo

    Startergo - 2024-03-02

    Thanks. How about including hybrid MBR (GPT with modified boot code)? You only need gdisk as an additional tool to convert the GPT to hybrid partition (requred on legacy macs).
    You can find the details here
    The only additional thing needed is to activate the BCD for MBR boot.

     

    Last edit: Startergo 2024-03-02
    • jpz4085

      jpz4085 - 2024-03-22

      Hi @Startergo, if you still want to enable legacy boot you may want to try the tool I linked in my post to@sergey-galan below. While I've not yet tried it with hybrid MBR the boot process should work the same way.

       
      👍
      1
      • Startergo

        Startergo - 2024-03-25

        Actually, the hybrid MBR scheme is nothing more than protecting GPT partitions you want to hide from the MBR boot sector. So, the WIndows partition does not see the EFI partition when booted. There is no need for system partition all files are written to the main Windows partition. I looked through your repo and combined with Serhii's tool, which provides NTFS write support can do everything needed.

         
  • Serhii

    Serhii - 2024-03-05

    They banned me on Macrumors, they wrote that I am engaged in advertising. Probably because I was a newcomer there))). But the topic is still on Insanlymac and TonyMacx86.
    In the old versions of the program, I used gdisk to obtain a GUID disk. But gdisk for some users refused to work in the script.
    BCD for loading UEFI I take ready and create a patch GUID and UUID. What to do with BCD for MBR I do not know. Perhaps there may be enough GUID and UUID, and maybe something else.

     

    Last edit: Serhii 2024-03-06
    • jpz4085

      jpz4085 - 2024-03-22

      Hi @sergey-galan, if you're interested in implementing support for MBR/BIOS booting in your utility you need to patch the BCD with the Windows Disk Signature from the MBR (found at offset 440 bytes) and the system partition offset in bytes. Also the file paths must have the extensions changed from efi to exe. It's probably better to use a different BCD file for legacy boot.

      I have a shell script called BCD-SYS that can do much of what the Microsoft bcdboot command does if you are interested. Let me know if you have questions.

       
      👍
      2
      • Serhii

        Serhii - 2024-03-22

        Hello. BCD for UEFI uses a ready-made one and patches the GUID and UUID in it.
        Is it enough to just use GUID and UUID patch for BCD MBR?

         
        • jpz4085

          jpz4085 - 2024-03-22

          Yes, that should be fine. You'll need to create a BCD for MBR first then patch the disk and partition identifiers. You can use my script or the Windows bcdboot utility to create one.

          The equivalent of the disk GUID will be the four byte Windows Disk Signature from the MBR. You may need to create this using signmbr or manually writing four random bytes (maybe using dd from /dev/random ) to the offset mentioned in my previous post. macOS does not automatically create one when partitioning as MBR unlike Linux or Windows.

          The equivalent of the partition GUID is the partition offset in bytes which can be found using "diskutil info disk#s#" under "Partition Offset:" then converting the value to hexadecimal in little-endian byte order.

          The fields for both items are sixteen bytes in length (size of GUID/UUID) so the remaining unused length must be zeros. You can probably just fill the disk and partition identifiers of the ready-made legacy BCD with a standard value that's easy to find and replace.

           
          👍
          2
          • Serhii

            Serhii - 2024-04-29

            Hi! I'm trying to understand your scripts. To adapt the script, I need to use an old version of bash. Mac uses an outdated version of bash (for licensing reasons). Is the problem only in the readarray, or is there something else?

             

            Last edit: Serhii 2024-04-29
            • jpz4085

              jpz4085 - 2024-05-02

              The problem I ran into with the old bash in macOS was a "bad substitution" error caused by the parameters where I convert the values to lower case (to avoid problems with case sensitivity) as well as the colorizing of warnings and error messages. I don't recall if there was an issue with readarray or other functions or substitutions.

               
              👍
              1
              • Serhii

                Serhii - 2024-05-09

                I studied your scripts, very great and good work. Thank you! For my program, I took and adapted only the creation of BCD and left the choice of UEFI and Bios (for the future).

                python3 -c 'import uuid; print(uuid.uuid4())'
                

                replaced

                uuidgen | tr A-Z a-z
                

                hivexregedit and the library could not be made dynamic. And I found a good replacement - reged.

                sudo -S ./tools/bin/reged -I -C $HOME/BCD-Windows BCD00000001 ./Templates/winload.reg
                

                True, reged created a lot of emptiness in the BCD, so it had to be cut off.

                    head -c 27000 $HOME/BCD-Windows > /Volumes/EFI/EFI/Microsoft/Boot/BCD
                    head -c 27000 $HOME/BCD-Recovery > /Volumes/EFI/EFI/Microsoft/Recovery/BCD
                

                This is what I added to the main script.

                build_BCD()
                {
                echo "Build the main BCD store..."
                sudo -S ./scripts/winload "$1" "$2" > $HOME/winload.txt
                cp ./Templates/BCD-NEW $HOME/BCD-Windows
                sudo -S ./tools/bin/reged -I -C $HOME/BCD-Windows BCD00000001 ./Templates/winload.reg
                ./tools/bin/hivexsh -w -f $HOME/winload.txt $HOME/BCD-Windows
                if [[ "$2" == "uefi" ]]; then
                    echo "Build the recovery BCD store..."
                    sudo -S ./scripts/recovery > $HOME/recovery.txt
                    cp ./Templates/BCD-NEW $HOME/BCD-Recovery
                    sudo -S ./tools/bin/reged -I -C $HOME/BCD-Recovery BCD00000001 ./Templates/recovery.reg
                    ./tools/bin/hivexsh -w -f $HOME/recovery.txt $HOME/BCD-Recovery
                    echo "Copy the BCD hives to the ESP folders..."
                    head -c 27000 $HOME/BCD-Windows > /Volumes/EFI/EFI/Microsoft/Boot/BCD
                    head -c 27000 $HOME/BCD-Recovery > /Volumes/EFI/EFI/Microsoft/Recovery/BCD
                elif [[ "$2" == "bios" ]]; then
                    echo "Copy the main BCD hive to the boot folder..."
                    head -c 27000 $tmpdir/BCD-Windows > "$1"/Boot/BCD
                fi
                rm $HOME/winload.txt
                rm $HOME/recovery.txt
                rm $HOME/BCD-Windows
                rm $HOME/BCD-Recovery
                }
                
                MountPoint=`diskutil info disk"$x"s"$y" | sed -n 's/.*Mount Point: *//p'`
                fwmode="uefi"
                
                build_BCD "$MountPoint" "$fwmode"
                

                winload

                gen_uuid () {
                uuidgen | tr A-Z a-z
                }
                
                guid_list () {
                    printf '%s\0\0' "$1" | hexdump -ve '/1 "%02x\0\0"'
                }
                
                firmware="$2"
                sourcepath="$1"
                
                winresguid=$(gen_uuid)
                winldrguid=$(gen_uuid)
                softhivepath="$sourcepath/Windows/System32/config/SOFTWARE"
                namescript="cd Microsoft\Windows NT\CurrentVersion\nlsval ProductName\nunload\n"
                winproduct=$(printf "$namescript" | ./tools/bin/hivexsh "$softhivepath" | cut -d' ' -f 1,2)
                
                echo "Loader GUID: {"$winldrguid"}" 1>&2
                echo "Resume GUID: {"$winresguid"}" 1>&2
                
                if   [[ "$firmware" == "uefi" ]]; then
                     ext="efi"
                     mempath="\EFI\Microsoft\Boot\memtest.efi"
                elif [[ "$firmware" == "bios" ]]; then
                     ext="exe"
                     mempath="\Boot\memtest.exe"
                fi
                
                ### Windows Resume Loader Entry ###
                printf "cd \Objects\n"
                printf "add {%s}\n" "$winresguid"
                printf "cd {%s}\n" "$winresguid"
                printf "add Description\n"
                printf "cd Description\n"
                printf "setval 1\n"
                printf "Type\n"
                printf "dword:0x10200004\n"
                printf "cd ..\n"
                printf "add Elements\n"
                printf "cd Elements\n"
                printf "add 11000001\n"
                printf "cd 11000001\n"
                printf "setval 1\n"
                printf "Element\n"
                ./scripts/update_device "$sourcepath"
                printf "cd ..\n"
                printf "add 12000002\n"
                printf "cd 12000002\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "string:\Windows\system32\winresume.%s\n" "$ext"
                printf "cd ..\n"
                printf "add 12000004\n"
                printf "cd 12000004\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "string:Windows Resume Application\n"
                printf "cd ..\n"
                printf "add 12000005\n"
                printf "cd 12000005\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "string:%s\n" "en-US"
                printf "cd ..\n"
                printf "add 14000006\n"
                printf "cd 14000006\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "hex:7:7b,00,31,00,61,00,66,00,61,00,39,00,63,00,34,00,39,00,2d,00,31,00,36,00,61,00,62,00,2d,00,34,00,61,00,35,00,63,00,2d,00,39,00,30,00,31,00,62,00,2d,00,32,00,31,00,32,00,38,00,30,00,32,00,64,00,61,00,39,00,34,00,36,00,30,00,7d,00,00,00,00,00\n"
                printf "cd ..\n"
                if [[ "$firmware" == "uefi" ]]; then
                   printf "add 16000060\n"
                   printf "cd 16000060\n"
                   printf "setval 1\n"
                   printf "Element\n"
                   printf "hex:3:01\n"
                   printf "cd ..\n"
                fi
                printf "add 17000077\n"
                printf "cd 17000077\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "hex:3:75,00,00,15,00,00,00,00\n"
                printf "cd ..\n"
                printf "add 21000001\n"
                printf "cd 21000001\n"
                printf "setval 1\n"
                printf "Element\n"
                ./scripts/update_device "$sourcepath"
                printf "cd ..\n"
                printf "add 22000002\n"
                printf "cd 22000002\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "string:\hiberfil.sys\n"
                printf "cd ..\n"
                printf "add 25000008\n"
                printf "cd 25000008\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "hex:3:01,00,00,00,00,00,00,00\n"
                if [[ "$firmware" == "bios" ]]; then
                   printf "cd ..\n"
                   printf "add 26000006\n"
                   printf "cd 26000006\n"
                   printf "setval 1\n"
                   printf "Element\n"
                   printf "hex:3:00\n"
                fi
                
                ### Windows Boot Loader Entry ###
                printf "cd ..\..\..\n"
                printf "add {%s}\n" "$winldrguid"
                printf "cd {%s}\n" "$winldrguid"
                printf "add Description\n"
                printf "cd Description\n"
                printf "setval 1\n"
                printf "Type\n"
                printf "dword:0x10200003\n"
                printf "cd ..\n"
                printf "add Elements\n"
                printf "cd Elements\n"
                printf "add 11000001\n"
                printf "cd 11000001\n"
                printf "setval 1\n"
                printf "Element\n"
                ./scripts/update_device "$sourcepath"
                printf "cd ..\n"
                printf "add 12000002\n"
                printf "cd 12000002\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "string:\Windows\system32\winload.%s\n" "$ext"
                printf "cd ..\n"
                printf "add 12000004\n"
                printf "cd 12000004\n"
                printf "setval 1\n"
                printf "Element\n"
                if  [[ -n "$winproduct" ]]; then
                    printf "string:%s\n" "$winproduct"
                else
                    printf "string:%s\n" "Windows"
                fi
                printf "cd ..\n"
                printf "add 12000005\n"
                printf "cd 12000005\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "string:%s\n" "en-US"
                printf "cd ..\n"
                printf "add 14000006\n"
                printf "cd 14000006\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "hex:7:7b,00,36,00,65,00,66,00,62,00,35,00,32,00,62,00,66,00,2d,00,31,00,37,00,36,00,36,00,2d,00,34,00,31,00,64,00,62,00,2d,00,61,00,36,00,62,00,33,00,2d,00,30,00,65,00,65,00,35,00,65,00,66,00,66,00,37,00,32,00,62,00,64,00,37,00,7d,00,00,00,00,00\n"
                printf "cd ..\n"
                if [[ "$firmware" == "uefi" ]]; then
                   printf "add 16000060\n"
                   printf "cd 16000060\n"
                   printf "setval 1\n"
                   printf "Element\n"
                   printf "hex:3:01\n"
                   printf "cd ..\n"
                fi
                printf "add 17000077\n"
                printf "cd 17000077\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "hex:3:75,00,00,15,00,00,00,00\n"
                printf "cd ..\n"
                printf "add 21000001\n"
                printf "cd 21000001\n"
                printf "setval 1\n"
                printf "Element\n"
                ./scripts/update_device "$sourcepath"
                printf "cd ..\n"
                printf "add 22000002\n"
                printf "cd 22000002\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "string:\Windows\n"
                printf "cd ..\n"
                printf "add 23000003\n"
                printf "cd 23000003\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "string:{%s}\n" "$winresguid"
                printf "cd ..\n"
                printf "add 25000020\n"
                printf "cd 25000020\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "hex:3:00,00,00,00,00,00,00,00\n"
                printf "cd ..\n"
                printf "add 250000c2\n"
                printf "cd 250000c2\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "hex:3:01,00,00,00,00,00,00,00\n"
                
                ### Windows Boot Manager Entry ###
                printf "cd ..\..\..\n"
                printf "cd {9dea862c-5cdd-4e70-acc1-f32b344d4795}\n"
                printf "cd Elements\n"
                printf "cd 11000001\n"
                printf "setval 1\n"
                printf "Element\n"
                ./scripts/update_device "/Volumes/EFI"
                printf "cd ..\n"
                if [[  "$firmware" == "uefi" ]]; then
                   printf "add 12000002\n"
                   printf "cd 12000002\n"
                   printf "setval 1\n"
                   printf "Element\n"
                   printf "string:\\\EFI\\Microsoft\\Boot\\\bootmgfw.efi\n"
                   printf "cd ..\n"
                fi
                printf "cd 12000005\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "string:%s\n" "en-US"
                printf "cd ..\n"
                printf "cd 23000003\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "string:{%s}\n" "$winldrguid"
                printf "cd ..\n"
                printf "cd 23000006\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "string:{%s}\n" "$winresguid"
                printf "cd ..\n"
                printf "cd 24000001\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "hex:7:%s\n" $(guid_list "{$winldrguid}")
                
                ### Windows Memory Tester Entry ###
                printf "cd ..\..\..\n"
                printf "cd {b2721d73-1db4-4c62-bf78-c548a880142d}\n"
                printf "cd Elements\n"
                printf "cd 11000001\n"
                printf "setval 1\n"
                printf "Element\n"
                ./scripts/update_device "/Volumes/EFI"
                printf "cd ..\n"
                printf "cd 12000002\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "string:%s\n" "$mempath"
                printf "cd ..\n"
                printf "cd 12000005\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "string:%s\n" "en-US"
                
                ### System and KeyName Entries ###
                printf "cd \\ \n"
                printf "cd Description\n"
                printf "setval 2\n"
                printf "KeyName\n"
                printf "string:BCD00000000\n"
                printf "System\n"
                printf "dword:1\n"
                printf "commit\n"
                printf "unload\n"
                

                recovery

                ### Windows Boot Manager Entry ###
                printf "cd \Objects\n"
                printf "cd {9dea862c-5cdd-4e70-acc1-f32b344d4795}\n"
                printf "cd Elements\n"
                printf "cd 11000001\n"
                printf "setval 1\n"
                printf "Element\n"
                ./scripts/update_device "/Volumes/EFI"
                printf "cd ..\n"
                printf "cd 12000005\n"
                printf "setval 1\n"
                printf "Element\n"
                printf "string:%s\n" "en-US"
                printf "commit\n"
                printf "unload\n"
                

                update_device

                endian () {
                v=$1
                i=${#v}
                
                while [ $i -gt 0 ]
                do
                    i=$[$i-2]
                    echo -n ${v:$i:2}
                done
                echo
                }
                
                guid_bytes () {
                guidstr="$1"
                IFS='-'
                
                   read -a strarr <<< "$guidstr"
                
                   guidbytes=$(endian ${strarr[0]})
                   guidbytes+=$(endian ${strarr[1]})
                   guidbytes+=$(endian ${strarr[2]})
                   guidbytes+=${strarr[3]}
                   guidbytes+=${strarr[4]}
                
                   echo $guidbytes
                }
                
                blksize () {
                sectsz=$(diskutil info $1 | grep "Device Block Size:" | awk '{print $4}')
                echo $sectsz
                }
                
                mntpoint="$1"
                part=$(diskutil info "$(basename "$mntpoint")" | grep "Device Node:" | awk '{print $3}')
                disk=$(printf $part | sed 's/s[0-9]*$//')
                scheme=$(diskutil info $disk | grep "Content (IOContent):" | awk '{print $3}')
                if [[ "$scheme" == "GUID_partition_scheme" ]]; then
                    if [[ ! -z $(sudo fdisk "$disk" | grep -E '2:|3:|4:' | grep -v unused) ]]; then
                       scheme="FDisk_partition_scheme" #Use fdisk option for GPT disk with hybrid MBR.
                    fi
                fi
                
                if   [[ "$scheme" == "GUID_partition_scheme" ]]; then
                     sectsize=$(blksize $disk)
                     diskbytes=$(sudo xxd -u -p -s $(($sectsize + 56)) -l 16 $disk | sed 's/.\{2\}/&,/g;s/,$//')
                      partguid=$(diskutil info $part | grep "Partition UUID:" | awk '{print $5}')
                      partbytes=$(printf "%s" $(guid_bytes $partguid) | sed 's/.\{2\}/&,/g;s/,$//')
                      schemebyte="00"
                elif [[ "$scheme" == "FDisk_partition_scheme" ]]; then
                      disksig=$(sudo xxd -u -p -s 440 -l 4 $disk)
                      partoffset=$(diskutil info $part | grep "Partition Offset:" | awk '{print $3}')
                      if [[ -z $partoffset ]]; then
                         hidsect=$(sudo fdisk $disk | tail -n +6 | awk -v partnum=${part##*s} 'FNR == partnum {print $11}')
                         sectsize=$(blksize $disk)
                         partoffset=$(($sectsize * $hidsect))
                      fi
                      diskbytes=$(printf "%s" $(printf "%x%024x" "0x$disksig") | sed 's/.\{2\}/&,/g;s/,$//')
                      partbytes=$(printf "%s" $(endian $(printf "%032x" "$partoffset")) | sed 's/.\{2\}/&,/g;s/,$//')
                      schemebyte="01"
                fi
                    printf "hex:3:00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,06,00,00,00,00,00,00,00,48,00,00,00,00,00,00,00,$partbytes,00,00,00,00,$schemebyte,00,00,00,$diskbytes,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00\n"
                
                 

                Last edit: Serhii 2024-05-09
      • Startergo

        Startergo - 2024-03-25

        Will bcd-sys be equivalent to these commands:

        mkdir S:\boot
        xcopy /E /H /K D:\boot S:\boot
        copy /b D:\bootmgr S:\bootmgr
        D:\boot\bootsect.exe /nt60 S: /mbr
        

        This is what is missing after conversion to hybrid partition of the GPT installation.
        you have another tool called ms-sys, which looks more suitable for legacy/hybrid partitions.
        Also to clarify hybrid partition cannot see the EFI partition and anything written to the EFI will not be visible from Windows. There is no system partition with Bootcamp (or gdisk). The system partition is the main Windows partition.

         

        Last edit: Startergo 2024-03-25
        • jpz4085

          jpz4085 - 2024-03-27

          The bcd-sys tool does the equivalent of the first three commands (plus builds a new BCD hive) and ms-sys does the equivalent of the bootsect command. So you will need to use both to enable a new Windows installation. I'm currently updating bcd-sys to detect a hybrid MBR configuration since the script gathers device information based on the partition scheme. The version in my repo does not yet work properly in this scenario.

           
          👍
          1
          • Startergo

            Startergo - 2024-03-27

            Thanks if you are using Sierra or earlier when you create a FAT32 partition through disk utility it automatically converts the GPT to Hybrid partition.

             
          • Startergo

            Startergo - 2024-04-02

            I saw you updated the BCD-SYS. Does it detect hybrid partitions now?

             

            Last edit: Startergo 2024-04-02
            • jpz4085

              jpz4085 - 2024-04-03

              Yes, as well as performs some sanity checks comparing firmware mode and partition schemes.

               
              👍
              1
    • Startergo

      Startergo - 2024-03-25

      I did not know they banned you. I thought they only removed the post. Shame on them.
      look here
      and here

       
  • Startergo

    Startergo - 2024-03-25

    Thanks all. I have a suggestion. For the Legacy boot the partition needs to be converted to hybrid partition scheme (with gdisk.exe) from GPT instead of converting the whole disk to MBR.

     
    • Serhii

      Serhii - 2024-05-24

      Now Install Windows (legacy boot) works, but I'm testing on a PC. Can you check if you have an old Mac?
      Conditions - the system is not higher than MacOS 12 Monterey and the disk should not be a system one (unless it is a hybrid one and Windows has not been installed before)

       

Log in to post a comment.