For script purpose, how to positively identify each hard drive?

I have two (2) Hitachi, 8Tb drives that I use for everyday backup. I formatted the drives with Debian as ext4 and gave the drives simple volume labels of "backup1" and "backup2". Debian with the LXQT desktop file manager displayed backup1 and backup2, but FreeBSD does not.

$ lsblk
DEVICE MAJ:MIN SIZE TYPE LABEL MOUNT
da0 0:125 231G MBR - -
<FREE> -:- 993K - - -
da0s1 0:126 231G ntfs gpt/ntfs /media/da0s1
da0s2 0:127 231G efi gpt/efi /media/da0s2
da1 0:157 7.3T GPT - -
da1p1 0:158 7.3T linux-data gpt/linux-data /media/HGST_HUH_728080ALE600_934960220651_p1
<FREE> -:- 328K - - -
da2 0:167 7.3T GPT - -
da2p1 0:168 7.3T linux-data gpt/linux-data /media/HGST_HUH_728080ALE600_WD-WXE1E14MVJ21_p1
<FREE> -:- 328K -

I purposely use backup1 for all of my daily use. I use a simple, rsync script that will synchronize both drives, but delete files on backup2 that do not exist on backup1.

rsync -ahcrvv --partial --inplace --append --progress --delete-after --stats /media/ed/backup1/ /media/ed/backup2

Since FreeBSD doesn't seem to "see" the volume labels that were created with Debian, I need a way to positively identify each drive. Any ideas on how I can do this? Is there a way to "label" a drive under FreeBSD that the desktop environment will display, and then incorporate that name back into my simple script?

Thank you!
Ed
 
It depends on where those labels are stored.
Are they part of the ext4 metadata?
Are they part of the gpt data?

On FreeBSD things with unwithered gpt labels wind up in /dev/gpt. gpart list shows gpt labels.
 
Thank you. Here's what gpart list shows:

Geom name: da1
modified: false
state: OK
fwheads: 255
fwsectors: 63
last: 15628053134
first: 2048
entries: 128
scheme: GPT
Providers:
1. Name: da1p1
Mediasize: 8001561821184 (7.3T)
Sectorsize: 512
Stripesize: 4096
Stripeoffset: 0
Mode: r2w1e0
efimedia: HD(1,GPT,4b7381a5-e11b-4283-b01b-c8f21ed5bc76,0x800,0x3a3812000)
rawuuid: 4b7381a5-e11b-4283-b01b-c8f21ed5bc76
rawtype: 0fc63daf-8483-4772-8e79-3d69d8477de4
label:
length: 8001561821184
offset: 1048576
type: linux-data
index: 1
end: 15628052479
start: 2048
Consumers:
1. Name: da1
Mediasize: 8001563222016 (7.3T)
Sectorsize: 512
Stripesize: 4096
Stripeoffset: 0
Mode: r2w1e1

Geom name: da2
modified: false
state: OK
fwheads: 255
fwsectors: 63
last: 15628053134
first: 2048
entries: 128
scheme: GPT
Providers:
1. Name: da2p1
Mediasize: 8001561821184 (7.3T)
Sectorsize: 512
Stripesize: 4096
Stripeoffset: 0
Mode: r2w1e0
efimedia: HD(1,GPT,35bcc5a4-f2ce-d143-862e-ab49d9708121,0x800,0x3a3812000)
rawuuid: 35bcc5a4-f2ce-d143-862e-ab49d9708121
rawtype: 0fc63daf-8483-4772-8e79-3d69d8477de4
label:
length: 8001561821184
offset: 1048576
type: linux-data
index: 1
end: 15628052479
start: 2048
Consumers:
1. Name: da2
Mediasize: 8001563222016 (7.3T)
Sectorsize: 512
Stripesize: 4096
Stripeoffset: 0
Mode: r2w1e1

There doesn't seem to be a "label". Can I assign them a label?

Ed
 
