Thomas Venturini
Raspberry Pi - Renaming a HDD

Raspberry Pi - Renaming a HDD

Today I struggled a bit to rename two hard drives from within raspbian. So here is the how-to for everyone else.

Log into your raspberry pi running raspbian via ssh or open up a terminal if you are already on the raspbian desktop.

Next we will need to install mtools so let's run do so.

sudo apt-get install mtools

With that done, we can now use mlabel to rename the label of the hard drive. But first we need to identify the device name of your hard drive. To do so, lets run the following command.

sudo lsblk -o UUID,NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL,MODEL

That should return something like the following.

UUID                                 NAME        FSTYPE   SIZE MOUNTPOINT          LABEL     MODEL
                                     sda                931,5G                               External USB 3.0
3284-E8C7                            └─sda1      vfat   931,5G /media/pi/INTENSO   INTENSO 
                                     sdb                  4,6T                               External USB 3.0
3284-E8C7                            └─sdb1      vfat     4,6T /media/pi/INTENSO1  INTENSO 
                                     mmcblk0             14,7G                               
1193-F799                            ├─mmcblk0p1 vfat    43,8M /boot               boot      
4bab068f-f791-48a4-8f8f-b4cf60c080a2 └─mmcblk0p2 ext4    14,6G /                   rootfs    

As you can see, I have two hard drives with the same UUID and label, thats why I ran into this issue.

In the column for name, you can see the values sda1 and sda2. These are the names we are looking for and you should see yours there. Check the label and or mount point to identify the right one for you. We will assume sda1 was the one you have been looking for.

Next we will have to unmount the drive. To do so run the following command but replace the path to the mount point of your HDD.

sudo umount /media/pi/INTENSO

Now if we would run the mlabel command right now we would probably run into the following issue.

sudo mlabel -i /dev/sda1 :: NewLabel
Total number of sectors (1953518017) not a multiple of sectors per track (63)!
Add mtools_skip_check=1 to your .mtoolsrc file to skip this test

I tried to do as instructed in the error message and created a file ~/.mtoolsrc with the setting in it, but that didn't work. But I could fix it by editing the mtools.conf configuration file. To do so open up the file /etc/mtools.conf and add the following line to the end of it.

mtools_skip_check=1

This should prevent the error message in which I ran into. So now we are free to change the name of the hard drive! Run the following command to do so. Replace NewLabel with the name you want to assign.

sudo mlabel -i /dev/sda1 :: NewLabel

So after I did this for my second hard drive to and restarted my pi to make sure it stayed that way, I could see the following information when I run lsblk.

sudo lsblk -o UUID,NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL,MODEL

UUID                                 NAME        FSTYPE   SIZE MOUNTPOINT          LABEL     MODEL
                                     sda                931,5G                               External USB 3.0
3284-E8C7                            └─sda1      vfat   931,5G /media/pi/INTENSO1T INTENSO1T 
                                     sdb                  4,6T                               External USB 3.0
3284-E8C7                            └─sdb1      vfat     4,6T /media/pi/INTENSO5T INTENSO5T 
                                     mmcblk0             14,7G                               
1193-F799                            ├─mmcblk0p1 vfat    43,8M /boot               boot      
4bab068f-f791-48a4-8f8f-b4cf60c080a2 └─mmcblk0p2 ext4    14,6G /                   rootfs 

As you can see I named them INTENSO1T and INTENSO5T.

Tipp: You can use the LABEL value in your fstab file.

I hope this short tutorial did help you to solve your problem as it did solve mine.