owned this note
owned this note
Published
Linked with GitHub
# 如何還原一 GUID 磁碟分割表之磁碟的 Hybrid MBR 設定?<br>How to Undo a Hybrid MBR Configuration on a GUID Partition Table Disk?
## 問題概覽<br>Problem Overview
```
# gdisk <disk device file>
GPT fdisk (gdisk) version 1.0.1
Partition table scan:
MBR: hybrid
BSD: not present
APM: not present
GPT: present
Found valid GPT with hybrid MBR; using GPT.
```
You want to revert a previously made Hybrid MBR configuration GUID partition table disk back to standard configuration to prevent programs not handling them well to misfunction(like Microsoft Windows installer)
## 解決方案<br>Solutions
### Using GPT fdisk (a.k.a. gdisk)
In fact `gdisk` *does* support replacing the hybrid MBR to proper GUID Partition Table's protective MBR
> "You can replace a hybrid MBR with a legal protective MBR by using the "n" option on the experts' menu." -- by Rod Smith, GPT fdisk's author
Simply press `x` in the `gdisk` interactive shell to enter the experts menu, press "n" the create a new protectie MBR and press "w" to write the changes to disk(and of course, press "q" to leave `gdisk`)
### Modify MBR Externally Then Put It Back In(obseluted)
1. Use `dd` command to make a copy of the MBR
```
# dd if=<block device file of the specific disk> of=mbr.bin bs=512 count=1
[sudo] password for Lin-Buo-Ren:
輸入 1+0 個紀錄
輸出 1+0 個紀錄
512 bytes copied, 0.00451046 s, 114 kB/s
```
1. Open the copied MBR file using `fdisk`, this time it won't consider it as GUID partition table
```
# fdisk mbr.bin
Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
命令 (m 以獲得說明): p
Disk mbr.bin: 512 B, 512 bytes, 1 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000
所用裝置 可開機 Start 結束 磁區 Size Id 類型
mbr.bin1 1 2047 2047 1023.5K ee GPT
mbr.bin2 2048 391167 389120 190M c W95 FAT32 (LBA)
mbr.bin3 * 393216 195702783 195309568 93.1G 7 HPFS/NTFS/exFAT
mbr.bin4 195702784 937701375 741998592 353.8G 83 Linux
```
1. In `fdisk`'s interactive shell, remove all partitions that not in type 0xEE(which is the indicator that this is a GUID partition table's protective MBR)
```
命令 (m 以獲得說明): d
分割區編號 (1-4, default 4): 2
Partition 2 has been deleted.
命令 (m 以獲得說明): d
分割區編號 (1,3,4, default 4): 3
Partition 3 has been deleted.
命令 (m 以獲得說明): d
分割區編號 (1,4, default 4): 4
Partition 4 has been deleted.
```
1. In `fdisk`'s interactive shell, write the result back to the external MBR and leave `fdisk`
```
命令 (m 以獲得說明): w
The partition table has been altered.
Syncing disks.
```
1. Write the modified MBR back to the disk using `dd`
```
# dd if=mbr.bin of=<block device file of the specific disk> bs=512 count=1
輸入 1+0 個紀錄
輸出 1+0 個紀錄
512 bytes copied, 0.000167607 s, 3.1 MB/s
```
1. Profit!
```
# gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.1
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
```
## 參考資料<br>Reference
* [\[Gptfdisk-general\] Support reverting a hybrid MBR configuration](https://sourceforge.net/p/gptfdisk/mailman/message/36060568/)
* [Managing EFI Boot Loaders for Linux: CSM: The Good, the Bad, and the Ugly](http://www.rodsbooks.com/efi-bootloaders/csm-good-bad-ugly.html)