How to restore a virtual system after accidentally removing all kernels?
You can solve this problem very easily, so go through the steps below one by one:
- Insert a Live CD ISO image into the Virtualbox disk drive.
- Change the boot order for the Virtualbox drives to boot from this ISO image and boot into it.
- choose 'Try Ubuntu' and open a terminal by pressing Ctrl+Alt+T.
- Run
lsblk
to find the proper device name for your VM main drive. Mount the drive into
/mnt
whereXX
is the proper drive label for the drive you want to rescue:mount /dev/sdXX /mnt
Now mount and bind the following to make a proper install possible:
sudo mount -o bind /dev /mnt/dev sudo mount -o bind /dev/pts /mnt/dev/pts sudo mount -t sysfs /sys /mnt/sys sudo mount -t proc /proc /mnt/proc sudo cp /proc/mounts /mnt/etc/mtab sudo cp /etc/resolv.conf /mnt/etc/resolv.conf
Chroot into the mountpoint with
sudo chroot /mnt
.Run an update of the packet-lists:
apt-get update # you might want to do an upgrade as well if you like apt-get upgrade
Now you can install the kernel again with:
apt-get install --reinstall linux-image-generic
Run
update-grub
to make sure grub points again to a working installed kernel.Now you can exit the chroot environment by pressing Ctrl+D and wrap up before you shut down the VM and reboot it on the normal drive:
sudo umount /mnt/dev/pts sudo umount /mnt/dev sudo umount /mnt/sys sudo umount /mnt/proc sudo umount /mnt
This should have done it and your VM now again has a kernel to boot from
Related videos on Youtube
gwalker
Updated on September 18, 2022Comments
-
gwalker over 1 year
I have seen answers for actual installs but am not sure this would work for Virtual.
Like a fool, I had not backed up the data on a VM I used at work. When I tried to upgrade I was out of space and like a bigger fool, wiped out all kernels instead of just old ones when trying to free up space. Now I boot into Memtest86 and can go no further because grub(?) sees no other kernel.
The VM was Ubuntu 14.04 running in Oracle VM VirtualBox. Is there a way to mount the image from another Ubuntu VM and reinstall the kernel? The directory has an Ubuntu.vbox file and a Ubuntu.vdi file as well as a Ubuntu.vbox.prev file that seems to just be XML data
UPDATE: Mounted from desktop in "Try Ubuntu" mode, chrooted in to
/media/ubuntu/<diskname>
and had to manually override to write a new/etc/resolv.conf
. When I did theapt-get install linux-image-generic
it seemed to have write issues. Did I mount incorrectly?I mounted just by selecting the HD listed in "Files" and after
sudo chroot /media/ubuntu/<diskname>
I confirmed that the existing users were listed in /home/ so I am pretty sure I was on the right drive, but when I tried to mount it the way other how-to show, I get:
sudo mount /media/ubuntu/<long HD name> mount: /media/ubuntu/<long HD name> is not a block device
-
Thomas Ward over 6 yearsComments are not for extended discussion; this conversation has been moved to chat.
-
Thomas Ward over 6 yearsThe above was done at one of the commentor's requests.
-
-
gwalker over 6 yearsWorked! Many thanks for your patience and help!