I have a Ubuntu 12.04 64-bit installation sided with a Windows 7 64-bit in dual-boot configuration. I was trying to remove older kernels packages to free some space, but the process is taking too long.
I entered the following command:
cat knlist.txt | xargs sudo apt-get -y purge
The file knlist.txt contains:
linux-headers-3.2.0-77
linux-headers-3.2.0-77-generic
linux-headers-3.2.0-80
linux-headers-3.2.0-80-generic
linux-headers-3.2.0-82
linux-headers-3.2.0-82-generic
linux-headers-3.2.0-83
linux-headers-3.2.0-83-generic
linux-headers-3.2.0-84
linux-headers-3.2.0-84-generic
linux-headers-3.2.0-85
linux-headers-3.2.0-85-generic
linux-headers-3.2.0-86
linux-headers-3.2.0-86-generic
linux-headers-3.2.0-87
linux-headers-3.2.0-87-generic
linux-headers-3.2.0-88
linux-headers-3.2.0-88-generic
linux-headers-3.2.0-89
linux-headers-3.2.0-89-generic
linux-image-3.2.0-77-generic
linux-image-3.2.0-80-generic
linux-image-3.2.0-82-generic
linux-image-3.2.0-83-generic
linux-image-3.2.0-84-generic
linux-image-3.2.0-85-generic
linux-image-3.2.0-87-generic
linux-image-3.2.0-88-generic
linux-image-3.2.0-89-generic
linux-tools-3.2.0-80
linux-tools-3.2.0-82
linux-tools-3.2.0-83
linux-tools-3.2.0-84
linux-tools-3.2.0-85
linux-tools-3.2.0-87
linux-tools-3.2.0-88
linux-tools-3.2.0-89
My current kernel is 3.2.0-91.
Normally it takes some minutes but now it is taking forever! I already left it running for the entire night. Each step take hours!
I tried pausing the process using ctrl+z and resuming with % + return, I have even aborted the process and restarted.
After resuming about 3 hours ago, the screen is like this (I have a Portuguese installation):
Removendo linux-image-3.2.0-77-generic ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.2.0-77-generic /boot/vmlinuz-3.2.0-77-generic
update-initramfs: Deleting /boot/initrd.img-3.2.0-77-generic
run-parts: executing /etc/kernel/postrm.d/zz-extlinux 3.2.0-77-generic /boot/vmlinuz-3.2.0-77-generic
P: Checking for EXTLINUX directory... found.
P: Writing config for /boot/vmlinuz-3.2.0-91-generic...
P: Writing config for /boot/vmlinuz-3.2.0-90-generic...
P: Writing config for /boot/vmlinuz-3.2.0-89-generic...
P: Writing config for /boot/vmlinuz-3.2.0-88-generic...
P: Writing config for /boot/vmlinuz-3.2.0-87-generic...
P: Writing config for /boot/vmlinuz-3.2.0-85-generic...
P: Writing config for /boot/vmlinuz-3.2.0-84-generic...
P: Writing config for /boot/vmlinuz-3.2.0-83-generic...
P: Writing config for /boot/vmlinuz-3.2.0-82-generic...
P: Writing config for Windows 7 (loader) on /dev/sdb1...
P: Installing debian theme... done.
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.2.0-77-generic /boot/vmlinuz-3.2.0-77-generic
(The last step appeared some minutes ago)
Here is my lsblk:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 74,5G 0 disk
├─sda1 8:1 0 5G 0 part [SWAP]
└─sda2 8:2 0 69,5G 0 part /
sdb 8:16 0 931,5G 0 disk
├─sdb1 8:17 0 100M 0 part
├─sdb2 8:18 0 50,1G 0 part
└─sdb3 8:19 0 881,4G 0 part /media/Dados
sdc 8:32 0 465,8G 0 disk
├─sdc1 8:33 0 349,3G 0 part /media/Storage
└─sdc2 8:34 0 116,5G 0 part /media/Extra
sr0 11:0 1 1024M 0 rom
What can I do to fix this sluggishness? Is it because there are too many kernels to remove?
I was thinking to leave it running the grub configurator, but it would take days and I'm really afraid to melt my drive due to intense hdd activity during the process.
Best Answer
Practically speaking, if you are about to uninstall a number of old kernels (or perhaps you are part-way through that process) and you want to speed things up, you could try the following:
Edit the file
/usr/sbin/update-grub
as root, and add the lineexit 0
after the line#!/bin/sh
.Use
apt-get
or Software Center to remove your unwanted kernels as planned.Afterwards, remove that line from
/usr/sbin/update-grub
.Important! Finally, run
update-grub
manually.It would be great if in future
dpkg
would work out to perform this behaviour automatically.One notable exception is when you are uninstalling the kernel which is currently the default in grub. In that case it might be preferable to run
update-grub
sooner rather than later.