WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: symlinks for external storage under /home/tc?  (Read 5779 times)

Offline jamtat

  • Jr. Member
  • **
  • Posts: 58
symlinks for external storage under /home/tc?
« on: January 25, 2012, 03:32:12 PM »
As what I hope will be a final issue, I'd like to ask the possibility of getting symlinks that point to connected USB drives to appear in /home/tc. What I mean is that, when someone brings a USB drive and plugs it in, the OS finds and assigns it a mount point, and the drive can then be mounted by clicking on the relevant entry in the mnttool menu. That's all working fine and dandy.

In legacy Linux fashion, those mounts points get created under /mnt. The problem is, my users are probably going to have problems finding /mnt and are thus liable to be unable to use their flash drives. Besides, I'd rather not have them rooting around the file system trying to find the drive anyway.

What I thought of as a possible solution is for a symlink to appear in /home/tc once a portable drive is mounted. That would be preferable because I've already got pcmanfm in wbar and it opens in /home/tc when clicked. If a symlink to, say, /mnt/sdb1 were to appear there when /dev/sdb1 gets mounted, I think it would be much less confusing to my users.

So can anyone suggest a way to get the system to create symlinks in /home/tc when external storage gets mounted using mnttool?

Thanks,
James

Offline jamtat

  • Jr. Member
  • **
  • Posts: 58
Re: symlinks for external storage under /home/tc?
« Reply #1 on: January 25, 2012, 05:36:21 PM »
I guess another possible option for getting the behavior I want would be to cause mnttool to, not just mount the drive when the relevant mnttool menu entry gets clicked, but to invoke pcmanfm as well and cause it to open in the directory where the drive gets mounted. I guess that might require tweaking mnttool's code, which is a bit beyond my capabilites, though.

James

Offline roberts

  • Administrator
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: symlinks for external storage under /home/tc?
« Reply #2 on: January 25, 2012, 07:02:44 PM »
mnttool will use file manger set via FILEMGR environment variable.
example:

FILEMGR=fluff
10+ Years Contributing to Linux Open Source Projects.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: symlinks for external storage under /home/tc?
« Reply #3 on: January 25, 2012, 07:24:12 PM »
Hi jamtat
Some scripting may be of use to you for this.
This will search for drives sda, sda1-sda8, sdb, sdb1-sdb8, ......, sdd1-sdd8
If a drive is found and not mounted, it gets mounted, the drive designation is saved in a file, and a
link is created.
Code: [Select]
#!/bin/sh
DRIVESMOUNTED="/tmp/newmounts"
for i in `grep -o "/mnt/[s]d[a-d][1-8, ]" /etc/fstab` 
do
j=`grep -o $i /etc/mtab`
[ -n "$j" ] && continue
mount "$i"
echo "$i" >> $DRIVESMOUNTED
ln -s /mnt/"$i" ~/"$i"
done
This will unmount only the drives mounted by the above script and remove the previously created
links. Lastly it syncs the file system and removes the /tmp/newmounts file.
Code: [Select]
#!/bin/sh
DRIVESMOUNTED="/tmp/newmounts"
while read -r i
do
umount "$i"
/bin/rm -f ~/"$i"
done < $DRIVESMOUNTED
rm -f $DRIVESMOUNTED
sync
That should be an adequate framework to get you started. Add a couple of icons to the wbar to call
the scripts and you're done.

Offline jamtat

  • Jr. Member
  • **
  • Posts: 58
Re: symlinks for external storage under /home/tc?
« Reply #4 on: January 25, 2012, 08:30:10 PM »
mnttool will use file manger set via FILEMGR environment variable.
example:

FILEMGR=fluff
Thanks for your input, roberts. You seem to be implying that mnttool can invoke a file manager: have I understood you correctly? If so, how does that occur? I've tried, for example, double-clicking on the menu entry for a connected drive but that does not invoke a file manager, even after I've issued env FILEMGR=pcmanfm (and confirmed that the setting "took" by inspecting the output of the env command). Further explanation will be appreciated, or a link to some documentation for mnttool, if there is any.

