From nobody Tue May 23 15:19:24 2023 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QQdJw1ckkz4CbSj for ; Tue, 23 May 2023 15:19:28 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "troutmask", Issuer "troutmask" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QQdJv60gNz4Dc6 for ; Tue, 23 May 2023 15:19:27 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Authentication-Results: mx1.freebsd.org; none Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.17.1/8.17.1) with ESMTPS id 34NFJODg036798 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 23 May 2023 08:19:24 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.17.1/8.17.1/Submit) id 34NFJOJw036797; Tue, 23 May 2023 08:19:24 -0700 (PDT) (envelope-from sgk) Date: Tue, 23 May 2023 08:19:24 -0700 From: Steve Kargl To: Warner Losh Cc: FreeBSD Hackers Subject: Re: gpart destroy efi partition? Message-ID: Reply-To: sgk@troutmask.apl.washington.edu References: List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 4QQdJv60gNz4Dc6 X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:73, ipnet:128.95.0.0/16, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N On Tue, May 23, 2023 at 04:43:52AM -0600, Warner Losh wrote: > On Mon, May 22, 2023, 10:35 PM 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 > > > > 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. Thanks for the advice, Warner. I thought about camcontrol last night, but it's been a long long time since I've had a need for it. % camcontrol modepage da0 -l 0x08 Caching 0x1c Informational Exceptions Control 0x05 Flexible Disk % camcontrol modepage da0 -m 0xa camcontrol: mode sense command returned error I suppose this is the end for that memstick. -- Steve