Restore grub2 with livecd. Linux bootloader recovery and removal.

For linux boot  The boot loaders Grub, Grub2 and Lilo are used. Sometimes, due to a software error or intentional user actions, such as installing a second operating system on a computer, inept editing of configuration files or entering commands unfamiliar to the console.

All this can cause a message to appear on the next boot, “Grub error” or even “Kernel panic”.

The second inscription may appear in other cases, and the first one means that it has either been erased boot recordor the bootloader configuration files have been changed or deleted.

For an experienced user it will not be difficult find a way to recover Linux bootloader. In general, the procedure is as follows - you need to boot LiveCD from Linux.

Many manuals write that any distribution is suitable for this, but it is better to use the same one that is installed on the computer. Then everything will go right. And finding such a LiveCD is not a problem.

How to restore Linux Grub bootloader

  We boot from LiveCD, open the console, enter the commands:

Sudo grub
  The bootloader settings window opens:

Grub\u003e
  We are looking for the resident part of the bootloader:

Find / boot / grub / stage2
  A list of partitions with stage2 will be displayed, if one Linux distribution is installed, the output will be as follows:

  (hd0.0)
  Go to this section:

Root (hd0.0)
  We must not forget to change the numbers, if they are different!

We put the bootloader again:

Setup (hd0)
  Exit from the Grub control window:

Quit
  And now you can try to boot from the main disk.

If Grub2 has flown, then recovery bootloader linux  happens like this:

We boot from LiveCD, go to the console, type there:

Sudo fdisk -l
  the command will display the existing partition table on the disk - / dev / sda1, / dev / sda2, etc.

Now mount the system partition and the partition on which the bootloader is installed with the command:

Sudo mount / dev / sda2 / mnt
  If the boot partition is separate, it must also be mounted.

Sudo mount / dev / sda1 / mnt
  The drive designation is the same as when installing the Linux distribution by default, if someone did it differently, he will easily figure out which numbers to put.

Now mount the file system to restore the Linux bootloader:

Sudo mount --bind / dev / mnt / dev sudo mount --bind / proc / mnt / proc
  And we change the working environment:

Sudo chroot / mnt
Now we are already in the main system, you do not need to use the sudo command, since now work is being done from the superuser.

You can tidy up the / etc / default / grub file, this is for advanced users, but in general, you just need to reinstall the bootloader with the command:

Grub-install / dev / sda
  If an error message appears, enter the command:

Exit sudo umount / mnt / dev sudo umount / mnt / proc sudo umount / mnt
  And reboot. The bootloader is restored.

The method to restore the Linux Lilo bootloader is the same as in Grub2, only at the end we enter the command instead of grub-install / dev / sda like this:

Lilo
  or for Slackware distributions:

How to remove Linux bootloader
  Sometimes you need to find out way to remove linux bootloader. Usually this is necessary when dual-boot is configured on the computer installed - loading two operating systems, Linux and Windows, and the first one is no longer needed.

There are a lot of methods on how to remove the Linux bootloader - this can be done with LiveCD with several tools. A simple way - boot from the installation windows drive, select system recovery, go to the command line and execute two commands:

BOOTREC.EXE / FixBoot BOOTREC.EXE / FixMbr
  Confirm Y actions, press enter and exit the console:

Exit
  You can reboot, the Linux bootloader is removed.

If anyone does not know, then GRUB is the Linux bootloader, if even easier, then this is the menu of operating systems, or the boot options that you see after loading the BIOS. If the bootloader is damaged or jammed, the operating system will not boot.

This usually happens when you are after Linux. Stupid, or maybe just wicked Windows does not like competitors, so it overwrites other people's bootloaders.

If you install Windows first, and then only Linux, then everything will be fine, the GRUB bootloader will save windows bootloader  and even include it in his menu. But it is perfect.

If everything was like this, then when Windows crashes and then resets it, the situation described above occurs and you need to restore the grub bootloader.

How to restore GRUB?

