Is there a way to check if the USB drive is stopped?

I wrote a script to back up my HD server every night. At the end of the script, I sync, wait a couple of minutes, sync and then I issue sg_start --stop

to stop the device. The idea is to extend the lifespan of the device by disabling HD after ten minutes of incremental backups (desktop drives will survive several thousand on / off cycles, but only a few hundred hours of continuous use).

This doesn't always work; The next morning I often find that the disc is still spinning. Is there a shell command I can use to check that the disk is stopped (so I can issue the stop command [EDIT2] again, or write a script to create a list of processes when the drive is running, so I can debug this [/ EDIT2]) ?

[EDIT] I've tried sg_inq (as suggested in the sg_start man page), but this command always returns 0.

I tried hdparm , but it always returns "disk status: unknown" for USB sticks (connected via / dev / sdX) and when you try to unscrew the drive I get "HDIO_DRIVE_CMD (setidle1): I / O error".

sdparm seems to support setting the idle timer on disk (see Power Status Page), but the IDLE parameter is Changeable: n and I haven't found an option that tells me the power status of the drive.

[EDIT2] Note. I can stop the disk using sg_start --stop

from the console. It always works; he just doesn't always stay until midnight. North is in the basement (where it's nice and cool) and I would rather check if the drive is up or not in the warm living room :) If I had a command that told me about the state of the drive, I could write a script. to alert me when it spins (check every minute) and then I can try to figure out what might be causing this.

If it matters: I'm using openSUSE 11.1.

+1


source to share


5 answers


When you say that you tried hdparm, you didn't say which which you tried. I have some usb hard drives in the case and some of them work for it and others don't, but I guess it all depends on all aspects of the transport mechanism.

  hdparm  -S 120  /dev/sda  

      

I must say that the disk sleeps by itself after ~ 10 minutes of inactivity.

I assume you've already tried this, but it's not obvious, and writing this as an answer might help a future reader.

Nothing accesses the drive but the backup script.

      

This is fine in theory, but I have found that in some cases it is not enough. There are many processes and tasks that, even if they are looking at the disk, reversals can occur if the search is for some reason due to the disk cache.

Common culprits are tools like updatedb

scanning all mounts for files, and fam

or gamin

- creating funky drives to track disks for changes.

When in doubt, add a layer of confidence by setting the device before executing the script and unmounting it when done.

See things that can cause awakening

 lsof +D /mountpoint

      

You should probably analyze the output of this file before trying to disable it to make sure it is still not trying to use it.



You should probably also be doing a lazy umount ,

 umount -l /mountpoint 

      

so if something is accessing it between you doing lsof| grep

and calling umount

, it will still unmount the disk and stop reading it.

HAL and friends

It is also possible that HAL and friends are awakening to probe probes for join / delete status. I really hope this is not the case, but it does happen on some types of devices. This seems like an unlikely cause, but I'll consider everything possible.

Try to please, for example

lsof /dev/devicehere 

      

and

lsof /dev/devicehere1 

      

It seems to be getting a complete list of all the things that will access the handle directly or indirectly.

+3


source


You also need to check the mount options and use "noatime" as the mount parameter, otherwise the kernel will periodically update the access time. This could be the cause of your problem.



+2


source


I often find that the disc is still spinning the next morning.

It can't just be because it was deployed again when the server, for example. was writing to a log file or something at night? You can try sdparm, which can return disk status information. But I think it's better to just set an option in your BIOS that allows your HD to auto-spin after some amount of inactivity, it's easier.

0


source


Have you tried to stop the disk with the following command:

eject -t /dev/yourHD

      

This works well for USB hard drives.

0


source


If you hdparm -C /dev/sda

said drive state is: unknown

what it is not supported for your disk, and there is no way to tell

Your additional questions (already answered by others)

  • what's using the disk?
    • Lsof
    • thermoelement
    • Triggers
  • how to make the disk stay asleep?
    • HDPARM
    • unmount
    • your device can still be woken up when unmounted, but most likely only with what you are doing (smartctl, blkid, etc.).

Related: You can also automatically pause backups or whatever for an hour if your drives are hot.

0


source







All Articles