How to power down external drive safely

I use a variant of the previously noted solutions, wrapped in a bash script, and launched from a desktop icon. Since my application is for an external USB drive, I include code to identify the relevant device name based on the specific name of my USB drive (SILICON16GB). The main components of the process are:

# Flush USB drive buffer
sync
# Identify the device name for the SILICON16GB USB drive
usblongname=$(lsblk -l | grep SILICON16GB)
usbname="${usblongname:0:4}"
# Unmount the USB drive
udisksctl unmount -b /dev/$usbname
# Power off the USB drive
udisksctl power-off -b /dev/$usbname

Note that the use of the sync command causes the script to wait until any writes to the USB drive have been completed. The script is failsafe in that it does nothing if the drive is already unmounted. More details, and a full listing of the bash script can be found at: https://linuxnorth.wordpress.com/2018/01/25/safely-removing-a-usb-drive-with-a-bash-script/


The GUI way to do this is (in Ubuntu)...

Unmount the mounted disk by clicking on the "eject" icon (Files/Nautilus), as shown below...

enter image description here

Open the Disks application and select "Power Off", as shown below...

enter image description here


after umounting the Partitons of your usb harddrive, you can run udisksctl power-off -b /dev/sd?

For ? you have to adapt it to your situation.

example for my backup drive udisksctl power-off -b /dev/sdc

Tags:

Hard Drive