In order to restore the GRUB bootloader, you need to boot Linux from a USB flash drive or from a CD-DVD. Personally, I keep this manual printed on paper so that I don’t look for it on the Internet, and the Internet may not be at hand. Which I advise you. After you boot into a flash drive or CD-DVD, you need to open the terminal, because it is in it that we will "conjure".

Step 1.We determine on which of hard drives is our Linux and what letter designation does it have. To do this, run the command:

Sudo fdisk -l

Step 2  We mount our disk into the system. To do this, run the command:

Sudo mount / dev / sdXY / mnt

Here you need to clarify a little. X is the disk in the system, for example sda, sdb, and so on. Y is the disk number, for example 1, 2, and so on. The win command will therefore be something like this:

Sudo mount / dev / sda1  / mnt

But this is just an example, you will have your own letters and numbers.

Step 3  And the last step is to restore GRUB. In order to restore GRUB, execute the command:

Sudo grub-install --root-directory \u003d / mnt / / dev / sd X

Again, X is your drive letter. After that, you need to reboot, for example, with this command:

Sudo reboot

All if you have not mixed anything up and restore grub  If you succeed, you will see a menu with a choice of operating systems. Everything, as everything, is quite simple!

Published on 5 Jun 2013 15:44   © Just Linux | All about Linux, Android and Windows.

On my laptop there are 2 OSes Ubuntu and Windows, I recently decided to upgrade Windows 8.1 to Windows 10. After the upgrade, the Grub bootloader was successfully wiped. Grub can be broken in other ways, for example, after making changes to the Grub configuration file. In this article I will tell you how to restore the bootloader.

If at boot of your computer you see a black screen with the inscription grub\u003e then most likely your configuration file /boot/grub/grub.cfg is damaged. First we need to define the visible sections, this can be done using the command ls:

In my case found 1 hDD  hd0, on which there are 3 sections: (hd0, msdos1), (hd0, msdos5), (hd0, msdos6).

Find the section containing the root / . This can be done by viewing the contents of the sections.

Ls (hd0, msdosX) /

In my case, it turned out to be msdos1:


Next, execute the following commands:

Grub\u003e set root \u003d (hd0, msdos1) grub\u003e linux / vmlinuz root \u003d / dev / sda1 grub\u003e initrd /initrd.img grub\u003e boot

The first command sets the path to the root / system. The second command tells GRUB the path to the kernel that you want to boot. The third line sets the INITRD file. And the last command loads.

If you did everything correctly, the operating system will boot, after loading, in order to generate the correct Grub configuration file, you must enter in the console:

Sudo update-grub

In grub rescue mode, similarly, using the ls command, we determine the partition with the root /.

Grub rescue\u003e set prefix \u003d (hd0, msdos1) / boot / grub grub rescue\u003e set root \u003d (hd0, msdos1) grub rescue\u003e insmod normal grub rescue\u003e normal

Grub rescue\u003e insmod linux grub rescue\u003e linux / boot / vmlinuz root \u003d / dev / sda1 ro grub rescue\u003e initrd /boot/initrd.img grub rescue\u003e boot

After a successful download, you need to install the bootloader and configure it:

Sudo update-grub sudo grub-install / dev / sdX

Boot loader recovery with Boot-repair

an excellent program that allows you to literally restore the bootloader in one click. To use the Boot-repair program, you must boot disk  from the same version of Ubuntu that you have installed. After loading into Live mode, install Boot-repair:

Sudo add-apt-repository ppa: yannubuntu / boot-repair sudo apt-get update && sudo apt-get install -y boot-repair

And run boot-repair

Sudo boot-repair

In the program window, click on “Recommended repair”:

After that, a script will be launched that restores most known issues  Grub

This instruction will help when:

  • we want to remove linux (any OS unix-like or not) system and leave only Windows
  • after installation linux windows  is not downloading
  • Windows stopped loading, even as the only OS (viruses, hard drive crash)

