Differences

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

Link to this comparison view

tech:linux:purge_linux_images [2016/08/17 06:26] (current)
Line 1: Line 1:
 +====== Purge Old Linux Headers/​Images with aptitude ======
 +If there is limited space on /boot, this becomes a necessity. ​ Identify what packages are installed and what is current with the following commands:
 +<code bash>
 +dpkg -l linux-image-\* | grep ^ii
 +uname -a
 +</​code>​
 +Sample output
 +<​code>​
 +ii  linux-image-3.2.0-38-generic ​    ​3.2.0-38.61 ​                        Linux kernel image for version 3.2.0 on 64 bit x86 SMP
 +ii  linux-image-3.2.0-39-generic ​    ​3.2.0-39.62 ​                        Linux kernel image for version 3.2.0 on 64 bit x86 SMP
 +ii  linux-image-3.2.0-40-generic ​    ​3.2.0-40.64 ​                        Linux kernel image for version 3.2.0 on 64 bit x86 SMP
 +ii  linux-image-3.2.0-43-generic ​    ​3.2.0-43.68 ​                        Linux kernel image for version 3.2.0 on 64 bit x86 SMP
 +ii  linux-image-server ​              ​3.2.0.43.51 ​                        Linux kernel image on Server Equipment.
 +
 +
 +Linux ub4 3.2.0-43-generic #68-Ubuntu SMP Wed May 15 03:33:33 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
 +</​code>​
 +
 +Considering that 3.2.0-43 is installed we can remove 3.2.0-38,​39,​40. ​ To remove 40 (run one at a time):
 +<​code>​
 +PACKAGE="​linux-image-3.2.0-40-generic"​
 +aptitude search $PACKAGE
 +aptitude remove $PACKAGE
 +aptitude -y purge $PACKAGE
 +</​code>​
 +
 +Outputs
 +<​code>​
 +# aptitude search $PACKAGE
 +i A linux-image-3.2.0-40-generic ​                       - Linux kernel image for version 3.2.0 on 64 bit x86 SMP
 +p   ​linux-image-3.2.0-40-generic:​i386 ​                  - Linux kernel image for version 3.2.0 on 32 bit x86 SMP
 +p   ​linux-image-3.2.0-40-generic-pae:​i386 ​              - Linux kernel image for version 3.2.0 on 32 bit x86 SMP
 +</​code>​
 +
 +<​code>​
 +# aptitude search $PACKAGE
 +i A linux-image-3.2.0-40-generic ​                       - Linux kernel image for version 3.2.0 on 64 bit x86 SMP
 +p   ​linux-image-3.2.0-40-generic:​i386 ​                  - Linux kernel image for version 3.2.0 on 32 bit x86 SMP
 +p   ​linux-image-3.2.0-40-generic-pae:​i386 ​              - Linux kernel image for version 3.2.0 on 32 bit x86 SMP
 +[07:49:46 AM][root@ub4]:/​etc/​cron.d[0]#​ aptitude remove $PACKAGE
 +The following packages will be REMOVED:
 +  linux-image-3.2.0-40-generic
 +0 packages upgraded, 0 newly installed, 1 to remove and 78 not upgraded.
 +Need to get 0 B of archives. After unpacking 150 MB will be freed.
 +(Reading database ... 111084 files and directories currently installed.)
 +Removing linux-image-3.2.0-40-generic ...
 +Examining /​etc/​kernel/​postrm.d .
 +run-parts: executing /​etc/​kernel/​postrm.d/​initramfs-tools 3.2.0-40-generic /​boot/​vmlinuz-3.2.0-40-generic
 +update-initramfs:​ Deleting /​boot/​initrd.img-3.2.0-40-generic
 +run-parts: executing /​etc/​kernel/​postrm.d/​zz-update-grub 3.2.0-40-generic /​boot/​vmlinuz-3.2.0-40-generic
 +Generating grub.cfg ...
 +Found linux image: /​boot/​vmlinuz-3.2.0-57-generic
 +Found initrd image: /​boot/​initrd.img-3.2.0-57-generic
 +Found linux image: /​boot/​vmlinuz-3.2.0-54-generic
 +Found initrd image: /​boot/​initrd.img-3.2.0-54-generic
 +Found linux image: /​boot/​vmlinuz-3.2.0-52-generic
 +Found initrd image: /​boot/​initrd.img-3.2.0-52-generic
 +Found memtest86+ image: /​memtest86+.bin
 +done
 +</​code>​
 +
 +<​code>​
 +# aptitude -y purge $PACKAGE
 +The following packages will be REMOVED:
 +  linux-image-3.2.0-40-generic{p}
 +0 packages upgraded, 0 newly installed, 1 to remove and 78 not upgraded.
 +Need to get 0 B of archives. After unpacking 0 B will be used.
 +(Reading database ... 106946 files and directories currently installed.)
 +Removing linux-image-3.2.0-40-generic ...
 +Purging configuration files for linux-image-3.2.0-40-generic ...
 +Examining /​etc/​kernel/​postrm.d .
 +run-parts: executing /​etc/​kernel/​postrm.d/​initramfs-tools 3.2.0-40-generic /​boot/​vmlinuz-3.2.0-40-generic
 +run-parts: executing /​etc/​kernel/​postrm.d/​zz-update-grub 3.2.0-40-generic /​boot/​vmlinuz-3.2.0-40-generic
 +</​code>​
 +
 +Repeat for 39 and 38 as well.  I usually leave a few versions behind and not remove all of them.
 +
 +===== Update to Latest Kernel =====
 +<code bash>
 +aptitude update
 +aptitude install linux-headers-generic
 +</​code>​
 +
 +===== Script =====
 +Create the list of existing images
 +<code bash>
 +dpkg -l linux-image-\* | grep ^ii | awk '​{print "/​tmp/​pimage " $2}' > /​tmp/​pimage_list
 +chmod 755 /​tmp/​pimage_list
 +</​code>​
 +DELETE the last few lines before running to avoid deleting recent/​current image!!!
 +
 +Create file ''/​tmp/​pimage''​ as:
 +<code bash>
 +#!/bin/bash
 +#
 +PACKAGE=$1
 +aptitude -y remove $PACKAGE
 +aptitude -y purge $PACKAGE
 +#
 +exit
 +</​code>​
 +Change permissions on ''/​tmp/​pimage''​
 +<code bash>
 +chmod 755 /tmp/pimage
 +</​code>​
 +
 +
 +===== References =====
 +http://​askubuntu.com/​questions/​258521/​unable-to-install-virtualbox-on-ubuntu-12-10-kernel-headers-cannot-be-found
  

QR Code
QR Code tech:linux:purge_linux_images (generated for current page)