When I plugged in an external drive to my laptop, the drive was displayed as a string consits random letters and numbers. Here is an example:

❯❯❯ df -Th | grep sdb
/dev/sdb1               xfs       481M   26M  456M   6% /run/media/kenno/5428b182-c92e-466b-89d2-b5b31b80ba48

Though the drive worked perfectly fine, I think it’s ugly, and I wanted to properly give it a good name. Let’s call it externo.

But how to do this? You may not believe it, I forgot how to do this. In fact, I couldn’t rememer when the last time I had to (re)label a file system. Fear not,Google can come to the rescue!

First unmount the mounted-file system if it was mounted. In my case, I need to unmount the /dev/sdb1 device.

❯❯❯ sudo umount /dev/sdb1

Next, I’m going to use the xfs_admin command to label this XFS partition. xfs_admin is provided by xfsprogs package on Fedora (31).

Let’s pring out the current label using xfs_admin -l.

❯❯❯ sudo xfs_admin -l /dev/sdb1
label = ""

Now, change the label to externo using xfs_admin -L new_label command.

~ ❯❯❯ sudo xfs_admin -L externo /dev/sdb1
writing all SBs
new label = "externo"

Next time this exernal drive is mounted, it should get the desired label as its name.

~ ❯❯❯ df -Th | grep sdb1
/dev/sdb1               xfs       481M   26M  456M   6% /run/media/kenno/externo

Two things I want to remind myself. If I can’t remember any of these flags, they are well documented in man xfs_admin. The second thing is that the name of the USB or external drive is taken from the label of the filesystem!

This post is about XFS filesystem. For other types of filesystem, a different programs can be used instead. The “RenameUSBDrive” wiki page found in the below references covers many filesystems.

References: