Renaming USB Devices in Linux

Sometimes you want to change the name of a USB device, for example because it has no name or because it has a new purpose. I usually give my USB flash drives my own name so that if I lose them, people will know who to return them to.

Modern desktop environments make it easy to rename your device by simply clicking it and selecting ‘rename’ from the context menu. However, sometimes you might want to do this from the command line 8) perhaps because you have no desktop environment, or your desktop environment does not allow you to easily rename your device, or because you feel you could do it faster this way.

This article covers changing the disk labels for FAT32, NTFS and EXT partitions, but first, some basics:

If you don’t have the programs used in the commands below, they should be in your distribution’s repository under that name, so you can install them with your package manager. You will usually need root privellages to run these commands; this is normally achived using the sudo or su commands.

You can get a list of drives connected to the computer by typing:

blkid

This is useful for checking the device name (e.g. /dev/sdb1) which you need to specify when you rename it and it will also show their labels (the names you have given them) so you can check if they’re already named or not. If it doesn’t provide enough information for you, try using fdisk instead:

sudo fdisk -l

In the following commands you should replace /dev/sdb1 with the device name of your own device.

FAT32

Since the 80s, portable media like floppy disks have used FAT. To date it is probably the most common file system type and is support by almost all operating systems. Therefore if you own a USB device, it’s probably using FAT and you can change the device label (name) with the following command:

mlabel -i /dev/sdb1 ::Camera

Usually mlabel requires you to specify a DOS style drive letter, like :C or :F but here we’re using a special device :: which allows us to specify a UNIX style device name. Replace Camera with your own device name. ❗ If you get an error like “Total number of sectors (7831520) not a multiple of sectors per track (63)!” then add a line of code to your mtools configuration file using the following command:

echo mtools_skip_check=1 >> ~/.mtoolsrc

NTFS

This is a Windows filesystem and is usually used for the hard disk drive in your computer or on large USB devices where you expect to store files bigger than 4GB, a size limitation in FAT. You can rename these kinds of drives using:

ntfslabel /dev/sdb1 movie_drive

EXT

The first filesystem created specifically for Linux, EXT is a fast journalling filesystem used by most distributions of GNU/Linux. Rename these kinds of filesystems like this:

e2label /dev/sdb1 live-usb

I suppose the instructions for the last two are easier than FAT but it’s very commonly used so it’s definitely worth remembering. If you think you have a better way to do this, please let me know in the comments, also if you get stuck or have any questions, feel free to comment as well.

2 thoughts on “Renaming USB Devices in Linux

  1. It worked great for my FAT-32 USB-Stick, but the folder in /media still has a long number for a name, ideas on how I can change this as well?

    • It sounds like the stick is still being treated as if it has no name and needs to be remounted. The easiest way to fix is this is to pull it out of the computer (check that the folder in /media is gone) and plug it back in again. If this doesn’t solve your problem, let me know and we’ll edit your fstab configuration file to fix it for sure.

Comments are closed.