We use some essential cookies to make our website work.

We use optional cookies, as detailed in our cookie policy, to remember your settings and understand how you use our website.

User avatar
manu2007
Posts: 157
Joined: Fri Apr 02, 2021 1:13 pm
Location: Brittany

A safe way to power off USB drive on system shutdown ?

Mon Apr 26, 2021 8:44 pm

Hi there,

when I shutdown the system from the desktop menu, with an USB hard drive plugged, I thought the drive would do a safe shutdown, the same way than my desktop PC do.

How naive I am. :mrgreen:

It seems that Raspberry Pi OS 64 bits turns down the drive a more abrupt way, the drive led doesn't blink as it should, and there is a noisy click.

Then if I check this :

Code: Select all

sudo smartctl -a /dev/sda -d sat | grep Power-Off_Retract_Count
I see that the retract count increase, which indicates an abrupt power off, just like a power outage.

So, I wonder if there's a way to turn off the system in a way that would also safely turn off all plugged USB drives.

Thanks in advance. :-P
RPI4 4GB
RaspiOS Trixie Lite + Labwc + xfce4-panel = 215 MiB
https://github.com/hotnuma?tab=repositories

pidd
Posts: 6564
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK

Re: A safe way to power off USB drive on system shutdown ?

Tue Apr 27, 2021 1:54 am

I agree, its not just the 64bit, the 32bit doesn't shutdown drives safely according to my SSD's.

32-bit

Code: Select all

Power_Cycle_Count    -    624
Unsafe_Shutdown_Count   -    615

32-bit

Code: Select all

Power_Cycle_Count   -    44
Unsafe_Shutdown_Count   -    43

64-bit

Code: Select all

Power_Cycle_Count     -    23
Unsafe_Shutdown_Count   -    22

User avatar
Imperf3kt
Posts: 4675
Joined: Tue Jun 20, 2017 12:16 am
Location: Australia

Re: A safe way to power off USB drive on system shutdown ?

Tue Apr 27, 2021 2:39 am

Unmount the drive before shutting down might help?
55:55:44:44:4C
52:4C:52:42:41

Rose tinted glasses are difficult to see through.

User avatar
manu2007
Posts: 157
Joined: Fri Apr 02, 2021 1:13 pm
Location: Brittany

Re: A safe way to power off USB drive on system shutdown ?

Tue Apr 27, 2021 7:51 am

The system does unmount so that there won't be any data corruption, it's fine.

What I'm missing is a way, a command line to safely power off the drive after unmount, to protect the drive from any mechanical damage.

Under W10 or with a HDMI player, when ejecting or turning off, a safe power off happens. The drive's led blinks 10 times during 5 seconds, the arm goes into parking, the platters no longer spins, the led is off.

I found "udisksctl power-off" :

https://linuxnorth.wordpress.com/2018/0 ... sh-script/

It seems better but it's still not a safe 5 seconds turn off sequence.
RPI4 4GB
RaspiOS Trixie Lite + Labwc + xfce4-panel = 215 MiB
https://github.com/hotnuma?tab=repositories

KeithMck
Posts: 761
Joined: Thu Dec 31, 2020 10:58 am

Re: A safe way to power off USB drive on system shutdown ?

Tue Apr 27, 2021 9:00 am

I've never thought anything of it, & after 22 years without any troubles from my disks, I don't think you need worry, as long as they are unmounted before being switched off.

RonR
Posts: 3922
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: A safe way to power off USB drive on system shutdown ?

Tue Apr 27, 2021 5:55 pm

manu2007 wrote:
Mon Apr 26, 2021 8:44 pm
It seems that Raspberry Pi OS 64 bits turns down the drive a more abrupt way, the drive led doesn't blink as it should, and there is a noisy click.

See: viewtopic.php?t=283849&p=1718514#p1718514

pidd
Posts: 6564
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK

Re: A safe way to power off USB drive on system shutdown ?

Wed Apr 28, 2021 12:06 am

On my three SSD's listed above almost all of the power cycles are reboots.

User avatar
manu2007
Posts: 157
Joined: Fri Apr 02, 2021 1:13 pm
Location: Brittany

