Dungeonomicon (DnD Other)/Thermodynaminomicon
From D&D Wiki
The G of Life Continues:
"Seriously, this cave is a mile below the surface, what do they eat?"
When you drop an egg on the ground, it breaks. But when you drop a broken egg it doesn't reform a perfect shell. That's entropy baby, the simple fact that it requires energy inputs to maintain an open system, and a closed system only degrades over time. If there is to be Life, let alone civilization, there has to be some way of getting energy into the system. For the surface worlders, that's not even a problem: the Sun shines energy down on the surface all day. But for those who live in the dark realms: be it sewers, the ocean floor, or the classic dungeon complex; there has got to be a source of energy in the D&D world that just doesn't exist in ours. You don't see lush forests in marine trenches because the energy inputs just aren't there. But in D&D neither the ocean floor not the underdark is a desert – it's a vibrant ecology. Here's why:
Those whacky Mushrooms
Ask any DM what people eat down there in the Underdark and they'll probably say "Mushrooms" because it is a well known fact that mushrooms are a fungus and not a plant and they don't need sunlight to grow. What they do need, however, is a source of chemical energy. That can be dead bodies or um… otherwise digested material, sure, but it still has to come from somewhere. When fungus grabs some organic material and converts it into more fungus, that's an inefficient process. You actually have less energy worth of fungus than you had energy worth of whatever it was that the fungus was eating.
Don't get me wrong – edible fungus will happily consume things that are inedible (like woodchips) or even poisonous (like waste) and turn it into something you can eat. It just won't make something out of nothing. So mushrooms are an excuse for why Underdark dwellers have something to eat if and only if there is some other way that energy is coming into the system. It could be anything really, just as the trees will turn useless sunlight into tasty peaches, the fungus will turn useless chemical waste into delicious mushrooms. But while mushrooms can handwave the problem of converting energy that you can't use into energy that you can, they don't explain how that energy gets in to the Underdark in the first place.
The Inner and Outer Planes are infinite in scope, and don't follow the same thermodynamic constraints as Prime worlds do. A portal to the plane of Fire simply heaps energy into whatever cavern it happens to be in, which is like having a little sun right in your closet. Plants and algae can use that energy input to grow, and ooze monsters can eat those plant and civilizations can eat the ooze monsters. As long as those portals stay open, energy can keep entering the system even underground.
Magical locations exist all over the place in the D&D world. Some of them are on the surface, and these become fairy rings or magical castles, or whatever. The point is, almost all of them are put to use, because even the ones in deadly jungles or on top of treacherous mountains simply are not hard to get to. One teleport and you're there. But the world isn't flat (unless you're in Bytopia or the Abyss), and actually there's a lot more volume of the planet that's under the ground than there is on the surface. And that means that the vast majority of magical locations are underground somewhere.
If you consider that in the D&D world, magic is approximately as important as the Sun is to life on the planet, that means that a significant amount of the total energy inputs in the system are underground to the exclusion of being above ground. The underdark has irregularly spaced Nausica-style gardens down there that are supported by magic upwellings. Each of these locations is massively more productive than a field or forest above ground of similar size, and the immutable fact that the surrounding territory is lifeless barren stone causes fights over these locations to be extremely brutal.
The world above is filled with living things, and even in D&D the vast majority of living things die. When living things die, they leave behind a body that other living things can eat. Some of this actually gets eaten, while other bodies end up sinking into the land. In our world, the organic material sucked into the ground eventually becomes fossil fuels, but in D&D there's actually stuff down there that will eat it. This is a relatively minor input into the dungeon eco system, but it essentially means that there aren't any oil deposits to be found in the D&D world.