2

I would like to know what would be the best practices to start/stop/switch safely an eSATA disk.

First : i've read this post : Safely removing eSATA disks but the given and accepted answer does not work for me. At first i wanted to ask for clarifications, but i've read this is to be avoided, so my only option was to open another question.

I'm running kUbuntu 13.04. My bios does support AHCI and i have specifically enables hotplug for the SATA port that links to my eSATA bay. My eSATA dock has a power button.

Starting seems easy enough. If i plug a disk in the bay, then power it up, the disk will mount automatically as a "fuseblk" disk (at least for the one i tested, looks like it's how an NTFS disk is reported)

However, i would like to know how i can stop the disk without stoping the computer, possibly to mount another disk, all of this while avoiding data loss and physical disk damage, and preferably in an (semi) automated way so i don't have to open my command line every time.

What i've found so far :

  • sdparm doesn't seem to be of any use, even thought it should be the right tool (disk is /dev/sda), but sdparm -C stop does nothing
  • hdparm on the other hand does work to put the disk to sleep sudo hdparm -Y /dev/sda will have the disk stop spinning. However, the disk is still mounted as reported by mount -l
  • sudo echo 1 > /sys/block/sda/device/delete will give me a permission refused error (even though i used sudo)
  • there is an "eject" icon if i right click the disk in Dolphin that will unmount the disk, but the disk won't stop spinning (and i sure don't want to physically remove a spinning disk)

So currently, i unmount the disk using the "eject" button, then put the disk to sleep. However, i don't know enough of the HDs management to be sure "sleep" is enough. Is there no real "stop" or "power off" command? When the OS is going to shutdown, does it simply put the drives to sleep and is it enough to allow safe handling.

Also, when following those steps and then switching to another disk, the disk will sometimes appear as /dev/sde rather than /dev/sda, wich leads me to believe there are some resources that are not correctly freed. Maybe this is precisely the point of the sudo echo 1 > /sys/block/sda/device/delete command, but as i can't run it, even with a sudo, it's not really helpful.

Is there any other command i should be aware of, and add to the sequence?

As for making this automatic, i guess i can make a shell script, but what if i have a multi partition disk. Using umount /dev/sda1 won't unmount other partitions, and i don't think it's possible to unmount using only /dev/sda is it? Would it work with /dev/sda*? Currently the only multi partition disk i have under hand is my system disk, so i can't try to unmount it and see what happens.

  • 1
    "sudo echo 1 > /sys/block/sda/device/delete will give me a permission refused error (even though i used sudo)" You're using sudo wrongfully here. It elevates the privileges of echo which isn't needed, but it fails to elevate privileges for the output redirection (which is needed). Try sudo sh -c "echo 1 > /sys/block/sda/device/delete" instead. – gertvdijk May 22 '13 at 15:33
4

You'll have to combine all the elements in the right order in case you're coming from the situation of a spinning disk which contains a volume being mounted.

  1. Unmount all volumes on this disk, e.g.:

    sudo umount /path/to/mount/point
    

    Verify it's unmounted using grep sda /proc/mounts. Repeat for other volumes on the physical disk.

  2. Stop the drive, e.g.:

    sudo hdparm -Y /dev/sda
    
  3. Tell the SATA controller you'd like to unplug it:

    sudo sh -c "echo 1 > /sys/block/sda/device/delete"
    
| improve this answer | |
  • Thanks for the syntax on the "echo" line. I'm not very familiar with redirections, and not familiar at all with superuser redirections. No way to automatically umount multiple parititions with a single statement that could fit in a script then? – r0k May 24 '13 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.