Announcement

Collapse
No announcement yet.

What best option to shutdown or sleep hard disks after x minutes?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    What best option to shutdown or sleep hard disks after x minutes?

    Hi,
    In my desktop I have a nvme for kubuntu and 2 mechanical hard disks for backups and info.
    I want shutdown or sleeps this hard disks (mechanicals) after 5 minutes of not use, but I don't want unmount before, I have a backup software and this soft need the hard drivers are mountes.
    I try some differents options, but I can't made this.
    Some iddea?
    Thanks in advance.

    #2
    I spin down my mechanical drives with, f. ex.
    Code:
    sudo hdparm -y /dev/disk/by-label/stuff
    (The label of any partition on the drive will do; if the labels are not stable or meaningful the block device /dev/sdX will be fine but can change if drives are plugged in or out. )

    I suggest you read the man page for hdparm.

    3 years ago I tried to set a time to go to standby but didn't get it to work. I quickly decided I didn't want to wait for a timeout anyway (the vibration got on my nerves) so I spin them down straight away. If I access the drives there's a few seconds delay as they spin up.
    Regards, John Little

    Comment


      #3
      Originally posted by jlittle View Post
      I spin down my mechanical drives with, f. ex.
      Code:
      sudo hdparm -y /dev/disk/by-label/stuff
      (The label of any partition on the drive will do; if the labels are not stable or meaningful the block device /dev/sdX will be fine but can change if drives are plugged in or out. )

      I suggest you read the man page for hdparm.

      3 years ago I tried to set a time to go to standby but didn't get it to work. I quickly decided I didn't want to wait for a timeout anyway (the vibration got on my nerves) so I spin them down straight away. If I access the drives there's a few seconds delay as they spin up.
      Thanks,
      I read about this, for me I prefer sleep or shut down my mechanical drives, not problem for me if when go to access to drive, wait 1, 2 or 3 seconds.
      But I don't know how configure the command for sleep or down the drivers after, for example, 5 minutes that last access, and I need insert the comand automaticaly, I'm explained, not input manually every time.
      The lavels of drives not changes, and not plugged in or out, are fixed in my desktop.

      PD: Sorry for my english.

      Thanks and regards.

      Comment


        #4
        Well, there is a thing called hd-idle, but you have to compile it from source.

        Otherwise it's a matter of putting the right parameters in /etc/rc.local.
        See here.

        Obviously, you don't use pluma or gedit, you use kate, and you don't need sudo - actually you don't want it - as you simply get asked for a password when you save the file. :·)

        Comment


          #5
          I had another look at this, and found that hdparm -S works on my (oldish) Seagate drive, but not my WD black. So you might be lucky. I found a report that for Samsung drives one can use the APM setting, using hdparm -B.

          If you have hdparm settings you want to use always, you can set them in /etc/hdparm.conf. I haven't used that.
          Regards, John Little

          Comment


            #6
            Sorry for my delay in reply, this week end I'm out.

            I go to try / config all about this, when I finish, I reply with results, and if its ok or some problem.

            Thanks and regards!

            Comment


              #7
              After some days, I return with this, this lasts days I can't made any about this, I don't have much time in the lasts days...

              I read the indicate for Don B. Cilly, goot link and instructions for this, thanks

              But after, I read this:

              Originally posted by jlittle View Post
              ...
              If you have hdparm settings you want to use always, you can set them in /etc/hdparm.conf. I haven't used that.
              I have /etc/hdparm.conf but all lines with #.
              I view -S and -B, I read the help page about hdparm, but I think that, the option -B not standby the hard disks, this is the description of -B option:
              Code:
              Get/set Advanced Power Management feature, if the drive supports it. A low value means aggressive power management and a high value means better performance. Possible settings range from values 1 through 127 (which permit spin-down), and values 128 through 254 (which do not permit spin-down). The highest degree of power management is attained with a setting of 1, and the highest I/O performance with a setting of 254. A value of 255 tells hdparm to disable Advanced Power Management altogether on the drive (not all drives support disabling it, but most do).
              Not indicate standby.
              But the option -S, yes, indicate standby, but I don't know how configure this in hdparm.conf
              This is the 2 lines about -S in hdparm.conf.
              Code:
              # -s Turn on/off power on in standby mode# poweron_standby = off
              # -S standby (spindown) timeout for the drive
              #spindown_time = 24
              First line, chage off to on
              Second, about time, the 24 value I don't know what time is this and if we can change of values are in the link of Don B. Cilly.

              After read this, I think, try first option, the indicate of Don B. Cilly, I go to try this tomorrow.

              Thanks and regards!
              Last edited by wonder; Oct 10, 2019, 03:02 PM.

              Comment


                #8
                In post #4, Don. B. Cilly suggested hd-idle, and I had a look at this. It's conceptually simple; in /proc/diskstats there's various statistics about each device, including read and write counts. If these don't change for a while, then disks are spun down.

                I'm giving it a whirl*. It doesn't check whether drives are rotational; seems not right. It works so far.

                (*That is, I'm trying it out, as we say in my part of the world; I'm not sure that's standard English.)
                Regards, John Little

                Comment


                  #9
                  Hello.
                  I view the /proc/disktats, but I don't know how read this file, I view a lot numbers
                  I supuse that, this numbers not change (or yes).
                  I continue this week end with my tests.

                  Regards.

                  Comment


                    #10
                    Originally posted by wonder View Post
                    I view the /proc/disktats, but I don't know how read this file, I view a lot numbers
                    See kernel.org short list, or with some explanation.
                    Regards, John Little

                    Comment


                      #11
                      Originally posted by jlittle View Post
                      I spin down my mechanical drives with, f. ex.
                      Code:
                      sudo hdparm -y /dev/disk/by-label/stuff
                      (The label of any partition on the drive will do; if the labels are not stable or meaningful the block device /dev/sdX will be fine but can change if drives are plugged in or out. )

                      I suggest you read the man page for hdparm.

                      3 years ago I tried to set a time to go to standby but didn't get it to work. I quickly decided I didn't want to wait for a timeout anyway (the vibration got on my nerves) so I spin them down straight away. If I access the drives there's a few seconds delay as they spin up.
                      Originally posted by Don B. Cilly View Post
                      Well, there is a thing called hd-idle, but you have to compile it from source.

                      Otherwise it's a matter of putting the right parameters in /etc/rc.local.
                      See here.

                      Obviously, you don't use pluma or gedit, you use kate, and you don't need sudo - actually you don't want it - as you simply get asked for a password when you save the file. :·)
                      (I go to try in /etc/rc.local, I view that I don't have this folder, but I can create and the file inside folder)

                      After some tests, this is the only works for me:
                      If I use:
                      Code:
                       [FONT=monospace]sudo hdparm -S60 /dev/sdd[/FONT]

                      Appears this:
                      Code:
                      [FONT=monospace]/dev/sdd:
                      setting standby to 60 (5 minutes)[/FONT]

                      But at the after 5 minutes, only 1 hard disk is down (I execute this command for every hard drive chage the sdx) only down the Toshiba hard drive, the others drivers (WDC) not down.

                      If I type:
                      [coded]
                      sudo hdparm -Y /dev/sd?[/code]
                      All devices is down (good).

                      All this in konsole.

                      Also with:
                      Code:
                      [FONT=monospace]sync && for a in /dev/sd? ; do sudo hdparm -Y "$a" ; done[/FONT]


                      I think that, I can configure hdparm.conf, I try some differents configurations,
                      but my knowledge and what I have read and tried have not worked ...

                      Thanks and regards!

                      Last edited by wonder; Oct 25, 2019, 03:36 AM.

                      Comment


                        #12
                        Hello again

                        Finally, after search, read, test... I view that:
                        Of my 3 hard drivers (mechanicals) only 1 is supported by hdparm, the others 2 hard drivers, aren't supported by hdparm (hdparm -S) at this option, with others options, yes, all hard drives work, but I want/need the option -S (stand by after x minutes...).

                        Finally, I "solved" (its a solution not perfect but work), adding this to the crontab of root:

                        Code:
                        #Shut down hard disks:
                        */10 *  * * *  root    sync && hdparm -y /dev/sda 
                        */10 *  * * *  root    sync && hdparm -y /dev/sdb 
                        */10 *  * * *  root    sync && hdparm -y /dev/sdc
                        With this, every 10 minutes stand by the hard drivers.

                        Is not the best solution, but work fine...

                        Regards.

                        Comment


                          #13
                          hd-idle works. I've been running it since 2019-10-11, and through the release upgrade to eoan. It's been set and forget. Using a cron job seems a bit clumsy, it might spin a disk down while you're using it.

                          If someone is interested, git clone and make were straightforward, but installing via the debian instructions was a bit messy. I got there without too much bother, but I suspect
                          • make install
                          • copying hd-idle.default to /etc/default/hd-idle and editing it according to the comments in that file
                          • copying hd-idle.init to /etc/init.d/hd-idle
                          • setting that to run via your favourite init system, such as systemd, if you were familiar with such, which I am not

                          would be simpler.
                          Regards, John Little

                          Comment


                            #14
                            Again, sorry for my delay in reply, the lasts days/weeks I'm working in others and this work, wait to get free time.
                            This week end I go to work in this.

                            Like you, I think the best option is hd-idle, like you indicate, using a cron job, its possible spin a disk down wile I'm using it.

                            About your instructions for install:

                            Originally posted by jlittle View Post
                            • make install
                            • copying hd-idle.default to /etc/default/hd-idle and editing it according to the comments in that file
                            • copying hd-idle.init to /etc/init.d/hd-idle
                            • setting that to run via your favourite init system, such as systemd, if you were familiar with such, which I am not

                            would be simpler.
                            I have kubuntu (like you?) if its yes, if you are using hd-idle since 2019-10-11, you install like you indicate in your post?

                            I search info about install, and I search this:
                            Code:
                            To install hd-idle on Ubuntu:
                            wget https://downloads.sourceforge.net/project/hd-idle/hd-idle-1.04.tgz
                            tar xvfz hd-idle*.tgz
                            cd hd-idle
                            sudo apt-get install debhelper
                            sudo dpkg-buildpackage -uc -us -rfakeroot
                            cd ..
                            sudo dpkg -i hd-idle_*.deb
                            # To run at startup:
                            sudo update-rc.d hd-idle defaults
                            nano /etc/default/hd-idle
                            Note: This instructions are very old...

                            Your steps all ok, except the last, for me, set that run via my favourite init system...what step suggest you for init at startup?

                            Thanks and regards!

                            Comment


                              #15
                              Well, after a long time, it was not something that urged me because I stopped the hard drives through cron, I finally got free time to get on this issue and be able to solve it.
                              The instructions mentioned in my previous post, installation instructions, did not work for me, specifically these:

                              Code:
                              To install hd-idle on Ubuntu:
                              wget https://downloads.sourceforge.net/project/hd-idle/hd-idle-1.04.tgz
                              tar xvfz hd-idle*.tgz
                              cd hd-idle
                              sudo apt-get install debhelper
                              [B]sudo dpkg-buildpackage -uc -us -rfakeroot[/B]
                              cd ..
                              sudo dpkg -i hd-idle_*.deb
                              # To run at startup:
                              sudo update-rc.d hd-idle defaults
                              nano /etc/default/hd-idle
                              The line marked in bold, gave me an error at the end, which I do not remember exactly, something similar to incompatibility of versions in, now I do not remember, exactly what (and what I have done this weekend )

                              Finally, I was able to install it with this method:

                              Code:
                              0) install additional 'build / make' files
                              sudo apt-get install debhelper
                              sudo apt-get install fakeroot
                              sudo apt-get install build-essential
                              
                              *Note: fakeroot and build-essentials, I was installed, but its good indicate that we need have installed this.
                              
                              1) make a download directory
                              mkdir hd-hidle_download
                              1.1) enter the directory **
                              cd hd-hidle_download
                              
                              2) download the 'hd-idle' source package file
                              wget sourceforge.net/projects/hd-idle/files/hd-idle-1.04.tgz
                              2.1) extract the package **
                              tar xvfz hd-idle*.tgz
                              
                              3) enter the extracted 'hd-idle' folder, it is one directory down
                              cd hd-idle
                              
                              4) make the '*.deb' file
                              sudo dpkg-buildpackage -rfakeroot
                              4.1) goto the made *.deb file, it is one directory up
                              cd ..
                              
                              5) install the '*.deb' file
                              dpkg -i hd-idle_*.deb
                              
                              - 'hd-idle' setup -
                              open the 'hd-idle' configuration file via the 'nano' editor or direct, go to file and edit (in kubuntu we can save with root permissions).
                              nano /etc/default/hd-idle
                              1) insert for each HDD (accessed via their UUIDs) a spin-down command '-a /dev/<...> -i 600', e.g. spin-down of 3 HDDs after approx. 600 seconds **
                              In my case, in the same line, I indicate my 3 hard disks:
                              HD_IDLE_OPTS="-i 0 -a /dev/disk/by-uuid/c577b4a5-5ab8-40f4-90f6-fedf81a61a47 -i 300 -a /dev/disk/by-uuid/6adfe9b4-5cc5-41da-a9f7-020ac625e96b -i 310 -a /dev/disk/by-uuid/c712aa79-a917-4385-9c77-89d8f23f124d -i 320"
                              -Note: One is at 300 seconds, the second hard disk at 310 and the third hard disk at 320 seconds.
                              
                              * hint: Parameter '-i 0' at the beginning avoids spin-down of not explicitly specified HDDs. 
                              2) allow hd-idle to start, in that file, uncomment the line:
                              START_HD_IDLE=true
                              3) save the file.
                              
                              Now, start the service:
                              
                              sudo service hd-idle start
                              or:
                              systemctl enable hd-idle-restart-resume.service
                              systemctl start hd-idle-restart-resume.service
                              
                              and then check the service:
                              
                              systemctl status hd-idle-restart-resume.service
                              
                              You can check, after the seconds configuated, the hard disks:
                              sudo hdparm -C /dev/sdx 
                              * x=value of the hard disk.
                              Everything perfect, it works perfectly! At the configured seconds, the hard drives sleep.
                              But ... if we suspend the computer or hibernate, when it resumes, hd-idle no longer works. It only works when we start the computer or restart, if we suspend or hibernate it, when it resumes, it no longer works.
                              After much reading, I saw that this happens because the hd-idle counter, I do not remember now exactly, does not count well when we wake up the computer to sleep or hibernate.

                              I have seen two solutions for this, I have used the first one, and it works perfectly for me, the second one, I don't know if it works but I imagine it does.

                              Code:
                               We need created a new systemd-unit that restarts the hd-idle service, see attachment (link indicate at the end). It needs to be put into
                              /etc/systemd/system/
                              and must be activated with the command
                              systemctl enable hd-idle-restart-resume.service
                              (I guess debhelper will care for this to be added to postinst)
                              
                              Link to the patch:
                              [URL="https://sourceforge.net/p/hd-idle/patches/2/attachment/hd-idle-restart-resume.service"]hd-idle-restart-resume.service[/URL]
                              With this, works pefect, also when start, wake up from sleep or hibernate, hd-idle works perfect!

                              The second solution for fix this issue is this:

                              Post and patch by Matthew Murdock
                              Code:
                              I created a patch to address the resume issue. The approach taken here is to identify if the sleep took longer than expected and reset the spum_down flag if we waited too long for the main loop sleep. This should capture suspend events as well as excessive machine load.
                              
                              I also added a few more log functions (included in the patch). Perhaps the logging could be revised as a separate thread, or employ syslog if your platform environment includes syslog?
                              
                              [URL="https://sourceforge.net/p/hd-idle/patches/_discuss/thread/9bcf69f6/14dc/attachment/hd-idle_resume.patch"]hd-idle_resume.patch[/URL]
                              The two solutions for fix the issue when resume from sleep or hibernate have a date of 2019-01-24 in this page/link.

                              I hope it can help someone, I am doing very well, I have 3 mechanical hard drives which I access very little (rather to save data and backups) and the computer is many hours on throughout the day, With this, I sleep with all the benefits that entails.
                              I also hope that the next Kubuntu 20.04 will work
                              Last edited by wonder; Feb 09, 2020, 07:44 PM.

                              Comment

                              Working...
                              X