How to use drive unique ID in fstab?

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...
 
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....
 
You can grab a ufsid via dumpfs(8) as [cmd=""]dumpfs filesystem| grep id[/cmd]
Code:
> 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.
 
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.
 
Won't glabel (and tunefs) potentially overwrite the last sector of the disk and corrupt data?

Code:
 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.
 
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..
 
[cmd=]glabel label swap1 /dev/ad0s1b[/cmd] ran without complaint but swap1 doesn't show up in [cmd=]glabel status[/cmd]. :\
 
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.
 
AndyUKG said:
Won't glabel (and tunefs) potentially overwrite the last sector of the disk and corrupt data?

Code:
 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.

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
Code:
# swapoff -a
# glabel label labelname /dev/da0s1b
# swapon /dev/label/labelname
[i]edit fstab[/i]
 
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?
 
Back
Top