LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Debian (https://www.linuxquestions.org/questions/debian-26/)
-   -   deleted /boot partition Need to reinstall kernel (https://www.linuxquestions.org/questions/debian-26/deleted-boot-partition-need-to-reinstall-kernel-547947/)

zoidburg016 04-21-2007 06:25 PM

deleted /boot partition Need to reinstall kernel
 
I got a virus or something on my linux partition, so I had to reinstall windows, so I did. Then I realized that I had to reinstall grub, so I booted into knoppix and tried to run grub-install /dev/hda3. It didn't work, so I formated my /boot partition not thinking about the fact that my kernel is there. now I need to reinstall it, but i don't know how. I don't have a /usr/src/linux folder.

btw, I'm using a debian based knoppix hd install.

Dutch Master 04-21-2007 06:33 PM

A virus on your Linux system? Highly unlikely, but there's always the proverbial exception...

Anyway, did you try installing grub as root? (or with the sudo command, provided Knoppix has that. Don't know about that). If all fails, re-installation isn't that difficult, just save your data on the Knoppix system before re-installing.

zoidburg016 04-21-2007 06:39 PM

Quote:

Originally Posted by Dutch Master
A virus on your Linux system? Highly unlikely, but there's always the proverbial exception...

Anyway, did you try installing grub as root? (or with the sudo command, provided Knoppix has that. Don't know about that). If all fails, re-installation isn't that difficult, just save your data on the Knoppix system before re-installing.

Sorry, I meant I got a virus on my windows partition.

zoidburg016 04-21-2007 07:40 PM

I don't want to have to reinstall. Grub isn't really the big problem, the problem is I deleted my kernel. Does anyone know how to re install it?

zoidburg016 04-21-2007 07:51 PM

Is there any package that I can install that has the kernel?

Daws 04-21-2007 08:20 PM

OK. This might work or might not. Boot up knoppix on Live cd.

Download the kernel image and the grub package (grub stores a lot of its files on /boot so you need to reinstall that too), assuming you have etch 4.0 you want linux-image-2.6.18-4-zzz and grub

As root:

Code:

mount -v /dev/hdax /mnt/tmp
chroot PATH=/bin:/sbin:/usr/bin:/usr/sbin /mnt/tmp

Where hdax is your Debian root (/) partition

From inside the chroot, mount all of your other partitions /boot,/var,/usr,/tmp etc. Make sure you have mounted them all.

apt will work if you want to set up an internet connection inside chroot, but we already have the debs. So install them with
Code:

dpkg -i package1 package2
Once that is done:

Code:

grub-install (hd0)
Then you can exit chroot and everything should be working nicely. (We need a fingers crossed smiley)

Dutch Master 04-21-2007 08:25 PM

Yes, open Synaptic and search for kernel or linux as keywords. Either one will give you a suitable kernel. But, that's not all! You also need the tools for making an initrd image and you'll need to make the /boot dir again. I think, given your inexperience, that re-installing Knoppix would be wiser and less time-consuming. It might not be the answer you're looking for because you don't learn anything from that, but for something complicated as this you lack the skills to do it properly. Over time you'll acquire those skills, but for now you're better of as a regular user IMHO.

<edit>@Daws: he's using Knoppix on his harddrive, so no Etch.</edit>

zoidburg016 04-21-2007 08:27 PM

where do I download the kernel?

Daws 04-21-2007 08:30 PM

Quote:

Daws: he's using Knoppix on his harddrive, so no Etch.
Oh yeah, well same procedure just different packages to download. Or he could just reinstall... (boooring)

EDIT:
Quote:

You also need the tools for making an initrd image
I didn't mention that because dpkg should automatically handle that. If its just /boot that was wiped then the rest of the system is still intact, initramfs/yaird/? included.

Quakeboy02 04-21-2007 08:43 PM

Oh come on Dutch Master, he'll learn a lot and maybe have a bit of fun fixing this! :)

Here are a few things that you may have to do get all the way there if there's not enough in Daws' post.

From a knoppix terminal:
Code:

su
mount /dev/hda1 /mnt  (or hda2 or whatever)
mount --bind /dev /mnt/dev
mount -t proc proc /mnt/proc
mount -t sysfs sysfs /mnt/sys
chroot /mnt
mkdir /boot
cd /var/cache/apt/archives

Install the linux-image you want with dpkg -i as per Daws post.
Install grub and run grub-install (hd0) as per Daws.
You may also need to install initramfs-tools and run "update-initramfs -u -k all".

And let us know on either success or failure. I haven't had to do quite what you're doing, but I've done stuff kinda close, so let us know what works!

zoidburg016 04-21-2007 09:00 PM

okay, I'm not sure if this has worked yet, but what I did was
mount /dev/hda2 /mnt/root
mount /dev/hda4 /mnt/root/boot
mount -t proc none /mnt/root/proc
chroot /mnt/root
apt-get install linux-image-2.6.18-4-386
apt-get install grub

right now it says it's generating menu.lst, but it's been doing it for a while.

BillyGalbreath 04-22-2007 01:50 AM

This has an easy easy solution. If the only thing you lost was your /boot partition then you are perfectly safe. The /boot partition actually does not hold your kernel, just some vital information about the kernel needed to boot. Your actual kernel is located in /lib/modules/2.6.x - And you should have a .deb package containing your custom kernel in the /usr/src dir. If not, you can download a stock kernel from http://packages.debian.org

1) bootup using the knoppix livecd

2) As Daws said:
Quote:

Originally Posted by Daws
Code:

mount -v /dev/hdax /mnt/tmp
chroot PATH=/bin:/sbin:/usr/bin:/usr/sbin /mnt/tmp

Where hdax is your Debian root (/) partition

From inside the chroot, mount all of your other partitions /boot,/var,/usr,/tmp etc. Make sure you have mounted them all.

What this does is put you in your real installation (as if you never booted from the livecd). Make sure /mnt/tmp exists (mkdir /mnt/tmp).

3) Run grub-install
Code:

grub-install (hd0)
This will build your default grub again inside /boot and it will install the grub image to MBR of hd0 overwriting the Windows mbr.

4) Install your kernel again from the .deb (either the custom one you built in the past, or a new stock from http://packages.debian.org). This step will fill up the /boot partition again with your kernel information and automagically update grub for you.

5) Reboot and take out the livecd to boot to your real system.


All times are GMT -5. The time now is 12:19 PM.