Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 5 Feb 2017 00:28:46 +0300
From:      "Andrey V. Elsukov" <bu7cher@yandex.ru>
To:        Warren Block <wblock@wonkity.com>
Cc:        "Rodney W. Grimes" <freebsd-rwg@pdx.rh.CN85.dnsmgr.net>, freebsd-hackers@freebsd.org, Slawa Olhovchenkov <slw@zxy.spb.ru>
Subject:   Re: How to safely remove rest of GTP?
Message-ID:  <ee9aaaf4-aa8f-2d51-3d2f-ab57ef1ece86@yandex.ru>
In-Reply-To: <alpine.BSF.2.20.1702041151110.91330@wonkity.com>
References:  <201701311543.v0VFh0Bl044986@pdx.rh.CN85.dnsmgr.net> <515e709a-5c34-0bc1-bc3b-7cff99f6dd97@yandex.ru> <alpine.BSF.2.20.1702041151110.91330@wonkity.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 04.02.2017 21:57, Warren Block wrote:
>> Please, give me some working example, when or where you have a
>> problem, and not some theoretical, based on previous negative
>> experience or memories.
>
> I just encountered something similar with a Windows 7 install on a disk
> that previously had a FreeBSD GPT layout.
>
> Clonezilla reported a conflicting GPT/MBR layout on the disk.  In gpart,
> it showed a valid GPT (not corrupt) with no partitions.  After all the
> cursing, I ran 'sudo sgdisk -z /dev/sda' as instructed by Clonezilla.
>
> It was only after that I realized I should have saved at least the
> partition tables.

Hi,

so, what is wrong here from your point of view?
I can imagine a way how to reproduce it.

Create two partition tables MBR and GPT.
# truncate -s 100m disk0
# truncate -s 100m disk1
# mdconfig -f disk0
md0
# mdconfig -f disk1
md1
# gpart create -s gpt md0
md0 created
# gpart create -s mbr md1
md1 created
# gpart add -t fat32 -s 25m md1
md1s1 added
# gpart add -t ntfs -s 25m md1
md1s2 added
# gpart add -t \!238 md1
md1s3 added
# gpart show md0 md1
=>    40  204720  md0  GPT  (100M)
       40  204720       - free -  (100M)

=>     9  204791  md1  MBR  (100M)
        9   51200    1  fat32  (25M)
    51209   51200    2  ntfs  (25M)
   102409  102391    3  !238  (50M)


Copy MBR from md1 to md0:

# dd if=/dev/md1 of=/dev/md0 count=1
1+0 records in
1+0 records out
512 bytes transferred in 0.285149 secs (1796 bytes/sec)
# gpart show md0 md1
=>    40  204720  md0  GPT  (100M)
       40  204720       - free -  (100M)

=>     9  204791  md1  MBR  (100M)
        9   51200    1  fat32  (25M)
    51209   51200    2  ntfs  (25M)
   102409  102391    3  !238  (50M)

Now md0 has correct MBR and GPT (not corrupt). GPT has higher priority, 
due to MBR has partition with type 0xee (PMBR).
https://svnweb.freebsd.org/base?view=revision&revision=258448

Remove "PMBR" partition and overwrite MBR on md0 again:
# gpart delete -i 3 md1
md1s3 deleted
# dd if=/dev/md1 of=/dev/md0 count=1
1+0 records in
1+0 records out
512 bytes transferred in 0.289039 secs (1771 bytes/sec)
# gpart show md0 md1
=>     9  204791  md0  MBR  (100M)
        9   51200    1  fat32  (25M)
    51209   51200    2  ntfs  (25M)
   102409  102391       - free -  (50M)

=>     9  204791  md1  MBR  (100M)
        9   51200    1  fat32  (25M)
    51209   51200    2  ntfs  (25M)
   102409  102391       - free -  (50M)

md0 still has both GPT and MBR, but GPT has lower priority, because 
there is no PMBR partition.

Destroy MBR on the md0:

# gpart destroy -F md0
md0 destroyed
# gpart show md0 md1
gpart: No such geom: md0.

And force retaste:
# true > /dev/md0
# gpart show md0 md1
=>    40  204720  md0  GPT  (100M)
       40  204720       - free -  (100M)

=>     9  204791  md1  MBR  (100M)
        9   51200    1  fat32  (25M)
    51209   51200    2  ntfs  (25M)
   102409  102391       - free -  (50M)


-- 
WBR, Andrey V. Elsukov



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ee9aaaf4-aa8f-2d51-3d2f-ab57ef1ece86>