There are two definitions for habeas corpus: one formal and the other substantive. The formal definition may be found in any law dictionary. This essay is about the substantive definition. The substantive definition of habeas corpus is not found in the dictionaries, but rather, in the history books.
In the early days (before Magna Carta), the king had many court systems operating: e.g. courts of Common Pleas, Exchequer, King's Bench, Chancery, etc. Each court had its jurisdiction defined. Of course, as an arm of government, courts are simply another form of bureaucracy with assigned functions. Like any bureaucracy, they always want to expand their jurisdictions. If a court exceeded its jurisdiction, a person could go to the proper court that should have had jurisdiction and ask for an order directing the errant court stop its proceedings and release jurisdiction to the proper court. The phrase, "habeas corpus," meaning, "you have the body" was put at the end of pleadings to the second court asking that the first court be required to produce the body if it was being held. In its most common form, the full formal phrase for habeas corpus was "habeas corpus ad subjiciendum."
Of course, as you might surmise, that would pit one court bureaucracy against another. The Habeas Corpus worked quite well because, as long as the defendant was not a common enemy to both bureaucracies, one bureaucracy would not miss any opportunity to put down a competing bureaucracy. The practical result of all this is that the defendant would often be ordered released, which was the second court's way of telling the first court that it didn't know what it was doing and had strayed from its original jurisdiction (i.e. exceeded jurisdiction). The habeas corpus, as a by-product of bureaucratic turf protection, tended to serve personal liberty well. Over the centuries it became known as the "Great Writ of Liberty." It was the only known privilege or right that became stronger with the passage of time.
In summary, habeas corpus is the process of one court sitting in judgment of another court's jurisdiction. It is NOT a civil or criminal proceeding, but rather it is a family fight between courts. That is why, even though you find habeas corpus rules in the civil procedure books (FRCP and Calif CCP) the procedures stand somewhat alone, independent of the rest of the procedures in those codes. The reason is obvious: Why would a court burden itself with procedural requirements? That stuff is ok for outsiders not part of the court system (i.e. plaintiffs, defendants, and attorneys) but not ok for judges themselves.
In America, everyone can be sovereign. When you move for habeas corpus, you are activating your own court, which is separate and distinct from their court. You sit in judgment of the jurisdiction of their court. When you order them to produce the injured party and to demonstrate the injury, and when they fail to produce, then your court can issue an order to dismiss the case for lack of jurisdiction. Your court is a court of record and takes precedence over the statutory court.
Also, see Congressional Research Service's overview on habeas corpus.
Here's an example.