HC1/HC2 - properly park harddisk on shutdown

Moderators: odroid, mdrjr

HC1/HC2 - properly park harddisk on shutdown

Unread postby fvolk » Sun Nov 19, 2017 6:13 pm

With the firmware utility the harddisk no longer autoparks constantly when not in use -> very good.
However, on HC1 shutdown the harddisk is not properly parked.
Observed on both official xenial 4.9. as well as Armbian.

Symptom:
With my mechanical harddisk everytime I shutdown I hear a noticeable *clack* sound from the disk.
Everytime this happens this increases the SMART attribute "Power-Off_Retract_Count" by 1.
This is indicative of a "hard" power cut to the disk, meaning emergency head parking is performed, which reduces the lifespan of the disk faster than normal head parking.

Workaround:
Unmount all filesystems from /dev/sda.
Give disk command to spin-down itself in a controlled way, e.g. by "hdparm -y /dev/sda".
Then do shutdown.
"Power-Off_Retract_Count" does not increase.

The HC1 is special in that the disk hangs of a USB/SATA bridge, so maybe this case is not properly handled in default shutdown scripts?
Ideally, something needs to check during shutdown that the disk is still spinning (e.g. hdparm -C) and if yes, park the disk.
fvolk
 
Posts: 187
Joined: Sun Jun 05, 2016 11:04 pm
languages_spoken: english
ODROIDs: C2, HC1

Re: HC1 - properly park harddisk on shutdown

Unread postby neal » Mon Nov 20, 2017 12:24 pm

fvolk wrote:Unmount all filesystems from /dev/sda.
Give disk command to spin-down itself in a controlled way, e.g. by "hdparm -y /dev/sda".
Then do shutdown.
"Power-Off_Retract_Count" does not increase.

It seems to be working.
Code: Select all
root@odroid:~# alias poweroff='udisksctl unmount -b /dev/sda1 && udisksctl power-off -b /dev/sda && poweroff'
root@odroid:~# poweroff
neal
 
Posts: 157
Joined: Fri Apr 14, 2017 10:02 am
languages_spoken: english

Re: HC1 - properly park harddisk on shutdown

Unread postby fvolk » Tue Nov 28, 2017 5:43 am

While a custom poweroff command alias is a workaround, I think most users don't know or are even aware of this problem.
This should be handled in the shutdown scripts after fs unmounts from sda. Does anyone know where is the proper location in the shutdown scripts?

Especially SSD users do not "hear" a difference, but I read SSDs are even more sensitive to hard power cuts than mechanical disks. On a Samsung SSD I found the SMART attribute "POR_Recovery_Count" that records unclean shutdowns. Anyone with an SSD can report whether they see increases?
fvolk
 
Posts: 187
Joined: Sun Jun 05, 2016 11:04 pm
languages_spoken: english
ODROIDs: C2, HC1

Re: HC1 - properly park harddisk on shutdown

Unread postby tkaiser » Thu Dec 14, 2017 10:53 pm

POR_Recovery_Count increases with a Samsung EVO 840 regardless of using internal JMS578 or external (ROCK64 SATA cable), it also doesn't matter whether I use firmware v173.01.00.01 or the SATA cable's original v0.4.0.5)

Sending the disk to sleep manually prior to shutting the board down prevents increasing the counter.
tkaiser
 
Posts: 572
Joined: Mon Nov 09, 2015 12:30 am
languages_spoken: english
ODROIDs: C1+, C2, XU4, HC1

Re: HC1 - properly park harddisk on shutdown

Unread postby tkaiser » Fri Dec 15, 2017 5:53 pm

I tested now with an ASM1153 enclosure (no problems at all, serial number reported correctly, no SAT / spindown problems, no POR increase at shutdown) and another JMicron. JMS567 with different firmware showing exactly same symptoms:

Code: Select all
root@odroidxu4:~# smartctl -a -d sat /dev/sdb | grep POR_Recovery_Count
235 POR_Recovery_Count      0x0012   099   099   000    Old_age   Always       -       607
root@odroidxu4:~# JMS578FwUpdater/JMS578FwUpdate -d /dev/sdb -v
Bridge Firmware Version: v46.3.0.2


Attribute 235 value increases with every shutdown when the disk hasn't been sent to sleep/standby before. So this smells like an issue that has to be adressed at the firmware layer?
tkaiser
 
Posts: 572
Joined: Mon Nov 09, 2015 12:30 am
languages_spoken: english
ODROIDs: C1+, C2, XU4, HC1

Re: HC1 - properly park harddisk on shutdown

Unread postby odroid » Fri Dec 15, 2017 6:19 pm

I think so. We may need to contact Jmicron people again.
User avatar
odroid
Site Admin
 
Posts: 29083
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: HC1 - properly park harddisk on shutdown

Unread postby tkaiser » Mon Jan 15, 2018 4:51 pm

I got a beta firmware from JMicron but can not test currently. So anyone curious might try it and report back:

http://kaiser-edv.de/tmp/mUCIx3/JMS578_ ... 1_beta.zip (ZIP MD5 hash is 9ce5c93b2f8ba501606c46b2dbcc9d9d)
tkaiser
 
