Author |
Message |
greengeek

Joined: 20 Jul 2010 Posts: 5624 Location: Republic of Novo Zelande
|
Posted: Wed 10 Oct 2012, 13:07 Post subject:
USB device non-detection at boot.[SOLVED] Subject description: Possibility of "USB wakeup" code? |
|
I am trying to set up a self-booting "server" using puppy and often find that some usb sticks are not detected at boot time, but DO get detected if I unplug them after boot, and replug them ("hotplug"?)
I wondered if it might be possible to make a script that has the ability to "tickle" the usb ports in such a way that the system thinks that a new device has been plugged in - kicking off the detection process without having to physically unplug the device?
My plan would be to place this script in the /root/Startup folder so that it ran after X started. (I would probably then follow this script with some code that I got from sunburnt which automounts all drives.)
(I know that the sensitivity of usb device detection varies between versions of puppy, but I would like to try to find a piece of code that is likely to run ok on a wide range of puppies - my server is likely to be built on PupServer435 which is based on 4.3.1 or I might even use an older more barebones puppy so it would be good if the code worked on older versions, but I have also had this problem on some more recent puppies too)
Last edited by greengeek on Fri 12 Oct 2012, 16:23; edited 1 time in total
|
Back to top
|
|
 |
rcrsn51

Joined: 05 Sep 2006 Posts: 12801 Location: Stratford, Ontario
|
Posted: Wed 10 Oct 2012, 13:28 Post subject:
|
|
Maybe something simpler would work. Go into your auto-mount script and put a "sleep 5" before the lines that mount the USB drives.
|
Back to top
|
|
 |
greengeek

Joined: 20 Jul 2010 Posts: 5624 Location: Republic of Novo Zelande
|
Posted: Wed 10 Oct 2012, 13:52 Post subject:
|
|
The problem is that I can't mount what has not yet been detected. I find that if the operating system itself has not detected the usb drive during the boot sequence then none of the various mount methods will work. However, if I then pull the drive out and plug it back in, an icon appears on the desktop and I can proceed to mount.
|
Back to top
|
|
 |
musher0
Joined: 04 Jan 2009 Posts: 14532 Location: Gatineau (Qc), Canada
|
Posted: Wed 10 Oct 2012, 14:01 Post subject:
|
|
Hi!
Would that be a Seagate FreeAgent external USB hard drive, by any chance ? They're notorious for "sleeping on the job", and Linux has apparently no way to wake them up besides reboot. (With the exception of dpup 4.85, in my experience.)
Best.
_________________ musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
|
Back to top
|
|
 |
greengeek

