How to establish a collaboration with other researcher?
It is generally good to be explicit about your expectations. You don't want to end up in a situation where one person thinks it is her/his project and the other person has a well deserved place in the "thank you section", while the other person thinks she/he deserves to be a co-author. Such a conflict is really bad for everybody involved.
So when I propose a collaboration or someone comes to me with a proposal, I will discuss co-authorship from the beginning. This makes the discussion less informal than you suggest in the question.
It may still happen (and it has happened to me) that someone comes for advise, and I give that advise under the assumption that I am not a co-author, and the original author is so happy with the advise that I end up being "upgraded" as author.
Similarly, but more tricky, it may happen that I am "downgraded" when my contribution is not significant enough to warrant authorship. Maybe because I did not invest enough time in it, or the sub-problem I am supposed to tackle turned out to be less relevant to the entire project than originally expected. The tricky part is that ideally the downgraded person has to agree otherwise we are in a conflict of the type we were trying to avoid.
Yes, usually it is an informal process. However, it implies the researchers to know each other work. That is why conferences are good to promote new collaborations: you have the opportunity to know more about other works through the seminars and then you have the social component (beer/poster sessions, coffee breaks and conference dinner) in order to facilitate the approach. The first objective is to find a common ground where the two researchers could work together complementing each other research.
As a Ph.D student you are stimulated to take Short-Term Scientific Missions(1) (STSM) in other labs, which is excellent to effectively establish and maturate a new collaboration. In addition, you start to open new perspectives for a possible postdoc position.
There are other possible approaches, such as inviting a professor to visit your lab, but I think that the best suitable for a PhD student is the formula conferences+STSM.
1 - A STSM could have a duration of a couple of weeks up to several months. If you are based on a European Union country you may be able to ask for financial support through the COST project (European Cooperation in Science & Technology).
I started several collaborations with other researchers as a PhD student.
All cases were "accidental" — i.e. I met my collaborators at a conference or seminar and found their talk interesting. The content of their talk was somewhat related to some part of my PhD thesis and I went to talk to them afterwards, asking a question and wondering if their approach to the subject could also work in the case I'm working with (or solve a particular problem I was working on).
I usually thought about their talk more in the weeks after and eventually contacted them by email, asking if they would be interested in working on some particular project together. (I guess their positive reply would be the official start date for the collaboration.)
Note that I was not head-hunting for collaborators — I wasn't trying to pick the most relevant talk, try to ask a meaningful question and relate their response back to my area of expertise — so I don't think the above would work as a manual How to Win Collaborators and Influence People¹.
However, attending talks and interacting with other researchers is certainly something you can try to do more, even if you are someone who is naturally held back / introvert (I am). (Actually, none of the collaborations were started during a social event such as a lunch discussion. If you have a question, my advice would be not to put it aside and wait for the "right" informal setting.)
¹ I haven't read the book I'm alluding to, I just find the title memorable.
The only collaboration that wasn't initiated by myself was with my advisor and his coauthor. My advisor had asked me to read over a preprint of his, where he and his coauthor were stuck for some time. I happened to be able to solve their problem.
Being approached as a PhD student about collaboration is naturally a rather rare case, as for most researchers PhD students of colleagues are not really the go-to expert — apart from your advisor not many people will know in what area you are trained and your advisor is more likely to have more expertise than you.