There’s a limited amount of coverage on this subject but, basically, we have no idea:
Is it known how the first viruses formed?
An fairly interested and very short read:
(Where did viruses come from?)
Then there are the viruses whose genomes are so large that scientists can’t quite figure out what part of the cell they would have come from. Take, for instance, the largest-ever virus so far discovered, mimivirus: its genome is some 50 times larger than that of HIV and is larger than that of some bacteria. Some of the largest known viruses infect simple organisms such as amoebas and simple marine algae. This indicates that they may have an ancient origin, possibly as parasitic life-forms that then adapted to the “virus lifestyle.” In fact, viruses may be responsible for significant episodes of evolutionary change, especially in more complex types of organisms.
The featured image is of the Grapevine fanleaf plant viruses. Yes; all living organisms can get viruses, including, presumably, viruses themselves (even some machinery is missing). People seem to be pretty defensive of the fact that viruses are alive, so I’d hate to tick anyone off.