Ubuntu under Hyper-V: Which kernel to keep and how to get rid of the rest?

Recently I needed to quickly set up fresh new VM with Ubuntu 18.04 TLS under Hyper-V (this is not my ordinarily toolbox but I can not use anything that Hyper-V this time).

Ok, I did the install (I used to choose ‘hwe’ install during the initial setup menu) and while try to find a way to use Hyper-V integration I found I need to do this magic:

echo 'hv_vmbus' >> /etc/initramfs-tools/modules
echo 'hv_storvsc' >> /etc/initramfs-tools/modules
echo 'hv_blkvsc' >> /etc/initramfs-tools/modules
echo 'hv_netvsc' >> /etc/initramfs-tools/modules
apt -y install linux-virtual linux-cloud-tools-virtual linux-tools-virtual
update-initramfs -u

Ok, I did that and everything is ok, but how to find out which kernel and packages I need not to keep and which can I remove for good? You see, now I have plenty of kernel packages and I understand I don’t need most of them:

# dpkg -l | grep linux
ii  console-setup-linux                  1.178ubuntu2.9                                  all          Linux specific part of console-setup
ii  libselinux1:amd64                    2.7-2build2                                     amd64        SELinux runtime shared libraries
ii  linux-base                           4.5ubuntu1                                      all          Linux image base package
ii  linux-cloud-tools-4.15.0-91          4.15.0-91.92                                    amd64        Linux kernel version specific cloud tools for version 4.15.0-91
ii  linux-cloud-tools-4.15.0-91-generic  4.15.0-91.92                                    amd64        Linux kernel version specific cloud tools for version 4.15.0-91
ii  linux-cloud-tools-common             4.15.0-91.92                                    all          Linux kernel version specific cloud tools for version 4.15.0
ii  linux-cloud-tools-virtual            4.15.0.91.83                                    amd64        Virtual Linux kernel cloud tools
ii  linux-firmware                       1.173.16                                        all          Firmware for Linux kernel drivers
ii  linux-generic-hwe-18.04              5.3.0.42.99                                     amd64        Complete Generic Linux kernel and headers
ii  linux-headers-4.15.0-91              4.15.0-91.92                                    all          Header files related to Linux kernel version 4.15.0
ii  linux-headers-4.15.0-91-generic      4.15.0-91.92                                    amd64        Linux kernel headers for version 4.15.0 on 64 bit x86 SMP
ii  linux-headers-5.3.0-42               5.3.0-42.34~18.04.1                             all          Header files related to Linux kernel version 5.3.0
ii  linux-headers-5.3.0-42-generic       5.3.0-42.34~18.04.1                             amd64        Linux kernel headers for version 5.3.0 on 64 bit x86 SMP
ii  linux-headers-generic                4.15.0.91.83                                    amd64        Generic Linux kernel headers
ii  linux-headers-generic-hwe-18.04      5.3.0.42.99                                     amd64        Generic Linux kernel headers
ii  linux-headers-virtual                4.15.0.91.83                                    amd64        Virtual Linux kernel headers
ii  linux-image-4.15.0-91-generic        4.15.0-91.92                                    amd64        Signed kernel image generic
ii  linux-image-5.3.0-42-generic         5.3.0-42.34~18.04.1                             amd64        Signed kernel image generic
ii  linux-image-generic-hwe-18.04        5.3.0.42.99                                     amd64        Generic Linux kernel image
ii  linux-image-virtual                  4.15.0.91.83                                    amd64        Virtual Linux kernel image
ii  linux-modules-4.15.0-91-generic      4.15.0-91.92                                    amd64        Linux kernel extra modules for version 4.15.0 on 64 bit x86 SMP
ii  linux-modules-5.3.0-42-generic       5.3.0-42.34~18.04.1                             amd64        Linux kernel extra modules for version 5.3.0 on 64 bit x86 SMP
ii  linux-modules-extra-5.3.0-42-generic 5.3.0-42.34~18.04.1                             amd64        Linux kernel extra modules for version 5.3.0 on 64 bit x86 SMP
ii  linux-tools-4.15.0-91                4.15.0-91.92                                    amd64        Linux kernel version specific tools for version 4.15.0-91
ii  linux-tools-4.15.0-91-generic        4.15.0-91.92                                    amd64        Linux kernel version specific tools for version 4.15.0-91
ii  linux-tools-common                   4.15.0-91.92                                    all          Linux kernel version specific tools for version 4.15.0
ii  linux-tools-virtual                  4.15.0.91.83                                    amd64        Virtual Linux kernel tools
ii  linux-virtual                        4.15.0.91.83                                    amd64        Minimal Generic Linux kernel and headers
ii  util-linux                           2.31.1-0.4ubuntu3.5                             amd64        miscellaneous system utilities

Please advice, as this is something that was a bit fuzzy for me for years.

Answer

Attribution
Source : Link , Question Author : Kevin M , Answer Author : Community

Leave a Comment