LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   I nuked my /boot partition and I'd like it back please (https://www.linuxquestions.org/questions/linux-software-2/i-nuked-my-boot-partition-and-id-like-it-back-please-419492/)

Tiggs 02-25-2006 02:38 PM

I nuked my /boot partition and I'd like it back please
 
Running Fedora Core 4 on a P4 box. I needed to back up the contents of one server (bsdboxer) to another (johnny5), so I decided to send a tar of a folder across SSH. I however, am a complete idiot, and dumped from the man pages of tar, I did this:

Code:

tar cvfb - 20 stuff/ | ssh johnny5 dd of=/dev/hda1 obs=20b
Hells yeah, I over wrote my boot parititon! ... :(

So, there's nothing in /boot now. I tried the advertised "Fedora rescue disk", typed in "linux rescue", was dumped to a terminal, and attempted to see if the drives were still there. An fdisk -l shows that the partitions are still intact, and the /mnt/sysimage still shows the contents of my drive which is great. However, if I try to "chroot /mnt/sysimage", the drives disappear, and I can't even begin to attempt to reinstall the GRUB loader.

Rebooting and praying that Knoppix could fix the the day, I wind up at in the face of a terminal and some very mean results.

1. I can see the devices when I do an fdisk -l. The parititions are there and happy, with the /dev/hda1 still being a boot partition, and /dev/hda2 still with the rest of the file system on it.
2. I can't mount either /dev/hda1 or /dev/hda2 to /mnt/hda1 or /mnt/hda2. Something about a wonky magic number error.
3. gpart /dev/hda1 doesn't quite work either. It hangs for a few minutes and I just smash my head on the coffee table a couple of times for the amount of stupidity I've done.
4. I can't do a reinstall of GRUB, well, because GRUB or any other program other than fdisk can't see the partitions.

Basically, what I'm asking is if there's anyway for me to fix the MBR and the partition table without having to kill the entire drive. Thanks.

Tiggs 02-25-2006 02:56 PM

Breaking news: I tried an fdisk /dev/hda1 (where the boot partition was)
Code:

root@0[/]# fdisk /dev/hda1
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help):

Should I write the changes? I'm really lost here.

jomen 02-25-2006 03:08 PM

you need to do:
fdisk /dev/hda
not fdisk /dev/hda1 - this will and can not work!

jomen 02-25-2006 03:10 PM

...but probably everything is ok. - just grub needs to be reinstalled (make a filesystem first...) and your kernel-image copied to /boot

Tiggs 02-25-2006 03:25 PM

Quote:

Originally Posted by jomen
you need to do: fdisk /dev/hda not fdisk /dev/hda1 - this will and can not work!

Code:

root@0[knoppix]# fdisk /dev/hda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
  (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot      Start        End      Blocks  Id  System
/dev/hda1  *          1          13      104391  83  Linux
/dev/hda2              14        9729    78043770  8e  Linux LVM

Command (m for help):

Okay, what do I do from here?

jomen 02-25-2006 04:11 PM

The partition is still there - as was to be expected by looking on what command you gave.
Don't do anything - apart from quitting fdisk without writing to the disk (hit "q").
You tried to mount your partitions from knoppix?
/dev/hda2 should be untouched - knoppix might not know how to mount the partition because it is a RAID
It is, right?
But I'm not sure here because I never have used RAID before.
But I think it is safe to assume that this did not get changed since you wrote to /dev/hda1.

/dev/hda1 will need a new filesystem on it - dd writes directly to the device without going through the filesystem - so that is messed up probably and its contents are deleted anyway.
Look into your /etc/fstab - if you can - for what it WAS when it existed...
mkfs.ext2 /dev/hda1 should do the trick - if there was ext2 on it before - which is likely as no journalling filesystem makes sense to have on a partition with just /boot on it

Tiggs 02-25-2006 04:20 PM

Quote:

Originally Posted by jomen
The partition is still there - as was to be expected by looking on what command you gave.
Don't do anything - apart from quitting fdisk without writing to the disk (hit "q").
You tried to mount your partitions from knoppix?
/dev/hda2 should be untouched - knoppix might not know how to mount the partition because it is a RAID
It is, right?
But I'm not sure here because I never have used RAID before.
But I think it is safe to assume that this did not get changed since you wrote to /dev/hda1.

/dev/hda1 will need a new filesystem on it - dd writes directly to the device without going through the filesystem - so that is messed up probably and its contents are deleted anyway.
Look into your /etc/fstab - if you can - for what it WAS when it existed...
mkfs.ext2 /dev/hda1 should do the trick - if there was ext2 on it before - which is likely as no journalling filesystem makes sense to have on a partition with just /boot on it

/dev/hda2 is actually the OS partition. There is a RAID on the box but its a logical drive and it's the only thing that shows up when I attempt to use the Fedora Rescue Disk. /dev/hda1 was the boot partition. I just wiped it with the mkfs.ext2 /dev/hda1 command, and I'm now trying to install GRUB on it, but I'm getting this:

root@1[/]# chroot /mnt/hda1
chroot: cannot run command `/bin/bash': No such file or director

?

jomen 02-25-2006 04:49 PM

If you want (or need) to chroot you will need to find a way to get your system mounted.
(I mean / and everything under it - with the exeption of /boot - which is on /dev/hda1)
Then you mount /dev/hda1 to /boot
Then you can chroot...
You try to chroot to /dev/hda1 - but there is _nothing_ on it! The whole system is on /dev/hda2 - or on the RAID...you need to get that mounted and then /dev/hda1 to it - as I said...

If /dev/hda2 is your OS partition:
mount /dev/hda2 to /somewhere
mount /dev/hda1 to /somewhere/boot
then chroot /somewhere

Tiggs 02-25-2006 05:18 PM

Quote:

Originally Posted by jomen
If /dev/hda2 is your OS partition:
mount /dev/hda2 to /somewhere

I can't mount /dev/hda2. It's running into the same problem as I had with /dev/hda1, before I reformatted hda1.

jomen 02-25-2006 05:28 PM

/dev/hda2 is not a RAID? And you can not mount it?
What command did you use? What error did you get? From where were you running the command?

syg00 02-25-2006 05:29 PM

I don't know FC, but it should do the chroot - maybe it needs the initrd for the LVM support.

Me, I always use Knoppix - can you explain the errors better ???. It should put you in X, not a terminal/console - also remember it always mounts the disks R/O; just remount them.

And recreating /boot/grub is only half the job - you'll still need the kernel image, initrd, System.map ...

jomen 02-25-2006 05:39 PM

Just the kernel-image will do and that should be still there - if he/she compiled a custom kernel - or does Fedora always use an initrd? System map not needed - as far as I know only in lilo.


All times are GMT -5. The time now is 10:34 AM.