James
« Last Edit: January 25, 2012, 08:32:41 PM by jamtat »

Offline jamtat

  • Jr. Member
  • **
  • Posts: 58
Re: symlinks for external storage under /home/tc?
« Reply #5 on: January 25, 2012, 08:31:53 PM »
Hmmm. Interesting option, Rich. So I'd replace mnttool with your script on this scheme, correct? Definitely a possibility to explore--thanks for offering that.

James

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: symlinks for external storage under /home/tc?
« Reply #6 on: January 25, 2012, 08:53:13 PM »
Hi jamtat
Actually two scripts, the first one mounts, the second unmounts.

Open  .profile  and add  FILEMGR=pcmanfm  under the  Environmental variables and prompt ......
section. Restart the computer. Now when you use  mnttool  to mount a drive, your file manager
should open.

Offline hiro

  • Hero Member
  • *****
  • Posts: 1217
Re: symlinks for external storage under /home/tc?
« Reply #7 on: January 26, 2012, 03:36:08 AM »
I use this for ex Windows users:
ln -s /mnt "/home/user/My Computer"

On the other hand explaining the root / folder and how everything else is a subfolder/file structure was also quite an enlightenment for them.

Offline jamtat

  • Jr. Member
  • **
  • Posts: 58
Re: symlinks for external storage under /home/tc?
« Reply #8 on: January 26, 2012, 07:42:05 AM »
Actually two scripts, the first one mounts, the second unmounts.

Open  .profile  and add  FILEMGR=pcmanfm  under the  Environmental variables and prompt ......
section. Restart the computer. Now when you use  mnttool  to mount a drive, your file manager
should open.
Thanks for those tips, Rich. Making that modification does, of course, cause the file manager to open when a portable drive is mounted. So that's getting close to what I need. The problem, though, is that the file manager opens in the /home/tc directory, rather than in the directory where the external media has been mounted. And I'm not sure many of my users would be able to navigate to the mount point and thus find files they need on the newly-attached drive.

It's sort of curious behavior. I note that, in the case of an inserted CD, when the relevant device name is clicked in the mnttool menu, the file manager does, in fact, open in the directory where the CD is mounted. Which behavior differs from the case of portable storage which, when the relevant entry is clicked in the mnttool menu, causes the file manager to open in the user's home directory.

Is the difference in behavior due somehow to the presence or absence of the device file and mount point entry in /etc/fstab? I may end up having to implement some kind of hybrid solution using your script. Still working on a resolution.

James
« Last Edit: January 26, 2012, 08:37:33 AM by jamtat »

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: symlinks for external storage under /home/tc?
« Reply #9 on: January 26, 2012, 07:49:44 AM »
All mountable CD/DVD and partitioned drives should appear in /etc/fstab.
Perhaps your portable drives are missing a partition table.

Offline jamtat

  • Jr. Member
  • **
  • Posts: 58
Re: symlinks for external storage under /home/tc?
« Reply #10 on: January 26, 2012, 08:57:27 AM »
I use this for ex Windows users:
ln -s /mnt "/home/user/My Computer"
This looks like it might be a good workaround. The "My Computer" analogy will be more familiar, and the presence of a folder by that name in the home directory, via a symlink to /mnt, may just do the trick. Thanks for offering that tip, hiro.

James
« Last Edit: January 26, 2012, 09:31:42 AM by jamtat »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: symlinks for external storage under /home/tc?
« Reply #11 on: January 26, 2012, 10:04:02 AM »
Hi jamtat
If you open a terminal and type  pcmanfm --help  you will probably find an option to open to a
specific dir/drive. If you add the following to the mount script:
Code: [Select]
pcmanfm -option ~/"$i"it should do what you are looking for. By using ~/"$i" it steers the user toward staying in the home
directory and away from /mnt and the rest of the system directories. If you add the line right above
the  done  statement in the mount script, and you plug in two drives before running the mount script, it
will open a copy of pcmanfm for each of those drives.