ubuntu:kernel:delete_old_kernel_images
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
ubuntu:kernel:delete_old_kernel_images [2019/12/15 22:15] – created peter | ubuntu:kernel:delete_old_kernel_images [2020/07/15 09:30] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 40: | Line 40: | ||
The **purge** removes packages and any configuration files are deleted too. | The **purge** removes packages and any configuration files are deleted too. | ||
+ | On newer system all obsolete kernels and headers should automatically be flagged as not being needed, and thus can be purged with the following single command: | ||
+ | |||
+ | <code bash> | ||
+ | sudo apt --purge autoremove | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | Reading package lists... Done | ||
+ | Building dependency tree | ||
+ | Reading state information... Done | ||
+ | The following packages will be REMOVED: | ||
+ | linux-headers-3.12.0-27* linux-headers-3.12.0-27-virtual* | ||
+ | 0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded. | ||
+ | After this operation, 64.7 MB disk space will be freed. | ||
+ | Do you want to continue [Y/n]? y | ||
+ | (Reading database ... 218493 files and directories currently installed.) | ||
+ | Removing linux-headers-3.12.0-27-virtual ... | ||
+ | Removing linux-headers-3.12.0-27 ... | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Delete kernel packages in remove/ | ||
+ | |||
+ | <code bash> | ||
+ | sudo dpkg --list | grep linux-image | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | rc linux-image-4.15.0-29-generic | ||
+ | rc linux-image-4.15.0-55-generic | ||
+ | rc linux-image-4.15.0-58-generic | ||
+ | rc linux-image-4.15.0-60-generic | ||
+ | rc linux-image-4.15.0-62-generic | ||
+ | rc linux-image-4.15.0-64-generic | ||
+ | rc linux-image-4.15.0-65-generic | ||
+ | rc linux-image-4.15.0-66-generic | ||
+ | rc linux-image-4.15.0-69-generic | ||
+ | ii linux-image-4.15.0-70-generic | ||
+ | ii linux-image-4.15.0-72-generic | ||
+ | ii linux-image-generic | ||
+ | </ | ||
+ | |||
+ | * **rc**: means package is in remove/ | ||
+ | * **ii**: means package is in install state and it is 100% installed on the system. | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ==== Remove all linux-image packages in rc state ==== | ||
+ | |||
+ | <code bash> | ||
+ | sudo x=$(dpkg --list | grep -i linux-image | grep ^rc| awk '{ print $2}') | ||
+ | sudo echo " | ||
+ | sudo apt --purge remove $x | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ==== Recheck kernel package state ==== | ||
+ | |||
+ | <code bash> | ||
+ | sudo dpkg --list | grep linux-image | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | ii linux-image-4.15.0-70-generic | ||
+ | ii linux-image-4.15.0-72-generic | ||
+ | ii linux-image-generic | ||
+ | </ | ||
+ | |||
+ | Note that all **rc** states have gone. | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Deleting all old kernels easily ===== | ||
+ | |||
+ | Get a list of kernels. | ||
+ | |||
+ | <code bash> | ||
+ | # Get kernel version. | ||
+ | v=" | ||
+ | |||
+ | # Create ignore list to avoid deleting the running kernel. | ||
+ | i=" | ||
+ | |||
+ | # Display the list. | ||
+ | echo dpkg --list | egrep -i ' | ||
+ | </ | ||
+ | |||
+ | To delete it simply run it as follows: | ||
+ | |||
+ | <code bash> | ||
+ | v=" | ||
+ | i=" | ||
+ | apt --purge remove $(dpkg --list | egrep -i ' | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Easy way to delete all old kernels ===== | ||
+ | |||
+ | <code bash> | ||
+ | sudo apt-get purge $(dpkg -l linux-{image, | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Simple way to delete all old kernels ===== | ||
+ | |||
+ | <code bash> | ||
+ | sudo purge-old-kernels | ||
+ | </ | ||
ubuntu/kernel/delete_old_kernel_images.1576448111.txt.gz · Last modified: 2020/07/15 09:30 (external edit)