h_ramus
Posts: 10
Joined: Tue Feb 17, 2015 6:21 pm

Pi 2 HDD eject before shutdown?

Tue Mar 03, 2015 11:41 am

Hello there

I've successfully included a 2.5" HDD to the Pi 2 and it seems to be working OK being mounted and read normally.

I do have a question regarding the HDD health. Whenever I use the shutdown command I can hear the HDD plates spinning down after the Pi shuts down. However, whenever connect the same drive to a laptop (Mac OSX) and eject the drive before pulling the USB cable no such sound is heard. It seems that when ejecting the drive from the laptop the HDD plates stop spinning normally. When executing the shutdown -h now command in the Pi the HDD plates seem to abruptly stop as if I had just pulled the USB cable without the shutdown command.

I've been reading on other posts that when executing the shutdown command the Pi unmounts the HDD and can be safely disconnected. However, the difference between ejecting the same drive in a laptop and a Pi 2 seems evident. I fear a shorter lifespan of the HDD with the Pi.

Question: is there any way of ejecting the HDD in the Pi that doesn't cause it to abruptly stop spinning when running the shutdown command?

Running a Pi 2 with OSMC Alpha 4.

Thanks

H.

User avatar
DougieLawson
Posts: 38882
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Pi 2 HDD eject before shutdown?

Tue Mar 03, 2015 11:45 am

Don't worry about it. All modern winchester disks have self-parking heads.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
RaTTuS
Posts: 10558
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Pi 2 HDD eject before shutdown?

Tue Mar 03, 2015 11:48 am

I would not worry about it - it is probably just responding slightly differently
hard disks will auto park themselves fine
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

h_ramus
Posts: 10
Joined: Tue Feb 17, 2015 6:21 pm

Re: Pi 2 HDD eject before shutdown?

Tue Mar 03, 2015 12:00 pm

Thanks for your replies. Indeed I've been reading that the shutdown command would allow the HDD to be safely disconnected. However, to my nontechnical mind it sounds wrong! The same HDD being ejected in two different machines should follow similar procedures but it doesn't seem to be the case.

If there's no way of replicating the eject procedures of OSX in the Pi then I'll have to live with it although I cringe each time I hear the HDD stop when shutting down the Pi.

User avatar
RaTTuS
Posts: 10558
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Pi 2 HDD eject before shutdown?

Tue Mar 03, 2015 12:13 pm

you could
umount the drive in raspbian
then just remove the power to the HD
that will do the same
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

h_ramus
Posts: 10
Joined: Tue Feb 17, 2015 6:21 pm

Re: Pi 2 HDD eject before shutdown?

Tue Mar 03, 2015 12:22 pm

RaTTuS wrote:you could
umount the drive in raspbian
then just remove the power to the HD
that will do the same
Thanks. I'm running OSMC, there's an option in the file manager to safely remove the HDD but I end up with the same abrupt halt to HDD spinning when shutting down. I've also tried unmounting in SSH but it doesn't seem to have an impact, the same abrupt HDD sound occurs.

h_ramus
Posts: 10
Joined: Tue Feb 17, 2015 6:21 pm

Re: Pi 2 HDD eject before shutdown?

Tue Mar 03, 2015 8:17 pm

OK, so running

Code: Select all

sudo hdparm -Y /dev/sda
before shutting down the Pi makes the HDD disk stop spinning and the shutdown goes softly.

Is there any way I can add this command to the shutdown option in the media center (OSMC)? /etc/rc.local runs boot scripts but I don't know where to find shutdown scripts.

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: Pi 2 HDD eject before shutdown?

Tue Mar 03, 2015 8:52 pm

My Seagate USB HD does the same. I try to remember not to switch power off to it until a short while after shutting down the Pi.

If you have root fs on the HD, trying to spindown/unmout before shutdown may not work as you expect.

It may all be down to the USB/SATA bridging stuff inside the HD enclosure

h_ramus
Posts: 10
Joined: Tue Feb 17, 2015 6:21 pm