The Windows boot loader does not perceive anything except itself, so it must be installed first in the case when it uses only Windows and in the case when there will be other OS besides it.

1) Boot from installation disk  Windows

2) Choose system recovery

3) Choose the recovery tool “command line”

Windows XP bootloader recovery

To restore boot Windows XP  execute commands

Fixboot fixmbr

Windows 7, 8 bootloader recovery

For Windows 7  execute commands

Bootrec / FixBoot bootrec / FixMbr

Parameter Scanos  (bootrec / scanos) will show the detected operating systems. If nothing is found, then fixboot and fixmbr will not help.

Restore Linux bootloader

boot loader grub 2

This instruction will help when:

  • Reinstalled Windows and besides it there was also linux, which became invisible
  • Linux stopped loading even as the only OS

1)   Boot from LiveCD (LiveDVD, LiveUSB)

2)   We look at the partition table:

$ sudo fdisk -l Device Zagr Start End Blocks Id System / dev / sda1 * 1 13 102400 7 HPFS / NTFS Section 1 does not end at the cylinder boundary. / dev / sda2 14 7749 62139420 7 HPFS / NTFS / dev / sda3 7750 23607 127377020 7 HPFS / NTFS / dev / sda4 23607 30402 54577153 5 Advanced / dev / sda5 23607 30119 52301824 83 Linux / dev / sda6 30119 30402 2274304 82 Linux swap / Solaris / dev / sdb1 * 1 5099 40957686 7 HPFS / NTFS / dev / sdb2 5100 16142 88701952 7 HPFS / NTFS / dev / sdb3 16143 19457 26627737+ 83 Linux / dev / sdc1 1 30401 244196001 7 HPFS / NTFS

Team response shortened for clarity. It can be seen that the system has three disks. The first two have boot areas and several partitions of both Linux and Windows (HPFS / NTFS). You need to decide which one will be restored (you can take turns, temporarily disconnecting the rest of the drives). In the case of one hard drive  The situation is simpler. It will be / dev / sda

3)   We mount the Linux partition (here sda5, but if there is a separate boot rezdel, then you need to mount it), add devices and processes to it, go to it, thus getting into the environment of the OS that is installed on the computer:

   $ sudo mount / dev / sda5 / mnt $ sudo mount --bind / dev / mnt / dev $ sudo mount --bind / proc / mnt / proc $ sudo chroot / mnt

After the transition, you do not have to use sudo, as now all commands are executed from root (root):

4)   Install the bootloader

   # grub-install / dev / sda

If you receive an error message, then update the device information / dev / sda and try to install again:

   # grub-install --recheck / dev / sda # grub-install / dev / sda

5)   We go into the environment of the LiveCD OS, unmount the partitions and reboot the computer:

   # exit $ sudo umount / mnt / dev $ sudo umount / mnt / proc $ sudo umount / mnt $ sudo reboot

the last command can be replaced with an alternative:

   $ sudo shutdown -r now

Footnotes

see also

  • Recreating the boot configuration data store (BCD) file
  • DiskPart - Console windows utility  for work with sections

useful links

  • http://startubuntu.ru/?p\u003d95 - Restore GRUB 2
  • http://startubuntu.ru/?p\u003d14 - Restore the GRUB bootloader

GRUB is the bootloader for most versions of the Linux operating system. With it, you can organize multi-boot and use several different OSs on the same computer. For example, you can work under Linux, and after rebooting, relax using gaming windows features. Unfortunately, in the life of any user there are times when, for various reasons, it may be necessary to restore the bootloader. In this article, we will talk about the most likely causes of this phenomenon and how to restore normal computer operation.

OS bootloader features

Let's see what function the bootloader performs on the computer and what its damage leads to. As part of the operating system, it takes the baton from the base I / O system and continues to run it after the POST test. Its role includes preparing equipment for work, loading the kernel of the OS and transferring further control to it.

