Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 31 Jan 2017 03:05:12 +0300
From:      "Andrey V. Elsukov" <bu7cher@yandex.ru>
To:        Warren Block <wblock@wonkity.com>
Cc:        Slawa Olhovchenkov <slw@zxy.spb.ru>, freebsd-hackers@freebsd.org
Subject:   Re: How to safely remove rest of GTP?
Message-ID:  <37c200a6-e2b3-6f5e-792d-4464d2e5ecae@yandex.ru>
In-Reply-To: <alpine.BSF.2.20.1701301607510.85129@wonkity.com>
References:  <20161230124407.GN37118@zxy.spb.ru> <d79b8568-72e8-415e-4923-14e3c730267e@FreeBSD.org> <alpine.BSF.2.20.1701300851400.85129@wonkity.com> <1793b0ec-3a86-5c9a-b275-aa93cd9d230e@yandex.ru> <alpine.BSF.2.20.1701301607510.85129@wonkity.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 31.01.2017 02:21, Warren Block wrote:
> On Mon, 30 Jan 2017, Andrey V. Elsukov wrote:
>
>> On 30.01.2017 18:55, Warren Block wrote:
>>>>> GEOM: da6: the primary GPT table is corrupt or invalid.
>>>>> GEOM: da6: using the secondary instead -- recovery strongly advised.
>>>>> GEOM: da22: the primary GPT table is corrupt or invalid.
>>>>> GEOM: da22: using the secondary instead -- recovery strongly advised.
>>>>> GEOM: da6: the primary GPT table is corrupt or invalid.
>>>>> GEOM: da6: using the secondary instead -- recovery strongly advised.
>>>>> GEOM: da22: the primary GPT table is corrupt or invalid.
>>>>> GEOM: da22: using the secondary instead -- recovery strongly advised.
>>>>
>>>> You may try attached patch, I did only basic tests, so first try
>>>> somewhere :)
>>>
>>> I really like the idea of gpart being able to remove the secondary GPT,
>>> but combining it with the existing destroy command is ambiguous.  It's
>>> hard for the user to tell what will happen, and the command itself
>>> implies that it will destroy all partitioning.
>>
>> I don't see any ambiguity here. A user sees corrupted GPT, it can only
>> destroy or recover it.
>
> Ah, but the user might not even see it.  "I wrote an MBR to my disk
> (with some other software) and now FreeBSD says it has a corrupted GPT."

I'm sure this is not true. GEOM_PART has several probe priorities. If 
there is valid MBR, GPT will not have a chance to print messages about 
corrupted tables.

Look at this example:

# truncate -s 100m disk
# mdconfig -f disk
md0
# gpart create -s gpt md0
md0 created
# gpart add -t freebsd-boot -s 128k md0
md0p1 added
# gpart show md0
=>    40  204720  md0  GPT  (100M)
       40     256    1  freebsd-boot  (128K)
      296  204464       - free -  (100M)

  # dd if=/dev/zero of=/dev/md0 count=2
2+0 records in
2+0 records out
1024 bytes transferred in 0.304545 secs (3362 bytes/sec)
# gpart show md0
=>    40  204720  md0  GPT  (100M) [CORRUPT]
       40     256    1  freebsd-boot  (128K)
      296  204464       - free -  (100M)

# dmesg | grep GEOM
GEOM: md0: the primary GPT table is corrupt or invalid.
GEOM: md0: using the secondary instead -- recovery strongly advised.

Now let's write the MBR:

# dd if=/boot/mbr of=/dev/md0
1+0 records in
1+0 records out
512 bytes transferred in 0.033823 secs (15138 bytes/sec)
# gpart show md0
=>     9  204791  md0  MBR  (100M)
        9  204791       - free -  (100M)

# mdconfig -du 0
# mdconfig -f disk
md0
# dmesg | grep GEOM
<no new messages about corrupted GPT>
# gpart show md0
=>     9  204791  md0  MBR  (100M)
        9  204791       - free -  (100M)


> In this case, it can have a valid MBR which the user does not want to
> destroy.  So re-using the gpart destroy command for this is ambiguous.
> It's also kind of dangerous, in that when the user finally does
> understand that "destroy" doesn't really destroy all partitioning, they
> might use it expecting to only destroy the "bad" partitioning and be
> surprised because things were not like they thought and it wiped out the
> "good" partitioning.

It is impossible to have two GEOM_PART's geoms on the same provider.

> Put another way:
>
> `gpart destroy -F` means "destroy the GEOM unconditionally".
>
> Adding this additional function to it makes it "destroy the GEOM, unless
> some specific condition, and then it means only destroy a part of it."

There is no need to add such "partial destroy", it still always destroys 
GEOM. It always destroys partition table metadata. The proposed patch 
only adds additional check. Since GPT has two parts of metadata, it 
checks, that each part of metadata is valid before wipe them.

> As I think I said before, the function is really needed.  It is just
> making the user interface unambiguous that is my concern.
>
> zfs has "labelclear".  If gpart did that, along with a set amount of
> space to clear at the beginning and end of the drive, I'd be happy with
> it.  It does not need to detect the type of geom.
>
>   gpart labelclear -F -s1m da22
>
> to clear the first and last 1M of da22.  Maybe force the user to give
> the -F flag.  (Yes, this can be done with dd, but slowly because of
> oseeking to the end of a big drive.  And it requires math, which is both
> scary and beyond the capacity of many people to calculate.)
>
>> It is impossible to have a corrupted GPT and some other type of
>> partition table in the same time.
>
> Maybe when only using FreeBSD and gpart, but I'm pretty sure I've seen
> forum users who have tried some crappy other formatting tool and have
> overwritten the primary GPT with a valid MBR and left the secondary GPT
> untouched.  This only becomes obvious when they bring the disk back to a
> FreeBSD system.

As I said, in this case MBR will have higher priority and there will no 
GPT, until you destroy MBR. After that GPT will appear. And you will be 
able correctly destroy GPT using 'gpart destroy -F'.

-- 
WBR, Andrey V. Elsukov



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?37c200a6-e2b3-6f5e-792d-4464d2e5ecae>