I have an external hard drive which attaches to my pc via usb. The drive is formatted for Linux, i.e. ext4 and is used to take backups. It has its own separate power supply. When I switch its power supply on it fires up and mounts automatically which is great. I take backups and then want to power it down. (There is no point in running it when I am not taking or using the backups and anyway it gets hot and consumes power unnecessarily). My question is what is the best and safest procedure for powering it down?
Thank you everybody for all the really helpful answers. I am using Ubuntu 18.04 so will use the GUI option until it disappears in the future. Then, I have saved all the other answers for when I need them! Really appreciate all the time taken to help me out: thank you.
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:
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...
Open the
Disks
application and select "Power Off", as shown below...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
I would unmount all mounted partitions on the external drive (maybe only one ext4 partition in your case),
or
where
mountpoint
is the path to the partition you want to unmount andx
is the device letter andn
the partition number of the partition you want to unmount.Check that the unmount command finishes successfully and the terminal window returns to prompt.
After the unmount operation(s) buffers are flushed and everything pending is written to the physical location of the drive, and it is safe to power off the external drive.