LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   USB Pen Drive / Flash Drive Unmounted but the power is there (https://www.linuxquestions.org/questions/linux-hardware-18/usb-pen-drive-flash-drive-unmounted-but-the-power-is-there-503208/)

teluguswan 11-20-2006 04:08 AM

USB Pen Drive / Flash Drive Unmounted but the power is there
 
Hello to all

Thanks to all for such a good solutions.

I have the problem with my Pen Drives i.e iam using the Redhat Enterprise Linux 4 and my problem is when iam inserting the pen drive it installed correctly and every thing went correct. After whenever i unmount the pen drive the icon on the desktop disappears but the light of the Pen drive is still glowing. When i removed the pen drive in this conditions twice my Pen Drive corrupted and i have to purchase another.

Any one please help me how i should remove the pen drive from the system in linux. After unmounting the pen drive how to turnoff the power to pen drive.

Please give the information


it will be very helpfull for us.

Samotnik 11-20-2006 08:15 AM

There are no way to turn off power on USB port (except unloading kernel module maybe) and no one care about this, becouse unmounting is sufficient. Power on USB line can't damage pen drive when unplugging. When you lose your drive it isn't a power problem, it's a defect in this drive.

wabbalee 11-20-2006 08:23 AM

i agree with Samotnik, another thing that might be a problem is that the drive is still being written to by the os. you should always wait for a few seconds (10 or so) before pulling it out. you can also tell if it is still in use when you look at the light and it is still flashing. I have noticed that windows 'unmounts' the drive differently as it turns off the led. I use a pendrive all the time and haven't come accross to actually damaging/corrupting the drive.

teluguswan 11-20-2006 11:25 PM

when
 
when i turnoff the or stop the pen drive in windows usually the light goes off.

But where as in Linux still the light glows.

Cause of loss of Pen-Drive: It is showing the pendrive but unable to browse the pen drive in linux when my previous pen drives went wrong.

Just i want to know is the light glows off like in windows or not.

Please give the info

with regards
teluguswan

J.W. 11-21-2006 12:30 AM

By design, all USB ports are powered, and anytime you insert a USB device into the slot, it will automatically be powered on. This is really useful and helpful, and the basic idea is simply that when you plug in the USB device, you clearly intend on using it, and therefore the computer should not force you to take any other actions to turn it on. Or to say it the other way, if you didn't want the device to be enabled, you wouldn't have plugged it into the slot in the first place.

Anyhow, in the case of pen drive (or any other USB storage unit), the act of mounting it to a mountpoint (and thus making the data accessible) could be automatic or require a manual step. It depends on your system, but either way it would be perfectly normal to have a pen drive be powered on but unmounted. The fact that the light still glows after you unmount it is OK.

gregtrounson 08-09-2007 09:16 PM

Quote:

Originally Posted by Samotnik
There are no way to turn off power on USB port (except unloading kernel module maybe) and no one care about this, becouse unmounting is sufficient. Power on USB line can't damage pen drive when unplugging. When you lose your drive it isn't a power problem, it's a defect in this drive.

I think he wants just what Windows users see. When a drive is unmounted under Windows, power to that port alone is cut and the drives light goes out. (note that simply removing the usb modules is not a solution here as there may be other devices still connected).

This is a rather sensible safeguard to teach your users if you ask me: "If the little light is on, don't pull it out".

teluguswan 08-09-2007 11:41 PM

Yes I thought the Same, When the Power goes off then only it is totally off. I thought like that if the same happens.

Electro 08-11-2007 03:14 AM

Check the logs. Could be a bad bit. If it is damaged, you should have some patience.

Flash NAND memory is very, very slow. The throughput is about a few hundred kilobytes. Also it is more prone to failing when power is abruptly disconnected during use (writing or reading).

All devices connected to USB are powered, so be careful disconnecting the cable while they are processing.

USB devices are always powered even if you think they are not.

romashka 11-17-2007 11:18 AM

What Windows does is putting USB device in suspend mode.

Use the following script for doing the same:

Code:

#!/bin/bash

if [ -z $1 ]; then
    echo 'device not specified'
    exit 1
fi

DEVICE=$(udevinfo --query=path --name=$1 --attribute-walk | grep 'USB Mass Storage Device' -B5 | head -n 1 | cut -d"'" -f2)

if [ -z $DEVICE ]; then
    DEVICE=$(udevinfo --query=path --name=$1 --attribute-walk | grep 'USB2.0 Storage Device' -B5 | head -n 1 | cut -d"'" -f2)
    if [ -z $DEVICE ]; then
        echo 'not an USB mass storage device'
        exit 1
    fi
fi

echo 'suspend' > /sys/$DEVICE/power/level

Example usage:
# ./suspend-device.sh /dev/sdc

gregtrounson 11-18-2007 04:04 PM

Thank you!
 
This is exactly what I was after, thank you.

It works perfectly too. When the drive is plugged in it is usually noticeably hot. When put into suspend it cools down to room temperature so not only is the light off, the unit itself is drawing very little (if any) current. I've extended the script a bit so you can wake it back up too without having to plug it back in. Just cat 'on' or 'auto' instead of 'suspend' to the level file.

Now to bring this to the masses we have to figure out how to tie it into Gnome and KDE's "safely remove" feature. Ideally 'removing' a USB drive should do something like this:

sync
umount /media/sd*
suspend-device.sh /dev/sd*

romashka 11-19-2007 02:50 AM

Quote:

Originally Posted by gregtrounson (Post 2963397)
Now to bring this to the masses we have to figure out how to tie it into Gnome and KDE's "safely remove" feature. Ideally 'removing' a USB drive should do something like this:

sync
umount /media/sd*
suspend-device.sh /dev/sd*

sync is not needed when mounting flash with the new 'flush' option (appeared in kernel 2.19 IIRC). With -o flush data are written on filesystem as soon as possible but the process is much faster than with -o sync.
The latest HAL releases already recognize 'flush' as a valid mount option, just add it to default mount options in KDE config centre.

romashka 10-04-2008 03:36 PM

updated version of suspend-device.sh
 
Wanted to try the script again today, and found that it doesn't work with the latest udev because there are many more ATTRS than grep -B5 intended to skip.
So here's an improved version that works with much greater number of ATTRS in the needed device.


Code:

#!/bin/bash

if [ -z $1 ]; then
    echo 'device not specified'
    exit 1
fi

DEVICE=$(udevinfo --query=path --name=$1 --attribute-walk | grep 'USB Mass Storage Device' -B50 | grep 'looking at parent device' | tail -n 1 | cut -d"'" -f2)

if [ -z $DEVICE ]; then
    DEVICE=$(udevinfo --query=path --name=$1 --attribute-walk | grep 'USB2.0 Storage Device' -B50 | grep 'looking at parent device' | tail -n 1 | cut -d"'" -f2)
    if [ -z $DEVICE ]; then
        echo 'not an USB mass storage device'
        exit 1
    fi
fi



All times are GMT -5. The time now is 05:43 PM.