What is the right way to claim a draw in the last two minutes? Also, is there a procedure to claim a draw after losing on time (I mean if you have a position where you can go for a win if you had time)?
The first point to note that this kind of draw claim only applies when there are no increments. Since digital clocks are almost universal in advanced and normal chess countries it should (I stress "should") rarely arise.
Note also that FIDE proposes to ban analogue clocks and insist on increments in FIDE rated tournaments from 2021, so then the problem should disappear entirely.
There are three cases which can arise:
1) No increments but one or more digital clocks is/are available. In this case the recommended course is for the arbiter to give both sides a 5 second increment, give the claimant's opponent an extra 2 minutes, offer the claimant's opponent a draw which he can decline or accept in the normal way and the game continues to one of the three normal conclusions of win, draw or loss.
2) The player makes a claim that his opponent is not trying to win the game by normal means but just shuffling the pieces quickly to try and win on time. In this case the arbiter will watch the game and if he judges this is correct he will award the draw. He may do this (award the draw) even after the flag has fallen but the claim cannot be made after the flag has fallen and if it is made with just a few seconds left the arbiter will not be able to come to a conclusion and the game will be lost on time.
3) The player makes a claim that his opponent cannot "win by normal means". This is different from "win by any means". For instance if the player is a queen up and crushing his opponent then his opponent might have enough material to win via helpmate but would almost certainly lose if the claimant had enough time.
Another possibility would be if the game was still in the middlegame when, clearly, anything could still happen. In this case the claim would be rejected immediately, the opponent would be given an extra 2 minutes and offered a draw which he could accept or decline.
These are straightforward cases. More problematic would be where the claimant has a rook against a rook and pawn in a theoretically drawn position. This would be the opposite extreme. In this case the arbiter would ask the players to continue and watch the game again possibly until the flag falls. He would then have to judge whether or not the claimant had displayed the required theoretical knowledge to hold the draw. Clearly if the claim is made with just a few seconds on the clock this is not going to be possible and the game is going to be lost.
This same principle applies to all endgame cases where best play would result in a draw but the opponent can win if the player lacks the required theoretical knowledge, even lone king against king and rook's pawn. It should be a trivial draw but the claimant must demonstrate during his time remaining that he has that theoretical knowledge.
Once your flag has fallen no claim can be made even if it is mate in 2.