How to safely distantly remove a usb hard drive in Debian using terminal

1

I'm connected via ssh to a Debian computer. What I need to to do is to safely remove the external usb storage device.

I have found this answer to a comparable question. One of the recommendations is just to eject or unmount by doing sudo eject /dev/sda. Now my problem is that I don't have a /dev/sd*. So the next proposed solution is by echo

'offline' > /sys/block/sdb/device/state
echo '1' > /sys/block/sdb/device/delete

Now my problem is another one. How do I now the my usb hard drive is sdb and not sda, sdc or sdd?

lsusb `just shows me` Bus 002 Device 008: ID 1058:25a2 Western Digital Technologies, Inc. Elements 25A2

Do you have any ideas? Thanks in advance

Jürgen K.

Posted 2019-10-31T13:45:03.117

Reputation: 113

check lsblk -output. – Hannu – 2019-10-31T15:34:43.140

this is for root only :( – Jürgen K. – 2019-10-31T15:45:30.767

$ lsblk -> NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT, sda 8:0 0 232,9G 0 disk, ├─sda4 8:4 0 30,5G 0 part [SWAP], .... i.e. no sudo. Ubuntu 16.04 (debian based) – Hannu – 2019-11-01T15:34:55.390

Answers

1

What you're doing is too compilcated. ;-)

Usually it suffices to do the following:

  1. umount the mounted media (if the device has multiple partitions then do that for all of them).
  2. Execute eject /dev/sdN (or whatever /dev/disk/by-id/... is more useful for you; or a device from another hierarchy under /dev/disk).

You might intersperse a call to sync between those two but I'd say it's for truly paranoid persons as eject should take care of forcing the kernel to push any buffered data to the device. See eject(1).

kostix

Posted 2019-10-31T13:45:03.117

Reputation: 2 435

Oh, I've misread your question. So the only useful portion of it is to check out the hierarchy under /dev/disk. Also you can run dmesg as root and see what device node was assigned to your drive when it was plugged in. – kostix – 2019-10-31T15:40:17.343