# glabel(8) outputs no error when there is no glabel



## Erichans (Jun 17, 2022)

When creating gpt partitions on a USB flash drive, glabel(8) behaves unexpectedly (repeatable behaviour):

```
[1] # gpart destroy -F da0
da0 destroyed
[2] # gpart create -s gpt da0
da0 created
[3] # gpart add -t freebsd-ufs -l FreeBLAH da0
da0p1 added
[4] # glabel dump da0p1
Can't read metadata from da0p1: Invalid argument.
glabel: Not fully done.
[5] # glabel stop Free-BLAH
glabel: Label Free-BLAH is invalid.
[6] # glabel stop FreeBLAH
[7] # echo $?
0
[8] # glabel stop FreeBLAH
glabel: Label FreeBLAH is invalid.
[9] # echo $?
1
```
Cmd #4 shows (as expected) that there is no glabel data on `da0p1`.
Cmd #5 is an intentionally made typo (the extra "-" in the glabel argument); its result is as expected.
Cmd #6 should output an error message; like cmd #8.

What is happening?



```
% uname -a
FreeBSD q210 12.3-RELEASE-p5 FreeBSD 12.3-RELEASE-p5 GENERIC  amd64
```


----------



## Phishfry (Jun 18, 2022)

Erichans said:


> [1] # gpart destroy -F da0 da0 destroyed


Personally step 2 for me is dd.
I know its rough on the disk but I want it zeroed.
You might need to enable some /boot/loader.conf settings (& reboot) to clear old labels :

```
kern.geom.label.ufsid.enable=0
kern.geom.label.gptid.enable=0
kern.geom.label.gpt.enable=0
```
Then after zeroing USB device disable or delete these settings.
These settings disable labels that get stored in /dev so you can fully wipe a disk.


----------



## Phishfry (Jun 18, 2022)

Erichans said:


> What is happening?


I am not sure but you should look at `tunefs -p` as well for investigation. See what label shows up there.
Try changing the label with `tunefs -L` . Revert to single user mode if really stubborn.


----------



## Phishfry (Jun 18, 2022)

Erichans said:


> Cmd #4 shows (as expected) that there is no glabel data on `da0p1`.


Why not? In step #3 you explicitly add a partition with -l FreeBLAH


----------



## Phishfry (Jun 18, 2022)

Erichans said:


> Cmd #5 is an intentionally made typo (the extra "-" in the glabel argument); its result is as expected.


Are you sure a special character is appropriate for a glabel? That to me is not a good typo to use for an example.


----------



## Erichans (Jun 18, 2022)

Thanks. My experimentation started with grahamperrin@'s message and his pastebin output:


> [...]
> root@mowa219-gjp4-8570p-freebsd:~ # glabel stop FreeBSD%20ZFS
> root@mowa219-gjp4-8570p-freebsd:~ # gpart show -l da1


I couldn't explain the absence of an error message as a result of the first command; so I took a brand-new USB stick.



Phishfry said:


> Personally step 2 for me is dd.


I tried `dd` as well: no effect. I also tried another brand-new USB stick, same results, see below.



Phishfry said:


> I am not sure but you should look at `tunefs -p` as well for investigation. See what label shows up there.
> Try changing the label with `tunefs -L` . Revert to single user mode if really stubborn.


tunefs(8) is about UFS specific labels. I haven't touched those at all; also used two new USB sticks.



Phishfry said:


> Erichans said:
> 
> 
> > Cmd #4 shows (as expected) that there is no glabel data on `da0p1`.
> ...


`[3] # gpart add -t freebsd-ufs -l FreeBLAH da0` adds a gpt label.
`[4] # glabel dump da0p1` (tries to) dump metadata (of glabels) stored on the given devices.
GEOM (glabel) labels (as in `glabel label blurp ada0s1b`) are not the same as gpt labels. In addition to that no entries appear in /dev/label*

AFAIK, glabel labels can only be set with glabel(8)—or `geom label`—and glabel(8) cannot set gpt labels. gpt labels can be read by glabel(8).

To the best of my knowledge a GEOM label cannot exist without its metadata, whether it is turned on or off, or whether it is made invisible by geom withering. Cmd #4 confirms that there isn't any glabel metadata on da0p1.

Cmd #5 is not strictly necessary to show the unexpected behaviour. It only serves as a contrast to the next cmd #6. glabel(1) should be able to handle a normal "-" (dash) quite well IMO. However the typo with the "-" replaced by an "x" yields the same result.

The second new USB stick (same make and model) fresh from its package shows the same results:

```
[10] # dd if=/dev/zero of=/dev/da0 bs=512 count=10
10+0 records in
10+0 records out
5120 bytes transferred in 0.136022 secs (37641 bytes/sec)
[11] # gpart destroy -F da0
da0 destroyed
[12] # gpart create -s gpt da0
da0 created
[13] # gpart add -t freebsd-ufs -l FreeBLAH da0
da0p1 added
[14] # glabel dump da0p1
Can't read metadata from da0p1: Invalid argument.
glabel: Not fully done.
[15] # glabel stop FreexBLAH
glabel: Label FreexBLAH is invalid.
[16] # glabel stop FreeBLAH
[17] # glabel stop FreeBLAH
glabel: Label FreeBLAH is invalid.
```


----------



## Phishfry (Jun 19, 2022)

What if you label it during formatting instead?
newfs -l ?


----------

