Difference between revisions of "Clean ubuntu"

 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:Linux]]
 
[[Category:Linux]]
  
 +
This page explains how to remove old and un-necessary kernels as well as cleaning the /boot partition.
  
=Clean /boot=
 
  
==Manual method==
+
=Know the current Kernel version=
 
 
===Kernel version===
 
  
 
Get your current kernel version
 
Get your current kernel version
Line 20: Line 18:
  
  
 +
=Installed kernels=
  
===Installed kernels===
+
==List kernels that can be removed==
  
Get a list of installed kernels
+
The following command will return the list of packages that can be removed:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
dpkg --list 'linux-image*'
+
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r|sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
 
</syntaxhighlight>
 
</syntaxhighlight>
  
You should see something like:
+
Source: Linux pratique no94, FR, mars|avril 2016
  
  
||/ Name                                        Version                    Architecture              Description
+
==List of all kernels (including current one)==
  
+++-===========================================-==========================-==========================-===========================================================
+
Get a list of installed kernels
  
un  linux-image                                 <none>                    <none>                     (no description available)
+
<syntaxhighlight lang="bash">
 +
dpkg --list 'linux-image*'
 +
</syntaxhighlight>
  
un  linux-image-3.0                            <none>                    <none>                    (no description available)
 
  
rc  linux-image-3.13.0-24-generic              3.13.0-24.47              amd64                      Linux kernel image for version 3.13.0 on 64 bit x86 SMP
+
You should see something like:
  
ii linux-image-3.13.0-30-generic               3.13.0-30.55               amd64                     Linux kernel image for version 3.13.0 on 64 bit x86 SMP
+
{| class="wikitable"
 +
|-
 +
! / !! Name !! Version !! Architecture !! Description
 +
|-
 +
| un || linux-image || <none> || <none> || (no description available)
 +
|-
 +
| un || linux-image-3.0 || <none> || <none> || (no description available)
 +
|-
 +
| rc || linux-image-3.13.0-24-generic || 3.13.0-24.47 || amd64 || Linux kernel image for version 3.13.0 on 64 bit x86 SMP
 +
|-
 +
| ii || linux-image-3.13.0-30-generic || 3.13.0-30.55 || amd64 || Linux kernel image for version 3.13.0 on 64 bit x86 SMP
 +
|-
 +
| ii || '''linux-image-3.13.0-32-generic''' || 3.13.0-32.57 || amd64 || Linux kernel image for version 3.13.0 on 64 bit x86 SMP
 +
|-
 +
| rc || linux-image-extra-3.13.0-24-generic || 3.13.0-24.47 || amd64 || Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
 +
|-
 +
| ii || linux-image-extra-3.13.0-30-generic || 3.13.0-30.55 || amd64 || Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
 +
|-
 +
| ii || '''linux-image-extra-3.13.0-32-generic''' || 3.13.0-32.57 || amd64 || Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
 +
|-
 +
|ii || linux-image-generic || 3.13.0.32.38 || amd64 || Generic Linux kernel image
 +
|-
 +
|}
  
ii  '''linux-image-3.13.0-32-generic'''        3.13.0-32.57              amd64                      Linux kernel image for version 3.13.0 on 64 bit x86 SMP
 
  
rc  linux-image-extra-3.13.0-24-generic        3.13.0-24.47              amd64                      Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
 
  
ii  linux-image-extra-3.13.0-30-generic        3.13.0-30.55              amd64                      Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
 
  
ii  '''linux-image-extra-3.13.0-32-generic'''  3.13.0-32.57              amd64                      Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
+
=Delete kernels=
 
 
ii  linux-image-generic                        3.13.0.32.38              amd64                      Generic Linux kernel image
 
  
 +
==Automatic deletion==
  
 +
<syntaxhighlight lang="bash">
 +
# list the package to remove
 +
dpkg -l | awk '{print $2}' | grep -E "linux-(image|headers)-$(uname -r | cut -d- -f1).*" | grep -v $(uname -r | sed -r -e 's:-[a-z]+.*::')
  
 +