Posts: 572
Joined: Mon Nov 09, 2015 12:30 am
languages_spoken: english
ODROIDs: C1+, C2, XU4, HC1

Re: HC1 - properly park harddisk on shutdown

Unread postby Nominal Animal » Tue Jan 16, 2018 4:17 am

fvolk wrote:This should be handled in the shutdown scripts after fs unmounts from sda. Does anyone know where is the proper location in the shutdown scripts?

/lib/systemd/system-shutdown/*.shutdown.

We should use blkid -o device to obtain the list of devices to unmount and power-off (in a loop, discarding errors), rather than hard-code sda. For example, we might use /lib/systemd/system-shutdown/poweroff-unmount.shutdown (untested):
Code: Select all
#!/bin/sh
exec >/dev/null 2>/dev/null
for dev in $(blkid -o device) ; do
    udisksctl unmount -b $dev
done
for dev in $(blkid -o device) ; do
    udiskctl power-off -b $dev
done
Nominal Animal
 
Posts: 67
Joined: Sat Sep 16, 2017 12:51 pm
Location: Finland
languages_spoken: English, Finnish
ODROIDs: C1+, HC1

Re: HC1 - properly park harddisk on shutdown

Unread postby neal » Tue Jan 16, 2018 11:32 am

tkaiser wrote:I got a beta firmware from JMicron but can not test currently. So anyone curious might try it and report back:

http://kaiser-edv.de/tmp/mUCIx3/JMS578_ ... 1_beta.zip (ZIP MD5 hash is 9ce5c93b2f8ba501606c46b2dbcc9d9d)


I've tested some commands with no issues.

1. hdparm -C /dev/sda
2. hdparm -y /dev/sda
3. hdparm -S 20 /dev/sda
4. smartctl -x /dev/sda -d sat
5. fstrim /media/hdd/
6. Copy 8G file to /media/hdd/samba folder via SAMBA

Code: Select all
root@odroid:~/JMS578FwUpdater# ./JMS578FwUpdate -d /dev/sda -v
Bridge Firmware Version: v255.1.0.1

root@odroid:~/JMS578FwUpdater#
neal
 
Posts: 157
Joined: Fri Apr 14, 2017 10:02 am
languages_spoken: english

Re: HC1 - properly park harddisk on shutdown

Unread postby tkaiser » Tue Jan 16, 2018 3:59 pm

neal wrote:
tkaiser wrote:I've tested some commands with no issues.


Good to know but this firmware version should additionally fix the Power-Off Retract Count issue (cutting the power too early on shutdown/poweroff which leads to a noticable 'clack' sound with connected HDDs and increasing the appropriate SMART value). Any news here?
tkaiser
 
Posts: 572
Joined: Mon Nov 09, 2015 12:30 am
languages_spoken: english
ODROIDs: C1+, C2, XU4, HC1

Re: HC1 - properly park harddisk on shutdown

Unread postby kris777 » Tue Jan 16, 2018 5:52 pm

Good to know but this firmware version should additionally fix the Power-Off Retract Count issue (cutting the power too early on shutdown/poweroff which leads to a noticable 'clack' sound with connected HDDs and increasing the appropriate SMART value). Any news here?


this fix did not change anything
.... when switching off HC1
then you can hear a sudden clicking of the HDD ..

Code: Select all
root@odroidxu4:~/JMS578FwUpdater# ./JMS578FwUpdate -d /dev/sda -v
Bridge Firmware Version: v255.1.0.1
kris777
 
Posts: 3
Joined: Tue Nov 28, 2017 4:23 am
languages_spoken: english
ODROIDs: Odroid HC1

Re: HC1 - properly park harddisk on shutdown

Unread postby tkaiser » Tue Jan 16, 2018 6:04 pm

kris777 wrote:this fix did not change anything


Did your JMS578 device go through a full power cycle (completely powered off for some seconds after applying the firmware update)?
tkaiser
 
Posts: 572
Joined: Mon Nov 09, 2015 12:30 am
languages_spoken: english
ODROIDs: C1+, C2, XU4, HC1

Re: HC1 - properly park harddisk on shutdown

Unread postby kris777 » Tue Jan 16, 2018 6:09 pm

Did your JMS578 device go through a full power cycle (completely powered off for some seconds after applying the firmware update)?

Yes ...
I had to disconnect HC1 for a moment from the power supply because otherwise it showed me the old version of JMS578 Firmware : v173.01.00.01
kris777
 
Posts: 3
Joined: Tue Nov 28, 2017 4:23 am
languages_spoken: english
ODROIDs: Odroid HC1

Re: HC1 - properly park harddisk on shutdown

Unread postby neal » Wed Jan 17, 2018 10:55 am

kris777 wrote:
Good to know but this firmware version should additionally fix the Power-Off Retract Count issue (cutting the power too early on shutdown/poweroff which leads to a noticable 'clack' sound with connected HDDs and increasing the appropriate SMART value). Any news here?


this fix did not change anything
.... when switching off HC1
then you can hear a sudden clicking of the HDD ..

Code: Select all
root@odroidxu4:~/JMS578FwUpdater# ./JMS578FwUpdate -d /dev/sda -v
Bridge Firmware Version: v255.1.0.1


Yes, same here :(
neal
 
Posts: 157
Joined: Fri Apr 14, 2017 10:02 am
languages_spoken: english

Re: HC1 - properly park harddisk on shutdown

Unread postby sebsan » Wed Jan 17, 2018 9:50 pm

Nominal Animal wrote:
fvolk wrote:This should be handled in the shutdown scripts after fs unmounts from sda. Does anyone know where is the proper location in the shutdown scripts?

/lib/systemd/system-shutdown/*.shutdown.

We should use blkid -o device to obtain the list of devices to unmount and power-off (in a loop, discarding errors), rather than hard-code sda. For example, we might use /lib/systemd/system-shutdown/poweroff-unmount.shutdown (untested):
Code: Select all
#!/bin/sh
exec >/dev/null 2>/dev/null
for dev in $(blkid -o device) ; do
    udisksctl unmount -b $dev
done
for dev in $(blkid -o device) ; do
    udiskctl power-off -b $dev
done


Hi folks !
I managed to build a little script following these instructions and it works !!
My HDD do not "CLICK!" any more at poweroff.
/lib/systemd/system-shutdown/stop-sd

Code: Select all
#!/bin/sh
exec >/dev/null 2>/dev/null
stop_disk()
{
        /sbin/hdparm -Y $1
        sleep 5s
}

stop_all_disks()
{
        #Partition selection...
#       for dev in $(blkid -o device) ; do
#               umount -b $dev
#       done

        #Disk selection without duplicates...
        for dev in $(blkid -o device | grep /dev/sd | sed -re 's/(\/dev\/sd[a-z])[0-9]/\1/' | sort -u) ; do
                stop_disk $dev
        done
}

case $1 in
  halt)
    stop_all_disks
    ;;
  poweroff)
    stop_all_disks
    ;;
esac

Thanks a lot for your help !
sebsan
 
Posts: 1
Joined: Wed Jan 17, 2018 9:38 pm
languages_spoken: french, english
ODROIDs: odroid-XU
odroid-HC1
odroid-W

Re: HC1 - properly park harddisk on shutdown

Unread postby tkaiser » Wed Jan 17, 2018 10:13 pm

I wouldn't rely on blkid since this wakes up sleeping disks (only to send them to sleep directly after again). Directly querying the kernel seems to be more straightforward (same with waiting only if the device in question understands the hdparm command):

Code: Select all
#!/bin/bash
exec >/dev/null 2>&1
export PATH=/usr/bin:/bin:/usr/sbin:/sbin

case $1 in
    halt|poweroff)
      awk -F" " '/sd[a-z]$/ {print $4}' /proc/partitions | while read ; do
         hdparm -Y /dev/${REPLY} && sleep 2.5
      done
      ;;
esac
tkaiser
 
Posts: 572
Joined: Mon Nov 09, 2015 12:30 am
languages_spoken: english
ODROIDs: C1+, C2, XU4, HC1

Re: HC1 - properly park harddisk on shutdown

Unread postby Nominal Animal » Wed Jan 17, 2018 11:57 pm

tkaiser wrote:I wouldn't rely on blkid since this wakes up sleeping disks (only to send them to sleep directly after again).

Good point. Perhaps the following would be even better?
Code: Select all
#!/bin/bash
export LANG=C LC_ALL=C >/dev/null 2>/dev/null

case "$1" in
    halt|poweroff)
        # Ensure unwritten data is synced to disk.
        sync

        # Sync md arrays, if any
        [ -x /sbin/mdadm ] && /sbin/mdadm --wait-clean --scan

        # Put known SATA/IDE devices to sleep
        wait=0
        for dev in /sys/block/sd* ; do
            [ -e $dev ] && hdparm -Y /dev/${dev##*/} && wait=3
        done
        sleep $wait
        ;;

