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 😎 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.
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 privileges to run these commands; this is normally achieved using the
You can get a list of drives connected to the computer by typing:
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
sudo fdisk -l
In the following commands you should replace
/dev/sdb1 with the device name of your own device.
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
: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
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
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.