Re: gpart destroy efi partition?

From: Julian H. Stacey <jhs_at_berklix.com>
Date: Tue, 23 May 2023 10:55:21 UTC
Steve Kargl wrote:
> On Mon, May 22, 2023 at 09:51:40PM -0600, Warner Losh wrote:
> > On Mon, May 22, 2023, 9:45 PM Steve Kargl <sgk@troutmask.apl.washington.edu>
> > wrote:
> > 
> > > Is there a secret incantation for destroying an EFI
> > > partition on a USB memstick?  After installing FreeBSD,
> > > I would like to re-use a memstick, but
> > >
> > > % gpart destroy da0
> > > gpart: geom 'da0': Read-only file system
> > > % gpart destroy -F da0
> > > gpart: geom 'da0': Read-only file system
> > > % gpart show da0
> > > =>      40  60063664  da0  GPT  (29G)
> > >         40  60063664    1  ms-basic-data  (29G)
> > > % gpart delete -i 1 da0
> > > gpart: geom 'da0': Read-only file system
> > > % dd if=/dev/zero of=/dev/da0 bs=1m
> > > dd: /dev/da0: Read-only file system
> > >
> > 
> > What's mounted?
> > 
>
> Nothing mounted other than the boot partition on
> an internal hard drive.  I plugged the memstick into
> a usb port, and use gpart to list disk info.
>
> % df
> Filesystem  1M-blocks  Used  Avail Capacity  Mounted on
> /dev/ada0p2    458231 62032 359539    15%    /
> devfs               0     0      0     0%    /dev
>
> ada0p1 is the EFI boot partition on the internal drive.
> ada0p3 is swap.
>
> % gpart list da0
> Geom name: da0
> modified: false
> state: OK
> fwheads: 255
> fwsectors: 63
> last: 60063703
> first: 40
> entries: 128
> scheme: GPT
> Providers:
> 1. Name: da0p1
>    Mediasize: 30752595968 (29G)
>    Sectorsize: 512
>    Stripesize: 0
>    Stripeoffset: 20480
>    Mode: r0w0e0
>    efimedia: HD(1,GPT,a2e07858-a4b6-11ec-ac6a-fcaa142bc587,0x28,0x3947fb0)
>    rawuuid: a2e07858-a4b6-11ec-ac6a-fcaa142bc587
>    rawtype: ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
>    label: (null)
>    length: 30752595968
>    offset: 20480
>    type: ms-basic-data
>    index: 1
>    end: 60063703
>    start: 40
> Consumers:
> 1. Name: da0
>    Mediasize: 30752636928 (29G)
>    Sectorsize: 512
>    Mode: r0w0e0
>
> I did find 
>
> % sysctl -a | grep da01
> kern.geom.disk.da0.flags: 1a8<CANFLUSHCACHE,DIRECTCOMPLETION,CANZONE,WRITEPROTECT>
>
> So, I suppose the question is how to clear WRITEPROTECT.

I dont use efi & gpart but some ideas:

Why da01 not da0 ? What is da01 ?
a typo, or pulling in some gpart kernel stuff ?

Is an escalated security level catching you ? I stick to default,
on 12.4-rel multi user thats: sysctl -a | grep level # kern.securelevel: -1

Try a fresh reboot, even staying single user,
& before you touch it with any gpart invoking command,
whack it with multiple dd if=/dev/zero of=/dev/zero count=5000

(multiple as sometimes Ive seen first attempt doesnt seem to clear
my sticks, a 2nd reboot after dd will clear any false cached memories)

If that doesnt work:
  Try an older BSD that does know about EFI & gpart ?
  Put it a Microsoft PC, or a USB to Go adapter on an android,
  that probbly will complain unknown & offer to bash it back to MBR ?
  Rumage around or ask friends, eg I have a tiny old match box size thing
  that clones sticks. Clone your stick from some other small stick,
  then repair the wrong sized MBR

Cheers,
-- 
Julian Stacey www.StolenVotes.UK/jhs/ Arm Ukraine, Zap Putin.  Brexit inflates
http://berklix.org/ferries/#dover_solution