esac


Instead of looking at the partitions the kernel knows about, let's put all block devices the kernel knows that begin with sd to sleep. If at least one accepted the command, we'll sleep for three seconds, just to be sure.
Nominal Animal
 
Posts: 67
Joined: Sat Sep 16, 2017 12:51 pm
Location: Finland
languages_spoken: English, Finnish
ODROIDs: C1+, HC1

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby odroid » Thu Jan 18, 2018 12:00 am

Very nice ideas indeed.
I've changed this topic "STICKY".
User avatar
odroid
Site Admin
 
Posts: 29083
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: HC1 - properly park harddisk on shutdown

Unread postby tkaiser » Thu Jan 18, 2018 12:40 am

Nominal Animal wrote:Instead of looking at the partitions the kernel knows about, let's put all block devices the kernel knows that begin with sd to sleep.


That's exactly what the regex '/sd[a-z]$/' does (skipping all partitions and only taking care about devices. /sys/block/sd* should work of course too but I try to avoid /sys/ when possible since I have to deal with some Linux systems where CONFIG_SYSFS=n is set for whatever weird reasons).

Anyway... those users who tested the new firmware... with which kernel version did you give it a try? Asking since I experienced different behaviour with different kernel versions (on different platforms -- eg. an ASM1153E that worked pretty well with XU4/HC1 and 4.14 kernel showed same power-off retract count behaviour with RK3328 4.4 BSP kernel).
tkaiser
 
