You can download a tarball from www.kernel.org. It is nicer to clone a git repository with the kernel in it if you know how (this makes it easy to track changes you may want to make to the kernel later).
Extract the source into <kernel dir>. (I am assuming that <kernel dir> is an absolute path, that is, one that starts with "/".)
In <kbuild>, run
yes "" | make -C <kernel dir> O=`pwd` config
This makes a configuration file with the default option selected.
In <kbuild>, run
make
(consider use of "-j" switch with make if you have more processors on the machine)
make INSTALL_MOD_PATH=<install_mod_dir> modules_install
For <install_mod_dir> a directory of your choice. This will collect all your built kernel modules into one place.
You should see one directory: "lib"
tar czf modules.tar.gz lib
This could take a while (perhaps order of a few minutes), you're zipping up a lot of modules.
-kernel
also probably helpful is
-append console=ttyS0,115200n8
which adds a serial console at boot so you can view boot messages.
One final potentially helpful option is to preface your image name
with "--snapshot". This ensures that no changes are made to your
image during an execution (so you can do something dangerous and have
the original image file preserved). You may want to investigate
qemu-img and qcow2 format images for how you can "do something
potentially dangerous, and preserve changes if it goes right", because
"--snapshot" will ALWAYS revert your changes.
Now we'll copy your modules over:
scp <username>@<cs host>:<path to modules tarfile> .
Sorry, line wrapping on a terminal is ugly. You also won't see any
boot info now because we're lacking the "-append" option.
This could also take a little while (but you'll have an ETA).
This will put the modules in /lib/modules/<kernel version> . This
could also take a little while.
You do know what sudo does, right? (If not, look it up with man.)
You might find the lspci and lsmod commands useful.
You might need a root= parameter to qemu.
Copy modules into your image
But you want to be able to use modules, right? Let's use your old
kernel (which has the ability to use a network card) to copy modules
over to your image. Boot without the "-kernel" and "-append" options.
Extract modules
sudo tar xzf Reboot
Halt the system (with halt). Now when you boot your kernel with the
-kernel and -append options, you can load modules for that kernel.
This will let you do things like load a network card (it should
automatically happen when you boot).
Use modules
Load modules with modprobe. Cause modules to load automatically at
boot by putting them in /etc/modules.
Additional issues