0

I have a production vm U16.04 LTS which have broken apt-get and full /boot directory with various kernels.

apt-get install -f

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:
  linux-headers-4.4.0-138 linux-headers-4.4.0-138-generic linux-headers-4.4.0-139 linux-headers-4.4.0-139-generic
  linux-headers-4.4.0-141 linux-headers-4.4.0-141-generic linux-headers-4.4.0-142 linux-headers-4.4.0-142-generic
  linux-headers-4.4.0-145 linux-headers-4.4.0-145-generic linux-headers-4.4.0-148 linux-headers-4.4.0-148-generic
  linux-headers-4.4.0-150 linux-headers-4.4.0-150-generic linux-headers-4.4.0-157 linux-headers-4.4.0-157-generic
  linux-image-4.4.0-138-generic linux-image-4.4.0-139-generic linux-image-4.4.0-141-generic linux-image-4.4.0-142-generic
  linux-image-4.4.0-145-generic linux-image-4.4.0-148-generic linux-image-4.4.0-150-generic linux-image-4.4.0-157-generic
  linux-image-extra-4.4.0-138-generic linux-image-extra-4.4.0-139-generic linux-image-extra-4.4.0-141-generic
  linux-image-extra-4.4.0-142-generic linux-modules-4.4.0-145-generic linux-modules-4.4.0-148-generic
  linux-modules-4.4.0-150-generic linux-modules-4.4.0-157-generic linux-modules-extra-4.4.0-145-generic
  linux-modules-extra-4.4.0-148-generic linux-modules-extra-4.4.0-150-generic linux-modules-extra-4.4.0-157-generic
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  linux-generic linux-headers-4.4.0-171 linux-headers-4.4.0-171-generic linux-headers-generic linux-image-4.4.0-157-generic
  linux-image-4.4.0-171-generic linux-image-generic linux-modules-4.4.0-157-generic linux-modules-4.4.0-171-generic
  linux-modules-extra-4.4.0-171-generic
Suggested packages:
  fdutils linux-doc-4.4.0 | linux-source-4.4.0 linux-tools
Recommended packages:
  thermald
The following NEW packages will be installed:
  linux-headers-4.4.0-171 linux-headers-4.4.0-171-generic linux-image-4.4.0-157-generic linux-image-4.4.0-171-generic
  linux-modules-4.4.0-157-generic linux-modules-4.4.0-171-generic linux-modules-extra-4.4.0-171-generic
The following packages will be upgraded:
  linux-generic linux-headers-generic linux-image-generic
3 upgraded, 7 newly installed, 0 to remove and 199 not upgraded.
7 not fully installed or removed.
Need to get 66.3 MB/85.2 MB of archives.
After this operation, 369 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirror.hetzner.de/ubuntu/packages xenial-updates/main amd64 linux-modules-4.4.0-171-generic amd64 4.4.0-171.200 [12.0 MB]
Get:2 http://mirror.hetzner.de/ubuntu/packages xenial-updates/main amd64 linux-image-4.4.0-171-generic amd64 4.4.0-171.200 [6,938 kB]
Get:3 http://mirror.hetzner.de/ubuntu/packages xenial-updates/main amd64 linux-modules-extra-4.4.0-171-generic amd64 4.4.0-171.200 [36.6 MB]
Get:4 http://mirror.hetzner.de/ubuntu/packages xenial-updates/main amd64 linux-generic amd64 4.4.0.171.179 [1,790 B]
Get:5 http://mirror.hetzner.de/ubuntu/packages xenial-updates/main amd64 linux-image-generic amd64 4.4.0.171.179 [2,442 B]
Get:6 http://mirror.hetzner.de/ubuntu/packages xenial-updates/main amd64 linux-headers-4.4.0-171 all 4.4.0-171.200 [10.0 MB]
Get:7 http://mirror.hetzner.de/ubuntu/packages xenial-updates/main amd64 linux-headers-4.4.0-171-generic amd64 4.4.0-171.200 [798 kB]
Get:8 http://mirror.hetzner.de/ubuntu/packages xenial-updates/main amd64 linux-headers-generic amd64 4.4.0.171.179 [2,282 B]
Fetched 66.3 MB in 1s (36.3 MB/s)                
Selecting previously unselected package linux-modules-4.4.0-171-generic.
(Reading database ... 415318 files and directories currently installed.)
Preparing to unpack .../linux-modules-4.4.0-171-generic_4.4.0-171.200_amd64.deb ...
Unpacking linux-modules-4.4.0-171-generic (4.4.0-171.200) ...
dpkg: error processing archive /var/cache/apt/archives/linux-modules-4.4.0-171-generic_4.4.0-171.200_amd64.deb (--unpack):
 cannot copy extracted data for './boot/System.map-4.4.0-171-generic' to '/boot/System.map-4.4.0-171-generic.dpkg-new': failed to write (No space left on device)
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Selecting previously unselected package linux-image-4.4.0-171-generic.
Preparing to unpack .../linux-image-4.4.0-171-generic_4.4.0-171.200_amd64.deb ...
Unpacking linux-image-4.4.0-171-generic (4.4.0-171.200) ...
dpkg: error processing archive /var/cache/apt/archives/linux-image-4.4.0-171-generic_4.4.0-171.200_amd64.deb (--unpack):
 cannot copy extracted data for './boot/vmlinuz-4.4.0-171-generic' to '/boot/vmlinuz-4.4.0-171-generic.dpkg-new': failed to write (No space left on device)
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)

