Clean up linux header files

Asked by Meet Dave

I am facing some issues while cleaning up linux header files. The files are eating up a lot of disk space which I want to clear up.

When I use the below command to clean up the files, it's not showing up anything:

sudo apt-get autoremove

    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    0 upgraded, 0 newly installed, 0 to remove and 93 not upgraded.

But when I look into the `/usr/src` directory, I see a lot of files:

  linux-aws-5.3-headers-5.3.0-1017 linux-aws-5.4-headers-5.4.0-1034 linux-aws-5.4-headers-5.4.0-1056
  linux-aws-5.3-headers-5.3.0-1019 linux-aws-5.4-headers-5.4.0-1035 linux-aws-5.4-headers-5.4.0-1057
  linux-aws-5.3-headers-5.3.0-1023 linux-aws-5.4-headers-5.4.0-1037 linux-aws-5.4-headers-5.4.0-1058
  linux-aws-5.3-headers-5.3.0-1028 linux-aws-5.4-headers-5.4.0-1038 linux-aws-5.4-headers-5.4.0-1059
  linux-aws-5.3-headers-5.3.0-1030 linux-aws-5.4-headers-5.4.0-1039 linux-aws-5.4-headers-5.4.0-1060
  linux-aws-5.3-headers-5.3.0-1032 linux-aws-5.4-headers-5.4.0-1041 linux-aws-5.4-headers-5.4.0-1061
  linux-aws-5.3-headers-5.3.0-1033 linux-aws-5.4-headers-5.4.0-1043 linux-aws-headers-4.15.0-1057
  linux-aws-5.3-headers-5.3.0-1034 linux-aws-5.4-headers-5.4.0-1045 linux-aws-headers-4.15.0-1058
  linux-aws-5.3-headers-5.3.0-1035 linux-aws-5.4-headers-5.4.0-1047 linux-aws-headers-4.15.0-1060
  linux-aws-5.4-headers-5.4.0-1025 linux-aws-5.4-headers-5.4.0-1048 linux-aws-headers-4.15.0-1063
  linux-aws-5.4-headers-5.4.0-1028 linux-aws-5.4-headers-5.4.0-1049 linux-aws-headers-4.15.0-1065
  linux-aws-5.4-headers-5.4.0-1029 linux-aws-5.4-headers-5.4.0-1051 linux-headers-4.15.0-1063-aws
  linux-aws-5.4-headers-5.4.0-1030 linux-aws-5.4-headers-5.4.0-1054
  linux-aws-5.4-headers-5.4.0-1032 linux-aws-5.4-headers-5.4.0-1055

Below of the output of `dpkg -l | grep linux-image-`

  ii linux-image-4.15.0-1063-aws 4.15.0-1063.67 amd64 Linux kernel image for version 4.15.0 on 64 bit x86 SMP

Can someone please help me with clearing up those files?

  Distributor ID: Ubuntu
  Description: Ubuntu 18.04.3 LTS
  Release: 18.04
  Codename: bionic

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
Last query:
Last reply:
Revision history for this message
Manfred Hampl (m-hampl) said :
#1

For diagnostic purposes, what output do you receive for the commands

