How to mount encrypted UFS partition using labels?

I recently started using FreeBSD.
I chose UFS.
On my laptop I have two drives.
On ada0 I use OpenBSD.
On ada1 I installed FreeBSD.

I partitioned the drive like this:

Code:
gpart show ada1
=>       40  250069600  ada1  GPT  (119G)
         40       1024     1  freebsd-boot  (512K)
       1064  104857600     2  freebsd-ufs  (50G)
  104858664  136313848     4  freebsd-ufs  (65G)
  241172512    8388608     3  freebsd-swap  (4.0G)
  249561120     508520        - free -  (248M)

ada1p4 is my encrypted partition.
I mount it like this:

Code:
 mount_encrypted_partition.sh
#!/bin/sh
doas geli attach -k /root/geli/ada1p4.key /dev/ada1p4
doas mount /dev/ada1p4.eli /home/MYUSER/usr

I dislike the hardcoded "ada1p4" in my script.
How can I use another identifier?
I would like to be able to remove a drive, put it
elsewhere and I would like my script to work?
On OpenBSD I have UUIDs instead of "raw" device names,
how to do the same in FreeBSD?

I tried something with labeling the UFS partition,
but it did not work - what is the correct way do
to it?

Thanks.
 
Last edited by a moderator:
I tried something with labeling the UFS partition,
but it did not work
Which utility did you use to label the UFS partition?

No problem here:

gpart(8)
Code:
 gpart modify -i 4 -l ufs0 ada1

label: /dev/gpt/ufs0

 geli attach -k /root/geli/ada1p4.key   gpt/ufs0

glabel(8)
Code:
 glabel create gl-ufs0 ada1p4

label: /dev/label/gl-ufs0

 geli attach -k /root/geli/ada1p4.key   label/gl-ufs0

Not sure about the uniqueness of those uuids, but it works.
Code:
 gpart list ada1 | egrep 'Name|rawuuid'

geli attach -k /root/geli/ada1p4.key   gptid/<rawuuid_of_ada1p4>

Following kernel state needs to be enabled for /dev/gptid (enabled by default: 1), in case it's disabled:
Code:
kern.geom.label.gptid.enable=1
 
Back
Top