6

In /boot there are a lot of vmlinuz.* files going back 4 years. Is it safe to remove some of these?

Edit: Most seem to have congig-3.* and System.map.* files to go with them. I would probably want to be rid of those too? Or instead?

  • 1
    You should remove the kernel packages, not just the files. – zhongfu Apr 10 '15 at 15:05
  • 1
    Are these kernels from your current install, so still in dpkg? If so I have always use synaptic. If from an older install and you have upgraded, they will not be in dpkg nor synaptic to delete and you have to manually delete them. Several ways to houseclean kernels: http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu – oldfred Apr 10 '15 at 15:17
  • Perfect. These two comments have helped me a lot. – Matthew Brown aka Lord Matt Apr 10 '15 at 16:02
  • @oldfred you comment was exactly what I needed. If you want to make it an answer I will be happy to accept it. That I guess community wiki is the other option? – Matthew Brown aka Lord Matt Apr 11 '15 at 11:52
  • 1
    I think the link has just about every method of deleting older kernels. Did you also check /var/cache/apt/archives? You may have the old .deb's taking up space. Also check dpkg -S /usr/src/* http://askubuntu.com/questions/301466/files-are-piling-up-in-usr-src-how-can-i-stop-this This with 14.04 is supposed to only keep 2 kernels, but not sure if working on my system. /etc/kernel/postinst.d/apt-auto-removal. – oldfred Apr 11 '15 at 15:15
  • /var/cache/... etc only had three deb files in it from tortoisehg and mercurial but dpkg -S /usr/src/* had a big old list. – Matthew Brown aka Lord Matt Apr 11 '15 at 16:11
  • I went into /usr/src/ and sudo rm -r on all the versions that were 2.x.x (about half) - I thake it that was the right approach? – Matthew Brown aka Lord Matt Apr 11 '15 at 16:18
  • NB: I have successfully moved on to 14.04 too. :) – Matthew Brown aka Lord Matt Apr 11 '15 at 16:32

2 Answers2

5

They will be removed automatically if you run the following:

sudo apt-get autoremove

Update: I found a VM where I haven't run those commands in a few weeks. Here is the output, showing that autoremove cleans up files in /boot, going from 127M in size down to 96M in size:

stephane@steph-dev-vm ~> du -hs /boot/
127M    /boot/

stephane@steph-dev-vm ~> sudo apt-get install -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-3.16.0-30 linux-headers-3.16.0-30-generic linux-image-3.16.0-30-generic
  linux-image-extra-3.16.0-30-generic
Use 'apt-get autoremove' to remove them.

stephane@steph-dev-vm ~> sudo apt-get autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  linux-headers-3.16.0-30 linux-headers-3.16.0-30-generic linux-image-3.16.0-30-generic
  linux-image-extra-3.16.0-30-generic
0 upgraded, 0 newly installed, 4 to remove and 0 not upgraded.
After this operation, 281 MB disk space will be freed.
Do you want to continue? [Y/n] y
...
Found linux image: /boot/vmlinuz-3.16.0-31-generic
Found initrd image: /boot/initrd.img-3.16.0-31-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
done

stephane@steph-dev-vm ~> du -hs /boot/
96M /boot/
A.B.
  • 90,397
Stéphane
  • 2,526
  • 1
    -1 Why sudo apt-get autoclean and sudo apt-get clean? – A.B. Apr 10 '15 at 15:06
  • I regularly run this set of commands. I forget which one of the 3 removes old kernel files from boot. Like I wrote, I think it is the middle one. – Stéphane Apr 10 '15 at 15:07
  • 3
    autoremove removes old automatically (e.g. as dependencies) installed packages which are no longer needed. clean deletes all locally cached .deb files downloaded by apt-get. autoclean does the same as clean but deletes only those .deb files which are outdated (version not available on server any more). So autoclean is included in clean and both do not touch installed packages, just the cached .debs (call them installation files, if you want). – Byte Commander Apr 10 '15 at 15:31
  • 1
    I cannot confirm that this helps to remove any files from /boot. There is a possibility that my apt-get is broken but it might also be that /boot is full. – Matthew Brown aka Lord Matt Apr 10 '15 at 15:55
  • 1
    Older versions did not remove kernels, I believe that they fixed that as there have been many users with full drive LVM and /boot partitions getting full. So may be in 14.04 but not in 12.04. – oldfred Apr 10 '15 at 20:44
  • I can confirm that autoclean did get rid of a bunch of stuff but not kernels in my 12.04. – Matthew Brown aka Lord Matt Apr 11 '15 at 16:23
0

The answer appears to be that there are lots of kernels installed and I should remove them.

I removed the oldest using sudo apt-get uninstall and a wild card. Risky if you get it wrong but otherwise effective.