Thus, damage to the bootloader leads to a situation in which, after the initial hardware test, even if it was completed without errors, the computer cannot find the kernel of the operating system and, therefore, start it. The OS will give you an error message about the inability to detect the boot configuration.

The main causes of damage can be:

  • installing a second OS on one hard drive;
  • reinstalling Windows in a multi-boot system;
  • error in the splitting process hard drive  into sections.

GRUB role

To be extremely precise, modern versions of Linux do not use GRUB, but its more modern version of GRUB 2. To get rid of an inconvenient figure in the name, old version  received the name GRUB Legacy, and the new one is called the name familiar to Linux users. We will not depart from the established designation.


After understanding the terminology, consider the possibilities of GRUB. The bootloader of Windows 7, the most common in the Microsoft family, as well as all its other versions, is not able to correctly determine file systems  other OS. GRUB copes with this task.

Therefore, if both Linux and Windows are installed on your computer, bootloader recovery must be performed for Linux. Otherwise, you will not get the opportunity to choose the OS when you turn on the computer.

OS installation procedure

As we have already said, the Windows 7 boot loader will not be able to detect the presence of another OS on the computer. Since this feature has long been known, there are several unwritten rules for multi-boot systems:

  • installation of several windows versions  produced from younger to older;
  • Linux is always installed second after windows.

Failure to comply with the second rule leads to the need to perform a GRUB recovery. Windows installed after Linux simply erases its bootloader, replacing it with its own, perceiving what is busy with this OS disk space  as unallocated. Of course, it is not always possible to follow the rules, even when you know them. Nevertheless, understanding the role and functions of GRUB, it is not difficult to restore it.

Training

Before starting any operation with a computer, preliminary preparation is necessary. Restoring GRUB is no exception. Ubuntu was the first operating system in which it became the default bootloader. We need a LiveCD with this version of Linux, whose bit depth matches the version installed on your system.


LiveCD is a removable media version of Linux that can boot without using a computer hard drive. Initially, this option was used to get acquainted with the capabilities of this operating system. After downloading from it, the user could study the OS without having to install it and get a general idea of \u200b\u200bit without any risk.

Such a disk can also be used if the GRUB bootloader is damaged. Recovery using it is described in detail in the free community documentation. Changes in the architecture of laptops, namely the gradual disappearance from new models of CD / DVD drives, lead to the fact that the term LiveCD has received a broader interpretation. It is understood not only as a laser disk, as it was originally, but also as a USB flash drive.


Before using such a drive, make sure your system is ready to boot from removable media. To do this, you will need to boot into the BIOS and check the installed priority of the boot devices.

Recovery

When all the preparatory operations are completed and the system is ready, we boot from the LiveCD. Since such discs are actually finished operating system, you will see an ordinary desktop of your chosen version of Linux. Further actions will require minimal command line skills for this OS. In the main menu, you need to find and launch the "Terminal". In the Linux command line window that opens, enter the command:

sudo fdisk -l

As a result, you will get a list hard sections the drive in which you want to select the one on which Linux is installed. On most systems, this will be sda5. If in your case this section will be different - replace the number in its designation with the necessary. Next, mount it using the following command:

sudo mount / dev / sda5 / mnt

The next step is to install the new bootloader:

sudo grub-install --root-directory \u003d / mnt / dev / sda

After a few seconds, in command line  The following notification will appear:

Installation finished. No error reported.



Therefore, you have successfully written the new GRUB bootloader. Recovery is almost complete. Perform a reboot and this time boot into the Linux that is installed on the hard drive. There is one final update operation left. Open the “Terminal” again and enter the command:

sudo update-grub

This action will need to be confirmed with the root password. After its execution, you get a fully functional and correctly determining the installed GRUB boot loader GRUB. Recovery is complete, you can use the computer in the usual mode.

Finally

As you can see, there is nothing complicated in this operation. All actions are performed in normal graphics mode. You can consider yourself to have passed the “baptism of fire” and entered the Linux army.