Easiest way to do it might be a lateral transfer...fm @your institution over to IM @your institution. That's if the relationship between the programs is decent. It will probably be very hard, realistically, to interview for IM without your current PD finding out. You may have to travel out of town to interviews at times when you don't have a scheduled vacation, for example. The IM programs will very likely want some LOR's from your current program, or at least to talk with your PD. What you could do is go ahead and apply in ERAS, and then if it looks like you are going to get some interviews (or if you basically know that you will, based on your competitiveness as an applicant) then you could level with your PD at that point. I'm not sure I'd let the cat out of the bag at this point though, as it's still going to be several months before interviews take place.
Also, you know your program and your PD, and can probably judge after 1 year whether he/she is likely to be supportive, neutral or not very helpful (and/or antagonistic). You need to plan/act accordingly.
Two other things to think about.
Not sure I'd want to "waste" a 3rd year in fm just to have finished the residency, if I was SURE I could/would finish up an IM residency. People tend to get burned out after 5 or 6 years of residency, and if your reason for switching is wanting to specialize, that may be all the more reason to get out of fm ASAP. Also, some programs may not want you as much if you've used up 3 years of Medicare GME funding already.
Make sure you switch for the right reasons. Many general IM and fp docs end up with similar jobs at the end of the day. If you are only bailing because you hate ob or something, realize that lots of fm docs don't do ob/gyn that much. Don't switch just because you think the grass is greener on the other side of the fence...a lot of the crap in IM residency is going to be the same crap as the fm residency (drug seeking patients, being the "dumping ground" for the ER and the surgeons and other services who don't want to admit patients, etc.). IM residents take more call and do more ICU months than most fp residents, which can lead to more fatigue and stress. However, we don't have to do peds or OB, which I felt was a big plus as I didn't want to take care of those type patients.
I know someone who switched and ended up very burned out by the end of IM residency, and now he's going to do outpatient primary care anyway, and not specialize. He could have stayed in fp residency another year and been done, and had the same job. I'm NOT trying to discourage you, but just make sure you have good reasons for switching.