[I haven't tried this but] you can add labels using gpart(1). Then the labelled partitions will show up in /dev/gpt. Now you can uniquely identify them. Use "gpart modify" to label an existing gpt partition.
 
The man page for gpart says: -i index Specifies the index of the partition to be modified.

So my command is: sudo gpart modify -i 1 -l backup1 /dev/da2p1

gpart: arg0 'da2p1': Invalid argument

I don't understand what it doesn't like about the command. Suggestions?

Ed
 
Thank you. That command worked.

$ gpart list

Geom name: da1
modified: false
state: OK
fwheads: 255
fwsectors: 63
last: 15628053134
first: 2048
entries: 128
scheme: GPT
Providers:
1. Name: da1p1
Mediasize: 8001561821184 (7.3T)
Sectorsize: 512
Stripesize: 4096
Stripeoffset: 0
Mode: r2w1e0
efimedia: HD(1,GPT,4b7381a5-e11b-4283-b01b-c8f21ed5bc76,0x800,0x3a3812000)
rawuuid: 4b7381a5-e11b-4283-b01b-c8f21ed5bc76
rawtype: 0fc63daf-8483-4772-8e79-3d69d8477de4
label:
length: 8001561821184
offset: 1048576
type: linux-data
index: 1
end: 15628052479
start: 2048
Consumers:
1. Name: da1
Mediasize: 8001563222016 (7.3T)
Sectorsize: 512
Stripesize: 4096
Stripeoffset: 0
Mode: r2w1e1

Geom name: da2
modified: false
state: OK
fwheads: 255
fwsectors: 63
last: 15628053134
first: 2048
entries: 128
scheme: GPT
Providers:
1. Name: da2p1
Mediasize: 8001561821184 (7.3T)
Sectorsize: 512
Stripesize: 4096
Stripeoffset: 0
Mode: r2w1e0
efimedia: HD(1,GPT,35bcc5a4-f2ce-d143-862e-ab49d9708121,0x800,0x3a3812000)
rawuuid: 35bcc5a4-f2ce-d143-862e-ab49d9708121
rawtype: 0fc63daf-8483-4772-8e79-3d69d8477de4
label: backup1
length: 8001561821184
offset: 1048576
type: linux-data
index: 1
end: 15628052479
start: 2048
Consumers:
1. Name: da2
Mediasize: 8001563222016 (7.3T)
Sectorsize: 512
Stripesize: 4096
Stripeoffset: 0
Mode: r2w1e1


Now, I'm trying to figure out how to determine which of the two drives it assigned the label to.

Ed
 
Ed_Flecko thanks for providing that.
Now that we've gotten past adding the gpt labels, your "which one is which" is going to take a bit of detective work.
I'm not sure if anything available on linux correlates to the gpart info on FreeBSD, but maybe look in Linux for the stuff in the efimedia and rawuuid. Beyond that, only thing I can think of is in Linux, on /backup1 do "touch iambackup1" which creates /backup1/imambackup1. Then reboot into FreeBSD, mount those partitions and see which one has the file iambackup1.
 
Ed_Flecko thanks for providing that.
Now that we've gotten past adding the gpt labels, your "which one is which" is going to take a bit of detective work.
I'm not sure if anything available on linux correlates to the gpart info on FreeBSD, but maybe look in Linux for the stuff in the efimedia and rawuuid. Beyond that, only thing I can think of is in Linux, on /backup1 do "touch iambackup1" which creates /backup1/imambackup1. Then reboot into FreeBSD, mount those partitions and see which one has the file iambackup1.
Thank you. I'll keep poking around to see how I can positively identify each drive in FreeBSD.

In the end, I wonder if FreeBSD does show a label, of some sort, will that be enough to allow my rsync script to run correctly?

Ed
 
In the end, I wonder if FreeBSD does show a label, of some sort, will that be enough to allow my rsync script to run correctly?
Yes.
Disk devices wind up by default in things like /dev/ada0p1, but there are a number of different labels that can be applied.
gpart labels wind up in /dev/gpt so check there.
there are a few other places that are autogenerated labels that all wind up under /dev.
 
Yes.
Disk devices wind up by default in things like /dev/ada0p1, but there are a number of different labels that can be applied.
gpart labels wind up in /dev/gpt so check there.
there are a few other places that are autogenerated labels that all wind up under /dev.
Thank you.

I don't understand what you mean by "gpart labels wind up in /dev/gpt so check there.". How do I do that? How could I use those labels in my command (script):

rsync -ahcrvv --partial --inplace --append --progress --delete-after --stats /media/ed/backup1/ /media/ed/backup2

Ed
 
I don't understand what you mean by "gpart labels wind up in /dev/gpt so check there.". How do I do that? How could I use those labels in my command (script):

When booted into FreeBSD:
ls -ltr /dev/gpt

to find out what gpt labels are available

Lets say you see /dev/gpt/backup1 and /dev/gpt/backup2. That means the partitions are available as gpt labels.
Now your rsync command is using mounted partitions; entirely dependent on how a paritition is mounted.
If something does "mount -t ext4 /dev/gpt/backup1 /media/ed/backup1" and "mount -t ext4 /dev/gpt/backup2 /media/ed/backup2" then your rsync command does not change.
You talk about using LXQT desktop which I think has some kind of automount in its filemanager. I have zero idea how that works so I am talking about "bare metal".

Best I can say is on FreeBSD, using whatever desktop, you need to see what is mounted/available and see what corresponds to your gpt partitions and use those in your rsync commands.

I can't offer more than that since I disable automount stuff and manually mount/make things available because that's the way I've been doing it for 30 yrs.
 
When booted into FreeBSD:
ls -ltr /dev/gpt

to find out what gpt labels are available

Lets say you see /dev/gpt/backup1 and /dev/gpt/backup2. That means the partitions are available as gpt labels.
Now your rsync command is using mounted partitions; entirely dependent on how a paritition is mounted.
If something does "mount -t ext4 /dev/gpt/backup1 /media/ed/backup1" and "mount -t ext4 /dev/gpt/backup2 /media/ed/backup2" then your rsync command does not change.
You talk about using LXQT desktop which I think has some kind of automount in its filemanager. I have zero idea how that works so I am talking about "bare metal".

Best I can say is on FreeBSD, using whatever desktop, you need to see what is mounted/available and see what corresponds to your gpt partitions and use those in your rsync commands.

I can't offer more than that since I disable automount stuff and manually mount/make things available because that's the way I've been doing it for 30 yrs.
Thank you for all of your help!

Ed
 
  • Like
Reactions: mer
Back
Top