Re: Pi 2 HDD eject before shutdown?

Tue Mar 03, 2015 9:45 pm

Thanks. This happens before cutting down power, I just ssh the pi to shutdown. Using the hdparm -Y command seems to shutdown the HDD properly. I was wondering if this command can somehow be inserted when executing the shutdown option of the media center.

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Pi 2 HDD eject before shutdown?

Tue Mar 03, 2015 10:49 pm

h_ramus wrote:Thanks. This happens before cutting down power, I just ssh the pi to shutdown. Using the hdparm -Y command seems to shutdown the HDD properly. I was wondering if this command can somehow be inserted when executing the shutdown option of the media center.
You could write a script that gets executed as the system goes down the run levels (0 is usually halt / shutdown /poweroff for the Pi).

Have a look at post #3 for the details (or here for a before-systemd-comes-along-and-breaks-it quick method).

h_ramus
Posts: 10
Joined: Tue Feb 17, 2015 6:21 pm

Re: Pi 2 HDD eject before shutdown?

Wed Mar 04, 2015 9:10 am

Thanks @asandford. I'll have a look at it.


h_ramus
Posts: 10
Joined: Tue Feb 17, 2015 6:21 pm

Re: Pi 2 HDD eject before shutdown?

Wed Mar 04, 2015 7:15 pm

No dice with the script in rc0.d. I've also created a script to create a log of the
shutdown process following this tutorial.

http://ubuntu.flowconsult.at/linux/ubun ... t-scripts/

It doesn't seem to work, somehow the newly created scripts are not run in the shutdown processes. Perhaps it's an issue with OSMC, being alpha some things will inevitably be broken...

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Pi 2 HDD eject before shutdown?

Wed Mar 04, 2015 7:32 pm

h_ramus wrote:No dice with the script in rc0.d. I've also created a script to create a log of the
shutdown process following this tutorial.

http://ubuntu.flowconsult.at/linux/ubun ... t-scripts/

It doesn't seem to work, somehow the newly created scripts are not run in the shutdown processes. Perhaps it's an issue with OSMC, being alpha some things will inevitably be broken...
You could always edit a script that does get run, it's not ideal, but gets the job done.

h_ramus
Posts: 10
Joined: Tue Feb 17, 2015 6:21 pm

Re: Pi 2 HDD eject before shutdown?

Thu Mar 05, 2015 5:26 pm

Thanks @asandford. I edited the K01bluetooth file to include the command but still no joy.

I think I'll wait for the release of the stable version of OSMC as it may work then.

ntate6630
Posts: 2
Joined: Mon Mar 14, 2016 4:37 pm
Location: East Sussex
Contact: Website

Re: Pi 2 HDD eject before shutdown?

Sat Apr 09, 2016 2:59 pm

Hi,

I found the best way to stop this happening is to connect a powered USB hub to the RPi and then the hard disk to the hub.
when you shut down your RPi or eject the disk it will give the disk time to park the heads correctly before you disconnect the drive or pull the power.
When it suddenly has to retract the heads it is known as an emergency retract condition and if you look at the drives S.M.A.R.T. info using a disk utility such as "gnome disk utility" it will tell you how many times this happens.

vladimir.k
Posts: 7
Joined: Mon Nov 28, 2016 7:52 pm

Re: Pi 2 HDD eject before shutdown?

Mon Jan 30, 2017 12:23 am

h_ramus wrote:Hello there

I've successfully included a 2.5" HDD to the Pi 2 and it seems to be working OK being mounted and read normally.

I do have a question regarding the HDD health. Whenever I use the shutdown command I can hear the HDD plates spinning down after the Pi shuts down. However, whenever connect the same drive to a laptop (Mac OSX) and eject the drive before pulling the USB cable no such sound is heard. It seems that when ejecting the drive from the laptop the HDD plates stop spinning normally. When executing the shutdown -h now command in the Pi the HDD plates seem to abruptly stop as if I had just pulled the USB cable without the shutdown command.

