Closed probonopd closed 3 years ago
On the Mac, you simply can do
diskutil rename /dev/diskXsY "Macintosh HD"
But what is the equivalent for this on FreeBSD?
https://www.freebsd.org/cgi/man.cgi?glabel says:
This GEOM class also provides volume label detection for file systems.
Those labels cannot be set with glabel, but must be set with the appro-
priate file system utility, e.g. for UFS the file system label is set
with tunefs(8). Currently supported file systems are:
+o UFS1 volume names (directory /dev/ufs/).
+o UFS2 volume names (directory /dev/ufs/).
...
+o MSDOSFS (FAT12, FAT16, FAT32) (directory /dev/msdosfs/).
+o CD ISO9660 (directory /dev/iso9660/).
+o EXT2FS (directory /dev/ext2fs/).
+o REISERFS (directory /dev/reiserfs/).
+o NTFS (directory /dev/ntfs/).
Unfortunately, "the appropriate file system utility" is not further elaborated upon. So we need to cobble this inormation together:
tunefs -L "Data" /dev/diskXsY
(comes with FreeBSD by default)tunefs -L "Data" /dev/diskXsY
(comes with FreeBSD by default)mlabel -i /dev/diskXsY ::'Data'
(needs sudo pkg install -y mtools
)sudo e2label /dev/diskXsY 'Data'
(needs sudo pkg install -y e2fsprogs
)sudo reiserfstune -l 'Data' /dev/sda1
(needs sudo pkg install -y progsreiserfs
)sudo ntfslabel /dev/diskXsY 'Data'
What about
xfs_admin -l 'Data' /dev/diskXsY
(needs sudo pkg install -y xfsprogs
)There should be a unified command line tool to rename volume labels for all sorts of filesystems on all sorts of Unix-like OSes. Then Filer could simply invoke that tool. If you know of such a tool, please let us know.
For Ubuntu, https://wiki.ubuntuusers.de/Labels/#Dateisystem-Label states:
Wow, it really seems to be that complicated. How many file managers expose this functionality in an easy-to-use way?
Side note: A neat way to quickly get all volume labels seems to be blkid
:
FreeBSD% blkid
/dev/da0: LABEL="AIRYX" TYPE="iso9660"
/dev/da0p1: SEC_TYPE="msdos" LABEL="MY DISK" UUID="1F23-1D1C" TYPE="vfat"
It can also be used to find the device name(s) of the volume(s) with a given name:
FreeBSD% blkid | grep 'LABEL="AIRYX"' | cut -d ":" -f 1
/dev/da0
This works for MSDOSFS:
FreeBSD% sudo pkg install -y mtools
FreeBSD% mount
/dev/da0p1 on /media/da0p1 (msdosfs, local, noatime)
FreeBSD% fstyp -l /dev/da0p1
msdosfs ESP
FreeBSD% sudo mlabel -i /dev/da0p1 ::MYDISK
Can't open /dev/da0p1: Operation not permitted
Cannot initialize '::'
mlabel: Cannot initialize drive
FreeBSD% sudo umount /dev/da0p1
FreeBSD% sudo mlabel -i /dev/da0p1 ::MYDISK
FreeBSD% fstyp -l /dev/da0p1
msdosfs MYDISK
Works. How about longer names with spaces in them?
FreeBSD% sudo mlabel -i /dev/da0p1 ::'My Disk'
FreeBSD% fstyp -l /dev/da0p1
msdosfs My Disk
But fsck_msdosfs
doesn't seem to like long names as volume labels, as can be seen in /var/log/automount.log
:
/dev/da0p1: fsck_msdosfs Invalid long filename entry for volume label
It is still there, though...
FreeBSD% fstyp -l /dev/da0p1
msdosfs My Disk
Here we go with a small command line tool that can serve as a stand-in for diskutil rename
:
Any thoughts appreciated.
I would like to replace the mount
command at the end with something that triggers the same notification that would get triggered if the device was plugged in, so that @vermaden's automount can do its thing... how?
Next step will be for Filer to invoke diskutil rename
to rename disks if the user does this in the GUI.
You can invoke the same automount
behavior that devd(8)
would with these:
# /usr/local/sbin/automount da0 detach
# /usr/local/sbin/automount da0 attach
...and we have something that is beginning to work.
But those -
instead of spaces...
You can invoke the same automount behavior that devd(8) would with these
That is exactly how I am doing it now - but this creates a hard dependency on automount
, making things less than portable.
With https://github.com/vermaden/automount/issues/30 well underway, it should become possible to rename disks ("volume labels") in the exact same way it is possible to rename folders and documents.
This is a prime example for basic things that should be simple, yet are surprisingly difficult anywhere but on the Mac.