Removing old kernel fails to remove /lib/modules/<kernel> directory

Asked by hwiechers

I tried to completely remove some old kernels (linux-image-2.6.24-16-generic and linux-image-2.6.24-17-generic) using Synaptic.

Synaptic ran but returned:
>> rmdir: failed to remove `/lib/modules/2.6.24-16-generic': Directory not empty
and
>> rmdir: failed to remove `/lib/modules/2.6.24-17-generic': Directory not empty

Is this a bug in the removal process or I am doing something wrong?
Can I safely delete those directories manually?

Below is relevant section from my /var/log/apt/term.log

Log started: 2008-06-22 08:12:47
(Reading database ... 156797 files and directories currently installed.)

Removing linux-restricted-modules-2.6.24-16-generic ...

Removing linux-ubuntu-modules-2.6.24-16-generic ...

update-initramfs: Generating /boot/initrd.img-2.6.24-16-generic

(Reading database ... 156239 files and directories currently installed.)

Removing linux-image-2.6.24-16-generic ...

Running postrm hook script /sbin/update-grub.

Searching for GRUB installation directory ... found: /boot/grub

Searching for default file ... found: /boot/grub/default

Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst

Searching for splash image ... none found, skipping ...

Found kernel: /boot/vmlinuz-2.6.24-19-generic

Found kernel: /boot/vmlinuz-2.6.24-18-generic

Found kernel: /boot/vmlinuz-2.6.24-17-generic

Found kernel: /boot/memtest86+.bin

Replacing config file /var/run/grub/menu.lst with new version

Updating /boot/grub/menu.lst ... done

Purging configuration files for linux-image-2.6.24-16-generic ...

Running postrm hook script /sbin/update-grub.

Searching for GRUB installation directory ... found: /boot/grub

Searching for default file ... found: /boot/grub/default

Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst

Searching for splash image ... none found, skipping ...

Found kernel: /boot/vmlinuz-2.6.24-19-generic

Found kernel: /boot/vmlinuz-2.6.24-18-generic

Found kernel: /boot/vmlinuz-2.6.24-17-generic

Found kernel: /boot/memtest86+.bin

Updating /boot/grub/menu.lst ... done

rmdir: failed to remove `/lib/modules/2.6.24-16-generic': Directory not empty

(Reading database ... 154152 files and directories currently installed.)

Removing linux-restricted-modules-2.6.24-17-generic ...

Removing virtualbox-ose-modules-2.6.24-17-generic ...

Removing linux-ubuntu-modules-2.6.24-17-generic ...

update-initramfs: Generating /boot/initrd.img-2.6.24-17-generic

(Reading database ... 153600 files and directories currently installed.)

Removing linux-image-2.6.24-17-generic ...

Running postrm hook script /sbin/update-grub.

Searching for GRUB installation directory ... found: /boot/grub

Searching for default file ... found: /boot/grub/default

Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst

Searching for splash image ... none found, skipping ...

Found kernel: /boot/vmlinuz-2.6.24-19-generic

Found kernel: /boot/vmlinuz-2.6.24-18-generic

Found kernel: /boot/memtest86+.bin

Replacing config file /var/run/grub/menu.lst with new version

Updating /boot/grub/menu.lst ... done

Purging configuration files for linux-image-2.6.24-17-generic ...

Running postrm hook script /sbin/update-grub.

Searching for GRUB installation directory ... found: /boot/grub

Searching for default file ... found: /boot/grub/default

Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst

Searching for splash image ... none found, skipping ...

Found kernel: /boot/vmlinuz-2.6.24-19-generic

Found kernel: /boot/vmlinuz-2.6.24-18-generic

Found kernel: /boot/memtest86+.bin

Updating /boot/grub/menu.lst ... done

rmdir: failed to remove `/lib/modules/2.6.24-17-generic': Directory not empty

Log ended: 2008-06-22 08:13:27

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Old_Soldier
Solved:
Last query:
Last reply:
Revision history for this message
Best Old_Soldier (charles.davis) said :
#1

workaround is to:
sudo rm -rf /usr/lib/modules/2.6.24-16-generic
sudo rm -rf /usr/lib/modules/2.6.24-17-generic

Revision history for this message
Old_Soldier (charles.davis) said :
#2

whoops /lib/modules/<kernel> i wasn't paying attention to what i typed :)

Revision history for this message
hwiechers (hwiechers) said :
#3

Thanks Old_Soldier, that solved my question.

Revision history for this message
Elias K Gardner (zorkerz) said :
#4

I just ran into this as well. Is there any reason not to consider this a bug?

Revision history for this message
A. Denton (aquina) said :
#5

We have some older machines in our data center running Ubuntu 8.04 LTS. A few days ago I had to upgrade the Kernel to a newer version and removed all old ones. Our policy denies us from booting into older kernels when they have security vulnerabilities. We have to use a clean media then and boot from external to chroot in case we need to do so.

Anyways I also removed old stuff under " /lib/modules/" which I normally don't. The next reboot was scheduled for Fri, Jun. 17th 2011 18:00 CEST. A few minutes later I realized the system would not boot as expected due to missing kernel-headers in "/lib/modules/".

In other words I recommend the following:

1. Do not remove old stuff by package management or by hand until you have visual verification of a successful boot of your machine with the latest kernel in use.

2. Do not remove stuff by hand neither in " /lib/modules/" nor in "/" or "/boot/". Use your package management to remove stuff. Do something like "dpkg-query -l | grep 'linux-'" or "dpkg-query -l | grep '2.6.xx'" to list everything. Avoid to unconciously remove stuff like "linux-generic" or other kernel stuff without numbers in its name. This may break your system!

3. In case you messed up your system use an image on CD or DVD which is the most equivalent to your installation, boot it and chroot to your drive. This is required since you won't have networking on a corrupted machine. After chroot configure your NIC and reinstall what you deleted accidentally. Also rebuild kernel modules if required, e.g. apt-get --reinstall <virtualbox> if you want to regenerate them.