From Manjaro Linux
Revision as of 04:56, 5 March 2018 by Handy (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Why & what is happening here

Due to udiskie not working for me anymore for some (at this stage) unknown reason. I created an alternate method for myself to mount/unmount external (USB in my case) drives. This method uses pmount/pumount, a wrapper for mount/umount, that does NOT require root privileges but does need the /media directory to exist. pmount creates its own sub-directory in /media for the mounted partition & pumount removes that sub-directory after it unmounts the partition. All without the need for su/sudo.

So using pmount, I've cobbled together a bash script that makes good use of a line of python that my buddy Joshua, from days gone by in Manjaro, made for me to use in another script (, that I made in March 2014).

This script (found below) I call (I like to use the deprecated .sh just because it makes it easy for me to see straight away that it is a script file that I'm looking at when I see it listed). When run, displays all of the partitions attached (internally & externally) to a machine via the lsblk -f command. This makes it relatively simple to identify the device that you want to mount & see its /dev/sd?? (without the /dev/ ) which you need to know to use pmount in this script.

Then echo's to the terminal that you use the Ctrl c key combination to terminate the script.

After which there are a few lines of instructions with an example. Followed by the command pmount /dev/sd with a live cursor sitting next to the "d" awaiting the next 2 characters.

So as you can see, this lot just tries to make the manual mounting of external drives as quick & easy, at least enough for me to be happy to use it to do the job. Which I am, as I've deleted udiskie from my machine. :)

With a name like (you could drop the .sh) you don't even have to make an alias for it! ;) After making the script executable, just drop the file in your /usr/bin or in your ~/ .

I run from a button in the Worker file manager, & have another RMB button underneath it that has the function of running pumount on an already highlighted/selected /media/sdc1 (c1 for this example), after which (as mentioned earlier) the partition is unmounted & the sdc1 used in this example is deleted from /media.

I'll make another little script that could be run as an alias that puts the command pumount/media/sd with a live cursor next to the "d" . When I do I'll add it to the bottom of this post.

The script

## a bash script by handy (with a little python thanks to Joshua). ;)
## This file is an attempt to make it a bit quicker to manually mount
## external storage devices (usually USB these days).
## You use the "pumount /media/<> command to unmount them.
## You must have the /media directory existent for pmount/pumount to work.  
## I have a button setup in Worker to do just that. 

# A little python FUNCTION - picked up from Joshua follows:

function input {
   python2 -c 'import sys,readline;readline.set_startup_hook(lambda: readline.insert_text(sys.argv[2]));sys.stderr.write(raw_input(sys.argv[1]))' "$@" 3>&1 1>&2 2>&3

clear # Clear the screen.

echo -e "\e[0;33m"

## The next line lists all of the available filesystems on the system:

lsblk -f

## Where the action is:

echo -e "Use the \e[0;31mCtrl c\e[0;33m key combination to exit this script."
echo -e "\e[0;33mTo mount an external device (usually USB), input the missing"
echo -e "parts directly after the \e[0;32md\e[0;32m\e[0;33m in the following command."
echo -e "(Like I have with the red \e[0;31me1\e[0;33m in this example -> \e[0;32mpmount /dev/sd\e[0;31me1 \e[0;33m)\e[0;32m"
versionNumber=$( input 'pmount /dev/sd')
printf "pmount /dev/sd$versionNumber\n"
echo -e "\e[0;31m"
pmount /dev/sd$versionNumber
echo -e "\e[0m"

exit 0