apt-get install isn't working

Updated at

2024.3.9

Created at

2020.8.3

There may be several causes, but here are some solutions for storage-related problems.

Error

When you try to run apt-get install, you may get an error saying that a package with the following dependencies cannot be found.

E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

In this case, Running apt-get -f install will fix the problem, but the command itself may not work.

E: Sub-process /usr/bin/dpkg returned an error code (1)

In my case, the storage was full and the file could not be created.

terminal
Unpacking linux-modules-4.4.0-186-generic (4.4.0-186.216) ...
dpkg: error processing archive /var/cache/apt/archives/linux-modules-4.4.0-186-generic_4.4.0-186.216_amd64.deb (--unpack):
 cannot copy extracted data for './boot/System.map-4.4.0-186-generic' to '/boot/System.map-4.4.0-186-generic.dpkg-new': failed to write (No space left on device)
No apport report written because the error message indicates a disk full error

Check storage usage

terminal
$ df -H
Filesystem      Size  Used Avail Use% Mounted on
udev            136G     0  136G   0% /dev
tmpfs            28G   95M   27G   1% /run
/dev/sda3       166G   24G  134G  15% /
tmpfs           136G  316k  136G   1% /dev/shm
tmpfs           5.3M  4.1k  5.3M   1% /run/lock
tmpfs           136G     0  136G   0% /sys/fs/cgroup
/dev/sda1       487M  480M     0 100% /boot
/dev/sda4       811G  265G  505G  35% /home
/dev/sdb2       3.1T  1.2T  1.9T  40% /media/...
tmpfs            28G   74k   28G   1% /run/user/1002
tmpfs            28G     0   28G   0% /run/user/1007

Indeed, /boot is at 100% utilization, which seems to be causing the error.

How to remove unwanted kernels

It seems that kernels other than the one currently being used are stored here, and you can free up space by removing unnecessary ones that can be detected as follows.

terminal
$ sudo dpkg --list 'linux-image*'| awk '{ if ($1=="ii") print $2}'| grep -v `uname -r`
linux-image-4.4.0-150-generic
linux-image-4.4.0-151-generic
linux-image-4.4.0-154-generic
linux-image-4.4.0-157-generic
linux-image-4.4.0-159-generic
linux-image-4.4.0-161-generic
linux-image-4.4.0-164-generic
linux-image-4.4.0-165-generic
linux-image-4.4.0-186-generic
linux-image-generic

If apt-get works, you should purge it, but it doesn't now, so you can remove it with rm.

terminal
$ sudo rm -rf /boot/*-4.4.0-1{5{0,1,4,7,9},6{1,4,5},86}-*                           
$ sudo rm -rf /boot/linux-image-generic

You should now have free space in /boot.

terminal
$ df -H
Filesystem      Size  Used Avail Use% Mounted on
udev            136G     0  136G   0% /dev
tmpfs            28G   95M   27G   1% /run
/dev/sda3       166G   24G  133G  16% /
tmpfs           136G  316k  136G   1% /dev/shm
tmpfs           5.3M  4.1k  5.3M   1% /run/lock
tmpfs           136G     0  136G   0% /sys/fs/cgroup
/dev/sda1       487M   86M  372M  19% /boot
/dev/sda4       811G  265G  505G  35% /home
/dev/sdb2       3.1T  1.2T  1.9T  40% /media/...
tmpfs            28G   82k   28G   1% /run/user/1002
tmpfs            28G     0   28G   0% /run/user/1007

Then, execute the same command to correct the problem as before.

terminal
$ sudo apt-get -f install

If there are no errors, all necessary packages are included, and from here, remove any relevant and unnecessary packages.

terminal
$ sudo apt-get autoremove

Finally, update GRUB and packages.

terminal
$ sudo update-grub
$ sudo apt-get update

Reference; Safest way to clean up boot partition - Ubuntu 14.04LTS-x64, Ubuntu 16.04LTS-x64 | GitHub Gist

mktia's note

Research & Engineering / Blockchain / Web Dev

© 2017-2025 mktia. All rights reserved.