SATA (hot) swapping for backup

Daniel Pittman daniel at rimspace.net
Fri Aug 4 13:28:37 UTC 2006


David Abrahams <dave at boost-consulting.com> writes:

> Thank you *very* much for your patient and complete answers.  I have a
> lot to learn and I really appreciate it when someone is willing to
> take the time to educate me...

No problem.  The way I got where I am is having someone answer my
questions, so don't mind helping out others.

> Daniel Pittman <daniel at rimspace.net> writes:
>
>> David Abrahams <dave at boost-consulting.com> writes:
>>> Daniel Pittman <daniel at rimspace.net> writes:
>>>> David Abrahams <dave at boost-consulting.com> writes:
>>>>
>>>>> 2. I'm not 100% sure that unmounting the drive, powering it off,
>>>>>    removing it, and putting a new disk in its place is legit.  Can
>>>>>    anyone confirm?  My motherboard *does* claim to support SATA
>>>>>    hotswap, but I'm not sure if Linux supports it.
>>>>
>>>> Linux probably doesn't, save in the most recent kernels, and possibly
>>>> only with appropriate patches.  
>>>
>>> In my case I'm wondering what could possibly go wrong?  If the drive
>>> is completely unmounted before it is powered down and removed, it
>>> seems as though the OS has no reason to be concerned with how/when I
>>> plug it in.  Any ideas?
>>
>> Well, the worst case is that the hardware can short and fry the entire
>> controller chip, resulting in a dead hard disk, motherboard and
>> potentially other components.
>>
>> That is a pretty bad worst case, but not unknown, for pulling hardware
>> at random.
>
> And seems rather unlikely considering that the motherboard supports
> SATA hotswap.  If I put Windoze on that machine I'd be able to do it.
> It would be a pretty perverse hardware implementation that would allow
> you to plug and unplug drives only if the OS were cooperative.

Actually, if you read the SATA hardware page you will note that a few
controllers support "warm-swap."  That is a polite way of saying, in
fact, that without the cooperation of the OS the hardware can't do
anything...

So, while it seems counter-intuitive there actually /is/ hot-swap
hardware out there that only works correctly with OS level support.

The part that doesn't happen, by the way, without that support *is* the
part where things like power toggling happen, more often than not, in a
design like that.  Foolish, but what are you going to do?

>> A much more likely fault is that your controller will get to
>> exercise those wonderful, poorly tested, error handling paths as it
>> suddenly discovers a missing device.
>>
>> That can lead to anything from the controller hanging to a panic when
>> the error handler turns out to have a bug.  Not nice.
>
> You're suggesting that the hardware/firmware hotswap handling *itself*
> (I take it that's what you mean by "the controller") is buggy?

Well, not buggy, but not designed to handle random device disconnects.
Again, because you generally can count on some level of OS support in
the controller you can take shortcuts in design.

Also, it isn't unknown for controllers to omit the resistors that will
pull the lines to a nice idle when the disk is connected, resulting in
the bus turning into random noise rather than a nice stable state.

In the face of effectively random inputs hardware has been known to go
belly up.  Again, this is uncommon, and I don't know which (if any) of
the hardware suffers the problem, but it can happen.  :)

>> Also, if you don't stop the drive spinning before you pull it then you
>> have cut power to a disk in rotation.  
>
> Huh.  I guess unmounting the drive isn't enough to stop the spindle.

No, though you can send the appropriate command sequences with sdparm or
hdparm to put the drive to sleep.  That should stop it well enough to
help here.

[...]

>>>>> Lastly, if there's any standard way to automate backup jobs (mounting
>>>>> disks, rsync or whatever, unmounting, etc.) I'd appreciate a
>>>>> reference.  I can always use cron scripts but I imagine someone has
>>>>> probably come up with something better.
>>>>
>>>> udev can fire off arbitrary code on insertion of a device.  You can use
>>>> that to trigger a script that will, basically, do all the work for you.
>
> Are there "standard" scripts for this purpose, or will I be whipping
> one up at home?

No, you would have to write that yourself.  Er, the line should be
something like this, I think:

    KERNEL="sda", RUN+="/path/to/my/script"

Except you want to use a better identifier (like the disk label) than
the kernel name, since that might change at random on you.

udev will then run your script when that device is inserted, as root,
and the script can do, well, whatever you want it to do. :)

>>> Is that really what "support for SATA hot-swap" amounts to?
>>
>> No.  That is the very last bit.  Hot-swap is the bit where the OS,
>> driver, controller and everything else is *aware* that changes are going
>> to happen, so they can handle them gracefully.
>>
>> udev (and hald, and a bunch of other code written on top of those) are
>> the icing of the cake: when hot-plug works it can react to it sensibly
>> and do things like configure your new network card, mount your hard
>> disk, or whatever.
>>
>> Hot-swap, as such, is all the bits below that which conspire to make it
>> work.  On a bus like USB this is well tested, while SATA ... isn't.
>
> Huh, too bad.
>
> Well I did also buy an external hotswapping USB enclosure that I can
> use, but I was really hoping to get the full speed of SATA for my
> backups.  I guess I just have to weigh that loss against the time it
> would take to research SATA kernel support and configure/build a new
> kernel.

Yeah.  I think, basically, SATA hot swap is still too new for me to want
to use it in production.  The USB case, for which hot swap is years old
and well tested, is much more likely to be a success.

>> Sorry if that wasn't clear to you -- the driver, OS and controller
>> hardware need to be hot-swap capable for this to have a chance of
>> working even remotely reliably.
>
> Sounds like I've one out of three at the moment.  Probably falling
> back to USB is my best bet in the near term.  I need to get the system
> going and a backup system in place -- that's far more important than
> having the backups be super fast.

Yeah, that is about the state of it.

I hope that all helps.
       Daniel
-- 
Digital Infrastructure Solutions -- making IT simple, stable and secure
Phone: 0401 155 707        email: contact at digital-infrastructure.com.au
                 http://digital-infrastructure.com.au/





More information about the ubuntu-server mailing list