Joined: 20 Jul 2010 Posts: 5624 Location: Republic of Novo Zelande
|
Posted: Wed 10 Oct 2012, 15:09 Post subject:
|
|
One of the devices I am mostly having this issue with is a Transcend 1TB external usb drive. I have it partitioned with one large NTFS, one small FAT32, and one Linux swap partition. ( I don't know which brand of HDD or controller chip it contains). I don't know if the non-detection is caused by the device itself or something to do with the partitioning (unfortunately I can't fiddle too much with it because it contains all my daughters uni work and media files).
However, I do have similar problems with different usb sticks - some of which have only a single FAT32 partition.
Some puppies seem very good at boot-time usb detection (Grays NOP511 is another lightweight puppy I am trialling for server use), but older puppies seem more variable. I just wanted to find a way to "simulate" a usb "hotplug" action so that the device detection routine gets triggered.
|
Back to top
|
|
 |
rcrsn51

Joined: 05 Sep 2006 Posts: 12801 Location: Stratford, Ontario
|
Posted: Wed 10 Oct 2012, 16:03 Post subject:
|
|
Have a look at this. But it may not fix your problem - if a device hasn't been detected yet, you probably can't reset it.
[Edit] I found a site that claims you can restart your USB system by reloading the module.
Code: | rmmod ehci_hcd
modprobe ehci_hcd |
Then maybe a sleep command so the drives can be re-detected before you try to mount them.
|
Back to top
|
|
 |
greengeek

Joined: 20 Jul 2010 Posts: 5624 Location: Republic of Novo Zelande
|
Posted: Thu 11 Oct 2012, 14:02 Post subject:
|
|
Thanks for those suggestions. The usbreset pet unfortunately did not work on the PupServer435 I am trialling because it is based on a "4" series puppy and does not understand the lsusb command.
However the rmmod/modprobe of the usb driver DID work. It allowed the missing partition to reappear. Thanks!
(I need to report back further once I have done some more testing because the cluster of symptoms I originally had seems to have changed - at the moment the one consistent symptom I have is that the usb stick is detected, but only 2 of the 3 partitions are detected - at least until I do the rmmod trick you suggested, after which all 3 partitions are back.
I need to quantify exactly what was happening across the three troublesome usb devices, two machines, and several remastered versions of Pupserver435 and NOP511. Will report back)
|
Back to top
|
|
 |
greengeek

Joined: 20 Jul 2010 Posts: 5624 Location: Republic of Novo Zelande
|
Posted: Fri 12 Oct 2012, 14:51 Post subject:
|
|
OK, here is a script that uses the rmmod to remove the usb driver, modprobe to reload the driver, then sunburnt's second version of mnt-all code to mount all partitions.
I've tested it with PupServer435 and it is successfully getting me past my problem. I also tested it on Slacko but found that the "sleep 5" after the reload usb had to be lengthened to "sleep 10"
I will be putting this in my startup folder.
(more testing to come re the varying nature of the symptoms regarding which partitions fail to detect..)
CAUTION: this script does not attempt to first unmount any partitions that may already have been mounted, and there may be a risk that this could cause a problem, depending on when you run it. (I don't actually know how big a risk this might be. Maybe none at all. However I recommend making sure that the pfix-fsck option is active in the menu.lst entry to correct any filesystem irregularities that might result. I plan to use this script immediately after boot, and before any other programmes are activated)
Code: | #!/bin/sh
######### This script unloads the usb driver then reloads it then mounts all partitions found.
#(Thanks sunburnt for the mnt-all code and rcrsn51 for the ehci_hcd idea...)
### Use at your own risk... No warranty!
# For auto. mounting at bootup, put this script in Puppy folder: /root/Startup
# After bootup, if other drives are plugged in, run mnt-all again to mount them.
#SECTION 1 - remove the usb driver, then reload it
rmmod ehci_hcd
sleep 2
modprobe ehci_hcd
sleep 5
#SECTION 2 - automount all drives and partitions
# This gets a list of all partition info. except swap and optical drives.
List=`probepart |egrep -v '(swap|sr|none)'`
# This "for" loop steps through the list one partiton at a time.
for Line in $List
do
Part=${Line%%\|*} # Get only partition.
Part=${Part##*/}
[ "`df |grep $Part`" ]&& continue # Don`t mount, if done already.
Type=${Line%\|*} # Get file system type.
Type=${Type##*\|}
[ -d /mnt/$Part ]|| mkdir /mnt/$Part # Make the mount dir., if none.
mount -t $Type /dev/$Part /mnt/$Part # Mount the partition.
echo "# Mount Partition: $Part Type: $Type" # Display mount info.
done
|
Last edited by greengeek on Fri 12 Oct 2012, 16:09; edited 1 time in total
|
Back to top
|
|
 |
rcrsn51

Joined: 05 Sep 2006 Posts: 12801 Location: Stratford, Ontario
|
Posted: Fri 12 Oct 2012, 15:38 Post subject:
|
|
Nice work.
This module reloading technique would probably also work for people whose USB wifi adapters occasionally lock up.
|
Back to top
|
|
 |
musher0
Joined: 04 Jan 2009 Posts: 14532 Location: Gatineau (Qc), Canada
|
Posted: Mon 15 Oct 2012, 16:43 Post subject:
|
|
Hello, greengeek.
Concerning
Quote: | > CAUTION: this script does not attempt to first unmount any partitions that may already have been mounted, and there may be a risk that this could cause a problem, depending on when you run it. (I don't actually know how big a risk this might be. Maybe none at all. |
the user could issue
before using your script, no?
The $HOME and swap disks (or $HOME and the disk the swap file is on) will remain on, but the other ones will close.
That said, I agree with a fsck at reboot.
BFN.
_________________ musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
|
Back to top
|
|
 |
musher0
Joined: 04 Jan 2009 Posts: 14532 Location: Gatineau (Qc), Canada
|
Posted: Mon 15 Oct 2012, 17:30 Post subject:
|
|
BTW, in case anybody needs to know how to (re)wake up a 160 Gb FreeAgent USB drive under Linux, it's here:
http://alienghic.livejournal.com/382903.html
BFN.
_________________ musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
|
Back to top
|
|
 |
greengeek

Joined: 20 Jul 2010 Posts: 5624 Location: Republic of Novo Zelande
|
Posted: Sat 20 Oct 2012, 20:36 Post subject:
|
|
Hi Musher0, I've just been trying inserting "umount -a" into the script before the usb reset, but getting some strange system hangs etc (when using the script on PupServer 435), so I then tried manually using umount -a in a terminal on my normal Slacko installation - and I got a lot of messages discussing the unmounting of pup-ro, pup-rw etc etc or similar messages (which looks to my untrained eye like unmounting filesystems rather than just drives...). Do you think the umount -a is safe to use or might there be a "softer" way to unmount only the drives?
Thanks for any suggestions.
|
Back to top
|
|
 |
musher0
Joined: 04 Jan 2009 Posts: 14532 Location: Gatineau (Qc), Canada
|
Posted: Sun 21 Oct 2012, 01:00 Post subject:
|
|
Hello, greegeek.
> might there be a "softer" way to unmount only the drives?
Strange. I've used the unmount -a command a lot and never had a problem.
Maybe you need something like this, then:
Code: | #!/bin/sh
# ~/my-applications/bin/umount-only-disks.sh
####
df -H -T -x squashfs -x tmpfs -x rootfs -x aufs -P | grep "/mnt/s" | cut -f2 -d'm' > spc_dsq.txt
while read line
do
umount /m$line
done < spc_dsq.txt
rm -f spc_dsq.txt |
Explanation:
We do a df avoiding the looped systems (-x means "exclude");
we "grep" only the lines with a /mnt in them (real disks);
we cut the resulting lines after the "m";
we read the lines one after other from the mini-log file we created,
adding the necessary characters removed by the cut command;
and umount does its job;
we clean up after ourselves once finished.
Of course, my code is crude, but it seems to do the job. (See illustration with xv set/unset.)
I hope this helps.
Description |
|
Filesize |
30.28 KB |
Viewed |
744 Time(s) |

|
_________________ musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
|
Back to top
|
|
 |
greengeek

Joined: 20 Jul 2010 Posts: 5624 Location: Republic of Novo Zelande
|
Posted: Sun 21 Oct 2012, 03:12 Post subject:
|
|
Thanks Musher0, that seems to have improved the behaviour on Slacko. The script now is:
Code: | #!/bin/sh
######### This script unmounts all disks, reboots the usb driver then reloads it then mounts all partitions found.
#(Thanks sunburnt for the mnt-all code, rcrsn51 for the ehci_hcd idea and musher0 for the unmount code)
### Use at your own risk... No warranty!
# For auto. mounting at bootup, put this script in Puppy folder: /root/Startup
# After bootup, if other drives are plugged in, run mnt-all again to mount them.
#PREPARATION - unmount devices already mountd during boot
sleep 2
# ~/my-applications/bin/umount-only-disks.sh
####Musher0 code to unmount only disks
df -H -T -x squashfs -x tmpfs -x rootfs -x aufs -P | grep "/mnt/s" | cut -f2 -d'm' > spc_dsq.txt
while read line
do
umount /m$line
done < spc_dsq.txt
rm -f spc_dsq.txt
sleep 5
#SECTION 1 - remove the usb driver, then reload it
rmmod ehci_hcd
sleep 2
modprobe ehci_hcd
sleep 10
#SECTION 2 - automount all drives and partitions
# This gets a list of all partition info. except swap and optical drives.
List=`probepart |egrep -v '(swap|sr|none)'`
# This "for" loop steps through the list one partiton at a time.
for Line in $List
do
Part=${Line%%\|*} # Get only partition.
Part=${Part##*/}
[ "`df |grep $Part`" ]&& continue # Don`t mount, if done already.
Type=${Line%\|*} # Get file system type.
Type=${Type##*\|}
[ -d /mnt/$Part ]|| mkdir /mnt/$Part # Make the mount dir., if none.
mount -t $Type /dev/$Part /mnt/$Part # Mount the partition.
echo "# Mount Partition: $Part Type: $Type" # Display mount info.
done
|
|
Back to top
|
|
 |
musher0
Joined: 04 Jan 2009 Posts: 14532 Location: Gatineau (Qc), Canada
|
Posted: Sun 21 Oct 2012, 09:24 Post subject:
|
|
Nice! The modest man forgot to include his name and the date!
_________________ musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
|
Back to top
|
|
 |
|