foxlet / macOS-Simple-KVM

Tools to set up a quick macOS VM in QEMU, accelerated by KVM.
13.56k stars 1.14k forks source link

[Question] How to boot into OS automatically? [Fixed] #566

Closed dougpuob closed 2 years ago

dougpuob commented 2 years ago

● Expected behavior

I want to make it boots into the OS automatically on QEMU.

● Current behavior

  1. QEMU will stop at CLOVER boot manager, waiting to select a bootable partition.
  2. I tried to modify the GUID in the EFI/CLOVER/config.plist file in the ESP.qcow2 , but QEMU still stopped at CLOVER boot manager.
  3. Now, I am still finding a solution to set the boot menu.

20220519_140235--QEMU Clover boot macos 2

● WHAT I DID

  1. List disk information by diskutil.

    Last login: Wed May 18 22:38:35 on console
    gliuser@gliusers-iMac ~ % diskutil list
    /dev/disk0 (internal, physical):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      GUID_partition_scheme                        *268.4 MB   disk0
       1:                        EFI EFI                     101.4 MB   disk0s1
       2:           Linux Filesystem                         163.9 MB   disk0s2
    
    /dev/disk1 (internal, physical):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      GUID_partition_scheme                        *68.7 GB    disk1
       1:                        EFI EFI                     209.7 MB   disk1s1
       2:                 Apple_APFS Container disk3         68.4 GB    disk1s2
    
    /dev/disk2 (internal, physical):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      GUID_partition_scheme                        *2.1 GB     disk2
       1:                  Apple_HFS macOS Base System       2.0 GB     disk2s1
    
    /dev/disk3 (synthesized):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      APFS Container Scheme -                      +68.4 GB    disk3
                                     Physical Store disk1s2
       1:                APFS Volume mac - Data              8.0 GB     disk3s1
       2:                APFS Volume Preboot                 25.3 MB    disk3s2
       3:                APFS Volume Recovery                525.8 MB   disk3s3
       4:                APFS Volume VM                      1.1 MB     disk3s4
       5:                APFS Volume mac                     11.1 GB    disk3s5
    
    gliuser@gliusers-iMac ~ %
  2. Find the GUID of the partition by diskutil.

    gliuser@gliusers-iMac ~ % diskutil info disk3
       Device Identifier:         disk3
       Device Node:               /dev/disk3
       Whole:                     Yes
       Part of Whole:             disk3
       Device / Media Name:       QEMU HARDDISK
    
       Volume Name:               Not applicable (no file system)
       Mounted:                   Not applicable (no file system)
       File System:               None
    
       Content (IOContent):       EF57347C-0000-11AA-AA11-00306543ECAC
       OS Can Be Installed:       No
       Media Type:                Generic
       Protocol:                  SATA
       SMART Status:              Verified
       Disk / Partition UUID:     D25D46DF-3DC0-43FB-B626-6433EDCBA348  <-- **FOUND THE GUID HERE**
    
       Disk Size:                 68.4 GB (68375502848 Bytes) (exactly 133545904 512-Byte-Units)
       Device Block Size:         4096 Bytes
    
       Read-Only Media:           No
       Read-Only Volume:          Not applicable (no file system)
    
       Device Location:           Internal
       Removable Media:           Fixed
    
       Solid State:               No
       Virtual:                   Yes
       Hardware AES Support:      No
    
       This disk is an APFS Container. APFS Information:
       APFS Physical Store:       disk2s2
       Fusion Drive:              No
    gliuser@gliusers-iMac ~ %
  3. Modified the EFI/CLOVER/config.plist file in the ESP.qcow2 image.

    <key>DefaultVolume</key>
    <string>D25D46DF-3DC0-43FB-B626-6433EDCBA348</string>
  4. Launch the QEMU again.

    • I modified the config.plist in ESP.qcow2.
    • the os image I use is macos-catalina10.15.7.qcow2.
    # basic.sh
    qemu-system-x86_64 \
        -enable-kvm \
        -m 2G \
        -machine q35,accel=kvm \
        -smp 4,cores=2 \
        -cpu Penryn,vendor=GenuineIntel,kvm=on,+sse3,+sse4.2,+aes,+xsave,+avx,+xsaveopt,+xsavec,+xgetbv1,+avx2,+bmi2,+smep,+bmi1,+fma,+movbe,+invtsc \
        -device isa-applesmc,osk="$OSK" \
        -smbios type=2 \
        -drive if=pflash,format=raw,readonly=on,file="$OVMF/OVMF_CODE.fd" \
        -drive if=pflash,format=raw,file="$OVMF/OVMF_VARS-1024x768.fd" \
        -vga std \
        -device ich9-intel-hda -device hda-output \
        -usb -device usb-kbd -device usb-tablet \
        -netdev user,id=net0 \
        -device e1000-82545em,netdev=net0,id=net0,mac=52:54:00:c9:18:27 \
        -device ich9-ahci,id=sata \
        -drive id=ESP,if=none,format=qcow2,file=ESP.qcow2 \
        -device ide-hd,bus=sata.2,drive=ESP \
        -drive id=InstallMedia,format=raw,if=none,file=BaseSystem.img \
        -device ide-hd,bus=sata.3,drive=InstallMedia \
        -drive id=SystemDisk,if=none,file=macos-catalina10.15.7.qcow2 \
        -device ide-hd,bus=sata.4,drive=SystemDisk