Re: A safe way to power off USB drive on system shutdown ?

Wed Apr 28, 2021 7:16 am

pidd wrote:
Wed Apr 28, 2021 12:06 am
On my three SSD's listed above almost all of the power cycles are reboots.
What type of SSD is it ? Removable or internal ?

My drives are Toshiba removable USB drives 1 TO, it's one of the best selling on Amazon, I've several ones and they work perfectly under W10.
RPI4 4GB
RaspiOS Trixie Lite + Labwc + xfce4-panel = 215 MiB
https://github.com/hotnuma?tab=repositories

pidd
Posts: 6564
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK

Re: A safe way to power off USB drive on system shutdown ?

Wed Apr 28, 2021 12:56 pm

manu2007 wrote:
Wed Apr 28, 2021 7:16 am
pidd wrote:
Wed Apr 28, 2021 12:06 am
On my three SSD's listed above almost all of the power cycles are reboots.
What type of SSD is it ? Removable or internal ?

My drives are Toshiba removable USB drives 1 TO, it's one of the best selling on Amazon, I've several ones and they work perfectly under W10.
They are on Raspeberry Pi's, they can't be internal but they are boot drives, Kingston A400's but that is irrelevant to the Operating System not shutting them down correctly on shutdown or reboot.

User avatar
Imperf3kt
Posts: 4675
Joined: Tue Jun 20, 2017 12:16 am
Location: Australia

Re: A safe way to power off USB drive on system shutdown ?

Wed Apr 28, 2021 9:58 pm

An "internal" drive refers to an SSD without a case, entirely possible to connect to a Pi via a usb adapter. An "external" drive would have a case and usb adapter included but the ssd inside is still an SSD, nothing special about it.

In both cases, a usb adapter is required, so there is no difference between them.
55:55:44:44:4C
52:4C:52:42:41

Rose tinted glasses are difficult to see through.

User avatar
manu2007
Posts: 157
Joined: Fri Apr 02, 2021 1:13 pm
Location: Brittany

Re: A safe way to power off USB drive on system shutdown ?

Wed Apr 28, 2021 10:37 pm

Imperf3kt wrote:
Wed Apr 28, 2021 9:58 pm
there is no difference between them.
An internal drive doesn't go into sleep mode, an external one goes into sleep mode.

I tried an internal drive from an old laptop and the Power-Off_Retract_Count flag doesn't increase with this one.

Anyway, the lack of a safe power off seems to be an old problem with LXDE/LXQt :

https://askubuntu.com/questions/98784/s ... on-lubuntu

It's 10 years old :-D

Another interesting post :

https://askubuntu.com/questions/951682/ ... ys-enabled

Code: Select all

# Make sure nothing is left in buffer and everything has been written to disk

 sync

# Unmount it

sudo umount /dev/sda1

# Power it off

udisksctl power-off -b /dev/sda
That seems to be the way to safely remove an USB drive.
RPI4 4GB
RaspiOS Trixie Lite + Labwc + xfce4-panel = 215 MiB
https://github.com/hotnuma?tab=repositories

User avatar
Imperf3kt
Posts: 4675
Joined: Tue Jun 20, 2017 12:16 am
Location: Australia

Re: A safe way to power off USB drive on system shutdown ?

Wed Apr 28, 2021 10:58 pm

None of my external hard drives go into sleep mode when I power form my pc (they don't even spin down), but my internal ones do. Might be because I have set my motherboard to continue supplying 5v even while on standby, whereas the internal 5v rail is shut down when the pc is turned off. So in this case, the difference is how it is connected to the pc (self powered usb vs sata 3 with power coming from a 5v rail that turns off)

Which is why I mentioned the usb adapter, to plug into a Pi, usb must be used (unless you have a CM4 and make use of the PCIe)
So in theory, both an internal and external drive should behave the same way. Unless the drive itself has differing firmware that changes this behaviour.

An external ssd or hard drive is literally just an internal drive stuck in a case and plugged into a usb to sata (or other) adapter
55:55:44:44:4C
52:4C:52:42:41

Rose tinted glasses are difficult to see through.

Return to “Beginners”