I've been reading on other posts that when executing the shutdown command the Pi unmounts the HDD and can be safely disconnected. However, the difference between ejecting the same drive in a laptop and a Pi 2 seems evident. I fear a shorter lifespan of the HDD with the Pi.

Question: is there any way of ejecting the HDD in the Pi that doesn't cause it to abruptly stop spinning when running the shutdown command?

Running a Pi 2 with OSMC Alpha 4.

Thanks

H.

I have the same problems with my usb-wd drive. hdparm do not work with my drive. Here is solution:

try to umnount your drive via

Code: Select all

apt-get update
apt-get install udisks
/usr/bin/udisks --unmount /dev/sda1
sleep 5
udisks --detach /dev/sda
if is ok => you can do script on poweroff
I found that /etc/inid.d/yourscrips will not work as dbus already off (udisks or udisks2\udisksctl don`t work without) so we need to run script before poweroff command.
Before unount drives you need kill all that can use your drive (this script do not do this!!!)
All error will be in file /123.txt

Code: Select all

nano /myrandomfolder/hddunmount
=============================
#! /bin/sh
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#please kill all that can use your drive before go farther
# this script do not do this!!!
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#print all possible error\messages to file
echo " " > /123.txt
for i in `seq 1 300`; do
#i mounted my drive /dev/sda with partition sda1   in folder "/mnt"  
#On hard drive i have folder "2TB"
# so if we have /mnt/2TB  - so drive is mounted 
#replace by your fo;der
if [ -e /mnt/2TB ]; then
	echo $i >> /123.txt
	#apt-get install udisks
	/usr/bin/udisks --unmount /dev/sda1 >>/123.txt 2>&1
	#/usr/bin/udisksctl unmount --block-device /dev/sda1 >>/123.txt 2>&1
	echo ok >> /123.txt
	break
fi
sleep 0.1
done

sleep 5
for i in `seq 1 300`; do
if [ -e /dev/sda ]; then
	echo $i >> /123.txt
	udisks --detach /dev/sda >>/123.txt 2>&1
	#/usr/bin/udisksctl unmount --block-device /dev/sda1 >>/123.txt 2>&1
	echo ok >> /123.txt
	break
fi
sleep 0.1
done
sleep 5
====




mv /sbin/reboot  /sbin/rebootok
nano /sbin/reboot
=============================
#! /bin/sh
/myrandomfolder/hddunmount
/sbin/rebootok
====



mv /sbin/poweroff  /sbin/poweroffok
nano /sbin/poweroff 
=============================
#! /bin/sh
/myrandomfolder/hddunmount
/sbin/poweroffok
====

mv /sbin/halt  /sbin/haltok
nano /sbin/halt 
=============================
#! /bin/sh
/myrandomfolder/hddunmount
/sbin/haltok
====

mv /sbin/shutdown  /sbin/shutdownok
nano /sbin/shutdown 
=============================
#! /bin/sh
/myrandomfolder/hddunmount
/sbin/shutdownok
====





chmod 755 /sbin/shutdown
chmod 755 /sbin/halt
chmod 755 /sbin/poweroff 
chmod 755 /sbin/reboot
chmod 755 /myrandomfolder/hddunmount
Last edited by vladimir.k on Mon Jan 30, 2017 12:49 am, edited 5 times in total.

vladimir.k
Posts: 7
Joined: Mon Nov 28, 2016 7:52 pm

Re: Pi 2 HDD eject before shutdown?

Mon Jan 30, 2017 12:26 am

ntate6630 wrote:Hi,

I found the best way to stop this happening is to connect a powered USB hub to the RPi and then the hard disk to the hub.
when you shut down your RPi or eject the disk it will give the disk time to park the heads correctly before you disconnect the drive or pull the power.
When it suddenly has to retract the heads it is known as an emergency retract condition and if you look at the drives S.M.A.R.T. info using a disk utility such as "gnome disk utility" it will tell you how many times this happens.
Do you use UPS before hub?


Return to “Beginners”