# How to use drive unique ID in fstab?



## palmboy5 (Nov 26, 2010)

I'm tired of seeing FreeBSD fail to boot just because I put in a new SATA card or changed SATA ports. I understand that it fails because the OS HDD now has a different device name, so how can I make it more like Ubuntu where fstab refers to the drive's unique ID instead?

I read that you could find each drive's unique ID in /dev/ufsid but that directory is empty for me...


----------



## graudeejs (Nov 26, 2010)

It will be empty if you don't have UFS filesystems... right now...
If you use partitions, you can also use labels... these are very easy to use.... and I prefer them much more than silly Unique IDs

you can great labels with different methods...

for example with newfs(8)
`# newfs -U -L test_label /dev/....`
or with glabel(8), or gpart(8) when you create partitions....


----------



## fronclynne (Nov 26, 2010)

You can grab a ufsid via dumpfs(8) as [cmd=""]dumpfs _filesystem_| grep id[/cmd]

```
> dumpfs /usr | grep id
superblock location     65536   id      [ 4bce0894 1a07cb0c ]
```

That number can be used *prior to filesystem mount* (usually by adding it to your /etc/fstab) as /dev/ufsid/4bce08941a07cb0c.

You can also use glabel(8) at creation time . . .

(Killer Smurf's tunefs(8) also works well)

Note that if you have multiple machines and you have need to mount a drive from a different machine you need to make sure your namespaces do not collide.  As in, don't just name your filesystems stuff like *usrfs*, make it something like *hostnameusrfs*.


----------



## kpa (Nov 26, 2010)

glabel(8) can be used after creating the filesystems but you'll have to do the labeling in single user mode.


----------



## palmboy5 (Nov 26, 2010)

Thanks for your replies! For glabel(8), does the file system also have to be unmounted? Basically I need a way to glabel the OS drive partitions.


----------



## fronclynne (Nov 26, 2010)

palmboy5 said:
			
		

> Thanks for your replies! For glabel(8), does the file system also have to be unmounted? Basically I need a way to glabel the OS drive partitions.



Easier to use tunefs(8) from a fixit disk (using tunefs(8) in single user mode the label won't "stick" to your root filesystem) as `# tunefs -L hostnamerootfs /dev/da0s1a` & mount your root fs and edit its etc/fstab.


----------



## AndyUKG (Nov 26, 2010)

Won't glabel (and tunefs) potentially overwrite the last sector of the disk and corrupt data?


```
label    Set up a label name for the given provider.  This is the
	      ``automatic'' method, where metadata is stored in a provider's
	      last sector.
```


----------



## palmboy5 (Nov 26, 2010)

I think I might just go with fronclynne's suggestion, but how would I find the unique ID for swap? dumpfs wants a mountpoint but swap isn't mounted..


----------



## graudeejs (Nov 26, 2010)

You can label swap partition


----------



## palmboy5 (Nov 26, 2010)

[cmd=]glabel label swap1 /dev/ad0s1b[/cmd] ran without complaint but swap1 doesn't show up in [cmd=]glabel status[/cmd]. :\


----------



## Nukama (Nov 26, 2010)

If you're using GUID-Partition-tables you could label the partition with (i.e. ad0s1 with LABEL)
`# [man]gpart[/man] modify -i 1 -l LABEL ad0`.

Then you should be able to access /dev/gpt/LABEL inside every sane Linux or BSD.


----------



## fronclynne (Nov 27, 2010)

AndyUKG said:
			
		

> Won't glabel (and tunefs) potentially overwrite the last sector of the disk and corrupt data?
> 
> 
> ```
> ...



tunefs(8) will not, AFIK, as the ufs label is stored in the same place as the other ufs information.  And glabel(8) will if there is information in that last sector, otherwise no.

Also, you need to have swap turned off on that partition to label it properly, so it should be 
	
	



```
# swapoff -a
# glabel label labelname /dev/da0s1b
# swapon /dev/label/labelname
[i]edit fstab[/i]
```


----------



## palmboy5 (Nov 27, 2010)

Thank you! I used the ufsid thing + glabel swap to fix up my fstab and now it doesn't fail to boot when I make an HDD change.

I'm wondering why FreeBSD doesn't just automatically do something like this? Why make the OS so sensitive to even a drive port change?


----------