Posts: 572
Joined: Mon Nov 09, 2015 12:30 am
languages_spoken: english
ODROIDs: C1+, C2, XU4, HC1

Re: HC1 - properly park harddisk on shutdown

Unread postby Nominal Animal » Thu Jan 18, 2018 2:48 am

tkaiser wrote:That's exactly what the regex '/sd[a-z]$/' does (skipping all partitions and only taking care about devices.

The situation I'm worried about, is when a user has an an external USB drive, and has it unmounted, and then powers off the machine. /proc/partitions won't list it or its partitions, but it'll still be visible in /sys/block/. I would like to handle those situations, too.
Nominal Animal
 
Posts: 67
Joined: Sat Sep 16, 2017 12:51 pm
Location: Finland
languages_spoken: English, Finnish
ODROIDs: C1+, HC1

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby kris777 » Thu Jan 18, 2018 4:58 pm

thanks @sebsan / @ Nominal Animal

I checked this fix works ..... there is no more clicking !
but it takes a long time to disconnect power from HC1 .... but it's not a problem :-)
regards!
kris777
 
Posts: 3
Joined: Tue Nov 28, 2017 4:23 am
languages_spoken: english
ODROIDs: Odroid HC1

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby moe » Mon Jan 22, 2018 10:14 pm

So, I installed OMV_3_0_92_Odroidxu4_4.9.61.img.xz on my HC1 and updated the installation. Do I have to worry about HDD parking on shutdown from the OMV web interface of my installation or do I have do fix something or wait for a new release? Sorry, this is not clear for me.
moe
 
Posts: 4
Joined: Thu Jan 11, 2018 11:53 pm
languages_spoken: english
ODROIDs: HC1

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby fvolk » Sun Jan 28, 2018 7:23 am

First of all, thanks to everyone for contributing to solve this issue.

I copied the script from viewtopic.php?f=97&t=29069#p211653
to /lib/systemd/system-shutdown/stop-sd.shutdown,
made it chmod +x, hdparm is installed, and.... doesn't work.

Do I have to do anything else? Or enable it explicitly somehow?
fvolk
 
Posts: 187
Joined: Sun Jun 05, 2016 11:04 pm
languages_spoken: english
ODROIDs: C2, HC1

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby Nominal Animal » Sun Jan 28, 2018 10:25 am

fvolk wrote:doesn't work.

Can you show the output of ls -laF /sys/block/ /lib/systemd/system-shutdown/ ?

fvolk wrote:Do I have to do anything else? Or enable it explicitly somehow?

It's probably a typo in the scriptlet I made; I cannot test it myself, because I'm still working on my power supply and microcontroller board for HC1, and stalled due to lack of test equipment. (A friend with those has offered to help me, though!)

If you don't mind, I can walk you through the steps to make sure it works right.

Otherwise, consider using this simplified version, /lib/systemd/system-shutdown/simple.shutdown:
Code: Select all
#!/bin/bash
exec </dev/null >/dev/null 2>/dev/null
export LANG=C LC_ALL=C

sync
[ -x /sbin/mdadm ] && /sbin/mdadm --wait-clean --scan

Wait=0
for Dev in /sys/block/sd* ; do
    [ -e $Dev ] && hdparm -Y /dev/${Dev##*/} && Wait=3
done
sleep $Wait
Nominal Animal
 
Posts: 67
Joined: Sat Sep 16, 2017 12:51 pm
Location: Finland
languages_spoken: English, Finnish
ODROIDs: C1+, HC1

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby fvolk » Sun Jan 28, 2018 6:15 pm

Tried this one, commented the line with mdadm because I don't have that, and this one works.
Tried two different cases:

1) Call "/lib/systemd/system-shutdown/stop-sd.shutdown" manually, then type "reboot"

2) Just type "reboot".

Both cases seems to spin-down the harddisk properly, SMART counter does not increase, the hard *clack* noise is gone. Yay! :-)

However, when after reboot the disk spins up again I hear a difference: In case 1 the disk spins up normally, in case 2 the disk spins up, seems to loose power for a fraction of a second and struggles, and then continues its spin up. So something is different here, depending how you send the disk to sleep on reboot, manually first or in a system shutdown process/script.
fvolk
 
Posts: 187
Joined: Sun Jun 05, 2016 11:04 pm
languages_spoken: english
ODROIDs: C2, HC1

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby Nominal Animal » Mon Jan 29, 2018 12:40 pm

fvolk wrote:commented the line with mdadm because I don't have that

The line should be completely safe to leave in. If you don't have an executable /sbin/mdadm, the line does nothing.

fvolk wrote:the disk spins up, seems to loose power for a fraction of a second and struggles, and then continues its spin up.

That is to be expected of the simplified version. The script should get called with a parameter, that describes the situation: halt, poweroff, reboot, or kexec. We want to avoid running the script in the reboot and kexec cases, as otherwise there will be that three-second hiccup then.

