LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 12-04-2012, 12:28 PM   #1
hilltownboy
Member
 
Registered: Jan 2008
Location: Ashfield, MA
Distribution: Debian 7 "wheezy", Arch, PCLinux, Crunchbang "waldorf"
Posts: 69

Rep: Reputation: 15
ubs stick access


Console commands like cd and ls do not access ubs stick after I plug it in (dmesg does show it). But if I first bring up pcmanfm it lists the ubs stick, and if I exit out of pcmanfm and go to a terminal, the terminal commands will access the ubs stick normally.
How can I make the ubs stick work from the terminal without going to pcmanfm first?
Why does pcmanfm succeed but the terminal at first does not?
 
Old 12-04-2012, 12:42 PM   #2
Lennie
Member
 
Registered: Aug 2012
Location: Sweden
Distribution: LFS, built with pacman
Posts: 301

Rep: Reputation: 60
You need to mount the usb before you can access it. That's what pcmanfm is doing. You can mount it from terminal with
Code:
sudo mount /dev/sdb1 /mnt
Change sdb1 to the number your usb has. You can find out by
Code:
lsblk -f
The mount point (in this example /mnt) must exist.
 
Old 12-04-2012, 02:31 PM   #3
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,970

Rep: Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848
If you want to be the USB stick to be mounted automatically, you should use a udev rule. On my system I use the following
Code:
SUBSYSTEMS=="usb", KERNEL=="sd?1", ACTION=="add", RUN+="/usr/local/bin/mount-usb.sh"
the script which is called by udev is
Code:
#!/bin/bash

# USB-Stick mounten
sleep 5
device=`dmesg | grep -e sd.: | tail -n 1 | sed -n 's/.*sd.:\s\+\?\(.*\)/\1/i p'`
name=`dmesg | grep -i product: | tail -n 1 | sed -n 's/.*product:\s\+\(.*\)/\1/i p' | sed -n 's/\ /_/g p'`

if [ ! -d /media/$name ]; then 
				mkdir /media/$name
fi
mount /dev/$device /media/$name
username=`who | head -n 1 | cut -d " " -f 1`
export DISPLAY=:0.0 
su $username -c "notify-send 'USB-Speicherstick eingehaengt auf /media/$name'"
which uses notify-send for a message to the user about where the stick is mounted. You can for example write your own script which notifies you in the terminal about the path to the stick.

Markus
 
1 members found this post helpful.
Old 12-05-2012, 11:10 AM   #4
hilltownboy
Member
 
Registered: Jan 2008
Location: Ashfield, MA
Distribution: Debian 7 "wheezy", Arch, PCLinux, Crunchbang "waldorf"
Posts: 69

Original Poster
Rep: Reputation: 15
ubs stick access

Thank you both. lsblk is not in my Debian current stable version (Squeeze) but seems to be in the next forthcoming stable version. Using df with the stick mounted showed the dev number.
Learning udev looks a bit challenging for a novice but is evidently the answer for automatic mounting.
 
Old 12-05-2012, 11:31 AM   #5
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,970

Rep: Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848
There is a nice tutorial http://www.reactivated.net/writing_udev_rules.html but it is somewhat dated. Some of the rules have changed since then. But for an overview it is very nice.

Markus
 
Old 01-04-2013, 03:54 PM   #6
hilltownboy
Member
 
Registered: Jan 2008
Location: Ashfield, MA
Distribution: Debian 7 "wheezy", Arch, PCLinux, Crunchbang "waldorf"
Posts: 69

Original Poster
Rep: Reputation: 15
usb stick access

Markush, could you explain your script a bit for a less experienced person? The "mount" line activates the mounting, does it not? And everything after that is a message that is not needed for the mounting?
Is the section on "name" needed if one always mounts to /media, not anywhere else?
The expressions after "sed -n" are difficult for me to visualize, never having used "sed". They appear to be the path, but how is that information collected and how does it become part of the udev rule?
 
Old 01-04-2013, 04:02 PM   #7
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,970

Rep: Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848
Quote:
Originally Posted by hilltownboy View Post
Markush, could you explain your script a bit for a less experienced person? The "mount" line activates the mounting, does it not? And everything after that is a message that is not needed for the mounting?
Is the section on "name" needed if one always mounts to /media, not anywhere else?
The expressions after "sed -n" are difficult for me to visualize, never having used "sed". They appear to be the path, but how is that information collected and how does it become part of the udev rule?
Well, here the explanation
Code:
#!/bin/bash

# USB-Stick mounten
sleep 5
device=`dmesg | grep -e sd.: | tail -n 1 | sed -n 's/.*sd.:\s\+\?\(.*\)/\1/i p'`
name=`dmesg | grep -i product: | tail -n 1 | sed -n 's/.*product:\s\+\(.*\)/\1/i p' | sed -n 's/\ /_/g p'`
Wait 5 seconds and then parse dmesg for the devicename and the product (which means: identify the memorystick), this is used later in order to create an appropriate mount-directory.
Code:
if [ ! -d /media/$name ]; then 
				mkdir /media/$name
fi
if the directory /media/$name where the device has to be mounted does not exist, create it.
Code:
mount /dev/$device /media/$name
mount the device.
Code:
username=`who | head -n 1 | cut -d " " -f 1`
export DISPLAY=:0.0 
su $username -c "notify-send 'USB-Speicherstick eingehaengt auf /media/$name'"
The rest of the code displays a message with the notify-send tool.

Markus

Edit: as for the regex, use them and check your dmesg output after you've pluged in an USB-memory device you will then understand.

Last edited by markush; 01-04-2013 at 04:06 PM.
 
Old 01-04-2013, 04:08 PM   #8
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,970

Rep: Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848Reputation: 848
Well, as of the regular expressions. Use this line
Code:
dmesg | grep -e sd.: | tail -n 1 | sed -n 's/.*sd.:\s\+\?\(.*\)/\1/i p'
and this line
Code:
dmesg | grep -i product: | tail -n 1 | sed -n 's/.*product:\s\+\(.*\)/\1/i p' | sed -n 's/\ /_/g p'
simply in a terminal after pluging in a USB-memory device. You will see what it all means, it is not that difficult.

Markus
 
Old 01-12-2013, 09:23 AM   #9
hilltownboy
Member
 
Registered: Jan 2008
Location: Ashfield, MA
Distribution: Debian 7 "wheezy", Arch, PCLinux, Crunchbang "waldorf"
Posts: 69

Original Poster
Rep: Reputation: 15
usb stick access

With a UDEV rule that runs the first part of the script my usb memory stick now mounts automatically to /media. But the cdrom (controlled by a later UDEV rule) is no longer in /media and mount does not find the /media.cdrom0 mount point in fstab.
The script that I used included the "device" line, the "name" line and the "mount" line but not the "if" to "if" section. Does that section prevent the loss of other entries in the /media directory?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ubs optical moiuse siawash Linux - Hardware 3 02-06-2008 08:18 PM
Need FreeBSD UBS/Parallel help ezor *BSD 8 09-24-2007 09:36 AM
how do i access my USB stick??? lenson Linux - Newbie 10 08-25-2005 12:45 PM
Mount ubs pen spots Linux - Hardware 1 07-12-2005 09:36 PM
Ubs JMK Linux - Newbie 1 12-22-2003 07:04 AM


All times are GMT -5. The time now is 01:22 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration