You are not logged in.

#1 2020-07-06 15:42:54

Anon_a
Member
Registered: 2020-02-01
Posts: 5

[SOLVED] Safely remove usb hdd from terminal

I’ve been searching for a way to safely remove a hard drive without causing it to have a screeching sound through the terminal, which seems to happen with most drives I’ve tested with ‘umount’, which also doesn’t seem to power down the disk. Using general search terms only brings up umount and udisks which is no longer supported.

Is there any way to safely spin down the disk and power it down through the terminal?

What required utilities do I need to install for this after a base Arch install?

Last edited by Anon_a (2020-07-06 18:10:25)

Offline

#2 2020-07-06 16:19:22

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,817

Re: [SOLVED] Safely remove usb hdd from terminal

umount should be sufficient.   You may want to run sync do be extra sure.   Old Unix Greybeards will run sync twice.
To spin it down try hdparam after unmounting by putting the drive to sleep (the -y option)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2020-07-06 16:50:46

Anon_a
Member
Registered: 2020-02-01
Posts: 5

Re: [SOLVED] Safely remove usb hdd from terminal

Is there any other way to power down the disk after unmounting it, like in GNOME with udisksctl power-off or is it the same as setting the disk to idle? I'd like to avoid having to use hdparm, but if the sound I'm hearing is normal then I think umount should be sufficient.
I was also wondering if I could install udisks2 without the full GNOME desktop and use that instead of hdparm to power off or idle the disk. Any other possible methods to achieve the same effect would also be helpful, since the sound is really bothering me.

Offline

#4 2020-07-06 17:03:28

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,925
Website

Re: [SOLVED] Safely remove usb hdd from terminal

Why do you think udisks is tied to any particular desktop environment?


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#5 2020-07-06 17:14:08

Anon_a
Member
Registered: 2020-02-01
Posts: 5

Re: [SOLVED] Safely remove usb hdd from terminal

I thought it did because I always saw it mentioned along with GNOME, but now that I take a look at the freedesktop.org website, I might be wrong, but then why doesn't anyone mention udisks2 when working with hard drives without GNOME, is there something I'm misunderstanding about working with hard drives in Linux?

The dependency list for udisks2 also requires gtk3 for gtk-doc, am I missing something?

Last edited by Anon_a (2020-07-06 17:53:51)

Offline

#6 2020-07-06 17:49:30

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,925
Website

Re: [SOLVED] Safely remove usb hdd from terminal

I can't talk for anyone else, but the Arch wiki page about udisks doesn't mention GNOME beyond stating that DEs may include wrapper scripts.

I think what you're missing is that there's no need for each DE to have their own unique ways to mount hard drives -- the kernel and hardware don't care what DE you're running (if any).


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#7 2020-07-06 17:56:39

Anon_a
Member
Registered: 2020-02-01
Posts: 5

Re: [SOLVED] Safely remove usb hdd from terminal

So to make sure I understand everything correctly, umount is the only command I need to remove a hard drive safely without any possibility of damaging it, even if I unplug it without having it spinned down or powered-off?
I can also install udisks2 without having to install most of the GNOME desktop and use udisksctl to power-off the disk.

Offline

#8 2020-07-06 18:08:44

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,866

Re: [SOLVED] Safely remove usb hdd from terminal

Yes. If the disk was mounted with udisks you could also unmount it with udiskctl but there will not be a functional difference between unmounting it with umount or with udisksctl.

Offline

#9 2020-07-06 18:09:28

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,817

Re: [SOLVED] Safely remove usb hdd from terminal

Modern drives will unload and park the heads upon removal of power.  That is the sound you are hearing.
Running sync first won't hurt.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#10 2020-07-06 19:10:07

twelveeighty
Member
From: Alberta, Canada
Registered: 2011-09-04
Posts: 1,096

Re: [SOLVED] Safely remove usb hdd from terminal

I've seen these documented over the years - please research them to make sure they are all still relevant.

# man sync
sync

# https://www.kernel.org/doc/Documentation/sysctl/vm.txt
# echo 3 > /proc/sys/vm/drop_caches

# man blockdev
# blockdev --flushbufs /dev/sdX

# man hdparm
# hdparm -F /dev/sdX

# Not sure if this still works on newer kernels:
# echo 1 > /sys/block/sdX/device/delete

Offline

Board footer

Powered by FluxBB