Accidentally deleted all kernel files from /boot

2

I have a virtual machine (VM) running Ubuntu Server 14.04. I access the VM remotely using putty. Recently I came into a problem when /boot was 100% full.

I came across numerous articles which recommended growing root size and others recommended deleting old kernel files i.e. everything except the original file, the latest and the one before the latest.

I accidentally deleted all kernel files i.e. files with the word 'img' in the file name. After deleting these files /boot 67% free space (which is good). But after restarting the VM I can't login anymore, I get 'Access denied' error. I tried to restart the VM but nothing.

Some of the articles for solving this issue talk about a Live CD but I don't have physical access to the NAS where I can stick the CD. Is there a way to recover the files without using a bootable disc? i.e. by just using SSH

Tumelo

Posted 2015-07-27T13:08:38.140

Reputation: 31

You can't SSH into an operating system that won't boot. You need to have someone stick the Live CD/USB or perform the recovery for you. – Larssend – 2015-07-27T13:23:26.440

Answers

1

This is what worked for me: I created a new virtual machine (using VirtualBox) with the same Ubuntu version as the one that crashed. Then using WinSCP I downloaded the corrupted VM (i.e. VDI file) locally on my machine and mounted it as a drive on the newly created VM. Then I just copied the initrd.img files to root directory of the corrupted VM and it worked after that.

Tumelo

Posted 2015-07-27T13:08:38.140

Reputation: 31

This is the way even for bare metal. But it is good to have an actual backup. – mckenzm – 2018-02-26T21:10:38.767

1

The initrd.img files contain all the drivers required to boot your VM. That means it probably can't boot to the point where the network is up, let alone sshd.

You'll need to get console access and (virtual) CD access, and boot from an ISO file. Or else roll back to a snapshot before you deleted the files from /boot.

You shouldn't delete files from /boot manually, instead you should uninstall linux-image packages that you don't need anymore.

Douglas Leeder

Posted 2015-07-27T13:08:38.140

Reputation: 1 375

I will have go to the data center. And I'm not very familiar with Linux . . . so can I run roll back to a previous snapshot in the state things are right now without running a Live USB? or do you mean run recovery from the bootable USB? – Tumelo – 2015-07-28T06:51:17.440

If your VM is on e.g. VMWare ESX, you can create snapshots on the VM from within vSphere, any then return a VM to a previous snapshot regardless of what has happened to the OS on the VM. I'm confused about your talk of data center and Live USB. For a VM you need to get to the virtual console, and connect a virtual Live CD ISO to the VM so that you can recover from that. – Douglas Leeder – 2015-07-28T09:26:50.513

maybe I should have said this earlier but we have a NAS of many TB sitting in a data center and it runs Ubuntu. I created a VM (using VBoxManage commands) which runs Ubuntu server . . . and there are other VMs running as well. – Tumelo – 2015-07-28T13:49:51.290

So for virtualbox you can use vboxmanage to attach an iso http://superuser.com/questions/741734/virtualbox-how-can-i-add-mount-an-iso-image-file-from-command-line

– Douglas Leeder – 2015-07-28T15:35:00.900

And then VNC to access the virtual console: https://grenville.wordpress.com/2012/03/14/using-vnc-with-headless-virtualbox-vms/

– Douglas Leeder – 2015-07-28T15:36:02.980

getting physical access to the machine is taking forever. I just copied the VDI file to my local machine and tried to open it with VirtualBox. I have a live USB but when I tried to boot from it, the only options I have is: hard disk, floppy and lan. And I enabled USB in the VB setttings – Tumelo – 2015-07-29T07:49:42.320

I suggest you ask a new question, since I don't know enough about Virtualbox to answer your question. I know you can boot from CD but don't know about USB. – Douglas Leeder – 2015-07-29T08:46:45.783

finally got it. I created a new virtual machine (locally) with the same Ubuntu version as the one that crashed. I then mounted the troublesome VDI file and just copied the intrid files to boot directory and it works, thanks! – Tumelo – 2015-07-30T05:20:36.393

0

You cannot SSH to machine, that cannot boot. In no way. You have to ask someone with physical access to machine (hypervisor management console in your case) to fix the problem.

For removing old kernels under Ubuntu you should use apt-get autoremove.

tymik

Posted 2015-07-27T13:08:38.140

Reputation: 143