User Tools

Site Tools


ubuntu:kernel:delete_old_kernel_images

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
ubuntu:kernel:delete_old_kernel_images [2019/12/15 22:27] peterubuntu:kernel:delete_old_kernel_images [2020/07/15 09:30] (current) – external edit 127.0.0.1
Line 87: Line 87:
 </code> </code>
  
- * **rc**: means package is in remove/deinstall state and only config file exists. +  * **rc**: means package is in remove/deinstall state and only config file exists. 
- * **ii**: means package is in install state and it is 100% installed on the system.+  * **ii**: means package is in install state and it is 100% installed on the system.
  
 ---- ----
Line 117: Line 117:
  
 Note that all **rc** states have gone. Note that all **rc** states have gone.
 +
 +----
 +
 +===== Deleting all old kernels easily =====
 +
 +Get a list of kernels.
 +
 +<code bash>
 +# Get kernel version.
 +v="$(uname -r | awk -F '-virtual' '{ print $1}')"
 + 
 +# Create ignore list to avoid deleting the running kernel.
 +i="linux-headers-virtual|linux-image-virtual|linux-headers-${v}|linux-image-$(uname -r)"
 + 
 +# Display the list.
 +echo dpkg --list | egrep -i  'linux-image|linux-headers' | awk '/ii/{ print $2}' | egrep -v "$i"
 +</code>
 +
 +To delete it simply run it as follows:
 +
 +<code bash>
 +v="$(uname -r | awk -F '-virtual' '{ print $1}')"
 +i="linux-headers-virtual|linux-image-virtual|linux-headers-${v}|linux-image-$(uname -r)"
 +apt --purge remove $(dpkg --list | egrep -i  'linux-image|linux-headers' | awk '/ii/{ print $2}' | egrep -v "$i")
 +</code>
 +
 +----
 +
 +===== Easy way to delete all old kernels =====
 +
 +<code bash>
 +sudo apt-get purge $(dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve "$(uname -r | sed -r 's/-[a-]+//')")
 +</code>
 +
 +----
 +
 +===== Simple way to delete all old kernels =====
 +
 +<code bash>
 +sudo purge-old-kernels 
 +</code>
  
ubuntu/kernel/delete_old_kernel_images.1576448857.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki