MacOS – Change label on USB drive in OSX Terminal

macosterminalusb

I am trying to write a program in Python that will rename a USB drive (from the standard "USB DISK" to my custom "MYDISK").

However, I can't find any way to do this neither in Python nor in OSX Terminal. (I figured, if I can make it work in Terminal, I can simply use os.system("command") in Python).

The USB drive is a FAT32 formatted flash drive on filesystem /dev/disk2s1, and it is by default mounted on /Volumes/USB DISK

What I have tried so far: (from http://techbu.com/2009/06/28/renaming-usb-drive-labels-in-linux)

sudo umount /Volumes/USB\ DISK            ## Works fine
sudo mlabel -i /dev/disk2s1 ::MYDISK      ## Command not found!

It seems that the "mlabel" command is not found in OSX Terminal. Is there an alternative?

Best Answer

See diskutil

sudo diskutil rename USB\ DISK MYDISK