How can I set different icons for drives in dock?

I'm trying to figure out how to change icons for individual drives.

As you can see the last three are indistinguishable until hovered:

img here


Use x-gvfs-icon in /etc/fstab

The trick with autorun.inf suggested by pLumo seems not to work anymore, but one can set icons via the x-gvfs-icon option in /etc/fstab.

For this option only icons that are provided through an icon theme can be used.

Set x-gvfs-icon with gnome-disks

If you want to be on the safe side, make a backup copy of your /etc/fstab first:

sudo cp /etc/fstab /etc/fstab.backup

Open gnome-disks (it is under Activities -> Utilities - Disks). Find the partition for which you want to change the icon, select it (it must be highlighted) and click on the gear icon ("Additional partition options").

In the menu, that pops up select "Edit Mount Options...".

In the dialog you must first switch off "User Session Defaults". Then under "Icon Name" you can place a name known to the icon theme. For a first test you could put gnome-cd, which will get you an CD-icon. How to find icon names and how to add custom ones I will explain in the following two sections.

Before clicking "OK", ensure yourself, that the other options are correct, for example "Mount at system startup". When you click "OK", enter your password, which will then save those settings in /etc/fstab. Usually gnome-disks provides you with good default options, but still you have to handle them with care.

The new entry in /etc/fstab that has been created for us could for example look like this:

/dev/disk/by-uuid/<the-uuid> /mnt/<the-uuid> auto nosuid,nodev,nofail,x-gvfs-show,x-gvfs-icon=<name-of-the-icon>,noauto 0 0

gnome-disks

Find some icon names in the theme

Icons are located under /usr/share/icons/<theme-name>/<size>/<topic>, so for example to look up 48x48 device icons in the Yaru theme one can do:

ls /usr/share/icons/Yaru/48x48/devices/

The name for x-gvfs-icon is simply without the file ending.

How to create a small custom icon theme

This are a few steps to create custom icons that can be used for x-gvfs-icon option.

I assume in this description that you have put an icon called mydrive.png into ~/Downloads. Formats accepted are PNG or SVG, ICO did not work for me. The size should be somewhere between 32 and 128 pixels for PNG.

  1. prepare the folders

    sudo bash
    cd /usr/share/icons/
    mkdir -p custom/any/devices
    

    I assume that you do not want to maintain different sizes, so I just used any for the size.

  2. create the index.theme file

    nano custom/index.theme
    

    and put the following content into it:

    [Icon Theme]
    Name=Custom
    Comment=Icons added by the user
    Directories=any/devices
    
    [any/devices]
    Context=Devices
    Size=48
    Type=Fixed
    

    Note that the "Size" parameter is just a hint for GTK, the actual size of the file can differ.

  3. copy a new icon

    cp ~/Downloads/mydrive.png /usr/share/icons/custom/any/devices
    
  4. link to the new theme from existing themes

    Here if you are using different theme now, you must replace Yaru with the name of your theme. I edit Humanity here too, because it is a fallback for many themes.

    Edit (nano ... or gedit ...) the files

    /usr/share/icons/Yaru/index.theme
    /usr/share/icons/Humanity/index.theme
    

    and add ...,custom to the Inherits= option. That gives for Yaru:

    Inherits=Humanity,hicolor,custom
    

    and for Humanity:

    Inherits=Adwaita,hicolor,custom
    

    Exit the super user bash with exit.

Done! Now the name mydrive can be used as "Icon Name" in gnome-disks!

After copying new icons, a restart of Gnome (logoff + logon) might be required!