Announcement

Collapse
No announcement yet.

Proper way to plug/unplug an eSATA hard disk?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Proper way to plug/unplug an eSATA hard disk?

    For my Linux hardware problems, Google is often my friend. Unfortunately with regard to SATA hot-plug (or hot-swap) support under Linux, all the links I've come across refer to solutions several kernel releases out-of-date.

    The problem: what is the proper procedure (on the software/OS side) to follow when plugging or unplugging an (e)SATA drive? Is a simple "umount /dev/sd[:alpha:][:digit:]" enough?

    Among the "obsolete" solutions I've come across is to use a program called "scsiadd":

    /usr/sbin/scsiadd -s
    scsiadd:scsiadd(): could not open /proc/scsi/scsi (w): No such file or directory

    Also SATA hot-plugging is as yet unsupported by the wonderful new devkit framework. To unplug a USB drive, I use "devkit-disks --detach /dev/sd[:alpha:]" or its GUI "safely remove hardware" equivalent. This doesn't work with the eSATA interface of my external hard disk enclosure.

    To be sure, an examination of the contents of /dev/ shows Linux gracefully removing the nodes (both disk and partition) for an unplugged eSATA drive. This is confirmed by the dmesg output.

    (Note: I have enabled AHCI and disabled IDE mode for SATA in the motherboard BIOS, so SATA device recognition is not the issue. I'm looking for the proper or most elegant way to unplug/replug an eSATA drive.)

  • #2
    I'm not completely sure on how devkit-disks does it, but have you tried eject -s /dev/sdX? A scsi eject might be the proper way.

    Comment


    • #3
      Unmount, then pull wire.

      Comment


      • #4
        I see you said "(e)SATA" and not "eSATA". If you're under the impression that all normal SATA drives can be unplugged, you're wrong. Your SATA controller has to specifically support this. If it doesn't say anything about SATA hotplugging, then it's not supported. Trying it should be safe, but there's always a chance of hardware damage.

        eSATA is always hotpluggable.

        Comment


        • #5
          It would help if you would specify your chipset on your motherboard. As RealNC said some chipsets do not support hotplugging in linux (Some AMD chipsets come to mind).

          Comment


          • #6
            Originally posted by deanjo View Post
            It would help if you would specify your chipset on your motherboard. As RealNC said some chipsets do not support hotplugging in linux (Some AMD chipsets come to mind).
            lspci gives it as:

            SATA controller: ATI Technologies Inc SB700/SB800 SATA Controller [AHCI mode]

            I'm assuming it does, since Linux appears to recognize that the disk has been unplugged or plugged. The "links" for both disk and partition (for example, /dev/sdb and /dev/sdb1) disappear when unplugged and appear when unplugged. This is not the case when I ran the disk in IDE mode (where the disk and partition were registered as /dev/hda and /dev/hda1).

            So my problem then is figuring out a more graceful way to, let's say, power down the drive. For USB, "devkit-disks --detach /dev/sdb" is able to turn off the LED of my USB Flash Drive. I see that as proof that the UFD has been turned off.

            Is there a software means of powering off an eSATA drive?

            Comment


            • #7
              Originally posted by droidhacker View Post
              Unmount, then pull wire.
              What I've read thus far says it should be power down first before pulling off wire.

              Comment


              • #8
                Originally posted by RealNC View Post
                eSATA is always hotpluggable.
                What then do you do on the software side before unplugging? Is it a simple "umount /dev/sd"[drive letter]?

                Comment


                • #9
                  Originally posted by An(noymous)droid View Post
                  What then do you do on the software side before unplugging? Is it a simple "umount /dev/sd"[drive letter]?
                  after unmounting the device, to "power off" (or sleep) the unit:

                  Code:
                  hdparm -Y /dev/sdX
                  (where X represents the device you wish to power off. for example: /dev/sdb)

                  this will power the drive down allowing for it's removal w/o risk of voltage surge.

                  Comment


                  • #10
                    All SATA and eSATA hardware is physically able to be hotplugged (ie. not damaged if you insert/pull the plug).

                    How the chipset and driver handles this is another question. Some driver/chipset combinations do not properly handle hotplugging and need a warmplug command such as the following one:
                    Code:
                    echo 0 - 0 > /sys/class/scsi_host/hostX/scan
                    Replace X with the appropriate number for your SATA/eSATA port.

                    Comment


                    • #11
                      @justsumdood:

                      that was the exact same way I did it - up until NOW


                      with kernel 3.3 rc3 & rc4 (afaik it worked with 3.2)

                      I only get the following:

                      [ 2093.960134] ata8: exception Emask 0x10 SAct 0x0 SErr 0x990000 action 0xe frozen
                      [ 2093.960139] ata8: irq_stat 0x00400000, PHY RDY changed
                      [ 2093.960144] ata8: SError: { PHYRdyChg 10B8B Dispar LinkSeq }
                      [ 2093.960151] ata8: hard resetting link
                      [ 2094.681797] ata8: SATA link down (SStatus 0 SControl 300)
                      [ 2099.673242] ata8: hard resetting link
                      [ 2099.977646] ata8: SATA link down (SStatus 0 SControl 300)
                      [ 2099.977660] ata8: limiting SATA link speed to 1.5 Gbps
                      [ 2104.969034] ata8: hard resetting link
                      [ 2105.273515] ata8: SATA link down (SStatus 0 SControl 310)
                      [ 2105.273528] ata8.00: disabled
                      [ 2105.273544] ata8: EH complete
                      [ 2105.273553] ata8.00: detaching (SCSI 7:0:0:0)
                      [ 2105.274064] sd 7:0:0:0: [sde] Synchronizing SCSI cache
                      [ 2105.274094] sd 7:0:0:0: [sde] Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK
                      [ 2105.274100] sd 7:0:0:0: [sde] Stopping disk
                      [ 2105.274108] sd 7:0:0:0: [sde] START_STOP FAILED
                      [ 2105.274111] sd 7:0:0:0: [sde] Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK


                      that means when after that I plug in another harddrive and power it up - it won't be recognized

                      the controller is the (in)famous Jmicron 36x (dunno 368 or 363, something)


                      the same happens when stopping via sdparm and remounting read-only (sdparm -C stop -r /dev/foo )


                      any idea how to get it recognize the new disk ?
                      Last edited by kernelOfTruth; 02-22-2012, 10:02 AM.

                      Comment


                      • #12
                        Verify with
                        Code:
                        # lspci -k
                        that ahci is the driver in use for your SATA chipset, and not pata_jmicron or worse. Only ahci will give you hotplug function.

                        Comment


                        • #13
                          Originally posted by An(noymous)droid View Post
                          What then do you do on the software side before unplugging? Is it a simple "umount /dev/sd"[drive letter]?
                          I'd say the safest way would be to first issue a umount to the (e)SATA device you want to remove...this will ensure all data has been written to the device and the inodes are updated so the device has a "clean" filesystem. Once that's done you can then power off the device and unplug it.

                          This should be applicable to USB sticks as well but as there's no need to power them off you can unplug after unmounting them.

                          Comment


                          • #14
                            Part of the specs

                            Part of the specs for USB and SATA is hot-plugging, however it is very prudent to unmount a (any) file-system before powering it down or removing it.

                            Comment


                            • #15
                              Originally posted by chithanh View Post
                              Verify with
                              Code:
                              # lspci -k
                              that ahci is the driver in use for your SATA chipset, and not pata_jmicron or worse. Only ahci will give you hotplug function.
                              thanks !

                              I'm pretty sure that the pata port isn't connected:

                              03:00.0 SATA controller: JMicron Technology Corp. JMB362/JMB363 Serial ATA Controller (rev 03)
                              Subsystem: Acer Incorporated [ALI] Device 036b
                              Kernel driver in use: ahci
                              03:00.1 IDE interface: JMicron Technology Corp. JMB362/JMB363 Serial ATA Controller (rev 03)
                              Subsystem: Acer Incorporated [ALI] Device 036b
                              Kernel driver in use: pata_jmicron
                              but it probably won't hurt to remove the driver all-together from the kernel

                              afaik it's set to ahci in bios - but I'll check again later that it's really the case

                              (strangely it actually has to be ahci since it worked before)

                              dmesg | grep AHCI
                              [ 0.759598] ahci 0000:00:1f.2: AHCI 0001.0300 32 slots 6 ports 3 Gbps 0x3f impl SATA mode
                              [ 0.782563] ahci 0000:03:00.0: AHCI 0001.0000 32 slots 2 ports 3 Gbps 0x3 impl SATA mode






                              Originally posted by DeepDayze View Post
                              I'd say the safest way would be to first issue a umount to the (e)SATA device you want to remove...this will ensure all data has been written to the device and the inodes are updated so the device has a "clean" filesystem. Once that's done you can then power off the device and unplug it.

                              This should be applicable to USB sticks as well but as there's no need to power them off you can unplug after unmounting them.
                              I wouldn't rely on solely un-mounting

                              todays harddrives have huge caches after all


                              my procedure usually goes:

                              sync && sdparm -C sync /dev/foo

                              then I unmount and issue the same again


                              * after that it can be stopped & remounted via sdparm

                              or sent to standby

                              * via hdparm -Y /dev/foo

                              Comment

                              Working...
                              X