Messed Up APFS/Bootcamp Partition Table
I messed up my partition table after trying to get Windows 7 Boot Camp installation bootable after being unbootable using option/alt on start up.
Back Story
At some point a few months ago, I had issues with my partition table after migrating to APFS. I can't exactly remember what happened, but I messed up my partition table. I followed instruction here. It successfully resolved the partition table for Mac OS, which was my urgent concern at the time. Around the same time, my Bootcamp became unbootable. I'm assuming something I did while trying to fix my partition table made bootcamp unbootable. When I boot into Windows using opt/alt on startup, I get "No bootable device -- insert boot disk and press any key" error. However, Windows still boots using Parallels on Mac OS without issue. I had been using this as a work around until I could resolve the issues with bootcamp.
Broken Partition Table
I started out this morning with a working Mac OS X and non-bootable Bootcamp partition. Boot camp would boot in Parallels, but not via System Preferences/Start Up Disk or option/alt on start up. In Disk Utility, it showed bootcamp was not bootable from the inspection panel. I tried to do several things to resolve the issue in Windows 7 including check disk, start up repair, etc. Upon further research, I found that the issue appears to related to the Protective MBR.
I installed a trial of Paragon Hard Drive Manager. It had some features that I thought might resolve my issues via a graphical interface. I disabled SIP. I ran "Correct BCD" and "Correct Bootcamp Boot Record" functions. Both seemed to run, with little output. I restarted and tried to run bootcamp from alt/option. Same error as before - no bootable device.
Next, I tried following the steps here. I rebooted. I tried to launch bootcamp from alt/option - same error. After booting back into Mac OS, I launched Paragon Hard Drive Manager. It said I needed to "resync" the partitions. I had stumbled upon gptsync from another post, and I assumed that's what the software was going to do. I clicked okay and that's when I first noticed disk0s4. I'm guessing something between these two steps created this extra partition.
I seem to have really screwed up my Partition table now. In Disk Utility, I can see disk0s4, which is a duplicate of my Mac OS APFS. Though, it's FAT32, not APFS. I only have a 1 TB drive, yet somehow I have two 848 GB partitions. I think it's just an additional entry in the partition table.
I still have the Mac running in Mac OS as I write this, but I'm afraid to reboot as I don't think it will come back up until I remove this extra FAT32 partition. It's no longer booting into Mac OS because it rebooted over night (unknown to me as to why). I also still haven't resolved the bootcamp issue - making the bootcamp partition bootable from opt/alt on start up.
Current Partition Information
$ sudo gpt -r -vv show /dev/disk0
gpt show: /dev/disk0: mediasize=1000555581440; sectorsize=512; blocks=1954210120
gpt show: /dev/disk0: PMBR at sector 0
gpt show: /dev/disk0: Pri GPT at sector 1
gpt show: error: bogus map
gpt show: unable to open device '/dev/disk0': Undefined error: 0
$ diskutil list
/dev/disk0 (internal, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *1.0 TB disk0
1: Apple_APFS Container disk1 848.3 GB disk0s2
2: Microsoft Basic Data 848.6 GB disk0s4 << Unknown partition
3: Microsoft Basic Data BOOTCAMP 152.0 GB disk0s3
/dev/disk1 (synthesized):
#: TYPE NAME SIZE IDENTIFIER
0: APFS Container Scheme - +848.3 GB disk1
Physical Store disk0s2
1: APFS Volume Macintosh HD 796.6 GB disk1s1
2: APFS Volume Preboot 53.0 MB disk1s2
3: APFS Volume Recovery 510.5 MB disk1s3
4: APFS Volume VM 1.1 GB disk1s4
/dev/disk2 (disk image):
#: TYPE NAME SIZE IDENTIFIER
0: Apple_partition_scheme +21.0 MB disk2
1: Apple_partition_map 32.3 KB disk2s1
2: Apple_HFS rEFIt 20.9 MB disk2s2
# From Mac OS Recovery Mode on 1-11-2021
# used a flash drive to attempt to run the command from the comments
# copy the output. I was able to manually run it
bash-3.2# -bash-3.2# diskutil list
/dev/disk0
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *1.0 TB disk0
1: Microsoft Basic Data 848.6 GB disk0s1
2: Microsoft Basic Data BOOTCAMP 152.0 GB disk0s2
/dev/disk1
<ADDITIONAL INFORMATION ABOUT RECOVERY PARTITION OMITTED>
-bash-3.2# diskutil info disk0
Device Identifier: disk0
Device Node: /dev/disk0
Part of Whole: disk0
Device / Media Name: APPLE SSD SM1024F Media
Volume Name: Not applicable (no file system)
Mounted: Not applicable (no file system)
File System: None
Content (IOContent): GUID_partition_scheme
OS Can Be Installed: No
Media Type: Generic
Protocol: PCI
SMART Status: Verified
Total Size: 1.0 TB (1000555581440 Bytes) (exactly 1954210120 512-Byte-Units)
Volume Free Space: Not applicable (no file system)
Device Block Size: 512 Bytes
Read-Only Media: No
Read-Only Volume: Not applicable (no file system)
Ejectable: No
Whole: Yes
Internal: Yes
Solid State: Yes
OS 9 Drivers: No
Low Level Format: Not supported
-bash-3.2# diskutil info disk0s0
Could not find disk: disk0s0
-bash-3.2# diskutil info disk0s1
Device Identifier: disk0s1
Device Node: /dev/disk0s1
Part of Whole: disk0
Device / Media Name: Basic data partition
Volume Name:
Mounted: No
File System Personality: MS-DOS
Type (Bundle): msdos
Name (User Visible): MS-DOS (FAT)
Partition Type: Microsoft Basic Data
OS Can Be Installed: No
Media Type: Generic
Protocol: PCI
SMART Status: Verified
Disk / Partition UUID: 7C89FB14-3E93-4F24-EF45-9C1F793F62DF
Total Size: 848.6 GB (848555933184 Bytes) (exactly 1657335807 512-Byte-Units)
Volume Free Space: 0 B (0 Bytes) (exactly 0 512-Byte-Units)
Device Block Size: 512 Bytes
Read-Only Media: No
Read-Only Volume: Not applicable (not mounted)
Ejectable: No
Whole: No
Internal: Yes
Solid State: Yes
-bash-3.2# diskutil info disk0s2
Device Identifier: disk0s2
Device Node: /dev/disk0s2
Part of Whole: disk0
Device / Media Name: Untitled 2
Volume Name: BOOTCAMP
Mounted: Yes
Mount Point: /Volumes/BOOTCAMP
File System Personality: NTFS
Type (Bundle): ntfs
Name (User Visible): Windows NT File System (NTFS)
Partition Type: Microsoft Basic Data
OS Can Be Installed: No
Media Type: Generic
Protocol: PCI
SMART Status: Verified
Volume UUID: D003F722-F8D8-404F-806C-6C88C3EAC665
Disk / Partition UUID: F7571F70-5458-4FF7-BBFB-BBC700DFD95E
Total Size: 152.0 GB (151999479808 Bytes) (exactly 296873984 512-Byte-Units)
Volume Free Space: 18.0 GB (18020077568 Bytes) (exactly 35195464 512-Byte-Units)
Device Block Size: 512 Bytes
Allocation Block Size: 4096 Bytes
Read-Only Media: No
Read-Only Volume: Yes
Ejectable: No
Whole: No
Internal: Yes
Solid State: Yes
-bash-3.2# diskutil info disk0s3
Could not find dis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\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
Disk: /dev/disk0 geometry: 121643/255/63 [1954210120 sectors]
Signature: 0xAA55
Starting Ending
#: id cyl hd sec - cyl hd sec [ start - size]
------------------------------------------------------------------------
1: EE 0 0 2 - 1023 89 4 [ 1 - 4294967295] <Unknown ID>
2: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
3: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
4: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
-bash-3.2# diskutil info /dev/disk0
Device Identifier: disk0
Device Node: /dev/disk0
Whole: Yes
Part of Whole: disk0
Device / Media Name: APPLE SSD SM1024F
Volume Name: Not applicable (no file system)
Mounted: Not applicable (no file system)
File System: None
Content (IOContent): GUID_partition_scheme
OS Can Be Installed: No
Media Type: Generic
Protocol: PCI
SMART Status: Verified
Disk Size: 1.0 TB (1000555581440 Bytes) (exactly 1954210120 512-Byte-Units)
Device Block Size: 512 Bytes
Media OS Use Only: No
Media Read-Only: No
Volume Read-Only: Not applicable (no file system)
Device Location: Internal
Removable Media: Fixed
Solid State: Yes
Virtual: No
Hardware AES Support: No
-bash-3.2# diskutil info /dev/disk0s0
Could not find disk: /dev/disk0s0
-bash-3.2# diskutil info /dev/disk0s1
Device Identifier: disk0s1
Device Node: /dev/disk0s1
Whole: No
Part of Whole: disk0
Volume Name:
Mounted: No
Partition Type: Microsoft Basic Data
File System Personality: MS-DOS
Type (Bundle): msdos
Name (User Visible): MS-DOS (FAT)
OS Can Be Installed: No
Media Type: Generic
Protocol: PCI
SMART Status: Verified
Disk / Partition UUID: 7C89FB14-3E93-4F24-EF45-9C1F793F62DF
Partition Offset: 512 Bytes (1 512-Byte-Device-Blocks)
Disk Size: 848.6 GB (848555933184 Bytes) (exactly 1657335807 512-Byte-Units)
Device Block Size: 512 Bytes
Volume Total Space: 0 B (0 Bytes) (exactly 0 512-Byte-Units)
Volume Free Space: 0 B (0 Bytes) (exactly 0 512-Byte-Units)
Media OS Use Only: No
Media Read-Only: No
Volume Read-Only: Not applicable (not mounted)
Device Location: Internal
Removable Media: Fixed
Solid State: Yes
Hardware AES Support: No
-bash-3.2# diskutil info /dev/disk0s2
Device Identifier: disk0s2
Device Node: /dev/disk0s2
Whole: No
Part of Whole: disk0
Volume Name: BOOTCAMP
Mounted: Yes
Mount Point: /Volumes/BOOTCAMP
Partition Type: Microsoft Basic Data
File System Personality: NTFS
Type (Bundle): ntfs
Name (User Visible): Windows NT File System (NTFS)
OS Can Be Installed: No
Media Type: Generic
Protocol: PCI
SMART Status: Verified
Volume UUID: D003F722-F8D8-404F-806C-6C88C3EAC665
Disk / Partition UUID: F7571F70-5458-4FF7-BBFB-BBC700DFD95E
Partition Offset: 848555933696 Bytes (1657335808 512-Byte-Device-Blocks)
Disk Size: 152.0 GB (151999479808 Bytes) (exactly 296873984 512-Byte-Units)
Device Block Size: 512 Bytes
Volume Total Space: 152.0 GB (151999475712 Bytes) (exactly 296873976 512-Byte-Units)
Volume Used Space: 134.0 GB (133979398144 Bytes) (exactly 261678512 512-Byte-Units) (88.1%)
Volume Free Space: 18.0 GB (18020077568 Bytes) (exactly 35195464 512-Byte-Units) (11.9%)
Allocation Block Size: 4096 Bytes
Media OS Use Only: No
Media Read-Only: No
Volume Read-Only: Yes (read-only mount flag set)
Device Location: Internal
Removable Media: Fixed
Solid State: Yes
Hardware AES Support: No
-bash-3.2# diskutil info /dev/disk0s3
Could not find disk: /dev/disk0s3
-bash-3.2#
# Update with Mac OS running: 1-12-2021
$ diskutil unmount disk0s3
Volume BOOTCAMP on disk0s3 unmounted
$ sudo dd if=/dev/disk0s3 count=1 | hexdump -Cv
1+0 records in
1+0 records out
512 bytes transferred in 0.000316 secs (1620742 bytes/sec)
00000000 eb 52 90 4e 54 46 53 20 20 20 20 00 02 08 00 00 |.R.NTFS .....|
00000010 00 00 00 00 00 f8 00 00 3f 00 ff 00 00 f0 c8 62 |........?......b|
00000020 00 00 00 00 80 00 80 00 ff ef b1 11 00 00 00 00 |................|
00000030 00 00 0c 00 00 00 00 00 02 00 00 00 00 00 00 00 |................|
00000040 f6 00 00 00 01 00 00 00 87 99 b4 e6 b8 b4 e6 16 |................|
00000050 57 e9 a5 e2 fa 33 c0 8e d0 bc 00 7c fb 68 c0 07 |W....3.....|.h..|
00000060 1f 1e 68 66 00 cb 88 16 0e 00 66 81 3e 03 00 4e |..hf......f.>..N|
00000070 54 46 53 75 15 b4 41 bb aa 55 cd 13 72 0c 81 fb |TFSu..A..U..r...|
00000080 55 aa 75 06 f7 c1 01 00 75 03 e9 dd 00 1e 83 ec |U.u.....u.......|
00000090 18 68 1a 00 b4 48 8a 16 0e 00 8b f4 16 1f cd 13 |.h...H..........|
000000a0 9f 83 c4 18 9e 58 1f 72 e1 3b 06 0b 00 75 db a3 |.....X.r.;...u..|
000000b0 0f 00 c1 2e 0f 00 04 1e 5a 33 db b9 00 20 2b c8 |........Z3... +.|
000000c0 66 ff 06 11 00 03 16 0f 00 8e c2 ff 06 16 00 e8 |f...............|
000000d0 4b 00 2b c8 77 ef b8 00 bb cd 1a 66 23 c0 75 2d |K.+.w......f#.u-|
000000e0 66 81 fb 54 43 50 41 75 24 81 f9 02 01 72 1e 16 |f..TCPAu$....r..|
000000f0 68 07 bb 16 68 70 0e 16 68 09 00 66 53 66 53 66 |h...hp..h..fSfSf|
00000100 55 16 16 16 68 b8 01 66 61 0e 07 cd 1a 33 c0 bf |U...h..fa....3..|
00000110 28 10 b9 d8 0f fc f3 aa e9 5f 01 90 90 66 60 1e |(........_...f`.|
00000120 06 66 a1 11 00 66 03 06 1c 00 1e 66 68 00 00 00 |.f...f.....fh...|
00000130 00 66 50 06 53 68 01 00 68 10 00 b4 42 8a 16 0e |.fP.Sh..h...B...|
00000140 00 16 1f 8b f4 cd 13 66 59 5b 5a 66 59 66 59 1f |.......fY[ZfYfY.|
00000150 0f 82 16 00 66 ff 06 11 00 03 16 0f 00 8e c2 ff |....f...........|
00000160 0e 16 00 75 bc 07 1f 66 61 c3 a0 f8 01 e8 09 00 |...u...fa.......|
00000170 a0 fb 01 e8 03 00 f4 eb fd b4 01 8b f0 ac 3c 00 |..............<.|
00000180 74 09 b4 0e bb 07 00 cd 10 eb f2 c3 0d 0a 41 20 |t.............A |
00000190 64 69 73 6b 20 72 65 61 64 20 65 72 72 6f 72 20 |disk read error |
000001a0 6f 63 63 75 72 72 65 64 00 0d 0a 42 4f 4f 54 4d |occurred...BOOTM|
000001b0 47 52 20 69 73 20 6d 69 73 73 69 6e 67 00 0d 0a |GR is missing...|
000001c0 42 4f 4f 54 4d 47 52 20 69 73 20 63 6f 6d 70 72 |BOOTMGR is compr|
000001d0 65 73 73 65 64 00 0d 0a 50 72 65 73 73 20 43 74 |essed...Press Ct|
000001e0 72 6c 2b 41 6c 74 2b 44 65 6c 20 74 6f 20 72 65 |rl+Alt+Del to re|
000001f0 73 74 61 72 74 0d 0a 00 8c a9 be d6 00 00 55 aa |start.........U.|
00000200
Additional Context
I have Paragon NTFS installed. It also causes issues in which Bootcamp won't show up. I have disabled write access to circumvent this issue. I have homebrew installed, which is how I installed gdisk. I'm a software engineer whose comfortable with the CLI, just unfamiliar with partitions tables.
Notes
- MacBook Pro 15" Mid 2014
- Mac OS 10.14.6
- Windows 7
Solution 1:
The output given in the OP's question can be use to reconstruct the GPT. Once reconstructed, the output from the gpt -r show /dev/disk0
command should appear as shown below.
start size index contents
0 1 PMBR
1 1 Pri GPT header
2 32 Pri GPT table
34 6
40 409600 1 GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
409640 1656926168 2 GPT part - 7C3457EF-0000-11AA-AA11-00306543ECAC
1657335808 296873984 3 GPT part - EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
1954209792 295
1954210087 32 Sec GPT table
1954210119 1 Sec GPT header
You should be able to boot to macOS Recovery (Option-Command-R at startup) and enter the following commands to reconstruct the GPT.
Note: You may need to start each command with a
sudo
, as insudo dd if=/dev/zero count=34 of=/dev/disk0
.
diskutil unmountdisk disk0
dd if=/dev/zero count=34 of=/dev/disk0
dd if=/dev/zero seek=1954210087 count=33 of=/dev/disk0
gpt -f create -f disk0
gpt -f add -i 1 -b 40 -s 409600 -t efi disk0
gpt -f add -i 2 -b 409640 -s 1656926168 -t apfs disk0
gpt -f add -i 3 -b 1657335808 -s 296873984 -t windows disk0
If the partitions have not been corrupted, then you should be able to boot macOS. If successful, then I will update this answer with instructions for fixing the MBR partition table.
Fixing the MBR Partition Table
Boot to macOS Recovery and enter the following command. (The sudo
may not be needed.)
sudo fdisk -e /dev/disk0
The the -e
option makes the fdisk
command interactive. The input is given below.
e 1
ee
n
1
1657335807
e 2
7
n
1657335808
296873984
f 2
q
y
Afterwards, the output from sudo fdisk /dev/disk0
should be similar to the output shown below.
Note: Only the
#
,id
,start
andsize
columns have to match your output.
Disk: /dev/disk0 geometry: 121643/255/63 [1954210120 sectors]
Signature: 0xAA55
Starting Ending
#: id cyl hd sec - cyl hd sec [ start - size]
------------------------------------------------------------------------
1: EE 0 0 2 - 1023 254 63 [ 1 - 1657335807] <Unknown ID>
*2: 07 1023 254 63 - 1023 254 63 [1657335808 - 296873984] HPFS/QNX/AUX
3: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
4: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
When finished, boot back to macOS.
Update Windows 7 Boot Data and Code
Note: Windows 10 can produce boot data and code that is compatible with Windows 7. You probably can substitute a Windows 7 installer flash drive, but I have only tested this answer by using Windows 10.
-
Insert the Windows 10 installer flash drive in a USB port on the Mac. Instructions for creating the Windows 10 installer flash drive is given the next section.
-
Start or restart the Mac and immediately hold down the option key until the Mac Startup Manager icons appear. Select the external drive icon with the label
EFI Boot
. -
If the message "Press any key to boot from CD or DVD" appears, press any key.
-
When the image shown below appears, press the shift+F10 key combination to open a Command Prompt window.
-
Enter the following commands.
attrib c:\boot\bcd -s -h -r del c:\boot\bcd bcdboot c:\windows /l en-us /s c: /f bios bootsect /nt60 c: /mbr exit
-
Select
Next
, thenRepair your computer
and finallyTurn off your PC
. -
After the Mac turns off, remove the flash drive.
How to Create the Windows 10 Installer Flash Drive
Note: This flash drive will not be used to install Windows 10.
-
Download the latest 64 bit Windows 10 ISO file from the Microsoft website Download Windows 10 Disc Image (ISO File). This is a free download.
-
Use the Disk Utility application to erase an 8 GB or larger flash drive. Enter the following in the popup.
-
Use the Finder application to mount the downloaded Windows 10 ISO file.
-
Use the Finder application to copy all the files in the mounted volume to the flash drive.
-
Use the Finder application or Disk Utility application to eject the mounted Volume.
(Optional:) How to Remove the Windows Boot Manager at Startup
This section outlines several methods to remove the following screen from appearing at startup.
-
Method 1
You can use this method if the Mac boots to Windows 7 after 30 seconds without user intervention.
Left click on the Start Menu button, then right click on
Computer
and selectProperties
, as shown below.Click on
Advanced system settings
, as shown below.Under,
Startup and Recovery
, click on theSettings
button, as shown below.Uncheck
Time to display list of operating systems:
. The result is shown below.Click on the
OK
button. -
Method 2
Boot back to the Windows 10 installer flash drive and enter the commands given below.
attrib c:\boot\bcd -s -h -r del c:\boot\bcd bcdboot c:\windows /l en-us /s c: /f bios exit
-
Method 3
Open an
Administrator: Command Prompt
window. Enter thebcdedit
command. In my case, the results are shown below.In this case, the second
Windows Boot Loader
entry needs to be removed. The commandbcdedit /delete {identifier}
will do this. In this case, the command would be entered as shown below.bcdedit /delete {70613c75-5568-11eb-807e-97d1c8053bbf}