Date: Tue, 23 May 2023 04:43:52 -0600 From: Warner Losh <imp@bsdimp.com> To: Steve Kargl <sgk@troutmask.apl.washington.edu> Cc: FreeBSD Hackers <freebsd-hackers@freebsd.org> Subject: Re: gpart destroy efi partition? Message-ID: <CANCZdfqjAAQJLa14OyzhqjruJPZE9fYROo5YQwYhqB0nRVeM3Q@mail.gmail.com> In-Reply-To: <ZGxCgdOOZHZsKRnh@troutmask.apl.washington.edu> References: <ZGw2tRM9edxKxXqO@troutmask.apl.washington.edu> <CANCZdfrPwX=1SXnqu4_i0cyt-R38KH8_Jt97PDjRqci0cOXTAw@mail.gmail.com> <ZGxCgdOOZHZsKRnh@troutmask.apl.washington.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --] On Mon, May 22, 2023, 10:35 PM Steve Kargl <sgk@troutmask.apl.washington.edu> 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. > Assuming you are running as root... WRITEPROTECT gets set when we do a MODE SENSE of the disk when we're probing it. That returns a status that indicates that the device is indicating it is write protected. So we set the write_protect flags in the disk structure which is what's reported above and used to generate the read only errors. if you are lucky, this is a software write protect. That's on mode page 0xa. camcontrol can read that: # camcontrol modepage da0 -m 0xa will report it. if SWP is 1, then it's a software lock. Add -e to the above to edit it and change the line with SWP on it from 1->0 and save. this will set the current value, turning it off temporarily. You can then proceed to write to the device, with luck. Without luck the drive encountered a condition that made it decide to lock you out forever from writing again. Warner [-- Attachment #2 --] <div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, May 22, 2023, 10:35 PM Steve Kargl <<a href="mailto:sgk@troutmask.apl.washington.edu" rel="noreferrer noreferrer" target="_blank">sgk@troutmask.apl.washington.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, May 22, 2023 at 09:51:40PM -0600, Warner Losh wrote:<br> > On Mon, May 22, 2023, 9:45 PM Steve Kargl <<a href="mailto:sgk@troutmask.apl.washington.edu" rel="noreferrer noreferrer noreferrer" target="_blank">sgk@troutmask.apl.washington.edu</a>><br> > wrote:<br> > <br> > > Is there a secret incantation for destroying an EFI<br> > > partition on a USB memstick? After installing FreeBSD,<br> > > I would like to re-use a memstick, but<br> > ><br> > > % gpart destroy da0<br> > > gpart: geom 'da0': Read-only file system<br> > > % gpart destroy -F da0<br> > > gpart: geom 'da0': Read-only file system<br> > > % gpart show da0<br> > > => 40 60063664 da0 GPT (29G)<br> > > 40 60063664 1 ms-basic-data (29G)<br> > > % gpart delete -i 1 da0<br> > > gpart: geom 'da0': Read-only file system<br> > > % dd if=/dev/zero of=/dev/da0 bs=1m<br> > > dd: /dev/da0: Read-only file system<br> > ><br> > <br> > What's mounted?<br> > <br> <br> Nothing mounted other than the boot partition on<br> an internal hard drive. I plugged the memstick into<br> a usb port, and use gpart to list disk info.<br> <br> % df<br> Filesystem 1M-blocks Used Avail Capacity Mounted on<br> /dev/ada0p2 458231 62032 359539 15% /<br> devfs 0 0 0 0% /dev<br> <br> ada0p1 is the EFI boot partition on the internal drive.<br> ada0p3 is swap.<br> <br> % gpart list da0<br> Geom name: da0<br> modified: false<br> state: OK<br> fwheads: 255<br> fwsectors: 63<br> last: 60063703<br> first: 40<br> entries: 128<br> scheme: GPT<br> Providers:<br> 1. Name: da0p1<br> Mediasize: 30752595968 (29G)<br> Sectorsize: 512<br> Stripesize: 0<br> Stripeoffset: 20480<br> Mode: r0w0e0<br> efimedia: HD(1,GPT,a2e07858-a4b6-11ec-ac6a-fcaa142bc587,0x28,0x3947fb0)<br> rawuuid: a2e07858-a4b6-11ec-ac6a-fcaa142bc587<br> rawtype: ebd0a0a2-b9e5-4433-87c0-68b6b72699c7<br> label: (null)<br> length: 30752595968<br> offset: 20480<br> type: ms-basic-data<br> index: 1<br> end: 60063703<br> start: 40<br> Consumers:<br> 1. Name: da0<br> Mediasize: 30752636928 (29G)<br> Sectorsize: 512<br> Mode: r0w0e0<br> <br> I did find <br> <br> % sysctl -a | grep da01<br> kern.geom.disk.da0.flags: 1a8<CANFLUSHCACHE,DIRECTCOMPLETION,CANZONE,WRITEPROTECT><br> <br> So, I suppose the question is how to clear WRITEPROTECT.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Assuming you are running as root... </div><div dir="auto"><br></div><div dir="auto">WRITEPROTECT gets set when we do a MODE SENSE of the disk when we're probing it. That returns a status that indicates that the device is indicating it is write protected. So we set the write_protect flags in the disk structure which is what's reported above and used to generate the read only errors.</div><div dir="auto"><br></div><div dir="auto">if you are lucky, this is a software write protect. That's on mode page 0xa. camcontrol can read that:</div><div dir="auto"># camcontrol modepage da0 -m 0xa</div><div dir="auto">will report it. if SWP is 1, then it's a software lock. Add -e to the above to edit it and change the line with SWP on it from 1->0 and save. this will set the current value, turning it off temporarily. You can then proceed to write to the device, with luck.</div><div dir="auto"><br></div><div dir="auto">Without luck the drive encountered a condition that made it decide to lock you out forever from writing again.</div><div dir="auto"><br></div><div dir="auto">Warner</div><div dir="auto"><br></div><div dir="auto"><br></div></div>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfqjAAQJLa14OyzhqjruJPZE9fYROo5YQwYhqB0nRVeM3Q>
