tag:blogger.com,1999:blog-9634563.post7102966818533922815..comments2024-01-20T06:05:44.200-08:00Comments on Yan Li's Words: Safely remove an USB hard drive in LinuxYan Lihttp://www.blogger.com/profile/02019884916024750698noreply@blogger.comBlogger89125tag:blogger.com,1999:blog-9634563.post-15779166149953901682019-03-27T04:14:17.063-07:002019-03-27T04:14:17.063-07:00Thanks for nice info. See my blog too wireless har...Thanks for nice info. See my blog too <a href="https://www.cdhpl.com/best-wireless-hard-drive/" rel="nofollow">wireless hard drive cdhpl</a>Atifhttps://www.cdhpl.comnoreply@blogger.comtag:blogger.com,1999:blog-9634563.post-16028396734458841002015-04-26T10:07:22.964-07:002015-04-26T10:07:22.964-07:00Those two pages are related and extremely useful:
...Those two pages are related and extremely useful:<br /><br /><a rel="nofollow">http://ubuntuforums.org/showthread.php?t=1122670</a><br /><br /><a rel="nofollow">http://sourceforge.net/projects/windirstat/</a>Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-9634563.post-10334180215887457742014-10-28T13:27:15.512-07:002014-10-28T13:27:15.512-07:00Hello,
The script works like a charm, thanks a l...Hello, <br /><br />The script works like a charm, thanks a lot.<br />only required to install sdparm.<br /><br /><br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-9634563.post-58686027598885981052014-01-06T04:45:54.783-08:002014-01-06T04:45:54.783-08:00I've got error bad argument while echo 'su...I've got error bad argument while echo 'suspend' ...<br />This was because commands have changed in new kernel.<br /><br />Solution found @ https://bbs.archlinux.org/viewtopic.php?id=95659<br /> <br />echo "0" > "/sys/bus/usb/devices/$port/power/autosuspend"<br />echo "auto" > "/sys/bus/usb/devices/$port/power/level"Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-9634563.post-82756600857291632002012-01-25T19:05:48.233-08:002012-01-25T19:05:48.233-08:00The answer to the users that report "Permissi...The answer to the users that report "Permission denied" is to go into a root shell by typing: sudo -i<br />then you can just write the echo ... > ... commandsAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-9634563.post-6756097445550171982011-12-07T07:22:04.748-08:002011-12-07T07:22:04.748-08:00I'm not sure but... udisks --detach /dev/sdxI'm not sure but... <i>udisks --detach /dev/sdx</i>Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-9634563.post-82018659142930985272011-11-11T03:58:34.776-08:002011-11-11T03:58:34.776-08:00interesting, but shouldn't there be a simple w...interesting, but shouldn't there be a simple way like in windows.<br />using the safe remove option in the <b>disk manager</b> after unmounting the external drive will stop the drive and save you the extra worka.r.hlayhelnoreply@blogger.comtag:blogger.com,1999:blog-9634563.post-41816002231937335152011-07-21T05:28:33.570-07:002011-07-21T05:28:33.570-07:00I'm happy that this old script is still useful...I'm happy that this old script is still useful to the world.<br /><br />Maybe you should report the Ubuntu/GNOME bug to them (that sounds serious to me). Personally I'm using various versions of Debian on many machines and I haven't observed such an issue so maybe it's Ubuntu-specific. Actually it's because I feel the GNOME is doing well enough on this little task so I don't have to maintain my ad hoc script any more.Yan Lihttps://www.blogger.com/profile/02019884916024750698noreply@blogger.comtag:blogger.com,1999:blog-9634563.post-27120839162411927682011-07-21T04:07:04.484-07:002011-07-21T04:07:04.484-07:00Yan Li, I've used your script countless times ...Yan Li, I've used your script countless times but I've never got the time to Thank you!<br /><br />Actually the stupid ubuntu/gnome does the same with safely remove, but AFTER A FEW SECONDS IT SPINS UP THE DRIVE AGAIN!!!<br /><br />Your script puts the drive for good in the powerdown mode!!!<br /><br />I had however recently the need to perform it on a centos 5 which does not have udevadm so I had to modify this line to make it work in centos 5:<br /><br />DEVICE=$(udevinfo -q path -n ${DEV_NAME} -a -p /sys/block/`echo ${DEV_NAME}|sed 's/\/dev\///'`/device/ | \Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-9634563.post-19709071474003294102011-05-19T08:27:44.949-07:002011-05-19T08:27:44.949-07:00Dude Thanks for this,demonstrating how to do this ...Dude Thanks for this,demonstrating how to do this help me a lot.mens bootshttp://www.mensusa.com/tools.aspx?ID=163&Page=3noreply@blogger.comtag:blogger.com,1999:blog-9634563.post-15803396260848074302011-05-19T08:26:19.853-07:002011-05-19T08:26:19.853-07:00ThanksThanksReview Daddyhttp://reviewdaddy.blogspot.com/noreply@blogger.comtag:blogger.com,1999:blog-9634563.post-57822959568532934352011-03-13T09:50:06.308-07:002011-03-13T09:50:06.308-07:00Well actually, Windows 7 dont power off my wd pass...Well actually, Windows 7 dont power off my wd passport anymore, while ubuntu and other udisk based distros do. So just use gnome disk utility to make that possible for your distroUnknownhttps://www.blogger.com/profile/00047047507655261137noreply@blogger.comtag:blogger.com,1999:blog-9634563.post-65791368763472794172011-03-13T09:40:19.562-07:002011-03-13T09:40:19.562-07:00Thank you for your answer.
Yes, it's the same...Thank you for your answer.<br /><br />Yes, it's the same behavior under Windows.<br />I expected a way to manually and completely power it down.<br />If it's no longer supported, I will do without.krnoreply@blogger.comtag:blogger.com,1999:blog-9634563.post-35164965393549442812011-03-12T02:26:49.296-08:002011-03-12T02:26:49.296-08:00@kr it's hard to say. Perhaps you can try the ...@kr it's hard to say. Perhaps you can try the driver on an officially supported OS (hint: Windows) and see whether it keeps spinning after being removed from the OS. If it spins similarly then I speculate it should be safe to be removed then.<br /><br />Actually after GNOME has built-in "Safe remove" function this script is no longer useful anymore. Moreover, I heard it doesn't work with latest kernels due to changes in the USB power management knob.Yan Lihttps://www.blogger.com/profile/02019884916024750698noreply@blogger.comtag:blogger.com,1999:blog-9634563.post-29286875422301835472011-03-09T04:16:06.338-08:002011-03-09T04:16:06.338-08:00Hi Yan Li,
I found your explanations useful, but ...Hi Yan Li,<br /><br />I found your explanations useful, but the script is not working as expected for me (or is it my drive ?).<br /><br />I'm using a 2.6.36 kernel and, as BlackFateGR said, I had an error with this line (at the end) :<br /><i>echo 'suspend' > "$POWER_LEVEL_FILE"</i><br />I replaced the 'suspend' by 'auto' (as suggested) and the error message disappeared...<br /><br />...but the drive is still spinning, with the lights off !<br /><br />It's a Seagate GoFlex. Is it safe to remove a spinning drive ?krnoreply@blogger.comtag:blogger.com,1999:blog-9634563.post-54212448277755980202011-01-28T01:57:26.736-08:002011-01-28T01:57:26.736-08:00This is brilliant, thanks for taking the time to w...This is brilliant, thanks for taking the time to write this post. I've struggled with this problem for quite a while until coming across this post. It's quite easy to follow your steps and I haven't come across any problems, thanks again.promotional usb driveshttp://www.promo-usb.netnoreply@blogger.comtag:blogger.com,1999:blog-9634563.post-80594739448439486132010-09-13T07:48:49.063-07:002010-09-13T07:48:49.063-07:00That's a very useful script, thanks!
Incident...That's a very useful script, thanks!<br /><br />Incidentally, is it possible to reverse the process, i.e. power the USB drive back on and have it reconnect? The reason is that I want to use USB drives for backup, and don't want them running when not doing backup (ideally I'd have one drive per day used in rotation, the way we used to do with tapes), and want them to be powered on by software. At the moment I do this with a timer switch, kill the power to the drive for 15 minutes once a day and let your script power it off after backup, but that's rather inelegant.Unknownhttps://www.blogger.com/profile/09748009919255519933noreply@blogger.comtag:blogger.com,1999:blog-9634563.post-23662167603740643092010-08-09T08:38:57.658-07:002010-08-09T08:38:57.658-07:00@Yan Li: You are completely right, I had to put so...@Yan Li: You are completely right, I had to put some sleep commands, and I only need one sdparm-stop.<br /><br />At the end, taken your original script and reducing the number of sleep commands, this is the only change needed (between sdparm-sync and sdparm-stop):<br /># send HD sleep command<br />[[ $VERBOSE == 1 ]] && echo "Sleeping device $DEV_NAME"<br />sleep 1<br />hdparm -Y "$DEV_NAME" >/dev/null 2>/dev/null || true<br /><br />There's still one little problem: the led doesn't switch off. I'm not sure why, because sometimes it does. Anyway, being on or off, later when the device is unbound, the led get switched on again.<br />Not a big problem, I think? But, the usb link is not in suspend state then, isn't it?<br /><br />I'll like to make this automatic when I press unmount or remove-safely. Do you know if this can be done with udev rules? (I've been looking here: http://reactivated.net/writing_udev_rules.html#external-run)<br /><br />Thanks for your comments!Enriquehttps://www.blogger.com/profile/01372162591620878430noreply@blogger.comtag:blogger.com,1999:blog-9634563.post-78511654262751728492010-08-09T06:25:27.772-07:002010-08-09T06:25:27.772-07:00@Enrique: an obviously difference between running ...@Enrique: an obviously difference between running commands from command-prompt and within a script is the pause between commands. Perhaps you can try to add a few "sleep 2" between the commands in the script. Also I'd suggest remove "2. sdparm-stop" and try again.Yan Lihttps://www.blogger.com/profile/02019884916024750698noreply@blogger.comtag:blogger.com,1999:blog-9634563.post-61337401762696781702010-08-09T06:16:40.814-07:002010-08-09T06:16:40.814-07:00I have tried to adapt your script to my iomega USB...I have tried to adapt your script to my iomega USB-HD. But something really weird is happening: the hdparm -Y instruction is very slow when it is run from the script. I don't know why.<br /><br />Thus, I've been playing with the following (you already know the full commands):<br />- sdparm-sync<br />- sdparm-stop<br />- hdparm-y<br />- unbind<br /><br />From the command line, the following seems to work:<br />1. sdparm-sync<br />2. sdparm-stop<br />3. hdparm-y (spindown)<br />4. sdparm-stop again to power down (switch led off)<br />5. unbind<br />If step 2 is not done, it doesn't work.<br />If step 5 is not done, after a few (~10) seconds the disc is resumed (spinning again).<br /><br />Unfortunately, if I adapt the script to do the 5 steps above, it doesn't work: hdparm-y takes so much time and the disc is resumed. Any idea, why the script behaves differently?Enriquehttps://www.blogger.com/profile/01372162591620878430noreply@blogger.comtag:blogger.com,1999:blog-9634563.post-46420083564805002302010-08-08T22:58:32.672-07:002010-08-08T22:58:32.672-07:00@Enrique, I'm sorry that I don't have an ...@Enrique, I'm sorry that I don't have an iomega USB-2.5"HD to test and your problem seems device-specific. As to my knowledge I think "hdparm -Y" is safe (but no guarantee).<br /><br />You can edit my script and replace the "sdparm --command=stop" line with the "hdparm -Y" and try it with your HD.<br /><br />Good luck!Yan Lihttps://www.blogger.com/profile/02019884916024750698noreply@blogger.comtag:blogger.com,1999:blog-9634563.post-28825775272498641722010-08-06T06:13:35.759-07:002010-08-06T06:13:35.759-07:00Nice to see that somebody is concerned with this i...Nice to see that somebody is concerned with this issue. I've been using Linux during 6 years and I've got 3 HD (1 external and 2 internal) broken. They've always shut down while still spinning, making an annoying noise.<br /><br />The script doesn't work with an iomega USB-2.5"HD. However, after (only!) unmounting the disk, the following seems to spin it down (only LED light is kept):<br />$ sudo hdparm -Y /dev/sdc1<br />/dev/sdc1:<br /> issuing sleep command<br /> HDIO_DRIVE_CMD(sleep) failed: Invalid exchange<br />where /dev/sdc1 is the USB-HD device.<br /><br />Is it safe? If note, How should I adapt your script to support my disk too, so the other/missing steps are done?<br />or, maybe, is there any cleaner and automatic solution (probably with udev rules)?<br /><br />ThanksEnriquehttps://www.blogger.com/profile/01372162591620878430noreply@blogger.comtag:blogger.com,1999:blog-9634563.post-84557048568691673002010-07-23T22:44:43.664-07:002010-07-23T22:44:43.664-07:00I suggest this site to my friends so it could be u...I suggest this site to my friends so it could be useful & informative for them also. Great effort.Canada flower shopshttp://www.flower-canada.canoreply@blogger.comtag:blogger.com,1999:blog-9634563.post-13912062627308527312010-06-07T18:59:43.555-07:002010-06-07T18:59:43.555-07:00Hi, great script! I discovered it after looking i...Hi, great script! I discovered it after looking into sdparm myself. I found that --command=stop didn't spin down my USB disk.<br /><br />When I run your script I get ./suspend-usb-device: line 180: echo: write error: Invalid argument<br /><br />This comes from the last command: echo 'suspend' > "$POWER_LEVEL_FILE". If I find the level file and try to echo to it myself (as root) I get the same error. I have CONFIG_USB_SUSPEND built into my kernel.<br /><br />The disk is an Hitachi HTS545016B9A300 in an Astone USB/eSATA external case (I'm using the USB port since I don't have eSATA on my laptop). The case is listed as:<br />152d:2339 JMicron Technology Corp. / JMicron USA Technology Corp.<br /><br />The device does disappear from /dev though.<br /><br />Any ideas? Thanks :)iaindbhttp://nthrbldyblg.blogspot.com/noreply@blogger.comtag:blogger.com,1999:blog-9634563.post-16499153383933629152010-05-29T08:40:58.512-07:002010-05-29T08:40:58.512-07:00There is not really a need to use hdparm. sdparm c...There is not really a need to use hdparm. sdparm covers all that's done through sd (including, but not limited to, SCSI, USB, IEEE1394, SATA and PATA).j.enghttps://www.blogger.com/profile/09615346206411435754noreply@blogger.com