Perhaps this one will perform better? /lib/systemd/system-shutdown/odroid.shutdown:
Code: Select all
#!/bin/bash
exec </dev/null </dev/null 2>/dev/null
export LANG=C LC_ALL=C

# In all cases, we want the media to be in quiescent, clean state.
sync
[ -x /sbin/mdadm ] && /sbin/mdadm --wait-clean --scan

# Function used to park all SATA disks.
function ParkDisks() {
    if [ -x /sbin/hdparm ]; then
        Wait=0
        for Dev in /sys/block/sd* ; do
            [ -e $Dev ] && /sbin/hdparm -Y /dev/${Dev##*/} && Wait=3
        done
        sleep $Wait
    fi
}

case "$1" in
    reboot|kexec)
        # Do not park disks when rebooting or switching kernels.
        ;;
    *)
        ParkDisks
        ;;
esac

Note that I wrote the check so that if it gets called without any parameters, it is treated as a shutdown. It shouldn't be necessary, but the systemd code is of crappy quality, so a defensive approach is warranted, in my opinion.

If you save the above in a file called temp.txt, you can install it (ensuring correct owner and file mode) by running
sudo install -o root -g root -m 0755 temp.txt /lib/systemd/system-shutdown/odroid.shutdown .

If you used another name for the previous version, you'll also want to remove the old version, of course.
Nominal Animal
 
Posts: 67
Joined: Sat Sep 16, 2017 12:51 pm
Location: Finland
languages_spoken: English, Finnish
ODROIDs: C1+, HC1

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby fvolk » Sun Feb 04, 2018 4:28 am

When doing nothing on reboot, meaning typing just "reboot" in console and no proper parking script run, the harddisk is parked audibly "hard", a short delay of wait, and on boot up again it spins up again. So ignoring reboot is not the solution....

On reboot USB/bridge power is always cut/reset for a short time, so keeping the disk running during reboot is not possible? @Odroid?

Edit: I just noted, this is on an Armbian install, because my USB Wifi does (still?) not work on Ubuntu from Odroid (see viewtopic.php?f=97&t=28743).
Do Armbian and Odroid Ubuntu differ in their reboot processes? :-/
fvolk
 
Posts: 187
Joined: Sun Jun 05, 2016 11:04 pm
languages_spoken: english
ODROIDs: C2, HC1

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby Nominal Animal » Tue Feb 06, 2018 2:05 am

fvolk wrote:So ignoring reboot is not the solution

Ah, okay; I didn't know that.

fvolk wrote:Do Armbian and Odroid Ubuntu differ in their reboot processes? :-/

I don't think so. If Armbian also has /lib/systemd/system-shutdown/, then the two are compatible in this particular regard. Does Armbian have any other files there?

Assuming there are no other files in that directory, could you try the following version of /lib/systemd/system-shutdown/odroid.shutdown?
Code: Select all
#!/bin/bash
exec </dev/null </dev/null 2>/dev/null
export LANG=C LC_ALL=C

# In all cases, we want the media to be in quiescent, clean state.
sync
[ -x /sbin/mdadm ] && /sbin/mdadm --wait-clean --scan

# Function used to park all SATA disks.
function ParkDisks() {
    if [ -x /sbin/hdparm ]; then
        Wait=0
        for Dev in /sys/block/sd* ; do
            [ -e $Dev ] && /sbin/hdparm -Y /dev/${Dev##*/} && Wait=3
        done
        sleep $Wait
    fi
}

case "$1" in
    reboot|poweroff|shutdown|halt)
        ParkDisks
        ;;
esac

It only differs in the final case .. esac part.
Nominal Animal
 
Posts: 67
Joined: Sat Sep 16, 2017 12:51 pm
Location: Finland
languages_spoken: English, Finnish
ODROIDs: C1+, HC1

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby fvolk » Fri Feb 09, 2018 7:50 am

As a summary:
1) no shutdown script at all -> harddisk parked hard with power cut -> bad, SMART counter increases :-(
2) with shutdown script for all cases, run "shutdown -h now" -> clean shutdown -> disconnect power -> reconnect power -> startup is fine
3) with shutdown script for all cases, run "reboot" -> clean shutdown -> on coming up again harddisk spins up, makes noise like it loses half a sec the power, then continues spin-up - does this hurt the disk?

Harddisk is a HGST Z5K1.
Tested with Armbian and now also with 4.14 based Odroid minimal image.
In my observation Armbian and Odroid behave the same way.

However, I had to stop testing now as the Odroid image all of a sudden does no longer come up, the blue LED blinks but network link LED is off - bad package in last updates? :-(
And everytime I hurt my disk I feel a little bit like a bad Odroids herder :-/

So for me the lesson is I'll use the script - thank you - and I won't do any reboots.
Looking forward to a 4.14 based image with up-to-date Docker version :-)
fvolk
 
Posts: 187
Joined: Sun Jun 05, 2016 11:04 pm
languages_spoken: english
ODROIDs: C2, HC1

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby Nominal Animal » Fri Feb 09, 2018 8:27 pm

