I was trying to delete old kernels, but I must have deleted all of the kernels on my Ubuntu 11.04 laptop. Is there any way to fix this via USB boot or mounting hard drive on another system?
Boot into a live CD (or live USB), mount some systems, chroot into it and install the kernel. After a successful installation of the kernel, unmount the filesystems.
- Open Terminal
- Mount the Ubuntu partition:
sudo mount /dev/sdXY /mnt
Mount some special partitions:
sudo mount --bind /dev /mnt/dev sudo mount --bind /proc /mnt/proc sudo mount --bind /sys /mnt/sys
(optional) When you are connected to a network, use the DNS servers from your Live environment (otherwise host names can possibly not be resolved):
cp /etc/resolv.conf /mnt/etc/resolv.conf
- Chroot into the
sudo chroot /mnt
- Install the Linux kernel:
apt-get install linux-image-generic(no sudo required as you are root after a chroot)
After a successful installation of the kernel, get out the chroot and unmount some filesystems:
exit sudo umount /mnt/sys sudo umount /mnt/proc sudo umount /mnt/dev sudo umount /mnt
- Reboot and remove CD or USB:
This expanded procedure accounts for most of the complications that could occur, including problems connecting to the Internet in the
chroot, not knowing which kernel package to install (before Ubuntu 12.10, it will not always be
linux-image-generic), not knowing at the outset which partition or even which physical drive contains the
/ filesystem, and having a separate
I have not written this with reference to any of the other procedures here, though you will notice some similarities. I did base it, loosely, on the procedure here (though those instructions are for something quite different, I have adapted them extensively, and only some commands, not prose, are copied).
You removed all the kernel packages, and Ubuntu cannot boot without a kernel installed. So the solution is to boot from a live CD/DVD/USB,
chroot into the installed system, and install a kernel in it.
Boot from an Ubuntu live CD/DVD or live USB flash drive.
Select Try Ubuntu (not Install Ubuntu).
When the desktop comes up, make sure you are connected to the Internet. If you are not, connect to the Internet. One way to see if you are connected to the Internet is to open a web browser. You can even follow the rest of the instructions by bringing this Ask Ubuntu answer up in your web browser, in the live CD/DVD/USB system. I strongly recommend doing that.
Open a Terminal window with Ctrl+Alt+T.
In the Terminal window, run this command to list your partitions:
sudo parted -l
You'll see something like this (but it won't be exactly like this):
Model: VMware, VMware Virtual S (scsi) Disk /dev/sda: 21.5GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 20.4GB 20.4GB primary ext4 boot 2 20.4GB 21.5GB 1072MB extended 5 20.4GB 21.5GB 1072MB logical linux-swap(v1) Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. Error: Can't have a partition outside the disk!
Examine the output you got, to determine the device name of the partition that contains the
/filesystem of the Ubuntu system that is installed on the hard drive (that you are repairing).
If you only have one
ext4partition, that's the one.
If you have more than one
ext4partition, it's probably the first one. However, if the first one is very small--less than a gigabyte--then that might be a separate
/bootpartition (remember that one too).
Please note that whether or not
bootis listed under
Flagshas very little to do with whether or not a partition is a separate
/bootpartition. My system, whose information is listed above, does not have a separate
The device name for the partition starts with the device name for the physical drive, stated immediately after
Diskin the second line. Then just add the partition number to the end of that. So, the device name for the partition that contains my
/dev/sda1. Here are the two lines where I found that information:
Disk /dev/sda: 21.5GB
1 1049kB 20.4GB 20.4GB primary ext4 boot
If you have more than one physical drive, you'll get more than one listing like what is shown above. But unless you have another Unix-like system installed, you probably will only have one drive that contains
ext4partitions, at least without having created them intentionally on another drive. If you do have multiple drives with
ext4partitions, then the
ext4partition that contains your
/filesystem is probably on a drive that also contains a
It's possible that your Ubuntu system's
/filesystem is on a partition of type other than
ext4. When this happens, it's almost always
ext3, and almost always on a quite old system. It's very uncommon for this to be the case, unless you intentionally set things up this way yourself.
Remember the device name of the partition that contained your
/filesystem (or write it down). If it's different from
/dev/sda1, then you'll replace
/dev/sda1with it in the steps below.
(If it looked like you have a separate
/bootpartition, remember the device name for that, too.)
/mnt, and mount its
sudo mount /dev/sda1 /mnt sudo mount --bind /dev /mnt/dev
Check if the broken Ubuntu system you're repairing has a separate
/bootpartition which must be mounted separately. (If you are sure it does not, you can skip this.)
To check, run:
If there is output (like
grub memtest86+.bin memtest86+_multiboot.bin, but not necessarily exactly that), then the broken system's
/bootis on the same partition as its
/and you don't have to mount anything to access it.
But if there is no output, then you will have to mount the
sudo mount BOOT-PARTITION /mnt/boot
BOOT-PARTITIONwith the device name of the
/bootpartition (see step 6 above).
chrootinto the broken system, mount the remaining important virtual filesystems, and set some important environment variables:
sudo chroot /mnt mount -t proc none /proc mount -t sysfs none /sys mount -t devpts none /dev/pts export HOME=/root export LC_ALL=C
Determine if Internet access works from within the
pinging some reliable host that is known to respond normally to pings:
ping -c 5 www.google.com
You should see something like this:
PING www.l.google.com (22.214.171.124) 56(84) bytes of data. 64 bytes from vc-in-f147.1e100.net (126.96.36.199): icmp_req=1 ttl=44 time=61.3 ms 64 bytes from vc-in-f147.1e100.net (188.8.131.52): icmp_req=2 ttl=44 time=62.3 ms 64 bytes from vc-in-f147.1e100.net (184.108.40.206): icmp_req=3 ttl=44 time=61.8 ms 64 bytes from vc-in-f147.1e100.net (220.127.116.11): icmp_req=4 ttl=44 time=63.8 ms 64 bytes from vc-in-f147.1e100.net (18.104.22.168): icmp_req=5 ttl=44 time=66.6 ms --- www.l.google.com ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4006ms rtt min/avg/max/mdev = 61.367/63.212/66.608/1.897 ms
If it looks mostly like that, and the number before
% packet lossis less than 100, then the Internet connection in the
5 packets transmitted, 5 received, 0% packet loss, time 4006ms
It's working, so you can skip step 11.
If it looks mostly like that, and the number before
% packet lossis 100, the connection needs troubleshooting. Make sure the connection on the live CD system (for example, through a web browser, or by running the same command in a separate, non-
chrooted Terminal tab/window) works. Make sure you're typing the command correctly. Use
www.google.comif you haven't been.
If the output doesn't look like the above at all, but instead says
ping: unknown host www.google.com, then networking isn't working yet in the
Set up networking in the
chroot. Skip this step unless you got an
unknown hosterror in step 10 above.
To set up networking, back up the broken system's
hostsfile, and copy over the live CD system's
resolv.conffiles. (You don't have to back up the broken system's version of
resolv.conf, as that file is automatically regenerated on-the-fly.)
Open a new Terminal tab (Ctrl+Shift+T) or, if you prefer, a new Terminal window (Ctrl+Shift+N, or just Ctrl+Alt+T). Run these commands in it:
sudo cp /mnt/etc/hosts /mnt/etc/hosts.old sudo cp /etc/hosts /mnt/etc/hosts sudo cp /etc/resolv.conf /mnt/etc/resolv.conf exit
exitcommand at the end closes the new tab/window.)
Repeat step 10 above to make sure Internet access works now from within the
chroot. It should.
Figure out which kernel package should be installed. Usually, this will be
linux-image-generic. But not always.
If you're not sure which to install, it will depend partly on which Ubuntu release you have installed, and partly on other information. If you are not sure which Ubuntu release you have installed, find out by running this command (in the
chroot, not in a separate Terminal window/tab):
On Ubuntu 12.04 LTS, likely possibilities are
linux-image-generic-pae. (Unlike previous versions, 12.04 no longer has separate server and desktop kernels.)
If the installed Ubuntu system (that you are fixing) is the 64-bit version, use
linux-image-generic-paeonly applies to 32-bit systems.)
It's possible to have a 32-bit Ubuntu system installed on a 32-bit or 64-bit computer. Furthermore, you might be using a 32-bit or 64-bit live CD to fix a 32-bit installed system. So if you don't know whether the installed Ubuntu system is 32-bit or 64-bit, check by running this command (in the
chroot, not in a separate Terminal window/tab):
The output will be either
(Please note that
uname -mis not a correct way to find this information, because even when run in the
chroot, that will tell you the architecture of the running kernel, which is the live CD system's kernel and not the installed (broken) system's kernel.)
If the installed Ubuntu system (that you are fixing) is the 32-bit version, the best kernel to use will depend on how much RAM you have. I recommend:
linux-image-genericif you have less than 3 GB of RAM
linux-image-generic-paeif you have 3 GB of RAM or more.
(This is how Ubuntu's installer chooses which one to set up, ever since the installer gained the ability to install PAE kernels. See the resolution to this bug. If you want to learn what PAE is, see this Wikipedia article. If you want to learn about PAE in Ubuntu, see this Ubuntu wiki page.)
If you don't know how much RAM you have, run this command to find out:
grep MemTotal /proc/meminfo
- 3 gigs = 3,145,728 kB
On Ubuntu releases before 12.04, likely possibilities are
- If you're running an Ubuntu Server system, use
- Otherwise, follow the advice above for 12.04 systems.
- If you're running an Ubuntu Server system, use
This is the moment you've been waiting for! Install a kernel in the broken system.
(Like before, except where explicitly indicated otherwise, these commands are run in the
chroot, not in a separate Terminal window/tab.)
apt-get update apt-get -y install linux-image-generic
linux-image-genericwith whatever other kernel package you decided to install in step 12 above, if different.
If you had to perform step 11 to set up networking in the
chroot, restore the old
hostsfile. If you skipped step 11, skip this step too.
To restore it, run this command:
cp /etc/hosts.old /etc/hosts
exiting out of the
umount /proc || umount -lf /proc umount /sys /dev/pts exit sudo umount /mnt/dev /mnt
Shut down the live CD/DVD/USB system, removing the live CD/DVD or USB flash drive. Boot into the system installed on the hard drive, that you just repaired. You've installed a kernel package in it (and as part of the installation, the kernel it provides will be added back to the GRUB2 boot menu). If everything worked correctly, your system should boot without problems. (I think it's possible that it will take a little longer to boot than usual, this time.)
DISCLAIMER: I did not test the above procedure on every possible Ubuntu system, so it is possible there is a mistake in it that I have not identified.
In the future, I recommend always trying to keep two kernels installed. It's good to have two in case one of them stops working for any reason (you can select the other in the GRUB2 boot menu). Plus, if you intend to keep two kernels and you accidentally uninstall one more than you meant to and reboot, you still have one left to boot from.
When I removed my kernel I found this solution on Ubuntu Forums. I followed every step and system was recovered. Hope it would help you.
A chroot might work, chroot means that when you start a system you change the root file system. For example you started from a live CD but you change the root "/" to where your ubuntu is installed.
Lets say your ubuntu is installed on /dev/sda2 then you can try the following commands:
sudo mount /dev/sda2 /mnt sudo cp /etc/resolv.conf /mnt/etc/ sudo cp /etc/hosts /mnt/etc/ sudo mount --bind /dev/ /mnt/dev sudo chroot /mnt mount -t proc none /proc mount -t sysfs none /sys mount -t devpts none /dev/pts export HOME=/root export LC_ALL=C dbus-uuidgen > /var/lib/dbus/machine-id dpkg-divert --local --rename --add /sbin/initctl ln -s /bin/true /sbin/initctl
now you're root "/" is on /dev/sda2, try installing the kernel
apt-get update apt-get install linux-image-2.6.32-26-generic update-initramfs -cv -k all update-grub
I had to do a little guesswork here since I never had to do this before but this should be about it. Don't know if you get some fstab error warning (like can't find root).
Now you need to clean up some stuff and unmount the mounted partitions: Code:
rm /etc/resolv.conf rm /etc/hosts rm /var/lib/dbus/machine-id rm /sbin/initctl dpkg-divert --rename --remove /sbin/initctl umount /proc # if this doesn't work try umount -lf /proc umount /sys umount /dev/pts exit sudo umount /mnt
And you can reboot to see if it worked.
URL for the thread: http://art.ubuntuforums.org/showthread.php?t=1688928
After I removed old kernels from Trusty14.04 yesterday (FTR: I did not remove the two most recent ones!) my system wouldn't boot anymore. GRUB showed
Error: File not found Error: You need to load the kernel first
No idea why.
I then followed Eliah Kagan's excellent instructions to install
linux-image-generic from a live CD. It did install 150 MB of new kernel, but sadly that didn't solve the problem.
Fortunately, I found this page. The
Boot-Repair tool got it right, my system is running again.
I just wanted to add my experience I went through today in upgrading to Willy. I cleaned up a little bit and I found myself with only memtest. google led me to understand that I had removed the kernels. One constraint I had is slow network and so downloading full ISO was not option. So I used Ubuntu Minimal CD (40MB only) and booted on it. After detecting hardware option (which helped me connect to wireless) I went into shell option. I followed @Lekensteyn instructions and I succeeded. few things though: you have to copy
resolv.conf before going chroot or else your DNS will be screwed and since the logged in user there is root no need for sudo anywhere.
I know its old but I thought adding this answer will add value to those wo would encounter the issue.