Linux kernel configuration - make localmodconfig - missing modules
Solution 1:
For example, the sound card goes to sleep after about 30 seconds and so the module for the sound card gets unloaded
It doesn't. Module unloading is not automatic on Linux – once something was loaded, it stays loaded until reboot, regardless of removing the physical device.
(More to that, the sound card's driver module is what puts the sound card to sleep and wakes it up in the first place. And an asleep sound card is still online – if it going to sleep meant the card disappeared entirely, that would mean your programs would have no way to interact with it. Thus even devices in power saving mode still need the driver modules to be loaded.)
The only time modules get removed is if you have something explicitly run rmmod
or modprobe -r
for some reason, or of course if you reboot.
How do I get lsmod to include the unloaded modules in the file?
You don't, it doesn't know what modules have been unloaded previously. A module either is loaded or isn't; there is no "has previously been loaded" state, and the reason for that is in the 1st part of the answer.