fvolk wrote:run "reboot" -> clean shutdown -> on coming up again harddisk spins up, makes noise like it loses half a sec the power, then continues spin-up - does this hurt the disk?

It's definitely not good for it.

I should be getting my HC1 in operation with a WD HDD soon-ish, so I can find out exactly what is the cause of the restart hiccup. (My setup is a bit weird, because I use a custom microcontroller carrier board connected to the serial connection via level shifters. I need some time with an oscilloscope to characterize the power supplies I have, to make sure they work and won't burn the HC1. I have a couple of DC-DC ones that can provide 8A comfortably, that also have a inhibit pin, meaning the microcontroller, powered using a separate 5V DC-DC converter, can then turn off the power from HC1. Testing is required, because these are off eBay, and I'm worried about their noise and stability at a variable load. I do have a set of power resistors I'll test the supplies with, at different loads. If I only had basic testing equipment -- oscilloscope, electronic load, and a programmable supply... ;-))

fvolk wrote:So for me the lesson is I'll use the script - thank you - and I won't do any reboots.

It could be that adding a longer delay for the reboot case, for example
Code: Select all
case "$1" in
    poweroff|shutdown|halt)
        ParkDisks
        ;;
    reboot)
        ParkDisks
        sleep 10
        ;;
esac

will take away the hiccup.

Unfortunately, it is also possible that the way the script shuts down the HDD causes the HDD to spin up immediately after the reboot sequence ends (since HC1 does not actually power-cycle at reboot), and that the hiccup occurs during the bootup process, after u-boot starts the kernel. If that is the case, we need to try to fix that using a different method of turning off the drive at reboot. That means trying udiskctl instead of hdparm, at least for the reboot case. It might not be solvable at all. I would like to do that testing with the absolute minimum number of "hiccuping" reboots, because it is true it might harm the drive; there is quite a bit of energy in the spinning platter, and having the motor power turn off and then back on while it is already rotating is not good for the motor control electronics. All sorts of back-EMF -- and quote likely the drive electronics are not designed or tested to do that at all.
Nominal Animal
 
Posts: 67
Joined: Sat Sep 16, 2017 12:51 pm
Location: Finland
languages_spoken: English, Finnish
ODROIDs: C1+, HC1

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby fvolk » Sat Feb 10, 2018 4:57 am

Nominal Animal wrote:Unfortunately, it is also possible that the way the script shuts down the HDD causes the HDD to spin up immediately after the reboot sequence ends (since HC1 does not actually power-cycle at reboot), and that the hiccup occurs during the bootup process, after u-boot starts the kernel.


This sounds more like what I'm hearing.
When powering down "hard" the harddisk-is-stopped phase is longer than a "nice" power-down and then sooner the disk spins up again - and then at the actual reboot(?) receives a power jolt.
But maybe it is specific to my HGST disk - unfortunately I have no other available to test with currently.
fvolk
 
Posts: 187
Joined: Sun Jun 05, 2016 11:04 pm
languages_spoken: english
ODROIDs: C2, HC1

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby neal » Sun Feb 18, 2018 2:38 am

Nominal Animal wrote:That means trying udiskctl instead of hdparm, at least for the reboot case.


When I using the script by @Nominal Animal on my HC1, I can't hear "hiccup" sound and doesn't increase "Power-Off_Retract_Count".
but, I once see "[sda] I/O error" when I tried the reboot, that is I'm not sure caused by the script.
Anyway, the above quote is a hint. so I just added my idea to the @Nominal Animal's script.
I hope that kernel fell for that trick "poweroff" with any of shutting down cases.

Code: Select all
#!/bin/bash
exec </dev/null </dev/null 2>/dev/null
export LANG=C LC_ALL=C

# In all cases, we want the media to be in quiescent, clean state.
sync
[ -x /sbin/mdadm ] && /sbin/mdadm --wait-clean --scan

