1

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.

2

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:

  1. Edit the file /usr/sbin/update-grub as root, and add the line exit 0 after the line #!/bin/sh.

  2. Use apt-get or Software Center to remove your unwanted kernels as planned.

  3. Afterwards, remove that line from /usr/sbin/update-grub.

  4. 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.

|improve this answer|||||
  • This answer saved me a lot of time when dealing with aging virtual servers. – Teddy Jan 11 '18 at 19:57
1

Every time you install/remove a kernel, the install-hook grub-configures every installed kernel. This is safer and less error-prone, and generally not too much slower to matter.

Offhand, I'd guess there was something wrong with that drive. Look into this.

If running the grub-reconfiguration and stuff is what's taking all the time, it may be possible to disable this, and only run it for the last of the kernel packages or something. Look into apt.conf(5), DPkg:: options to apt, and related stuff.

|improve this answer|||||
  • I don't know if it is related but I recently did a fresh install on the windows OS on a separate partition (/dev/sdb2). Anyway, thanks for the help. – Hydren Oct 6 '15 at 4:22
1

I solved the slowness. I unplugged one of secondary hard drives and it worked.

From what I researched, it looks like this kind of problem is related with some fault partition/drive.

EDIT:

The unplugged drive was dying. I needed to buy a replacement.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.