Welcome! Log In Create A New Profile


Rescan USB Bus

Posted by sambul14 
Rescan USB Bus
October 21, 2012 07:16AM
Lets say, one has installed XFCE desktop to a Plug, and hooked a USB thumb to it after boot. In a desktop environment the USB Thumb can later be ejected by the Eject command. But often there is no need to detach it from the Plug after that. Once ejected, it reads like /dev/sdb hooked to USB bus, with no volume IDs.

So, is there a way to rescan the USB Bus aiming to assign device name / number again to the Thumb, so that it's rediscovered and auto mounted by UDEV? Is fstab record required to re-mount in this case? Or may be restarting Udev or using udevadm will do - how exactly? Pls test before giving advice. :)
Re: Rescan USB Bus
October 21, 2012 04:58PM

You can just run a script to remount the unmounted devices. The only drawback is your script will mount all of them! but if that's what you want then it's the most flexible way. Otoh, if you can manually remove/insert the USB connector then udev will assign it again. So rescan is just a matter of running the script. Here my script for this purpose:


logger -s -i "Pmounting all unmounted USB drives"

PMOUNT=`which pmount`
if [ -z "$PMOUNT" ]
  logger -s -i  "Error: $0 cant find pmount!" 1>&2
 exit 1

DEV_LIST=`ls -1 $ROOT`

logger -s -i "Mounting all unmounted USB disks: $DEV_LIST (skip rootfs)"

for DEV in $DEV_LIST; do
   if [ "$DEV" != "rootfs" ]; then
      if  ! /bin/mountpoint /media/$DEV -q ; then
         $PMOUNT --noatime --umask 000 --read-write $ROOT/$DEV $DEV        


logger -s -i "Done Pmounting USB drives"

exit 0
Re: Rescan USB Bus
October 22, 2012 05:53PM
The problem is, Eject feature assigns 0 value to thumb size. So the partition is no longer visible, i.e. /dev/sdb1 doesn't exist, only /dev/sdb , and rescanning the thumb proven difficult. Are you saying, this script will rediscover missing /dev/sdb1 ?
Re: Rescan USB Bus
October 22, 2012 06:40PM
Your xfce Eject action might have some issue. Even after Eject, it should have left the sdb1 there until you physically remove it. I think that's the default behavior for Gnome. As I recall, Gnome even leaves the icon there so you can remount it by double clicking on the icon (I could be mistaken here because I did not look under the hood with Gnome, but on the surface, that's how it looks).

On xfce, I actually disabled Volume Management by thunar, and rely strictly on udev rules to automount the USB drives (with pmount). And added a xfce Customed Action (on context menu) to Eject with pumount. This is because I don't want to rely on xfce to manage the USB automount so I can remove xfce or replace it later, if need be. I think the extra Customed Action on the context menu is a much cleaner solution.
Re: Rescan USB Bus
October 22, 2012 07:12PM
I'll try that. I don't have access to XFCE at the moment. Are you saying, the custom action can be selected from a list, or do you need to write a command - which one? And, Eject is a separate package, not sure, its part of XFCE.

Did you try LXDE? It seems to be lighter and faster than XFCE, but not sure about its completeness...
Re: Rescan USB Bus
October 22, 2012 07:33PM
To create Eject command on xfce context menu:

File Manager -> Edit -> Configure custom actions...

pumount %f

Appearance conditions
file pattern: * 
file tyes: directory

Note that your udev rules should have pmount to automount the USB drives (to mount drives under /media). pumount will un-mount the drive and remove the mount point.

If you use mount/umount then the mountpoint could be any where, and will not be removed automatically by umount. IOW, that pumount %f command could be replaced by umount %f (if mount was used to mount the drive).

I have not tried lxde, so don't know. I like xfce enough to stay with it :-)
Re: Rescan USB Bus
October 22, 2012 08:53PM
Does that imply, I need to install pmount, and change installed udev rules manually to replace mount with pmount?
Re: Rescan USB Bus
October 22, 2012 10:22PM
Not necessarily, it meant that if you use mount in udev rules, then it needs to pair with umount in the script. And the mount point has to be created before hand. If you use pmount then the mount point is created automatically under /media, and removed by pumount.

So yes, to use pmount then just install pmount if it's not there, and the udev rules must be changed to use the correct syntax.

Your Email:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.