During a disk analyzer session to clean up space, I saw that /lib was taking up a ton of space, and I have never before seen this taking up this much space before in Disk Analyzer. The thing is, I have recently made a /lib folder under my /home/Development for building some Android kernels. So when I looked at this and not having seen it like this before, I thought I was looking at my /lib folder for my Android kernels. I didn't even take a second to look at the hierarchy before going into it and pulling it up in terminal, I was just set on removing what was taking up excessive amounts of space. When I saw how much space was being taken up, my thinking just went to - "remove." So I went into the lib folder and deleted all the old ones. I don't remember the whole names exactly but I do remember there were ones from I believe 29 and up, in .0-29-generic-pae, and all the way up to forty. I normally don't mess around in these folders, especially deleting things, only adding things I may need for Android Development.

I accidentally deleted all my modules from /lib/modules

Now my Ubuntu boots and runs and I have access to all my system, but I have no modules.


  1. I have no drivers, which means I can't connect my external HDD where I copied .0-40-generic-pae to, and I can't connect to the internet to download the modules.

  2. The accidentally deleted modules aren't in my trash because I used rm -r, so no restoring from trash.

  3. I was told to just purge my kernel and reinstall it, and that was headache free, I'm getting a headache just figuring out how to properly do so with what I have access to.

  4. I do not want to just wipe and re-install when there could be an alternate way to fix this, possibly even easy way, because I have tons of data that I do not want to loose, and without those modules I can't back them up anywhere.

Another suggestion was to boot into a live session and download what I need, back it up (I guess mount my current Ubuntu partition and put it there), and then install. Well I can do that, I can boot live session, plug in my external HDD, mount my Ubuntu partition, and copy the 40-generic-pae modules I have to that system.

  • I believe I can do this, correct?
  • Would this be the way to go?
  • If so, should I just copy the whole folder /package straight back into /lib/modules, and then reboot?
  • Or is there a different way I should do it?

Can anyone help me with this?

  • A bit of whitespace would make this a lot easier to read. (not sure why I can not edit that ATM though).
    – Hennes
    May 18, 2013 at 0:33
  • As to fixing it, that might be as simple as 'cd /usr/src/linux && make modules && make modules_install`, assuming you have the kernel source installed in /usr/src/linux.
    – Hennes
    May 18, 2013 at 0:37
  • Okay, yeah I actually tried to space it out but I didn't know that I had to add an entire line of blank space to separate lines from one another. As far as the comment on fixing it, I'll try that now. I mean, I haven't deleted the source from /usr/src/linux, so it should be there correct? May 18, 2013 at 0:52
  • Okay Hennes, I tried the command and it said /usr/src/linux didn't exist so I ls'd /usr/src and I have a list of differetn linux headers and linux headers generic-pae, when I deleted the files last night they were in generic-pae files, but these headers probably don't contain the modules do they? May 18, 2013 at 0:59
  • Which kernel are you running? (Use uname -a to check). Then cd into that kernels folder. Ofc. this assumes a logic naming scheme so you know which kernel to change to. Also, if you only have the headers then you lack the source. In that case you can download the full kernel ( ftp to ftp.kernel.org and cd to pub/linux/kernel ). Or use the package tools to deinstall and reinstall a kernel. That would no longer match 'repairing modules' or 'reinstalling modules', but it would solve your problems.
    – Hennes
    May 18, 2013 at 1:05

2 Answers 2


Determine the output of uname -a. For example: 4.2.0-18-generic. Then as you described above, use the LiveCD method to boot.

Download the following packages (replace 4.2.0-18-generic with your output above):

apt-get download linux-image-4.2.0-18-generic, linux-headers-4.2.0-18-generic, linux-image-extra-4.2.0-18-generic

Next copy these into your broken system's hard-drive. Reboot into your broken system and sudo dpkg -i all of these packages.


I made the same mistake and here is what worked for me (with a cable connection):

In a terminal, run the command:

dpkg -l | grep linux-image-.*-generic

Select the kernel version you want to reinstall and run (typing the actual version instead of 4.X.Y-ZZ):

sudo apt-get install --reinstall linux-image-4.X.Y-ZZ-generic

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .