Well, it depends. For the books I've posted here, I've always started with a
legal copy of an HTML or TXT file that's on the internet somewhere (usually
Project Gutenberg). Some people, including our Good Master RWood, often start by using a scan of a paper copy (which seems like waaaaay too much effort for me) and running optical character recognition (OCR) software to generate the text which then needs to be checked manually (get my picture of effort?).
After that, there are a few software tools around that can generate the ebook files.
BookDesigner is a pretty tough to use but powerful and free program that will create the LRF, PRC, and IMP files. It has some drawbacks but it's what I almost always use. But it took me many attempts to become adept at using it without tears. Fortunately, HarryT wrote
a great tutorial to start with.
Some others use
Mobipocket Creator, another free program which HarryT probably also uses a lot now and which he wrote another excellent tutorial for (see the other tutorial link above). But it only generates PRC files.
I know there are other tools floating around now but I really haven't looked at them much.