notAperson535 commented 2 years ago

@dougpuob At least for opencore, if you hold ctrl as you press enter on the boot entry, it will se it to default boot.

dougpuob commented 2 years ago

@dougpuob At least for opencore, if you hold ctrl as you press enter on the boot entry, it will se it to default boot.

Hi @notAperson535 , thank you for the information, I will have it a try.

dougpuob commented 2 years ago

Close this issue because I found the solution. The following is the solution and details.

I found the description of <key> DefaultVolume </key> in the "Khaki Clover" document. I should use the volume name instead GUID, so I modified the value from <string>D25D46DF-3DC0-43FB-B626-6433EDCBA348</string> to <string>mac</string>. Then it works to boot into OS automatically.

Why do I know the volume name is mac in the <string>mac</string>. I execute the diskutil list command in macOS console.

/dev/disk3 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +68.4 GB    disk3
                                 Physical Store disk1s2
   1:                APFS Volume mac - Data              8.0 GB     disk3s1
   2:                APFS Volume Preboot                 25.3 MB    disk3s2
   3:                APFS Volume Recovery                525.8 MB   disk3s3
   4:                APFS Volume VM                      1.1 MB     disk3s4
   5:                APFS Volume mac                     11.1 GB    disk3s5  <-- **HERE**

● config.plist (✔️correct)

sudo nano ~/workspace/myesp/EFI/CLOVER/config.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Boot</key>
        <dict>
                <key>Arguments</key>
                <string>-v</string>
                <key>DefaultVolume</key>
                <string>mac</string>
                <key>Log</key>
                <true/>
                <key>Secure</key>
                <false/>
                <key>Timeout</key>
                <integer>5</integer>
        </dict>
...

● config.plist (❌incorrect)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Boot</key>
        <dict>
                <key>Arguments</key>
                <string>-v</string>
                <key>DefaultVolume</key>
                <string>D25D46DF-3DC0-43FB-B626-6433EDCBA348</string>
                <key>Log</key>
                <true/>
                <key>Secure</key>
                <false/>
                <key>Timeout</key>
                <integer>5</integer>
        </dict>
...

● The document I mentioned

https://drovosek01.github.io/CloverHackyColor-WebVersion/english/from%20Word/Clover_Of_Khaki_Color_eng_5129.htm#_bookmark86

" DefaultVolume " " MacHDD "

the name of the section, as you named it, as you see it in the bootloader log. However, the name can also be set in NVRAM after reboot from the "Startup Disk" control panel. The name set in NVRAM takes precedence. There is an option "LastBootedVolume". That is, we will boot from the volume from which we loaded last time. If the parameter is not specified at all, then only from the control panel.