# Function used to park all SATA disks.
function ParkDisks() {
    if [ -x /sbin/hdparm ]; then
        Wait=0
        for Dev in /sys/block/sd* ; do
        [ -e $Dev ] && /sbin/hdparm -y /dev/${Dev##*/} && Wait=2
   sleep $Wait
   echo 1 > /sys/class/block/${Dev##*/}/device/delete
        done
        sleep $Wait
    fi
}

case "$1" in
    # reboot|kexec)
        # Do not park disks when rebooting or switching kernels.
    #     ;;
    *)
        ParkDisks
        ;;
esac
neal
 
Posts: 157
Joined: Fri Apr 14, 2017 10:02 am
languages_spoken: english

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby neal » Tue Feb 20, 2018 2:21 pm

It seems to be working. but...I'm not 100 percent sure.
Could you please anyone checks that this script works or not?

Nominal Animal wrote:If you save the above in a file called temp.txt, you can install it (ensuring correct owner and file mode) by running
Code: Select all
sudo install -o root -g root -m 0755 temp.txt /lib/systemd/system-shutdown/odroid.shutdown


neal wrote:
Nominal Animal wrote:That means trying udiskctl instead of hdparm, at least for the reboot case.


When I using the script by @Nominal Animal on my HC1, I can't hear "hiccup" sound and doesn't increase "Power-Off_Retract_Count".
but, I once see "[sda] I/O error" when I tried the reboot, that is I'm not sure caused by the script.
Anyway, the above quote is a hint. so I just added my idea to the @Nominal Animal's script.
I hope that kernel fell for that trick "poweroff" with any of shutting down cases.

Code: Select all
#!/bin/bash
exec </dev/null </dev/null 2>/dev/null
export LANG=C LC_ALL=C

# In all cases, we want the media to be in quiescent, clean state.
sync
[ -x /sbin/mdadm ] && /sbin/mdadm --wait-clean --scan

# Function used to park all SATA disks.
function ParkDisks() {
    if [ -x /sbin/hdparm ]; then
        Wait=0
        for Dev in /sys/block/sd* ; do
        [ -e $Dev ] && /sbin/hdparm -y /dev/${Dev##*/} && Wait=2
   sleep $Wait
   echo 1 > /sys/class/block/${Dev##*/}/device/delete
        done
        sleep $Wait
    fi
}

case "$1" in
    # reboot|kexec)
        # Do not park disks when rebooting or switching kernels.
    #     ;;
    *)
        ParkDisks
        ;;
esac
neal
 
Posts: 157
Joined: Fri Apr 14, 2017 10:02 am
languages_spoken: english

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby fvolk » Sun Feb 25, 2018 2:26 am

neal wrote:Could you please anyone checks that this script works or not?


I don't know about any sda I/O error, but with this script
on reboot the disk still has the spin-up half-a-second-pause problem,
whereas on shutdown, disconnect power, reconnect power and boot it does not.

I'm not doing reboots anymore, even if SMART counters do not increase I don't think it's healthy for the disk.
fvolk
 
Posts: 187
Joined: Sun Jun 05, 2016 11:04 pm
languages_spoken: english
ODROIDs: C2, HC1

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby neal » Tue Feb 27, 2018 2:56 pm

I want more people to use the script @Nominal Animal's idea to park HDD safely. so I made the wiki page.
https://wiki.odroid.com/odroid-xu4/troubleshooting/shutdown_script
Thank you, guys ;)
neal
 
Posts: 157
Joined: Fri Apr 14, 2017 10:02 am
languages_spoken: english

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby trohn_javolta » Tue Feb 27, 2018 3:55 pm

neal wrote:I want more people to use the script @Nominal Animal's idea to park HDD safely. so I made the wiki page.
https://wiki.odroid.com/odroid-xu4/troubleshooting/shutdown_script
Thank you, guys ;)

Is this also working when I reboot my HC2 or only when I use shutdown?
trohn_javolta
 
Posts: 45
Joined: Fri Nov 03, 2017 6:16 am
languages_spoken: english, german
ODROIDs: none (plans for XU4)

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby rooted » Tue Feb 27, 2018 4:02 pm

The script specifically doesn't park when rebooting.
User avatar
rooted
 
Posts: 5872
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby trohn_javolta » Tue Feb 27, 2018 4:18 pm

So what's the sense of this script then? I hardly ever shutdown the board, I reboot it.

Ok, and after shutdown, could I savely unplug power and plug it in again, or do I get the clacking sound also after unplugging?
trohn_javolta
 
Posts: 45
Joined: Fri Nov 03, 2017 6:16 am
languages_spoken: english, german
ODROIDs: none (plans for XU4)

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby rooted » Tue Feb 27, 2018 4:40 pm

This one from above deals with reboot.

Code: Select all
#!/bin/bash
exec </dev/null </dev/null 2>/dev/null
export LANG=C LC_ALL=C

# In all cases, we want the media to be in quiescent, clean state.
sync
[ -x /sbin/mdadm ] && /sbin/mdadm --wait-clean --scan

# Function used to park all SATA disks.
function ParkDisks() {
    if [ -x /sbin/hdparm ]; then
        Wait=0
        for Dev in /sys/block/sd* ; do
            [ -e $Dev ] && /sbin/hdparm -Y /dev/${Dev##*/} && Wait=3
        done
        sleep $Wait
    fi
}

case "$1" in
    reboot|poweroff|shutdown|halt)
        ParkDisks
        ;;
esac
User avatar
rooted
 
Posts: 5872
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby neal » Tue Feb 27, 2018 5:06 pm

trohn_javolta wrote:
neal wrote:I want more people to use the script @Nominal Animal's idea to park HDD safely. so I made the wiki page.
https://wiki.odroid.com/odroid-xu4/troubleshooting/shutdown_script
Thank you, guys ;)

Is this also working when I reboot my HC2 or only when I use shutdown?


Hi, @trohn_javolta
Did you apply the shutdown script on your HC2?
if so, Could you please feedback on your result?
In my case, I have tested many times with my HC2. and there is no issue with poweroff and reboot.
neal
 
Posts: 157
Joined: Fri Apr 14, 2017 10:02 am
languages_spoken: english

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby trohn_javolta » Tue Feb 27, 2018 5:07 pm

