I would like to build an optimized kernel for a machine that runs Ubuntu 20.04 but in my scenario I cannot "pollute" the Linux installation with all the dependencies required to do the build. So, ideally, everything that is installed via
sudo apt-get install build-essential
sudo apt-get build-dep linux
(and whatever other dependencies are required)
should be isolated and once I've done the build and installed the new kernel I should be able to easily roll back as if nothing was installed, kernel aside. Since I've never used LXC, I am not sure about the potential complications there might be in using it for this purpose so I'm asking:
Is it possible to cleanly build a kernel inside an LXC container, move it to the host system and later get rid of the container?
Also a quick how to would help a lot. Many thanks