R2D2 was essentially a generic astromech droid. He was purchased as a maintenance droid for the Queen's ship, one of several. He was brand new, one owner, at the start of Phantom Menace. He may have been on the ship for a few months, but not much longer.

His first mention in the Star Wars universe (according to Wookieepedia, which takes into account the Extended Universe) is his appearance in Episode I. R2D2 was basically a standard droid who developed his personality and status over time as he became involved in the major events. Nothing quite so colourful as C3PO's origin story.

Droids in the Star Wars universe are occasionally memory wiped so not to build up personality quirks, this hasn't happened to R2-D2, but it explains why he is unique.