Wandering the halls of archivy
I have heard that this originally came from the making of Kilts. A full kilt need nine yards of cloth, but inferior Kilts could be made from less. When A Scotsman wanted the best Kilt, he asked for the "Whole nine yards."
That theory is in the discussion archives along with several others. A search using "kilt" will locate it.