Resolving authorship when PhD student does most of the work on paper, but originally agreed to support another PhD student (first author)? I am a senior PhD student (in electrical engineering) who has been working on a project for approximately two years with another student (call him John, same year as me) and our advisor.

It was decided at the beginning of the project that John would be the leader of the research and I would help. Over the past two years, John's research interests have drifted away from the topic of the project, and he has increasingly lost interest in the project. This has pushed more responsibility on myself (coincidentally, my interests have drifted towards the topic). We published a conference paper on the topic (which had John as the first author even though I wrote the majority of it).

I raised concerns with my advisor about six months ago that I was doing more of the work. He listened and spoke with John that he needs to put in more effort. Shortly after I mentioned my concerns to my advisor, we were invited to submit the work to a book chapter to which we agreed (with the same author order, since John was still labeled as the leader of the project).

Over the course of the past six months, John and I have been writing the chapter. John has not been putting much effort into the chapter (John's written English is very poor and he is not detailed oriented at all, resulting in many equations being incorrect), so I have taken it upon myself to undergo the (very time-consuming) task of fixing the paragraphs and math. The quality of the chapter would have been very poor if it was not for my efforts.

I mentioned to my advisor in private that I basically wrote the entire chapter to which he responded that John's work was primarily in the theory. I know that John has not contributed more to the theory than I have. Furthermore, my advisor mentioned that John needs this work as a chapter of his thesis so he must be first author.

We are now a couple of days away from submission and I am feeling like I was exploited. I am sacrificing my own projects in order to finish this. Since my name is on the chapter, I have put in a lot of effort to make sure it is good quality. It is upsetting that John will end up getting more credit than myself. Furthermore, I am questioning the ethics of the fact that I wrote a chapter of someone else's thesis.

How should I proceed with this? My advisor has already seemed to make up his mind. Should I request/demand that a footnote be added that John and I contributed equally?
I personally find the "* authors contributed equally" footnotes to be supremely awkward, though perhaps you're in a discipline where they are common, in which case go for it....  And in this case you're arguing it isn't even true.  I'd say you're getting a raw deal, but the time to push back was earlier, when you could have argued for the appropriate recognition and then declined the chapter inclusion if you didn't get either the proper recognition or more work from your colleague.  

My advice: treat this as a learning experience, be gracious, and move on.