Bootloader and File-System Issues

Bootloader Reinstall

Sometimes you make a mistake and wipe your disk's MBR (Master Boot Record), or some misbehaving program does it, or you dual boot with Windows and catch a virus that does it. So, you say, I won't be able to boot my system anymore, right? Wrong! There are many ways to recover the boot record.

To recover your boot loader you will need a boot disk. Without a boot disk of some kind you might be completely lost[20]. You have made a boot disk, haven't you?

Put the diskette in the floppy drive and reboot your computer from it. What you do next varies according whether you use LILO or grub. No matter which boot loader you use, all the commands you have to execute will need to be run as root.

With LILO

If you use LILO, you just need to issue the following at the command prompt: /sbin/lilo. This will reinstall LILO in your disk's boot sector and that will fix the problem.

With GRUB

If you use grub things are a little bit different than when using LILO... but don't be afraid, we are here to help.

Note

The following example will assume that you are trying to install grub in the MBR of your first IDE drive, and that the file stage1 is in the directory /boot/grub/.

First, invoke grub's shell by issuing the command: grub. Once there, issue the following command: root (hd0,0); this will tell grub that the files it needs are in the first partition (0) of your first hard disk (hd0). Then issue the following command: setup (hd0); this will install grub in the MBR of your first hard disk. That's it!

You can also try to use grub-install /dev/hda to install grub on your first hard drive's MBR, but the method described above is the preferred one.

Some Considerations For Dual-Booting Systems

Windows 9x, NT, 2000 and XP upgrades. If you are running a dual-boot system, be very careful to always have a GNU/Linux boot disk prepared. Windows (all versions) usually replaces LILO or grub (the boot loader that starts up GNU/Linux and other operating systems) without any warning at all, and if you do not have a boot disk, you will not be able to boot GNU/Linux after you perform the Windows upgrade.

Repairing a Damaged Super-Block

Note

The information below only applies to ext2 and ext3 file systems. If you have another file system, please check its documentation.

The super-block is the first block of each ext2FS/ext3FS partition. It contains important data about the file system, like size, free space, etc. (It is similar to the method used by FAT partitions). A partition with a damaged super-block cannot be mounted. Fortunately, ext2FS/ext3FS keep several super-block backup copies scattered over the partition.

Boot your system with a boot disk. The backup copies' location depends on the block size of the file system. For file systems with 1 KB block sizes it is at the beginning of each 8 KB (8192 bytes) block, for file systems with 2 KB sizes it is at the beginning of each 16 KB (16384 bytes) block, and so on. You can use the command mke2fs -n [your_disk_device_name] to find out at which byte positions the super-block copies are. Assuming a 1 KB block size, the first backup copy is in byte number 8193. To restore the super-block from this copy, execute e2fsck -b 8193 /dev/hda4; change hda4 accordingly to reflect the name of your damaged partition. If that block also happens to be damaged, try the next one at byte number 16385, and so on until you find a suitable one. Reboot your system to activate the changes.

Backing Up and Restoring the MBR

To make a backup copy of your hard disk's Master Boot Record (MBR), insert a blank floppy in your floppy disk drive and issue the following:

     # dd if=/dev/hda of=/dev/fd0/mbr.bin bs=512 count=1
    

If you want to restore a backed up copy of your hard disk's Master Boot Record (MBR), insert the floppy containing it into your floppy disk drive and issue the following:

     # dd if=/dev/fd0/mbr.bin of=/dev/hda bs=512
    

Note

The above examples assume that the MBR of your first IDE (/dev/hda) hard disk is backed up to a file named mbr.bin on your first floppy diskette drive (/dev/fd0) and should be run as the root user.

Recovering Deleted Files

Abstract

We discuss some ways of recovering deleted files and directories. Please bear in mind that the recovery tools are not magical, and they will work depending on how recently you deleted the file you are trying to recover.

You might be wondering “Well, I accidentally deleted this file, how can I recover it?”. Do not fear, there are some utilities designed for GNU/Linux's ext2 file system which allow you to recover deleted files and directories. However, these utilities won't recover the files you deleted a few months ago because of disk usage, space marked as “free” will be overwritten; so the best way to protect against accidental or not so accidental deletions is doing backups.

Note

Please bear in mind that there are not (as yet) tools to recover files deleted on ReiserFS file systems. Keep in touch with the ReiserFS home page for the latest news about ReiserFS.

Anyway, on to the tools for recovering your deleted files. One such tool is Recover. It is an “interactive” tool. If you are the proud owner of a Mandrake Linux –– PowerPack Edition™, you already have this tool in the “contribsCD-ROM. Otherwise, you can find it on the Rpmfind web site. Go there and download the RPM. Once you have the RPM, install it. Then, run it with recover [command_line_opts] and answer the questions it asks you. The questions are for setting a time span to look for deleted files and directories to minimize the time it takes to do the search.[21]

Once the tool finishes its search, it will ask you where you want to save the recovered files and directories. Pick a directory of your choice, and you will have all the files and directories recovered in it. Note that you will not be able to recover the filenames, just their contents, but you can inspect them or try to rename them with different names until you get the right one. This is better than nothing.

Note

There are also mini-HOWTOs related to “undeletion” for ext2, look at Ext2fs-Undeletion and undeletion of whole directory structures.



[20] Unless you make a backup of your MBR, more on that later...

[21] You can search for all deleted files too, but it will take longer...