cd /boot && ls

abi-4.4.0-138-generic     config-4.4.0-154-generic      retpoline-4.4.0-138-generic   System.map-4.4.0-154-generic
abi-4.4.0-139-generic     grub                          retpoline-4.4.0-139-generic   vmlinuz-4.4.0-138-generic
abi-4.4.0-141-generic     initrd.img-4.4.0-138-generic  retpoline-4.4.0-141-generic   vmlinuz-4.4.0-139-generic
abi-4.4.0-142-generic     initrd.img-4.4.0-139-generic  retpoline-4.4.0-142-generic   vmlinuz-4.4.0-141-generic
config-4.4.0-138-generic  initrd.img-4.4.0-141-generic  System.map-4.4.0-138-generic  vmlinuz-4.4.0-142-generic
config-4.4.0-139-generic  initrd.img-4.4.0-142-generic  System.map-4.4.0-139-generic  vmlinuz-4.4.0-143-generic
config-4.4.0-141-generic  initrd.img-4.4.0-143-generic  System.map-4.4.0-141-generic  vmlinuz-4.4.0-145-generic
config-4.4.0-142-generic  initrd.img-4.4.0-145-generic  System.map-4.4.0-142-generic  vmlinuz-4.4.0-148-generic
config-4.4.0-143-generic  initrd.img-4.4.0-148-generic  System.map-4.4.0-143-generic  vmlinuz-4.4.0-150-generic
config-4.4.0-145-generic  initrd.img-4.4.0-150-generic  System.map-4.4.0-145-generic  vmlinuz-4.4.0-151-generic
config-4.4.0-148-generic  initrd.img-4.4.0-151-generic  System.map-4.4.0-148-generic  vmlinuz-4.4.0-154-generic
config-4.4.0-150-generic  initrd.img-4.4.0-154-generic  System.map-4.4.0-150-generic
config-4.4.0-151-generic  lost+found                    System.map-4.4.0-151-generic

uname -r
4.4.0-143-generic

df -h
Filesystem      Size  Used Avail Use% Mounted on
udev             63G     0   63G   0% /dev
tmpfs            13G  1.3G   12G  11% /run
/dev/md2        1.8T  714G  953G  43% /
tmpfs            63G     0   63G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            63G     0   63G   0% /sys/fs/cgroup
/dev/md1        488M  486M     0 100% /boot
/dev/sdc1       1.8T   68M  1.7T   1% /var/lib/mysql-extra-disk
tmpfs            13G     0   13G   0% /run/user/0
tmpfs            13G     0   13G   0% /run/user/111

I don't want to use any rm command if it's not safe. Any help appreciated.

Edit:

Removed:

root@Ubuntu-1604-xenial-64-minimal-no-hwe /boot # rm abi-4.4.0-138-generic
root@Ubuntu-1604-xenial-64-minimal-no-hwe /boot # rm abi-4.4.0-139-generic
root@Ubuntu-1604-xenial-64-minimal-no-hwe /boot # rm initrd.img-4.4.0-138-generic
root@Ubuntu-1604-xenial-64-minimal-no-hwe /boot # rm initrd.img-4.4.0-139-generic
root@Ubuntu-1604-xenial-64-minimal-no-hwe /boot # rm retpoline-4.4.0-138-generic
root@Ubuntu-1604-xenial-64-minimal-no-hwe /boot # rm retpoline-4.4.0-139-generic
root@Ubuntu-1604-xenial-64-minimal-no-hwe /boot # rm System.map-4.4.0-138-generic
root@Ubuntu-1604-xenial-64-minimal-no-hwe /boot # rm System.map-4.4.0-139-generic
root@Ubuntu-1604-xenial-64-minimal-no-hwe /boot # rm vmlinuz-4.4.0-138-generic
root@Ubuntu-1604-xenial-64-minimal-no-hwe /boot # rm vmlinuz-4.4.0-139-generic

and apt-get install -f worked. Thanks!

  • Have you tried to run sudo apt autoremove to clean up old unneeded kernel versions ? – Soren A Jan 21 at 13:53
  • Yes. - apt-get autoremove -y Reading package lists... Done Building dependency tree Reading state information... Done You might want to run 'apt-get -f install' to correct these. – Prologas Jan 21 at 13:58
  • No it's not helping. I tried to delete one config file from /boot dir, but no space was freed. – Prologas Jan 21 at 14:08
1

Check which kernel version you're using with uname -a, then remove all config-, initrd-, System.map-* and config-* files from the kernels that you're not using, just to be sure, left one version behind (ie. if uname -a returns something like: 4.4.0-169-generic, leave the files 4.4.0-166 and newer versions). Then, just run

apt -y autoremove

And you're good to go. If you don't wanna remove any files, you can also just move the /boot files somewhere else.

I use this procedure on all my 350 servers and it's pretty safe.

| improve this answer | |
  • apt dosen't work. You might want to run 'apt-get -f install' to correct these. – Prologas Jan 21 at 15:18
  • The reason apt doesn't work is because the /boot partition is full. Once you remove these files I've told you, probably it'll. – Stefano Martins Jan 21 at 16:21
  • if you rm the files it does not free the space. – Prologas Jan 21 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.