3

I'm trying to remove old kernels on Ubuntu 17.10, but am being hit with an unmet dependencies error. My current kernel is linux 4.13.0-38-generic.

My output from dpkg -l | grep linux-image | awk '{print$2} is this:

linux-image-4.13.0-36-generic
linux-image-4.13.0-37-generic
linux-image-4.13.0-38-generic
linux-image-4.13.0-39-generic
linux-image-extra-4.13.0-36-generic
linux-image-extra-4.13.0-37-generic
linux-image-extra-4.13.0-38-generic
linux-image-extra-4.13.0-39-generic
linux-image-extra-4.13.0-41-generic
linux-image-generic

When I try to remove older kernels (sudo apt-get purge linux-image-x.x.x-x-generic ), this is the error:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 linux-image-extra-4.13.0-41-generic : Depends: linux-image-4.13.0-41-generic but it is not installed
 linux-image-generic : Depends: linux-image-4.13.0-41-generic but it is not installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

To fix the broken dependencies, I use sudo apt --fix-broken install, click Yes when asked whether I want to continue, and get this output:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  libqpdf18 linux-headers-4.13.0-37 linux-headers-4.13.0-37-generic
  linux-image-4.13.0-37-generic linux-image-extra-4.13.0-37-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  linux-image-4.13.0-41-generic
Suggested packages:
  fdutils linux-doc-4.13.0 | linux-source-4.13.0 linux-tools
The following NEW packages will be installed:
  linux-image-4.13.0-41-generic
0 upgraded, 1 newly installed, 0 to remove and 15 not upgraded.
5 not fully installed or removed.
Need to get 0 B/20.9 MB of archives.
After this operation, 72.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
(Reading database ... 374331 files and directories currently installed.)
Preparing to unpack .../linux-image-4.13.0-41-generic_4.13.0-41.46_amd64.deb ...
Examining /etc/kernel/preinst.d/
run-parts: executing /etc/kernel/preinst.d/intel-microcode 4.13.0-41-generic /boot/vmlinuz-4.13.0-41-generic
Done.
Unpacking linux-image-4.13.0-41-generic (4.13.0-41.46) ...
dpkg: error processing archive /var/cache/apt/archives/linux-image-4.13.0-41-generic_4.13.0-41.46_amd64.deb (--unpack):
 cannot copy extracted data for './boot/vmlinuz-4.13.0-41-generic' to '/boot/vmlinuz-4.13.0-41-generic.dpkg-new': failed to write (No space left on device)
No apport report written because the error message indicates a disk full error
    dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
    Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.13.0-41-generic /boot/vmlinuz-4.13.0-41-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.13.0-41-generic /boot/vmlinuz-4.13.0-41-generic
Errors were encountered while processing:
 /var/cache/apt/archives/linux-image-4.13.0-41-generic_4.13.0-41.46_amd64.deb

Output of uname -r is: 4.13.0-38-generic

Output of df -h is:

Filesystem              Size  Used Avail Use% Mounted on
udev                     63G     0   63G   0% /dev
tmpfs                    13G  2.7M   13G   1% /run
/dev/mapper/sdb2_crypt  1.9T 1004G  779G  57% /
tmpfs                    63G   39M   63G   1% /dev/shm
tmpfs                   5.0M  4.0K  5.0M   1% /run/lock
tmpfs                    63G     0   63G   0% /sys/fs/cgroup
/dev/nvme0n1p1          1.1T  472G  573G  46% /mnt/scratch
/dev/sdb1               231M  222M     0 100% /boot
/dev/md126p1            9.1T  3.0T  6.2T  33% /mnt/10TB
tmpfs                    13G   84K   13G   1% /run/user/1001
tmpfs                    13G     0   13G   0% /run/user/1004
Kevin Bowen
  • 19,615
  • 55
  • 79
  • 83

1 Answers1

2

You need to free up space in your /boot directory first. You have four 4.4.13.0 chain kernels: -36, -37, -38 and -39. You only need -38 and -39. So you need to remove -36 and -37. I don't have them installed but to give you an idea of what they would look like I used this command:

$ ll /boot/*4.4.0-124*
-rw-r--r-- 1 root root  1251054 May  2 08:58 /boot/abi-4.4.0-124-generic
-rw-r--r-- 1 root root   190654 May  2 08:58 /boot/config-4.4.0-124-generic
-rw-r--r-- 1 root root 43369621 May 17 06:00 /boot/initrd.img-4.4.0-124-generic
-rw-r--r-- 1 root root      255 May  2 08:58 /boot/retpoline-4.4.0-124-generic
-rw------- 1 root root  3898100 May  2 08:58 /boot/System.map-4.4.0-124-generic
-rw------- 1 root root  7143952 May  2 08:58 /boot/vmlinuz-4.4.0-124-generic

Repeat this command on your system by substituting 4.4.0-124 with 4.13.0-36 and 4.13.0-37. As you will see each kernel takes about 450 MB in /boot.

Then very carefully type these commands (but not the comments #):

sudo rm -f /boot/*4.13.0-36*
sudo rm -f /boot/*4.13.0-37*
sudo apt install -f  # Ensure all dependency errors are now fixed.
sudo apt update      # There should be no errors reported.
sudo apt autoremove  # This will finish removing kernels -36 & -37.
sudo apt upgrade     # This should install new kernel 4.13.0-41
sudo reboot          # You will now boot into kernel 4.13.0-41

After rebooting, and any other time after booting a new kernel update run:

sudo apt autoremove  # This will keep you at current kernel plus previous version (4.13.0-39) and remove all others

If you have the slightest doubt or uncertainty post a comment below.