Shell Script to Unmount Multiple Hard Drives?

You could simply create a bash script that does what you want, one line should do it, doesn’t even need to be executable, following DBMandrake…
umount /media/*
and then your python runscript becomes…
call(["/bin/bash", “/full/path-to/bash_script”])
though this will generate errors trying to unmount anything in /media/ that isn’t a mount point.

More elegantly your bash one-liner could be
df | grep “/media/” | cut -f1 -d ’ ’ | while read n; do umount $n; done

or Sam’s suggestion
for disk in $(ls /dev/sd*); do grep -q $disk /proc/mounts; if [ $? == 0]; then sudo umount $disk; fi; done


I would like to setup a custom menu shortcut to unmount the external USB Drive. I need that to deconnect the drive in order to use it on another computer that cannot access it through the network.

To do that I’m going to : Settings / Interface / Skin setup / Customize Home Menu.
There I would like to define a custom action, but I didn’t find anything that is working after trying the following :

  • RunScript(“umount ‘/media/MyDrive’”)
  • RunScript(“/bin/bash -c umount /media/MyDrive”)
  • RunScript(“udisks --unmount /media/MyDrive”)
  • System.Exec(“umount ‘/media/MyDrive’”) => calling shortcut twice crashes OSMC.

I’m not a Linux user and I’m only using a Vero 4K and a Rii i25 remote (having a keyboard).
In case it is mandatory to create a python file, can someone advise a simple way to do that? Is there a Kodi AddOn to create and edit a python file from Kodi’s UI / File Manager?

This question is also related to this subject :

Thanks in advance for any help.

I have tested the solution provided here :

It wasn’t easy to me but I could create the file as described, then I added the following action to the shortcut:


Unfortunately the first time I use the shortcut it doesn’t work, and the second time it makes OSMC crash.

I found the answer, explained here :