Rescan USB bus

MontysEvilTwin

Well-Known Member
I'd like to be able to rescan the USB bus to allow ejected USB drives to be remounted without rebooting. I found a script here that looks promising, but I don't know if it will run on the HDR-FOX as is, if it needs modification, or if it is a non-starter. A slightly modified version is available here. Any help would be appreciated.
 

af123

Administrator
Staff member
It's worth playing with but might not be possible as the bulk of the hardware is managed through the Broadcom interface.. I'll give it a go later.
 

raydon

Well-Known Member
Could we not scan the device nodes in /sys/block then compare the result with current mounts to determine if there are USB device nodes present but not mounted ?
 

prpr

Well-Known Member
I'd like to be able to rescan the USB bus to allow ejected USB drives to be remounted without rebooting. I found a script here that looks promising, but I don't know if it will run on the HDR-FOX as is, if it needs modification, or if it is a non-starter. A slightly modified version is available here. Any help would be appreciated.
I just did this (having ejected the stick using the Webif):
Code:
humax ~ # mkdir /media/drive1
humax ~ # mount -t vfat /dev/sdb1 /media/drive1 -o fmask=22,dmask=22,iocharset=utf8,shortname=mixed
OK, so I needed prior knowledge to generate this having looked at what it was before I unmounted it.

Adapting the script works though and the Humax software seems to mount the drive after a short delay:
Code:
#!/bin/sh
SYSUSB=/sys/bus/usb/drivers/usb-storage
cd $SYSUSB
for dev_id in *:* ; do
  printf "${dev_id}"
  printf "${dev_id}" >unbind
  printf "${dev_id}" >bind
done
 

raydon

Well-Known Member
For the purpose he made clear in post #1. I'm sure he is already aware that hot plugging the device will achieve the same result but may not be so convenient.
 
Last edited:

af123

Administrator
Staff member
Thanks prpr, I'll find this very useful.
Is it something that you'd like worked into the web interface somewhere? Perhaps it could be shown in the new USB eject drop-down, although that isn't there if no drives are detected..
 

prpr

Well-Known Member
Is it something that you'd like worked into the web interface somewhere? Perhaps it could be shown in the new USB eject drop-down, although that isn't there if no drives are detected..
Does the detection work on mounted devices currently? You could change it so that it detects devices plugged in (which may or may not be mounted), as above, in order to display the drop-down. Then you could have a mount/unmount facility depending...
 

Black Hole

May contain traces of nut
For the purpose he made clear in post #1. I'm sure he is already aware that hot plugging the device will achieve the same result but may not be so convenient.
For pity sake! Post 1 does not explain why!! For an apparently clever person you really are very obtuse.
I'd like to be able to rescan the USB bus to allow ejected USB drives to be remounted without rebooting.
Why? What will this achieve? I'm not saying we shouldn't, just trying to find out what it's utility will be. Why has the user ejected the USB drive and then wants to mount it again - by mistake? This is not something that would happen on a regular basis.
 

prpr

Well-Known Member
Why has the user ejected the USB drive and then wants to mount it again - by mistake? This is not something that would happen on a regular basis.
Sometimes I do this on my computer and then realise I need to copy something else to/from it. It's really annoying to have to physically remove and reinsert the device just to get the stupid OS to remount the filesystem. Sometimes you may just want to leave things unmounted most of the time and then just mount it while you need it, or select one from a number of devices to mount. Just because you don't see the point doesn't mean somebody else doesn't...
 
OP
MontysEvilTwin

MontysEvilTwin

Well-Known Member
To explain. I have a HDR-FOX in a bedroom that has a 2TB WD USB drive (NTFS format) connected, which is used as a programme archive, and is mounted on other units. Occasionally if I try and playback a programme it fails and folders disappear. The issue is intermittent and a reboot cures it. I have used the WD tools to prevent automatic power down but the problem still occurs occasionally. If it happens during a recording the unit can't be rebooted straight away which means waiting or going upstairs, unplugging and replugging the USB cable. So it is just a matter of convenience.

I have tried prpr's script and it works, so thanks again. Instructions are as follows:

Copy the text of prpr's script into a text file and save (I called it 'usbscan')
Copy 'usbscan' into /mod/usr/bin (I did this by FTP - betaftpd as root. You may need to create the directories under '/mod')
Open a Telnet connection (command line - CLI option) and run the following command:
Code:
chmod +x /mod/usr/bin/usbscan
This only needs to be done once and will set up permissions.

To rescan the USB bus enter the command 'usbscan' in Telnet.
 
OP
MontysEvilTwin

MontysEvilTwin

Well-Known Member
Is it something that you'd like worked into the web interface somewhere? Perhaps it could be shown in the new USB eject drop-down, although that isn't there if no drives are detected..
I am happy running the script, but building it into the menu would be nice.
 

raydon

Well-Known Member
Running the script as-is will unmount all attached USB storage devices, including virtual-USB, before mounting them all again to include the previously umounted device. Could this have any adverse effects ? Maybe there's a way to match ID's such as "1-2:1.0" in "/sys/bus/usb/drivers/usb-storage" to mounted device ID's like "/dev/sdb1" in order to only "unbind/bind" unmounted devices.
Edit: I've modified the script to just do this matching. Nothing else.
Code:
#!/bin/sh
cd /sys/bus/usb/drivers/usb-storage
for drv_id in *:* ; do
   for device in /sys/block/sd*/device; do
     if echo $(readlink -f $device)|grep -q "$drv_id"; then
       dev_id=`echo $device | cut -f4 -d/`   
       echo "$drv_id is bound to $dev_id"
     fi
   done
done
which gives this output on my box.
1-2:1.0 is bound to sda
5-1:1.0 is bound to sdc
 
Last edited:

prpr

Well-Known Member
Running the script as-is will unmount all attached USB storage devices, including virtual-USB, before mounting them all again to include the previously umounted device. Could this have any adverse effects ?
It's not great. I suppose it depends if there are any open files as to whether anything 'bad' might happen.
Maybe there's a way to match ID's such as "1-2:1.0" in "/sys/bus/usb/drivers/usb-storage" to mounted device ID's like "/dev/sdb1" in order to only "unbind/bind" unmounted devices.
Haven't managed to find out how yet. Does the Humax have some sort of 'udev' equivalent?
 
Top