Thx. So could I combine the two?
Install it this way right?

Code: Select all
sudo install -o root -g root -m 0755 temp.txt /lib/systemd/system-shutdown/odroid.shutdown


Name one odroid.reboot and one odroid.shutdown and I'm set.

Edit: Oh, I see.. is there also /lib/systemd/system-reboot where I can put the reboot script?
Last edited by trohn_javolta on Tue Feb 27, 2018 5:10 pm, edited 1 time in total.
trohn_javolta
 
Posts: 45
Joined: Fri Nov 03, 2017 6:16 am
languages_spoken: english, german
ODROIDs: none (plans for XU4)

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby neal » Tue Feb 27, 2018 5:10 pm

You can just copy & paste into your HC2 shell.
Code: Select all
root@odroid:~# wget https://dn.odroid.com/5422/script/odroid.shutdown
root@odroid:~# sudo install -o root -g root -m 0755 ./odroid.shutdown /lib/systemd/system-shutdown/odroid.shutdown
neal
 
Posts: 157
Joined: Fri Apr 14, 2017 10:02 am
languages_spoken: english

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby trohn_javolta » Tue Feb 27, 2018 5:11 pm

neal wrote:You can just copy & paste into your HC2 shell.
Code: Select all
root@odroid:~# wget https://dn.odroid.com/5422/script/odroid.shutdown
root@odroid:~# sudo install -o root -g root -m 0755 ./odroid.shutdown /lib/systemd/system-shutdown/odroid.shutdown


Yeah, but this doesn't handle safe park on reboot, right?
trohn_javolta
 
Posts: 45
Joined: Fri Nov 03, 2017 6:16 am
languages_spoken: english, german
ODROIDs: none (plans for XU4)

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby neal » Tue Feb 27, 2018 5:15 pm

trohn_javolta wrote:Yeah, but this doesn't handle safe park on reboot, right?

I guess It handles safely to park on both poweroff and reboot.
neal
 
Posts: 157
Joined: Fri Apr 14, 2017 10:02 am
languages_spoken: english

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby Valsi » Tue Feb 27, 2018 7:30 pm

Hello,

have running OMV (OMV_3_0_92_Odroidxu4_4.9.61.img.xz) on my HC1, this "Klack" noise I have already heard while shutting down the HC1. I'm not an expert as many other user here, so I have no clear picture how to solve this issue. I understood that the lifetime of the HDD can be reduced, but for me it's not clear which steps are necessary to get rid of it. May someone make the picture clearer for me and eventually for other too?
Valsi
 
Posts: 14
Joined: Sun Feb 25, 2018 3:40 am
languages_spoken: english
ODROIDs: Hc-1

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby Valsi » Tue Feb 27, 2018 9:17 pm

Have found in WIKI the description to apply the script. Will try it. Have never doe it but should work...hopefully :D
Valsi
 
Posts: 14
Joined: Sun Feb 25, 2018 3:40 am
languages_spoken: english
ODROIDs: Hc-1

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby lufkinOrange » Fri Mar 02, 2018 2:55 am

quick question,
what about deleting the disk from the system ? I think on recent disk this will park the head of the disk. On older disk it might not do it thought.
Code: Select all
# echo 1 > /sys/class/block/sda/device/delete
# dmesg
[  621.156409] sd 0:0:0:0: [sda] Synchronizing SCSI cache

It would prevent issue with your spindown/spinup on reboot.
Also for the script, it would be useful to a a proper systemd service file. I'll leave this task to someone else; or if it's not done when I do it I'll post; probably need defaultdependencies=false.
lufkinOrange
 
Posts: 21
Joined: Mon Jan 22, 2018 7:50 am
languages_spoken: english, français

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby Un4Seen » Sat Apr 14, 2018 9:19 pm

Hi!

Can anybody please post a version of this script which also works on reboot? I've tried the official version form the odroid wiki and the version posted above, all of them are supposed to handle reboot too (that's what the code tells me), but they don't. When I shut down my Odroid HC1 units, the HDDs do not clack, but on reboot (which is what I use almost all the time) they clack. Western Digital Black 1TB.

Thanks!
Un4Seen
 
Posts: 174
Joined: Thu Apr 10, 2014 6:16 pm
Location: Romania
languages_spoken: english, hungarian, romanian

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby odroid » Sun Apr 15, 2018 12:45 pm

Did you try the script in this WiKi page?
https://wiki.odroid.com/odroid-xu4/trou ... own_script

Did you check the number of wrong shutdown counter via S.M.A.R.T. information?
User avatar
odroid
Site Admin
 
Posts: 29083
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: HC1/HC2 - properly park harddisk on shutdown

Unread postby Un4Seen » Sun Apr 15, 2018 6:02 pm

Yes, the script from the Wiki is the first one I tried, doesn't work for reboot.
I don't know how to check the number of wrong shutdown via SMART.
Un4Seen
 
Posts: 174
Joined: Thu Apr 10, 2014 6:16 pm
Location: Romania
languages_spoken: english, hungarian, romanian

Next

Return to Hardware and peripherals

Who is online

Users browsing this forum: No registered users and 3 guests