Score:0

How to remove unnecessary files from /boot

cn flag

I wanted to upgrade my Ubuntu 18.04 but could not do that because there is not enough space available in /boot.

The content of /boot is:

System.map-4.15.0-173-generic
System.map-4.15.0-204-generic
System.map-4.15.0-29-generic
abi-4.15.0-29-generic
config-4.15.0-173-generic
config-4.15.0-204-generic
config-4.15.0-29-generic
grub
initrd.img-4.15.0-204-generic
lost+found
retpoline-4.15.0-29-generic
vmlinuz-4.15.0-173-generic
vmlinuz-4.15.0-204-generic
vmlinuz-4.15.0-29-generic

Following How do I free up more space in /boot? I did `sudo apt purge -y linux-{image,headers}-VERSION for all VERSIONs other than the one loaded.

This indeed removed all those version, the command dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' shows:

linux-headers-4.15.0-204
linux-headers-4.15.0-204-generic
linux-image-4.15.0-204-generic

However, it did NOT remove any files from /boot - so the accepted answers for this problem did not work at all for me. Are there any alternatives?

UPDATE: the output of apt-mark showmanual | grep linux-'[g|h|m|i]' is

linux-generic
linux-headers-generic

Is it possible und safe to simple sudo rm ... the files that belong to unneded versions?

UPDATE: I started with trying sudo apt autoremove --purge which did not do anything at all.

UPDATE: output of dpkg -l | grep linux-'[g|h|i|m|e]' | cut -d ' ' -f 3 is

binutils-x86-64-linux-gnu
linux-generic
linux-headers-4.15.0-204
linux-headers-4.15.0-204-generic
linux-headers-generic
linux-image-4.15.0-204-generic
linux-image-generic
linux-image-unsigned-4.15.0-173-generic
linux-image-unsigned-4.15.0-29-generic
linux-modules-4.15.0-173-generic
linux-modules-4.15.0-204-generic
linux-modules-4.15.0-29-generic
linux-modules-extra-4.15.0-204-generic

UPDATE: output of for f in /boot/* ; do dpkg -S $f ; done | grep -v 204-generic | cut -f 1 -d ":" is :

linux-modules-4.15.0-173-generic
linux-modules-4.15.0-29-generic
linux-modules-4.15.0-29-generic
linux-modules-4.15.0-173-generic
linux-modules-4.15.0-29-generic
linux-modules-4.15.0-29-generic
linux-image-unsigned-4.15.0-173-generic
linux-image-unsigned-4.15.0-29-generic

Removing them all with for f in /boot/* ; do dpkg -S $f ; done | grep -v 204-generic | cut -f 1 -d ":" | xargs -n 1 sudo apt purge -y:

This indeed removed all the unnecessary files in /boot - thank you @user535733 who shared the relevant idea in the comments!

ru flag
**Comments have been [moved to chat](https://chat.stackexchange.com/rooms/143047/discussion-on-question-by-jpp1-how-to-remove-unnecessary-files-from-boot); please do not continue the discussion here.** Before posting a comment below this one, please review the [purposes of comments](/help/privileges/comment). Comments that do not request clarification or suggest improvements usually belong as an [answer](/help/how-to-answer), on [meta], or in [chat]. Comments continuing discussion may be removed.
Score:0
cn flag

Solution based on the suggestion of user @user535733: remove all the packages whic still relate to the files in /boot, except those which contain the currect version string:

cur=`uname -r`
`for f in /boot/* ; do  dpkg -S $f ; done | grep -v $cur | cut -f 1 -d ":" | xargs -n 1 sudo apt purge -y` 
nobody avatar
gh flag
Not sure I do not "speak" bash, but should it not be `cur='uname -r'` ?
jpp1 avatar
cn flag
Thanks I inserted the missing space. The quotes do indeed need to be backquotes though.
es flag
This is a harsh solution. In my system it would remove memtest86+ package
jpp1 avatar
cn flag
@jarno - thank you for pointing this out, it could of course get prevented by filtering out anything one wants to keep using additional grep -v filters. In my case, removing it was not only not a problem, but actually necessary to free enough space to make the subsequent upgrade work.
es flag
Oh, I checked that memtest86+ occupies less than 1% compared to what a kernel occupies in /boot. I doubt that upgrade would have failed for that.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.