# remove all old kernels at once
 +
apt-get purge $(dpkg -l | awk '{print $2}' | grep -E "linux-(image|headers)-$(uname -r | cut -d- -f1).*" | grep -v $(uname -r | sed -r -e 's:-[a-z]+.*::'))
  
 +
# update grub
 +
update-grub
 +
</syntaxhighlight>
  
 +
Source: Linux pratique no94, FR, mars|avril 2016
  
  
 +
==Manual deletion==
  
 
Delete the kernels you don't want/need anymore
 
Delete the kernels you don't want/need anymore
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
apt-get remove linux-image-VERSION
+
# Remove old kernels (repeat for each version)
 +
OLD_KRNL_VERSION=4.4.0-21
 +
apt-get remove --purge linux-headers-${OLD_KRNL_VERSION}* linux-image-${OLD_KRNL_VERSION}* linux-image-extra-${OLD_KRNL_VERSION}*
 +
 
 +
# at the end update Grub
 +
update-grub
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Replace VERSION with the version of the kernel you want to remove.
+
set ''OLD_KRNL_VERSION'' to the version of the kernel you want to remove.
 
 
When you're done removing the older kernels, you can run this to remove ever packages you won't need anymore:
 
 
 
sudo apt-get autoremove
 
And finally you can run this to update grub kernel list:
 
 
 
sudo update-grub
 
 
 
<syntaxhighlight lang="bash">
 
sudo add-apt-repository ppa:caffeine-developers/ppa
 
sudo apt-get update && sudo apt-get install caffeine
 
</syntaxhighlight>
 

Latest revision as of 15:31, 22 May 2016


This page explains how to remove old and un-necessary kernels as well as cleaning the /boot partition.


Know the current Kernel version

Get your current kernel version

uname -r


You should see something like:

3.13.0-32-generic


Installed kernels

List kernels that can be removed

The following command will return the list of packages that can be removed:

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r|sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'

Source: Linux pratique no94, FR, mars|avril 2016


List of all kernels (including current one)

Get a list of installed kernels

dpkg --list 'linux-image*'


You should see something like:

/ Name Version Architecture Description
un linux-image <none> <none> (no description available)
un linux-image-3.0 <none> <none> (no description available)
rc linux-image-3.13.0-24-generic 3.13.0-24.47 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
ii linux-image-3.13.0-30-generic 3.13.0-30.55 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
ii linux-image-3.13.0-32-generic 3.13.0-32.57 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rc linux-image-extra-3.13.0-24-generic 3.13.0-24.47 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
ii linux-image-extra-3.13.0-30-generic 3.13.0-30.55 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
ii linux-image-extra-3.13.0-32-generic 3.13.0-32.57 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
ii linux-image-generic 3.13.0.32.38 amd64 Generic Linux kernel image



Delete kernels

Automatic deletion

# list the package to remove
dpkg -l | awk '{print $2}' | grep -E "linux-(image|headers)-$(uname -r | cut -d- -f1).*" | grep -v $(uname -r | sed -r -e 's:-[a-z]+.*::')

# remove all old kernels at once
apt-get purge $(dpkg -l | awk '{print $2}' | grep -E "linux-(image|headers)-$(uname -r | cut -d- -f1).*" | grep -v $(uname -r | sed -r -e 's:-[a-z]+.*::'))

# update grub
update-grub

Source: Linux pratique no94, FR, mars|avril 2016


Manual deletion

Delete the kernels you don't want/need anymore

# Remove old kernels (repeat for each version)
OLD_KRNL_VERSION=4.4.0-21
apt-get remove --purge linux-headers-${OLD_KRNL_VERSION}* linux-image-${OLD_KRNL_VERSION}* linux-image-extra-${OLD_KRNL_VERSION}*

# at the end update Grub
update-grub

set OLD_KRNL_VERSION to the version of the kernel you want to remove.