# How to label partitions



## balanga (Jan 28, 2018)

I'm trying to label partitions so that I can reference them in/etc/fstab but I don't understand the difference between glabel() and tunefs().

Can anyone explain the difference?


----------



## ShelLuser (Jan 29, 2018)

Check their manualpages and you'll see. tunefs is a tool specifically meant to tune an UFS filesystem. So obviously it has little to do with partitions / slices. glabel is used to (quote): "_GEOM provider labelization_". This should of course raise the question "What is a GEOM class?". Well, check geom(8). You'll notice once again that it is filesystem related and not so much with partitions (or slices).

Depending on your setup the best way to apply a label to a partition is by using gpart(8).


----------



## hk7 (Jan 29, 2018)

`tunefs` operates on partitions of ufs, `glabel` operates on partitions (e.g. `/dev/da0p1`) and/or entire disk (e.g. `/dev/da0`)
Below are the steps of labeling a partition using glabel.
1. umount the partition you want to label
2. label the partition using `glabel label <label_name> <provider>`. where `<provider>` is the disk partition entry in `/dev` you want to label, e.g. `/dev/ada0p1`
After step 1 and step 2, you can see an entry in `/dev/label/<label_name>`, to which you can then refer in your `fstab`


----------



## usdmatt (Jan 29, 2018)

Just to add extra complication.., there's also gpt labels. (ShelLuser has already mentioned this is likely the best way to label partitions)

If you are creating partitions on a new disk (or the disk is already gpt partitioned), I would highly recommend using gpt over glabel.

gpt labels are stored as part of the partition table. They appear on the system as /dev/gpt/labelname, and are part of the spec. Any other operating system with support for gpt will be able to see/use the labels.

glabel is FreeBSD specific and a bit of a hack. It just stores the label in the last block of the partition, and creates a new device called /dev/label/labelname which is one block smaller than the original. Not that it ever really causes a problem but it does mean the label is part of the active partition if you look at the original device.


```
# glabel label test /dev/md0
# diskinfo /dev/label/test
/dev/label/test 512     10485248        20479   0       0
#
# diskinfo /dev/md0
/dev/md0        512     10485760        20480   0       0
#
# dd if=/dev/md0 bs=512 skip=20479 | hd
1+0 records in
1+0 records out
512 bytes transferred in 0.000071 secs (7243814 bytes/sec)
00000000  47 45 4f 4d 3a 3a 4c 41  42 45 4c 00 08 00 00 00  |GEOM::LABEL.....|
00000010  02 00 00 00 74 65 73 74  00 fe fe fe fe fe fe fe  |....test........|
...
```

It was useful when we only had MBR and you could easily label swap/root etc with glabel and use those labels in fstab, but now you may as well just use gpt (via the gpart() command in FreeBSD) unless you already have existing non-gpt partitions you need to label.


----------



## sko (Jan 29, 2018)

Be careful with glabel - it acts as an additional layer and therefore places its own header on the disk/slice/partition, which might interfere with other headers (e.g. gmultipath). I had some headaches with a system that booted from multipath FC targets and GPT/gmultipath/glabel were fighting for the same addresses to put their headers/labels in.

My recommendation is to stick to GPT and its labels if possible, so you don't have to handle multiple types of headers and labels (and multiple tools to manage them).

To make sure FreeBSD uses the gpt labels as primary source for identification (e.g. to show GPT labels in `zpool status` output), disable the other labeling methods in /boot/loader.conf:

```
kern.geom.label.disk_ident.enable="0"
kern.geom.label.gptid.enable="0"
```

After rebooting you should end up with:

```
% sysctl kern.geom.label
kern.geom.label.disk_ident.enable: 0
kern.geom.label.gptid.enable: 0
kern.geom.label.gpt.enable: 1
[...]
```

If you are using UFS you might also want to disable ufs label and id to make sure only GPT labels are used/displayed.


----------



## balanga (Feb 12, 2018)

hk7 said:


> `tunefs` operates on partitions of ufs, `glabel` operates on partitions (e.g. `/dev/da0p1`) and/or entire disk (e.g. `/dev/da0`)
> Below is the steps of labeling a partition using glabel.
> 1. umount the partition you want to label
> 2. label the partition using `glabel label <label_name> <provider>`. where `<provider>` is the disk partition entry in `/dev` you want to label, e.g. `/dev/ada0p1`
> After step 1 and step 2, you can see an entry in `/dev/label/<label_name>`, to which you can then refer in your `fstab`



I'm trying following these instructions and am missing something...

I have a laptop with two hard disks ada0 and ada1. I want to to put a label of S01 on ada1s3 which is a FreeBSD partition, and I'm booting from ada0 so as not to mount the parttion I want to label. When running `gpart show` it shows 

label/S01 

against the correct partition but the directory (ada1s3a)/dev is blank...

Strangely, when I boot from ada1 there is a /dev/label but it contains
S07p3
S07p3a
S07p3b

which must be a throwover from when I last tried to get labels to work.

Is there any way to unlabel partitions?


----------



## SirDice (Feb 12, 2018)

balanga said:


> I want to to put a label of S01 on ada1s3 which is a FreeBSD partition,


The sX is a slice, not a partition.


----------



## hk7 (Feb 13, 2018)

balanga said:


> I'm trying following these instructions and am missing something...
> 
> I have a laptop with two hard disks ada0 and ada1. I want to to put a label of S01 on ada1s3 which is a FreeBSD partition, and I'm booting from ada0 so as not to mount the parttion I want to label. When running `gpart show` it shows
> 
> ...


try `glabel destroy <label_name>` (e.g. `glabel destroy S07p3`). glabel()


----------

