Some have speculated that the virus preceded life, being as they are nothing more than amino acid/DNA/RNA chains. This would seem to be plausible. However, being as we likely do not (and possibly never will) have the ability to reproduce the conditions in which life formed, this may have to remain speculation for some time to come.
That in mind, another interesting possibility came to mind; that life itself generated the virus as a means to more effectively compete amongst each other. This has some real world backing, insofar as all life that is a carrier of a particular virus generally tends to be more successful than those who are not; such obviously reduces competitive pressure. We have also many cases of life generating other poisons to reduce competitive pressure, so it is not a stretch to posit that they may have branched out into virological warfare.
So, with the motive and use of such a mechanism in place, we have merely to show now that life can indeed spontaneously generate the virus where previously there was none. This would likely be as a result of random mutation in one of several competing strains of a particular species.
An experiment to verify such would be as follows: Take a number of strains of a particular bacterium species, and culture them isolated from each other until they reach some particular population level. Then put them into competition on the same substrate, and see which (if any) particular strain achieves dominance. Study said strain for traits that are new (and virological in particular). If no evidence of new viruses is found, separate the winner and culture into groups much like the original experiment, and repeat until one of these conditions are met:
It is likely that the latter outcome will occur, in my opinion, as life is notoriously tight-fisted with it's origin story. However, it would be an enlightening experiment to carry out either way.