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

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 me 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. That sub-directory is the name that is input for the partition - so if you input sdc1 then pmount creates sdc1 directory in /media like /media/sdc1 . (I'm sure there was a simpler way to say that!)

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 ( [1], 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), you can remove the .sh & beyond that you can name it whatever you want!

What's it do

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 quick & easy, at least enough for me to be happy to use it to do the job permanently. Which I am, as I've deleted udiskie from my machine. :) (I won't user autofs as it uses at least one insecure package.)

With a name like (as mentioned, 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 [2] 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

To use this script you need to install pmount & you need to create (if it doesn't already exist) the /media directory. Copy the script to your text editor, save it in ~/home (or /usr/bin if you like). Make it executable or it won't run.

Then just call it by name like so at the terminal prompt:


## 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


Following is a link to this page's forum counterpart where you can post any related feedback: [3]