USB device non-detection at boot.[SOLVED]

Using applications, configuring, problems
Post Reply
Message
Author
User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

USB device non-detection at boot.[SOLVED]

#1 Post by greengeek »

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, 20:23, edited 1 time in total.

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#2 Post by rcrsn51 »

Maybe something simpler would work. Go into your auto-mount script and put a "sleep 5" before the lines that mount the USB drives.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#3 Post by greengeek »

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.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#4 Post by musher0 »

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
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#5 Post by greengeek »

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.

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#6 Post by rcrsn51 »

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: Select all

rmmod ehci_hcd
modprobe ehci_hcd
Then maybe a sleep command so the drives can be re-detected before you try to mount them.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#7 Post by greengeek »

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)

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#8 Post by greengeek »

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: Select all

#!/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, 20:09, edited 1 time in total.

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#9 Post by rcrsn51 »

Nice work.

This module reloading technique would probably also work for people whose USB wifi adapters occasionally lock up.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#10 Post by musher0 »

Hello, greengeek.

Concerning
> 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

Code: Select all

umount -a 
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
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#11 Post by musher0 »

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
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#12 Post by greengeek »

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.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#13 Post by musher0 »

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: Select all

#!/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.
Attachments
umount-only-disks.jpg
(30.28 KiB) Downloaded 753 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#14 Post by greengeek »

Thanks Musher0, that seems to have improved the behaviour on Slacko. The script now is:

Code: Select all

#!/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

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#15 Post by musher0 »

Nice! The modest man forgot to include his name and the date! :wink:
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

midmen
Posts: 4
Joined: Wed 20 Jun 2012, 18:25

USB device non-detection at boot.[Solved]

#16 Post by midmen »

Thank you greengreek and Musher0. Nice code.
I tried using this code running from a flash drive.
A problem occurs: On initial boot up the USB flash drive containing the operating system and save file is on sdc2. When this codes runs, the flash drive containing the operating system and save file is then relabeled as sdd2. The save on shutdown fails because the save file is now on sdd2 instead of sdc2.

Is is possible to have a code that mounts only the USB flash drives (no hard drives or CD drives) that are already plugged in on startup excluding the USB flash drive that contains the operating system and the save file?

I have one USB flash drive with Puppy 528 on it and another USB flash drive for downloads. I would like only the downloads USB flash drive to mount automatically at boot up. Any ideas?

Thanks

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#17 Post by rcrsn51 »

Instead of unloading/reloading the USB kernel module, try this:

Code: Select all

udevadm trigger --subsystem-match="usb*"

boof
Posts: 579
Joined: Wed 26 Sep 2012, 22:53

crypta*.2fs not loading from usb Slacko5.3.3-4g

#18 Post by boof »

usb is ext2 and boot flag set
usb is 1st choice in boot sequence
usb is for storage only.
crypta*.2fs exists.


does not get acknowledged after "searching for puppy files"

boof
Posts: 579
Joined: Wed 26 Sep 2012, 22:53

#19 Post by boof »

Same happens when usb is bootable system. USB has 3 partitions, system on sda1,--boot flag set
crypta*.2sf on sda2
laptop has latest BIOS.
No hard drive installed.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#20 Post by greengeek »

Just want to add some other links that may help around the edges with mounting and booting issues etc....

http://www.murga-linux.com/puppy/viewtopic.php?t=89929
http://murga-linux.com/puppy/viewtopic. ... ost#743723
http://www.murga-linux.com/puppy/viewtopic.php?t=88390

Post Reply