After
Landing on Tatooine, the droids were captured by Jawas and sold to Owen Lars, a moisture farmer; Lars charged his nephew, Luke Skywalker, with care of the droids -- but Artoo proved difficult to control.
As such, R2D2 appears to be the state property of Naboo. Queen Amidala as the head of state exercised her control over R2D2. The Droid continued his service to Amidala while she was a Senator. C3PO was built by Anakin Skywalker.
R2-D2 was part of the repair crew for the Naboo Royal Starship. He technically is owned by Naboo's elected royalty until Padme took him along for her senator duties. By the Clone Wars, Padme gave him to Anakin as she felt a droid like R2 was far more useful to aid Anakin.
The two droids bickered -- Artoo called Threepio a “mindless philosopher” -- and separated, but both were eventually recovered by Jawas. The scavengers sold the droids to Owen Lars, a moisture farmer, who charged his nephew Luke Skywalker with care of the droids.
R2-D2 was present when Padmé gave birth to Leia and Luke, so he knew Luke was Anakin's son – but what he didn't know was that Anakin became Darth Vader. In addition to that, Anakin's fall was surely a painful event in R2-D2's life, one that he definitely wouldn't like to remember or even talk about.
Because R2-D2 did not know. The last time R2 saw Anakin was when he accompanied Padme and Obi-Wan to Mustafar; while Anakin and Obi-Wan fought, R2 and C-3PO loaded Padme onto the ship, then saw Obi-Wan return alone, upset, and holding Anakin's lightsaber.
In Star Wars: The Force Awakens, set approximately 30 years after Return of the Jedi, R2-D2 is revealed to be kept in storage at the Resistance base on the planet D'Qar, having put himself in a low-power mode after Luke Skywalker's disappearance.
R2 was later able to restore his companion during the Battle of Geonosis. After the battle, R2-D2 and C-3PO were the sole witnesses to the marriage of Anakin Skywalker and Padmé Amidala in Lake Country. After this Padmé gave ownership of R2 to Anakin while she kept 3PO.
To keep audiences thinking that R2-D2 was moving all by himself, Kenny Baker's legs were hidden using pipes that led to the droid's feet. This allowed him to control the astromech's movement when he was hidden inside.
Obi-Wan Was Pretending He Didn't Know R2-D2
The base assumption of why Obi-Wan doesn't remember R2-D2 -- in light of the prequels -- is that Obi-Wan is feigning ignorance in A New Hope to downplay the importance of the droid's arrival.
Unfortunately, the entire chapter is told from Yoda's perspective, so it's unknown if R2-D2 recognized Yoda as well. One would imagine he did, since he did not have his memory wiped in Revenge of the Sith, and Yoda has a very distinct appearance and manner of speech.
Yoda recognized R2-D2 during The Empire Strikes Back.
R2-D2, sometimes spelled Artoo-Detoo and often referred to as Artoo, was an R2-series astromech droid manufactured by Industrial Automaton prior to 32 BBY, who would participate in major galactic events for nearly two centuries alongside the Skywalker family.
Starting with Star Wars: Episode I - The Phantom Menace, Obi-Wan and R2-D2 helped free Naboo from the Trade Federation's invasion. Later, both served in the Clone Wars with R2-D2 assigned to Jedi Knight Anakin Skywalker. Since Obi-Wan and Anakin often fought together, Obi-Wan was friends with R2-D2 as well.
C-3PO returns in Star Wars: Episode I – The Phantom Menace, the first chapter of the Star Wars prequel trilogy, where it was revealed that nine-year-old slave Anakin Skywalker (Jake Lloyd) built him out of spare parts.
In fact, R2 didn't witness Anakin and Obi-Wan's duel, but he returned to the ship and left the place with the latter, presumably with the knowledge that his former master isn't alive anymore. So, essentially, the droid had no idea that Darth Vader is, in fact, Anakin Skywalker.
Anakin Skywalker is the son of Shmi Skywalker, born without a father through the Force. He is the secret husband of Padmé Amidala, the father of Luke Skywalker and Leia Organa, the father-in-law of Han Solo, and the maternal grandfather of Ben Solo.
"We were working late one night on THX 1138, and we were looking for 'Reel 2, Dialogue 2' and so somebody yelled out get 'R2D2' – and Walter Murch, who was mixing the film, and I both loved that name so much that we decided that it was a good name for something," Lucas said in The Making of Star Wars.
The following year, he became the property of Anakin Skywalker, who he had a trustful friendship with. R2 served in several missions during the Clone Wars, alongside his owner. Following the fall of the Republic, R2 was handed off to Bail Organa, who took care of the droid for several years.
R2-D2 Captured by Jawas | A New Hope (Episode IV) | StarWars.com.
Of course, the Father almost immediately wiped Anakin's memory, because he couldn't very well achieve balance knowing what he knew of his future. That's very interesting, though. It means that the Father knew that Anakin will become Vader, will destroy the Jedi, will literally annihilate whole worlds….
“It's good to fly with you again, my old friend,” the old man said, so softly Han wasn't sure he had heard him right. C-3P0 didn't; his memory was wiped at the end of Revenge of the Sith to prevent him from spilling the beans.
Darth Vader didn't learn he had a daughter until Return of the Jedi, when he stood before Emperor Palpatine. The Emperor's power probed Luke's mind, attempting to goad him to fall to the dark side, and he discovered Leia's existence. "Sister," the Emperor taunted.