|A little 'Photoshop' for your amusement.|
To rack one's brains: to stretch the brain beyond its normal limits, in order to remember something, to find something appropriate to say, etc.
As most know, the rack was used in torture. The victim was strapped to a frame with rollers at each end, and then slowly, painfully stretched. From the sixteenth century onwards the rack was a favorite figure for expressing something that caused intense suffering. In this case, to rack one's brains takes two uncommon objects - brains and rack - and relates them together by comparing the mental pressure of stretching one's thoughts or memory to this physical torture. Apparently the phrase dates to the second half of the seventeenth century. In 1583 the composer William Byrd is quoted as saying "racke not thy wit to winne by wicked waies". This idiom conjures up a related one: to strain the nerves which invokes the notion of nerves as tendons. That seems to be the idea expressed in this quote by Boswell on Samuel Johnson.