dpkg -l | grep ' linux-'
du -schx /usr/src/*

Revision history for this message
Meet Dave (meetdave2611997) said :
#2

Output of "dpkg -l | grep ' linux-'":

    ii linux-aws-5.3-headers-5.3.0-1017 5.3.0-1017.18~18.04.1 all Header files related to Linux kernel version 5.3.0
    ii linux-aws-5.3-headers-5.3.0-1019 5.3.0-1019.21~18.04.1 all Header files related to Linux kernel version 5.3.0
    ii linux-aws-5.3-headers-5.3.0-1023 5.3.0-1023.25~18.04.1 all Header files related to Linux kernel version 5.3.0
    ii linux-aws-5.3-headers-5.3.0-1028 5.3.0-1028.30~18.04.1 all Header files related to Linux kernel version 5.3.0
    ii linux-aws-5.3-headers-5.3.0-1030 5.3.0-1030.32~18.04.1 all Header files related to Linux kernel version 5.3.0
    ii linux-aws-5.3-headers-5.3.0-1032 5.3.0-1032.34~18.04.2 all Header files related to Linux kernel version 5.3.0
    ii linux-aws-5.3-headers-5.3.0-1033 5.3.0-1033.35 all Header files related to Linux kernel version 5.3.0
    ii linux-aws-5.3-headers-5.3.0-1034 5.3.0-1034.36 all Header files related to Linux kernel version 5.3.0
    ii linux-aws-5.3-headers-5.3.0-1035 5.3.0-1035.37 all Header files related to Linux kernel version 5.3.0
    ii linux-aws-5.4-headers-5.4.0-1025 5.4.0-1025.25~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1028 5.4.0-1028.29~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1029 5.4.0-1029.30~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1030 5.4.0-1030.31~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1032 5.4.0-1032.33~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1034 5.4.0-1034.35~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1035 5.4.0-1035.37~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1037 5.4.0-1037.39~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1038 5.4.0-1038.40~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1039 5.4.0-1039.41~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1041 5.4.0-1041.43~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1043 5.4.0-1043.45~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1045 5.4.0-1045.47~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1047 5.4.0-1047.49~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1048 5.4.0-1048.50~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1049 5.4.0-1049.51~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1051 5.4.0-1051.53~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1054 5.4.0-1054.57~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1055 5.4.0-1055.58~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1056 5.4.0-1056.59~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1057 5.4.0-1057.60~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1058 5.4.0-1058.61~18.04.3 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1059 5.4.0-1059.62~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1060 5.4.0-1060.63~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-5.4-headers-5.4.0-1061 5.4.0-1061.64~18.04.1 all Header files related to Linux kernel version 5.4.0
    ii linux-aws-headers-4.15.0-1051 4.15.0-1051.53 all Header files related to Linux kernel version 4.15.0
    ii linux-aws-headers-4.15.0-1057 4.15.0-1057.59 all Header files related to Linux kernel version 4.15.0
    ii linux-aws-headers-4.15.0-1058 4.15.0-1058.60 all Header files related to Linux kernel version 4.15.0
    ii linux-aws-headers-4.15.0-1060 4.15.0-1060.62 all Header files related to Linux kernel version 4.15.0
    ii linux-aws-headers-4.15.0-1063 4.15.0-1063.67 all Header files related to Linux kernel version 4.15.0
    ii linux-aws-headers-4.15.0-1065 4.15.0-1065.69 all Header files related to Linux kernel version 4.15.0
    ii linux-base 4.5ubuntu1.2 all Linux image base package
    ii linux-headers-4.15.0-1063-aws 4.15.0-1063.67 amd64 Linux kernel headers for version 4.15.0 on 64 bit x86 SMP
    ii linux-image-4.15.0-1063-aws 4.15.0-1063.67 amd64 Linux kernel image for version 4.15.0 on 64 bit x86 SMP
    ii linux-modules-4.15.0-1051-aws 4.15.0-1051.53 amd64 Linux kernel extra modules for version 4.15.0 on 64 bit x86 SMP
    ii linux-modules-4.15.0-1063-aws 4.15.0-1063.67 amd64 Linux kernel extra modules for version 4.15.0 on 64 bit x86 SMP
    ii linux-modules-5.4.0-1064-aws 5.4.0-1064.67~18.04.1 amd64 Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
    ii linux-modules-5.4.0-1065-aws 5.4.0-1065.68~18.04.1 amd64 Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP

Output of "du -schx /usr/src/*":

    109M /usr/src/linux-aws-5.3-headers-5.3.0-1017
    109M /usr/src/linux-aws-5.3-headers-5.3.0-1019
    109M /usr/src/linux-aws-5.3-headers-5.3.0-1023
    109M /usr/src/linux-aws-5.3-headers-5.3.0-1028
    109M /usr/src/linux-aws-5.3-headers-5.3.0-1030
    109M /usr/src/linux-aws-5.3-headers-5.3.0-1032
    109M /usr/src/linux-aws-5.3-headers-5.3.0-1033
    109M /usr/src/linux-aws-5.3-headers-5.3.0-1034
    109M /usr/src/linux-aws-5.3-headers-5.3.0-1035
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1025
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1028
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1029
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1030
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1032
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1034
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1035
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1037
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1038
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1039
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1041
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1043
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1045
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1047
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1048
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1049
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1051
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1054
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1055
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1056
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1057
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1058
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1059
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1060
    108M /usr/src/linux-aws-5.4-headers-5.4.0-1061
    113M /usr/src/linux-aws-headers-4.15.0-1057
    113M /usr/src/linux-aws-headers-4.15.0-1058
    113M /usr/src/linux-aws-headers-4.15.0-1060
    113M /usr/src/linux-aws-headers-4.15.0-1063
    113M /usr/src/linux-aws-headers-4.15.0-1065
    19M /usr/src/linux-headers-4.15.0-1063-aws
    4.2G total

Revision history for this message
Manfred Hampl (m-hampl) said :
#3

This is a problem that has been discussed in Bug #1607845 and has been solved only in Ubuntu focal and later.
You are running bionic, so you have to do a cleanup yourself.

What is the output of the commands
apt-mark showmanual
uname -a

Revision history for this message
Meet Dave (meetdave2611997) said :
#4

Here is the output of command "apt-mark showmanual":

    bash
    cloud-init
    dash
    diffutils
    eatmydata
    ec2-hibinit-agent
    findutils
    grep
    gzip
    hibagent
    hostname
    init
    libdumbnet1
    libeatmydata1
    libwrap0
    linux-aws-5.3-headers-5.3.0-1017
    linux-aws-5.3-headers-5.3.0-1019
    linux-aws-5.3-headers-5.3.0-1023
    linux-aws-5.3-headers-5.3.0-1028
    linux-aws-5.3-headers-5.3.0-1030
    linux-aws-5.3-headers-5.3.0-1032
    linux-aws-5.3-headers-5.3.0-1033
    linux-aws-5.3-headers-5.3.0-1034
    linux-aws-5.3-headers-5.3.0-1035
    linux-aws-5.4-headers-5.4.0-1025
    linux-aws-5.4-headers-5.4.0-1028
    linux-aws-5.4-headers-5.4.0-1029
    linux-aws-5.4-headers-5.4.0-1030
    linux-aws-5.4-headers-5.4.0-1032
    linux-aws-5.4-headers-5.4.0-1034
    linux-aws-5.4-headers-5.4.0-1035
    linux-aws-5.4-headers-5.4.0-1037
    linux-aws-5.4-headers-5.4.0-1038
    linux-aws-5.4-headers-5.4.0-1039
    linux-aws-5.4-headers-5.4.0-1041
    linux-aws-5.4-headers-5.4.0-1043
    linux-aws-5.4-headers-5.4.0-1045
    linux-aws-5.4-headers-5.4.0-1047
    linux-aws-5.4-headers-5.4.0-1048
    linux-aws-5.4-headers-5.4.0-1049
    linux-aws-5.4-headers-5.4.0-1051
    linux-aws-5.4-headers-5.4.0-1054
    linux-aws-5.4-headers-5.4.0-1055
    linux-aws-5.4-headers-5.4.0-1056
    linux-aws-5.4-headers-5.4.0-1057
    linux-aws-5.4-headers-5.4.0-1058
    linux-aws-5.4-headers-5.4.0-1059
    linux-aws-5.4-headers-5.4.0-1060
    linux-aws-5.4-headers-5.4.0-1061
    linux-aws-headers-4.15.0-1051
    linux-aws-headers-4.15.0-1057
    linux-aws-headers-4.15.0-1058
    linux-aws-headers-4.15.0-1060
    linux-aws-headers-4.15.0-1065
    linux-modules-4.15.0-1051-aws
    login
    ncurses-base
    ncurses-bin
    ncurses-term
    nfs-common
    openssh-server
    openssh-sftp-server
    python3-blinker
    python3-jinja2
    python3-json-pointer
    python3-jsonpatch
    python3-jsonschema
    python3-jwt
    python3-markupsafe
    python3-oauthlib
    rabbitmq-server
    ssh-import-id
    sysvinit-utils
    ubuntu-minimal
    ubuntu-server
    ubuntu-standard

Output of "uname -a":

  Linux ip-172-30-3-171 4.15.0-1063-aws #67-Ubuntu SMP Mon Mar 2 07:24:29 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Can you please suggest the manual cleanup steps for this?

Revision history for this message
Best Manfred Hampl (m-hampl) said :
#5

That is weird.
You are running a 4.15.0-* version of the kernel, but you have the header files for kernel versions 5.3.0-* and 5.4.0-* installed. that does not make sense.

For a partial cleanup I recommend the following commands:

sudo apt-mark auto linux-aws-5.3-headers-*
sudo apt-mark auto linux-aws-5.4-headers-5.4.0-102*
sudo apt-mark auto linux-aws-5.4-headers-5.4.0-103*
sudo apt-mark auto linux-aws-5.4-headers-5.4.0-104*
sudo apt-mark auto linux-aws-5.4-headers-5.4.0-105*
sudo apt --purge autoremove

And then you should make up your mind whether you want to run the 4.15 or the 5.4 family of the kernel. Please note that your current kernel is outdated (current version ends with 1123, yours is 1063, 2 years old.).

Revision history for this message
Meet Dave (meetdave2611997) said :
#6

Thank you so much!! This helped and worked!!

Revision history for this message
Meet Dave (meetdave2611997) said :
#7

Thanks Manfred Hampl, that solved my question.

Revision history for this message
Manfred Hampl (m-hampl) said :
#8

Just a warning:
If you have done a clean-up with the commands above but nothing else, then I assume that with every new kernel version available new header files will pile up again and fill your disks with redundant files.

Revision history for this message
Meet Dave (meetdave2611997) said :
#9

So If I update kernel version to a newer one, it is not going to create files for new headers, right?

Revision history for this message
Manfred Hampl (m-hampl) said :
#10

Whether you will get new versions of the header files or not, depends on the way that you update packages.
Normally you should have one kernel meta package installed, which cares for installing the related set of kernel packages and header packages for the kernel release family that you have selected.

One cause of your problem was that you are running the 4.15 version of the kernel, but you have collected dozens of header files for 5.3 and 5.4.

First step is deciding whether you want to run the 4.15 or the 5.4 family of the kernels.