From nobody Tue May 23 10:43:52 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 4QQWC92Nlgz4CK0X for ; Tue, 23 May 2023 10:44:05 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QQWC91f6Pz3MKZ for ; Tue, 23 May 2023 10:44:05 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-9707313e32eso178172566b.2 for ; Tue, 23 May 2023 03:44:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20221208.gappssmtp.com; s=20221208; t=1684838644; x=1687430644; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=R03MZ0gA7HzhkWoXbWAoK1OPmv5iOLrtobBAm0hIaos=; b=xUmOyeDruqfeq6bhyqdLt9f8CeoQkulPoXDP+Ymwq/LM4SbT0h/7OppBPoYDWaw7Ki rC1c6vQXoiA+07XJ1Qx/ZxSG84GHfsQwtylizEExvHoDC51vkuHFM6hwrCSvYq1hp5ze h0PVou3t5pS8ShZtq3bxKtw4MgPhulMGWZxILcSbUDjR2srnnB+VRrNgnRAKJzkCi1aG qe/ft7jzESWEirrfo67CYr9HanpuS+lGvYg/g5SmqRM0qgDxf6lyTWMDfG5LF85GJNt3 04Sg97GSD2SCoeAhjxDVVKM5Y+vzBCLncz890JAHHHjQnX6eSc7A/jtFI1D0AnPICU2W 3c9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684838644; x=1687430644; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=R03MZ0gA7HzhkWoXbWAoK1OPmv5iOLrtobBAm0hIaos=; b=a+9JprEHshWz/UHA1UZHFC7M/EF/27A3+C286J1Vvv/BaZRdGD5yyYmL1k0yOB5NBD J+tMr1GLlyu18z0JMvZqfSRe0Ff8u5sndp37k6QrpQgqsquTDwQTq5wBK/lrgzBh147v i8eIVWP1Y7ww8TYS7aPHWanNgmZXXohaDxCVIt7qtaoru1fh5kqkCsrSG1N728j+dc3C RIZfSyAAzDzMPiMRqEI36WMbMeDRT/J9nLpjuM1yHvWp9aW0z9mYDy4rDHiUeaxTQnvW EhGQmQCZAkPlKkOm8Dh5vqkXPAZMkGG+zvp8/P94dmLWx/WdUtbhegitiVrxJ4lewjaF wPOw== X-Gm-Message-State: AC+VfDwcrZ8Yg50wFoPZaKsIZrMSYTOBiKDd/7nSMQMAOO5h59WdXdaA d/0GfTFF4M4IDRkKszb08jhgKz4AhFciAJ+meP37lJXehefp4sRj X-Google-Smtp-Source: ACHHUZ6IAdwvIomdF0JJ/4m4AhVnmWepgLQSha+WZueg3LzHG+PBmLcsJ+HnifecHxNWkJAE44NLbf5XmR+Yf26WSnA= X-Received: by 2002:a17:907:1c1e:b0:96f:e080:4f56 with SMTP id nc30-20020a1709071c1e00b0096fe0804f56mr6607908ejc.31.1684838643757; Tue, 23 May 2023 03:44:03 -0700 (PDT) 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 References: In-Reply-To: From: Warner Losh Date: Tue, 23 May 2023 04:43:52 -0600 Message-ID: Subject: Re: gpart destroy efi partition? To: Steve Kargl Cc: FreeBSD Hackers Content-Type: multipart/alternative; boundary="000000000000dd841805fc5a1027" X-Rspamd-Queue-Id: 4QQWC91f6Pz3MKZ X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N --000000000000dd841805fc5a1027 Content-Type: text/plain; charset="UTF-8" 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. Warner --000000000000dd841805fc5a1027 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


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, Wa= rner 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?=C2=A0 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
> > =3D>=C2=A0 =C2=A0 =C2=A0 40=C2=A0 60063664=C2=A0 da0=C2=A0 GPT= =C2=A0 (29G)
> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A040=C2=A0 60063664=C2=A0 =C2=A0 1= =C2=A0 ms-basic-data=C2=A0 (29G)
> > % gpart delete -i 1 da0
> > gpart: geom 'da0': Read-only file system
> > % dd if=3D/dev/zero of=3D/dev/da0 bs=3D1m
> > dd: /dev/da0: Read-only file system
> >
>
> What's mounted?
>

Nothing mounted other than the boot partition on
an internal hard drive.=C2=A0 I plugged the memstick into
a usb port, and use gpart to list disk info.

% df
Filesystem=C2=A0 1M-blocks=C2=A0 Used=C2=A0 Avail Capacity=C2=A0 Mounted on=
/dev/ada0p2=C2=A0 =C2=A0 458231 62032 359539=C2=A0 =C2=A0 15%=C2=A0 =C2=A0 = /
devfs=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00=C2=A0 =C2=A0 = =C2=A00=C2=A0 =C2=A0 =C2=A0 0=C2=A0 =C2=A0 =C2=A00%=C2=A0 =C2=A0 /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
=C2=A0 =C2=A0Mediasize: 30752595968 (29G)
=C2=A0 =C2=A0Sectorsize: 512
=C2=A0 =C2=A0Stripesize: 0
=C2=A0 =C2=A0Stripeoffset: 20480
=C2=A0 =C2=A0Mode: r0w0e0
=C2=A0 =C2=A0efimedia: HD(1,GPT,a2e07858-a4b6-11ec-ac6a-fcaa142bc587,0x28,0= x3947fb0)
=C2=A0 =C2=A0rawuuid: a2e07858-a4b6-11ec-ac6a-fcaa142bc587
=C2=A0 =C2=A0rawtype: ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
=C2=A0 =C2=A0label: (null)
=C2=A0 =C2=A0length: 30752595968
=C2=A0 =C2=A0offset: 20480
=C2=A0 =C2=A0type: ms-basic-data
=C2=A0 =C2=A0index: 1
=C2=A0 =C2=A0end: 60063703
=C2=A0 =C2=A0start: 40
Consumers:
1. Name: da0
=C2=A0 =C2=A0Mediasize: 30752636928 (29G)
=C2=A0 =C2=A0Sectorsize: 512
=C2=A0 =C2=A0Mode: r0w0e0

I did find

% sysctl -a | grep da01
kern.geom.disk.da0.flags: 1a8<CANFLUSHCACHE,DIRECTCOMPLETION,CANZONE,WRI= TEPROTECT>

So, I suppose the question is how to clear WRITEPROTECT.

Assuming you are ru= nning as root...=C2=A0=C2=A0

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 indi= cating 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. camc= ontrol can read that:
# camcontrol modepage da0 -m 0= xa
will report it. if SWP is 1, then it's a soft= ware lock. Add -e to the=C2=A0 above to edit it and change the line with=C2= =A0 SWP on it from=C2=A0 1->0 and save. this will set the current value,= turning it off temporarily. You can then proceed to write to the device, w= ith luck.

Without=C2=A0 = luck the drive encountered a condition that made it decide to lock you out = forever from=C2=A0 writing again.

Warner


--000000000000dd841805fc5a1027--