1

How do I remove last, the originally installed kernel?

Goal: I am trying to configure smallest possible linux server install (Debian 9) machine which will be running application server (PHP7) in a Nginx-PHP7-Database chain. My PHP7 app server(s) will run on blade server(s) living inside enclosure. Machines are 32cores+8GB ram, but diskless, with os booted from 2GB (ONLY 2GB!) pendrive.

What I have done so far:

  • Minimal install of Debian 9 (took 700MB), cmdline + sshd.
  • Compiled and tested custom kernel 4.9.65 for this machine, profiled to existing hardware and requirements.
  • Deployed custom kernel to the machine (as linux-image.*.deb package)
  • Successfully booted from pen-drive using custom kernel

Now I would like to remove original bloated kernel 4.9.0.4 which came with initial Debian 9 installation, which is now polluting my tiny pen-drive. I od not need to keep last-good kernel.

When I try to remove original, now unused kernel, it wants to upgrade it (to keep dependencies happy, I presume)

sudo apt-get purge linux-image-4.9.0-4-amd64

I get

The following packages will be REMOVED:
  linux-image-4.9.0-4-amd64*
The following NEW packages will be installed:
  linux-image-4.9.0-6-amd64

But I want to delete it, not upgrade.

Question: How do I remove original, LAST standard kernel? Is there any way to re-link package dependencies to my new custom kernel and free the original for deletion?

FYI: I cannot simply buy big pen-drives, as these are awfully slow under ext2 file system. The small ones I have are special 'enterprise' grade.

I could try some magic with generic image on iSCSI drive and overlayfs the pendrive to get personality. Not there yet, maybe in few months.

ANSWER: I let apt-get purge [...] install next version of kernel, which I was able to remove without further problems.

Clean, useful minimal server on Debian9 is 465MB, all packages kept.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89

3 Answers3

0

The one of interesting things when you are working with packages is package holding. Hold - mark package in hold state which prevents it from changes (updates, removes).

Set hold:

sudo apt-mark hold <package-name>

Remove the hold:

sudo apt-mark unhold <package-name>
Yurij Goncharuk
  • 217
  • 1
  • 2
  • 13
0

I let apt-get purge [...] install next version of kernel, which in turn I was able to remove without further problems.

Clean, useful minimal server on Debian9 is 465MB, all packages kept.

0

After the upgrade to the new kernel and a system reboot, run the following commands:

sudo apt-get autoremove -y
for kernelimage in $(dpkg -l | tail -n +6 | grep -E 'linux-image-[0-9]+' | grep -Fv $(uname -r) | awk '{print $2}'); do dpkg --purge $kernelimage; done
Itai Ganot
  • 10,644
  • 29
  • 93
  • 146