Page 1 of 1

How to recover lilo and mbr?

Posted: 21. Apr 2016, 22:44
by jsfarinet
My son played around with my machine and in some way the result was a total crash of the machine. Partition table etc all erased. Working hard with ddrescue and testdisk i was able to re- establish the 2 main partitions, / and /home (as well as swap - not that deal the latter one ;) ). But there is still missing mbr with lilo.

Anyone here would be able to give me a helping hand, how to install mbr and lilo on top of an already existing system? (I have a sizewise identical external hd and i could dd the entire internal to the external and test around with the latter one). Would be great since i loved my Salix setup ...

Thanks a lot in advance for any pointer!

Re: How to recover lilo and mbr?

Posted: 22. Apr 2016, 17:23
by maximus
Assuming / and /home are the only two partitions in your Linux system, this shouldn't be too hard to fix. This is from memory so hopefully I haven't missed anything :oops:

With the drive plugged into your motherboard, boot from a Salix CD or USB stick. When the installer starts, you need to exit the installer and drop to the command line.

You need to first mount the / partition; assuming the problem drive is the only one in your system and / is the first partition on that drive you could use the following command:

Code: Select all

mount /dev/sda1 /mnt
Now you need to chroot to the mounted / partition:

Code: Select all

chroot /mnt
Now you should be able to run lilo and reinstall it to the drive's MBR:

Code: Select all

lilo -v
Lillo will probably throw some error messages, but these you should be able to ignore. Type exit to exit the chroot, remove the boot CD/USB stick and type reboot to reboot your system.

Re: How to recover lilo and mbr?

Posted: 23. Apr 2016, 01:40
by Atip
For such an occasion it is nice to have a Slackware Linux custom USB boot stick handy!

sudo pkgtool > Setuo > Create a USB Linux boot stick > mark with space press Enter
and follow instructions. :)

Re: How to recover lilo and mbr?

Posted: 23. Apr 2016, 15:35
by westms
jsfarinet wrote:My son played around with my machine and in some way the result was a total crash of the machine. Partition table etc all erased. Working hard with ddrescue and testdisk i was able to re- establish the 2 main partitions, / and /home (as well as swap - not that deal the latter one ;) ). But there is still missing mbr with lilo.

Anyone here would be able to give me a helping hand, how to install mbr and lilo on top of an already existing system? (I have a sizewise identical external hd and i could dd the entire internal to the external and test around with the latter one). Would be great since i loved my Salix setup ...

Thanks a lot in advance for any pointer!
If the above was carried out right, then you must now restore the partition table. Then write the LILO's bootloader part into place.

The programs gpart (not gparted) and testdisk will restore the MBR. Both can determine the partitions (within limits) and use it to create the data for the partition table. If the hard drive is often repartitioned gpart detect more partitions than actually exist. Then you have to decide which are the right ones. Gpart does not know all file systems and therefore can not recognize all partitions.

Gpart allows recovery into a file as a target. If you are satisfied with the result, then the file can be written to the MBR place.

gpart -i -W mbr-new /dev/sda

File mbr-new is not, of course, on your damaged disk.

Testdisk works directly on the MBR.

Both programs are usable from a Knoppix live medium immediately. For Salix both programs are also available, but must be provided by Sourcery / slapt-src first.

Cautious users, like me, have along with backups as well copies of MBR's (good) and written notes of the partition tables (better). With notes the recovery would be very easy.

I hope the above helps.

Re: How to recover lilo and mbr?

Posted: 23. Apr 2016, 20:29
by jsfarinet
First of all: thanks to you all. :) :)

With the help of Didier_Spaier from the chat i got it to recover the boot block and the mbr. If i find the notes i wrote down, i'll describe the procedure.

The problem now is: The machine boots just fine into Salix and goes thru just to gdm, but then in run in a lot of trouble. I think the "/" is heavvily corrupted by saving it to a *.dd and restoring it from them to the still existing partition. The "/home" otoh is fine. I tried forward and backward to repair the "/" to no extent.

Now, my question is, because probably it would be easier and less time consuming: Is there a way, to keep what exist in good shape (i.e. mbr + boot block) and to only reinstall a basic "/" adding then step by step what i had?

Re: How to recover lilo and mbr?

Posted: 23. Apr 2016, 20:32
by jsfarinet
Atip wrote:For such an occasion it is nice to have a Slackware Linux custom USB boot stick handy!

sudo pkgtool > Setuo > Create a USB Linux boot stick > mark with space press Enter
and follow instructions. :)
Good idea!!! I worked with a grml live usb ;)

Re: How to recover lilo and mbr?

Posted: 25. Apr 2016, 18:02
by westms
jsfarinet wrote:The problem now is: The machine boots just fine into Salix and goes thru just to gdm, but then in run in a lot of trouble. I think the "/" is heavvily corrupted by saving it to a *.dd and restoring it from them to the still existing partition. The "/home" otoh is fine. I tried forward and backward to repair the "/" to no extent.
The MBR is not all. Before first use of the partitions you had should perform a filesystem check for each partition. This includes the consideration of the superblocks. Perhaps you forgot to restore the superblocks. You'll never know what you have lost.
jsfarinet wrote:Now, my question is, because probably it would be easier and less time consuming: Is there a way, to keep what exist in good shape (i.e. mbr + boot block) and to only reinstall a basic "/" adding then step by step what i had?
My answer is no. And my question is: Why?
What is to come out with this fumbling? You have not written that you have checked the file system. Only the MBR and files themselves. I suppose your root filesystem is dead. A clean way is to reinstall Salix, while preserving the home partition.

You may keep your home partition and renew the root and swap partitions. To do this, boot your installation media and start a Salix installation.

When the partitioner shows up, remove the partitions where root and swap are bind to from the partitions list, then add them again, with new defined begin and end sectors and filesystem types. Keep the partition where home was bind to. Write the partition table and exit the partitioner. A matching MBR with partition table will be created automatically. Also in the installation process, bind root and swap again to the renewed partitions and home to the untouched partition.

When you will be asked to test the swap partition surface, then let test it. When you will be asked to test the root partition surface and write the filesystem to it, then do so. When you will be asked to test the home partition surface and write the filesystem to it, then prevent it. Don't touch home.

Go further with the installation. The LILO bootloader will be written automatically to the MBR. After rebooting run an update. Then configure what is neccessary (HOSTNAME, hosts, CUPS, ...). Install your needed user programs and configure them. If home is unaffected by the incident, you do not need to configure anything in home. All together will take 30 to 60 minutes and you will be ready. You need to fsck home too. Thus you can be sure to have a functioning system.

Good luck!

Re: How to recover lilo and mbr?

Posted: 25. Apr 2016, 20:02
by gapan
This:
westms wrote:A clean way is to reinstall Salix, while preserving the home partition.