10.  Making the memory stick accessible to users

What we have described so far, are simply the procedures of setting up the system and formatting memory sticks. We have to make the mounting of the USB filesystem more permanent, and we have to make mounting of such a device easier for non-root users. There are only a few things to be done.

The procedure described below is for the more complex situation of a memory stick with a dual partition (Section 9, “ Setting up a dual partition”). If the partition is a single ext2, the procedure should be simplified by leaving out the line referring to the vfat part and changing sda2 to sda1.

Suppose that the mount points /mnt/memstick and /mnt/fatstick have been created. You do not have to use those words and they don't even have to be sub-directories of /mnt

To make remembering easier, create the following symbolic links:

 
             # ln -s /dev/sda1 /dev/fatflash
             # ln -s /dev/sda2 /dev/flash 
   

For smoother and easier mounting add the following lines to /etc/fstab : ( See NOTE at the end of Section 7.3, “ Mounting the USB filesystem” )

             none          /proc/bus/usb usbfs       defaults       0 0 
             /dev/flash    /mnt/memstick ext2,vfat   rw,user,noauto 0 0 
             /dev/fatflash /mnt/fatstick vfat        rw,user,noauto 0 0 
   

The middle line enables mounting either in ext2 or vfat. The last two lines make it possible for any user to mount the device by the command

             $ mount /dev/flash  [for ext2 or vfat] 
             $ mount /dev/fatflash  [for vfat] 
   

It is possible to mount both partitions simultaneously. See Section 9, “ Setting up a dual partition”.

In the case of an ext2-formatted device it does not seem possible for a user (other than root) to mount in read-write mode. The solution is to create a directory on the memory stick owned by the particular user with complete permissions. Root should do that:

             # mount /dev/flash 
             # mkdir -m 777 /mnt/memstick/superdir 
             # chown charles:charles /mnt/memstick/superdir 
   

If the device is in the vfat format, this step is unnecessary.

In conclusion, here is a small script I use to mount and unmount my (ext2) flash drive:

             #!/bin/bash 
             EXCODE="keepit" 
             green='\033[0;32m' 
             yellow='\033[0;33m' 
             ## ___________________________ 
             ## Function to echo in colours 
             echo_in_color () 
             { 
                  message=$2 
                  message1=$4 
                  color=$1 
                  color1=$3 
                  echo -e -n $color 
		      echo -n $message 
                  echo -e -n $color1 " " 
                  echo  -n $message1 " " 
                  tput sgr0 
                  return 
             } 
             ## ___________________________ 
             clear 
             mount /dev/flash 
             echo_in_color $green "Flash drive mounted" 
             sleep 2 
             while [ $EXCODE != "flexit" ] 
                  do 
                     clear 
                     echo_in_color $yellow "Enter [flexit] to unmount and exit:" 
                     read EXCODE 
                  done 
             umount /dev/flash 
             exit 
   

I call this from an FVWM menu by Exec exec xterm -geometry 43x2+1250+0 -e /home/nikos/bin/flashdrive which places it on a tiny x-term in one corner of the screen. The horizontal displacement of 1250 may have to be modified according to the horizontal resolution of your screen.