How to fix GRUB2 if Ubuntu does not want to boot. Cure for GRUB

Repairing GRUB is a fairly common operation that many people have to deal with. The bootloader becomes damaged or overwritten when installing Windows as a second system. It doesn’t matter what Linux build you have – Ubuntu, Mint, Debian or any other: you can restore GRUB through the terminal or using a special utility.

Recovery via terminal

Windows is not friendly with Linux, so if you install a Microsoft system after Ubuntu, Mint 17 or another Linux build, then be prepared for the bootloader to be overwritten. To avoid getting lost in this situation, print out the instructions and keep them near your computer.

After rewriting the bootloader, you need to reboot the computer, use the “sudo reboot” command. After rebooting, the operating system selection window should appear. If GRUB was overwritten as a result of installing a new version of Windows, but the system selection window continues to display the old version, then you need to update the boot record. To do this, boot into Ubuntu and run the command “sudo update-grub” in the terminal.

Using the Recovery Utility

If working with the terminal seems difficult, you can automate the recovery process by using the special boot-repair utility.

Start building Linux from a flash drive or disk. Open a terminal and run three commands in sequence:

  • sudo add-apt-repository ppa:yannubuntu/boot-repair.
  • sudo apt-get update.
  • sudo apt-get install boot-repair.

The installed program will be called “Bootloader Recovery”. Run the utility (run “boot-repair” in the console) and select the operating mode. For beginners, “Recommended recovery method” is suitable. After starting this mode, GRUB will be automatically restored.

There is also a clumsy way to restore GRUB - reinstalling Linux. Many beginners use this radical method just to avoid dealing with the terminal. However, reinstallation leads to the deletion of user files, so using it due to banal damage to the bootloader is too much of a luxury.

In this article I will answer questions about the bootloader for linux os - Grub. You will learn how to set the default bootloader, how to edit Grub, how to return the boot partition, fix the boot record and much more. etc.

Here is a complete list of questions that I will try to address in this material:

Typically, when you boot your computer, only one operating system is loaded. As long as she is alone, there are no problems. If there are several systems, when loading, a boot menu is displayed, which is not always optimally convenient for loading. It's a small thing, isn't it? But in reality, everything is not so when the computer is rebooted a good dozen times a day.

Loader- this is software that is installed on the first sector boot disk(MBR - master boot record). It is different for each operating system, and not otherwise. And each of them has its own characteristics and “relationship” to other boot loaders and operating systems. For example, when installing Windows XP (or Windows Vista) on top of Ubuntu, the bootloader of the latest OS is overwritten without any warning, and Ubuntu becomes impossible. Problem? Problem. After all, in essence, the operating system continues to exist, but it is impossible to load it.

Nobody is going to scare you. We have raised several problems and will try to find possible solutions to them. Two options: free and paid. In the first case, we will do all the setup manually, in the second, we will install the Acronis OS Selector boot program or free bootloader editors.

One, two, three... How many?

The functionality of one operating system is quite enough to solve simple everyday tasks. We need more features - install additional software.

When installing two operating systems, a certain compromise is reached between paid and free software. What is offered for money on the Windows platform, Linux puts at your disposal, as a rule, for free (open source software). True, many professional packages are designed for only one environment, mainly Windows. Examples from Adobe and OpenOffice, unfortunately, are still rare to say otherwise. There is software that has no analogues and cannot yet be found in a particular OS.

Each system has both its wonderful advantages and disadvantages. For example, in our opinion, Windows is a more “entertaining” environment, Linux is a working system designed to solve resource-intensive tasks, work with data, etc. It is impossible to optimize Windows to work like Linux. However, judging by the distributions of Ubuntu, Fedora and other “friendly” operating systems of the family, one can only partially agree with the greater “multimedia” nature of Windows.

Three operating systems are, in most cases, overkill. True, there are some nuances here too. Sometimes difficult situations arise when it is impossible to do without having three operating systems on one computer. To do this, you don’t have to have the nickname “computer genius.” And this is hardly something that can surprise anyone... For example, what to do if, due to the nature of your work, you constantly change the environment (Ubuntu/Vista/XP) to conduct any reviews or tests? Every time you tear down one and install another OS in its place? Yes, there is such a “pass-through” option. To do this, you need to install Windows XP on one drive (for example, C:\), and Vista or Ubuntu on the other (D:\). Every time you need to change the OS, you put the desired OS on D:\. The only question is time.

The easiest way is to stop at two, or, even better, at one operating system. But we will go a different way.

Note. There are ported versions of the Mac OS X operating system, which are quite successfully installed on the PC platform. In this material we do not consider OS X for the following reasons:

  1. this is not the original, but an illegally modified version of the OS
  2. The audience of readers using these distributions is extremely small. Just imagine the number of users of Apple products.

Sequence of actions

If you need a super-functional computer with a working bootloader, you need to worry about the correct installation sequence for each OS in advance. After all, if you install the same Vist last, then the Ubuntu bootloader, GRUB, will be erased from the MBR. XP simply doesn't install on top of Vista, so it can't be left for last. Based on the above, all actions are performed on the computer in the following order:

1) Windows XP. Installed on a disk with a boot sector. All bootloaders in the future will be automatically installed on the partition with this label. How can I find out which drive it is on? Specialized programs for working with the disk subsystem will help with this - Norton Partition Manager, Acronis Disc Director, Acronis Partition Expert and many others.

A disk marked as "Active" must have a boot sector.

2) Windows Vista. We install it on a disk different from the one where XP is located. After installing Vista, there should be two items in the boot menu: Vista itself and “Earlier operating systems,” which means XP. That is, if XP was installed before Vista, it will be successfully detected and added to the list.

3) Ubuntu (this rule applies to any OS of the Linux family). Since this operating system is installed last, the bootloader installed by it will become the main one. At the last stage of installing Ubuntu, do not change the settings (the “Advanced” button) so that GRUB, as expected, is installed on the disk with boot label.

It must be said GRUB It is very “tolerant” in relation to its “competitors”: it correctly identifies the systems available on the computer and adds them to its own list. If you have XP and Vista, GRUB does not remove the Windows boot loader. And when you select the menu item that comes after “Other operating systems” (“Windows Vista/Longhorn loader”), a second screen will appear where you can select one of the Windows operating systems.

Subsequently, the list created by GRUB can be corrected by changing the names, deleting unnecessary boot items, or changing their order. Fortunately, there is sufficient documentation for GRUB. In general terms, this is a highly configurable, documented, user-friendly bootloader.

Where to download and how to install Grub

GRUB sources can be downloaded from the server ftp://alpha.gnu.org/pub/gnu/grub.
Next, unpack the downloaded distribution using the command “tar -xvzf filename.tar.gz”. If we take into account the name of the grub file-
0.5.96.1.tar.gz, the list of operations will look like this:

# tar -xvzf grub-0.5.96.1.tar.gz

So, we unpacked the contents into a directory called “grub-0.5.96.1”. We perform the following steps:

# ./configure

You can change certain options during compilation:

# ./configure --help

This will display all available options. You can use the prefix –enable or -
disable , which ensures that the bootloader supports certain devices.

To start compiling, enter

#make

Installation occurs after entering the following command:

# make install

A little about editing GRUB

Linux traditionally uses LILO (LInux Loader) or GRUB. If a few years ago they were still talking about LILO (and it was present in considerable numbers), now the leadership belongs to GRUB.

In fact, this “monopoly” is only a plus, because initially GRUB is more functional. All its features are available from the command line or by editing the configuration file. In addition, it is very important that this loader can be directly edited directly in command mode. Why is this good? Let's say a tragic situation occurred when, due to your actions, the bootloader broke. By reading the documentation first, you can manually debug GRUB directly from the menu. The “scientific poking” method, alas, will not work here, as in all Linux.

Immediately after installation, GRUB adds several additional items to the menu, such as: backup boot, memory test. There are only about three or four points of low importance. If by default the OS that is needed is loaded, and you are not bothered by the variety in the menu, you can leave everything “as is”. By default, Ubuntu is set to boot first.

In Mandriva or OpenSUSE, this menu can be edited during installation. In our case, we will have to take a more “cunning” route - change a few lines in the menu.list configuration file. It is located at /boot/grub.

Open the terminal (Programs -> Utilities -> Terminal and enter the command ($ - designation of the beginning of the command, which is not entered into the terminal):

$ sudo cp /boot/grub/menu.lst /boot/grub/menu.lst.old

This way we will save a backup copy of the file. In Ubuntu, this is simply necessary, so that in case of a serious error you can return to the previous settings. Here, however, you should take note of the following: restoring the bootloader without access to the OS session is not an easy task. To avoid such situations, treat the bootloader configuration file with special care. If you are not confident in your abilities, it is not worth the risk. Let Ubuntu work as long as possible...

$ sudo gedit /boot/grub/menu.lst

When you enter this command, the Gedit text editor will display the contents of menu.lst. We'll look at a few of the most important settings in this configuration file. It is commented in detail, so you can figure out what is not said on your own. All comments are followed by a #, they do not affect the progress of the download in any way and can be deleted.

Parameters:

  • timeout 10 - menu display time. After 10 seconds, the default operating system loads. Instead of "10" assign any number
  • hiddenmenu - if you uncomment this line, the GRUB menu will not be displayed, the default OS will boot

But then there are settings directly related to the output of menu lines in GRUB. They can be freely edited and deleted. Of course, knowing the purpose of this or that item. Changing anything other than the first line is contraindicated! The same applies to Windows. The block starting with “title Windows XP” should remain intact.

How to change the boot order of Windows and Linux

If you need to change the boot order from Ubuntu to Windows, simply swap the blocks starting with “title” in places. After editing menu.lst, save the document (we remind you that this can only be done in administrator mode) and reboot the system.

About setting up XP and Vista boot loaders

The “weakest” bootloader that can only overwrite the existing one Ubuntu bootloader. Since we cannot officially install XP over Vista, we actually cannot change the Vista bootloader to XP. The downside of these two bootloaders is the lack of any documentation, but the plus is easy access to the settings.

If you installed Windows Vista before Ubuntu, then when you select “Windows...” in GRUB, a second menu appears. You can temporarily or permanently disable one of the submenu items - then it will disappear. To do this, go to the properties of “My Computer”, open the “Advanced” tab, the “Startup and Recovery” section, the “Options” button and change the menu. Here, delete that (and only that!) line in which the extra menu item is located.

The described setup procedure applies to Windows XP, but for Vista it is almost the same.

Programs for working with bootloaders

Fortunately, all the routine methods we described today do not need to be resorted to. There are several programs that significantly simplify the handling of the bootloader, making it intuitive. In the case of Acronis OS Selector the program developer will have to pay, since the demo version does not allow you to use the full capabilities. EasyBCD and VistaBootPRO are free programs.

Program: Acronis OS Selector
Distribution terms: shareware

Program for low-level boot management. Here is an excerpt from the official website:

With Acronis OS Selector you can:

  • install several different operating systems on one computer;
  • load them from any partition of any hard drive;
  • boot any installed operating systems directly from Windows;
  • install multiple operating systems on one partition;
  • hide any of the operating systems on your computer from strangers or set a password for loading them;
  • duplicate existing operating systems by copying and create the necessary boot configuration for each of them.

The program supports a large list of operating systems. It includes all kinds of Windows and Linux distributions. Unfortunately, the program is no longer distributed separately, as it was before, but is part of Acronis Disk Director Suite, a fairly large (40 MB) package. The program is paid, and changes cannot be applied in the limited version. You can download the old version separately using a direct link, but this is a demo version, again, not intended for direct use.

After installation, OS Selector will ask you to reboot. During download, the program, with your permission, will be installed on the boot sector, as regular bootloader. If you refuse, the system will continue loading and the program will simply stop reminding you of itself - neither after nor before loading the OS.

What else is the advantage of this program, besides simplicity? The most convenient thing is that a list of all installed OSes immediately appears in the boot menu. There is only one bootloader - and it is installed by Acronis OS Selector. The names are correctly defined and can be easily changed if desired. In addition, you do not need to press the Enter key twice in the menu. It also includes several additional service utilities, which will be extremely useful for restoring any of the OS.

EasyBCD

Interestingly, instead of GRUB as the default bootloader, you can make it the one from Windows Vista. After installing EasyBCD, first of all you need to go to the “Manage Bootloader” section and then select the “Reinstall the Vista Bootloader” option. GRUB will be overwritten. You can now configure the Vista boot loader to add Ubuntu to the boot menu.

In addition to working with Linux, EasyBCD recognizes BSD and Mac OS X boot loaders. Works in the Windows environment.

VistaBootPRO

Distribution terms: freeware

We recently wrote about VistaBootPRO in a program review. It works in the Windows environment and is intended purely for editing Windows boot loaders. Moreover, you can replace one bootloader with another by uninstalling the extra one. It is easy to remove unnecessary menu items in the program. We must not forget about the backup copy, which can and should be made in one of the settings sections!

How to restore the boot menu?

If after the actions you have taken an error occurs, after which loading the menu becomes impossible, do not despair. Like any software, it can be reinstalled. True, it is not as simple as it is described in words. After all, logically, if you can’t boot the OS, you can’t restore the bootloader? In such cases, as always, a boot disk comes to the rescue. Of the three operating systems, we need to restore either Vista or Ubuntu; XP is out of the question for the reasons described above.

For Ubuntu. The easiest way is to restore the GRUB bootloader for Ubuntu. Fortunately, Ubuntu is a live distribution that can be used for all kinds of recovery. After loading the OS (the version does not matter), you need to open a terminal and enter the following commands there:

//start boot manager $sudo grub

// displaying information about the partition with the bootloader $ find /grub/stage1

As a result, information about the location of the bootloader will appear

Substitute the resulting values ​​by replacing X and Y with the given numbers:

$ root (hdX,Y) $ setup (hdX)

For Windows Vista. You can learn more about restoring the Vista boot loader in Windows online help.

So, for recovery you will need a boot disk with Windows Vista (from which you installed the OS). The course of action is as follows.

  1. Boot from the Windows Vista installation disc.
  2. Select the installation and input language. It is recommended to select the US input language.
  3. Select "System Restore".
  4. Select the operating system to restore and click Next.
  5. Select "Command Prompt". In the line enter the command

E:\boot\Bootsect.exe /NT60 All

The Windows Vista Master Boot Record has been restored.

Warning. The author does not bear any responsibility for your actions. Producing actions on the bootloader, think about whether you can cope with the assigned task successfully and whether you can prevent a possible breakdown. The article is addressed only to fairly experienced users.

The boot loader is used to initialize the kernel and start the Linux operating system. This is a program that runs after the BIOS hardware check is completed, prepares the hardware for operation, sets the necessary kernel parameters and allows you to select the operating system. The main task of the bootloader is to allow the user to select the operating system to boot.

Previously, several bootloaders were used to boot Linux, these are isolinux, lilo, grub. But now Grub or its full name GRand Unified Bootloader is most often used. This article will cover installing the Grub boot loader through the terminal. We will also talk about how to install grub on a computer with UEFI, also manually.

As I said, the main task of the bootloader is to provide the ability to select an operating system before booting. Don't think that Windows doesn't use a bootloader, it exists there too and works, just like Grub works.

The bootloader can be installed in various disk partition tables. Currently the most used ones are GPT and MBR. Installing the Grub boot loader is slightly different for each of these tables, given their specific features. You can read more about the differences in a separate article. Here I will say that GPT is a newer and more functional partition table, MBR is already outdated, but still often used.

There are few options in MBR; Grub writes to the MBR area of ​​the disk. The MBR sector size occupies the first 512 bytes and this is quite enough to install the bootloader there.

GPT provides more advanced features. Firstly, for compatibility, GPT emulates the MBR sector, and we can install GRUB there, but this option is very unreliable and not recommended. Secondly, it is now possible to install Grub on a disk partition. We simply create a 1 MB partition on the disk and write there what was previously written to the MBR, this makes the bootloader installation more reliable and fail-safe.

UEFI provides a completely different way to install the bootloader. Here you don’t need to write it anywhere, the bootloader is a regular EFI application that is placed on the EFI partition and already works there completely successfully along with other applications.

The grub-install command will be used to install Grub in all cases. Let's take a quick look at its syntax and parameters. Syntax:

$ grub-install options disk

There are quite a lot of parameters here, but we will only need a few:

  • --compress- compress bootloader files;
  • --install-modules=modules- install only these modules;
  • --modules- write these modules to the MBR;
  • --boot-directory- use a different directory for Grub files;
  • --bootloader-id- bootloader name in the EFI menu;
  • --core-compress- compress the image loaded into the MBR;
  • --efi-directory- use the EFI system partition;
  • --force- install despite errors;
  • --recheck- delete the existing device map, helps if errors occur;
  • --removable- installing grub on a USB flash drive (EFI only);

The base was dismantled. Now let's move on to the installation. In what follows, I will assume that all actions are performed from the system for which the bootloader needs to be installed or from the chroot environment of this system.

Installing Grub bootloader in MBR for BIOS

Let's start with the simplest and most familiar. These instructions on how to install the Grub boot loader are suitable for any distribution, since the commands are almost the same everywhere. There is no need to install any additional packages or create partitions here. Installing Grub on your hard drive is done with the command:

sudo grub-install /dev/sda

sudo grub2-install /dev/sda

Grub utilities on different distributions may or may not include two. Here /dev/sda is your hard drive. Now we generate a configuration file so that the installed operating systems are automatically detected:

sudo grub-mkconfig -o /boot/grub/grub.cfg

Ready. There is the same remark about the deuce. If you want to install Grub on a flash drive in the MBR, then there is also no problem, just mount the flash drive and run the following command:

sudo grub-install --root-directory=/mnt/USB/ /dev/sdb

Here /mnt/USB is the folder where your flash drive was mounted, and /seb/sdb is the flash drive itself. There is only one problem here: the configuration file will have to be created manually.

Installing Grub bootloader in GPT for BIOS

Firstly, we can not change anything and install Grub as described in the previous method. But then it will be installed in the MBR compatibility area, and this is not reliable. Therefore, it is recommended to install grub as described below on a separate partition.

The partition we need can be created in the installer of any distribution if you install in the graphical interface or using gparted. We need a 1 Megabyte partition without a file system and labeled grub_bios:

Ready. If you don't have access to a GUI handy, you can create such a partition through the terminal. The fdisk utility does not support working with gpt, so we will use gfdisk. First run the utility:

sudo gdisk /dev/sda

To create a new partition press n and select the partition number:

We agree with the initial sector, the first free one will be used:

Select the final sector of the partition. The default will be maximum. We need a 1 MB partition. The size of one GPT sector is 512 bytes, so we need a partition size of 2048 sectors. So the final sector will be 24,000 something.

HEX Code is the code that will tell the system that this partition needs to be used for Grub, needs to be installed ef02:

Done, all you have to do is press w to write the changes to disk:

sudo grub-install /dev/sda3

All that remains is to create the grub configuration file:

sudo grub2-mkconfig -o /boot/grub2/grub.cfg

Now let's move on to the hard part, how to install grub efi.

Installing GRUB UEFI GPT

Installing Grub UEFI is somewhat similar to installing in GPT, here we will also have a separate partition, only this time not for the bootloader, but an EFI partition. If you already have Windows installed, then most likely it already exists. This partition usually takes up 100 MB, has a fat32 file system and an ESP flag. This is what it will look like:

If there is no such partition, we can create it using gparted. To do this, create a section with the following parameters:

Size 100 Megabytes, partition name ESP, file system fat32. Next, apply the changes and set the flag for the section ESP:

You can do the same thing in Gdisk, only this time you need to set the partition's HEX Code ef00. After the partition has been created, we connect it to our file system:

sudo mkdir /boot/efi
$ sudo mount /dev/sda2 /boot/efi

sudo apt install grub-efi efibootmgr

grub-install /dev/sda

Installing Grub efi on MBR looks exactly the same, only there are a few limitations. The ESP partition needs to be created only at the beginning of the disk. In EFI mode, you can also install GRUB on a flash drive, and this is not very difficult. The command is used for this.

As a rule, no additional configuration of GRUB is required; all necessary files are installed on the computer independently during installation of the Linux OS. There is no need to reinstall the bootloader if, for example, the user needs to carry out configuration, since in this case only the contents of /boot/grub/menu.lst should be edited.

How to perform the correct installation and configuration - in the article below

Installing GRUB is advisable if it does not physically exist on the device, in other words, it can be erased after installing another system (most often Windows). Sometimes it happens that copies of the bootloader do not function properly or GRUB, at the request of the PC owner, is replaced by another standard bootloader. Whatever the reasons, installing GRUB, in any case, should be done exclusively from a “live” system (Knoppix, for example). The fact is that without a functioning bootloader, it is simply not possible to run a Linux distribution on a PC, which is located on the hard drive. In this article we will look at ways to install and configure the GRUB boot loader.

What is the boot sector?

If the PC owner is confident in his abilities and knowledge, he will only need to read the section that describes the step-by-step process of installing the GRUB boot loader, but for those users who are encountering a similar problem for the first time, it is better to first learn about the features of the BIOS and MS DOS.

The hard disk is divided into several sectors, in the first of which the main recording of the disk is carried out (users are accustomed to calling it MBR). This requires only 512 bytes, in which a small program is “hidden”. The next sector is occupied by the disk partition table, which, as usual, consists of four main sections, 64 bytes in size, and a digital signature (only 2 bytes).

Boot sector features

The boot sector can be called the backbone of the system, as it is found in the MBR and in all other partitions. As practice shows, it is included in all 16 sectors into which any hard drive is divided. Despite the fact that in most modern file systems, the data that the bootloader includes is not located in the first sector: the XFS system, for example, needs all valid sectors of the disk. Therefore, in the case where the bootloader data is erased, the file system is completely destroyed.

Turning on the device

When the computer starts, the BIOS itself begins to launch first. At this moment, the data stored in the MBR of the first disk is read. After a few seconds, the content “goes” to RAM, where it is checked for the presence of 55 AA hexadecimal codes in the last bytes. This check involves the need to identify media for subsequent loading. A small program stored in the MBR is required when the presented codes match. The first program “catches” the next one, located in the boot sector of the active partition, in order to subsequently activate it, and, as a result, launch the Windows OS.

If there is more than one hard drive, the user can configure in the BIOS the order in which specific hard drives will be launched at the time the system boots. Thanks to this feature, new PCs have the ability to boot the system from both an external drive and a USB drive. Naturally, by changing the boot order in the BIOS, the user can boot the system using CDs and DVDs.

To avoid having to deal with bootloaders in the future and think about how to configure GRUB, the user should know how to install two operating systems from different manufacturers so that they do not conflict with each other. As practice shows, it is best to install the Linux system bootloader initially, so that you can subsequently choose which system to launch.

However, if the device has one of the latest versions of the OS from Microsoft (later 9x/ME), then you can make the system bootloader so that it independently “worries” about GRUB. The huge advantage of this feature is that there is no need to once again understand the features of the MBR. True, not every modern user will be able to independently perform such a manipulation, since this process is quite complex. Everything will have to be done manually.

Among other ways, you can configure the normal operation of two systems by resorting to an additional installation of GRUB. The bootloader must be placed directly in the boot sector of the main partition and subsequently marked as active. This method also eliminates the need to use the MBR, but it can only work with primary partitions and file systems that do not affect the partition's boot sector.

Why is it important to create a copy of the MBR?

Once the decision is made to perform a GRUB install, the user needs to create a backup copy of the MBR. The fact is that incorrectly made changes will “help crash” both Windows and Linux. In this case, you will inevitably need a Knoppix system or a Windows installation DVD to help edit the boot sector. You can correct your actions several times faster if you have an MBR backup. To do this, run the following commands:

root# dd if=/dev/sda of=/boot/bootsektor.scsi bs=1 count=446

Recovering the boot sector can only be done using the command:

root# dd if=/boot/bootsektor.scsi of=/dev/sda bs=1 count=446

However, it should be noted that using these commands the user will only be able to change 446 bytes of the MBR.

Installation in MBR hard disk

GRUB install can be performed as soon as the corresponding configuration file is created (set using the /boot/grub/menu.lst command). The grub directory must contain files such as stage1, stage2 and *_stagel_5. If they are missing, the files contained in GRUB should be written to this partition.

Further manipulations consist of launching the GRUB bootloader and executing the setup command. The hdl,12 values ​​must be replaced with the GRUB device name of the disk partition containing /boot. You should be careful, since the /boot partition may be located in a folder other than the system folder. Hd0 is responsible for the storage area of ​​the boot sector of the main hard drive.

During installation, SUSE is updated with the /etc/grub.conf. file, which contains commands related directly to GRUB install. If something goes wrong, the PC user can restart the installation at any time during the procedure. The grub command can help with this.< /etc/grub.conf.

Bootloader installation methods

GRUB installation can be done not only in the MBR. If desired, the bootloader can be located in any boot sector of absolutely any hard drive. Despite the fact that there are situations when such a solution turns out to be unjustified, in the cases listed below, installing GRUB in another partition greatly simplifies the user’s task.

You can resort to GRUB install if the boot loader is launched using a similar Windows device. Also, the solution would be appropriate if several versions of the Linux OS are installed on the computer and the user does not intend to change the previously installed GRUB to another bootloader.

It is preferable to choose a Linux system partition to optimize the process. In other words, if the operating system is located in /dev/sda7, for proper installation, the user must use the commands below. The main difference between installing GRUB on an MBR or system partition is that you need to specify the selected partition in setup instead of hd0.

root# grub grub> root (hd1,12)

grub> setup (hd0,6) (Installation to /dev/sda7 boot sector) grub> quit

Before performing GRUB install, you should take into account one feature of some file systems, since sometimes the boot sectors of a partition cannot be used by the bootloader or other typical application. In particular, one of such systems is XFS - GRUB installed in its boot sector will simply destroy the entire file system.

Installation on a USB drive

Thanks to modern technologies, anyone can boot an operating system via a USB drive. If GRUB install will be performed directly from an external storage medium, and not using Windows or Linux, the user must check that the drive is correctly recognized by the motherboard.

Before you start, you should format the flash drive in one of two known ways. With the first method it will be cleaned like a superfloppy, with the other - like a hard drive. You should choose a cleaning option based on the features of the BIOS.

The next step should be to enable USB storage support, for which there is a separate option in the BIOS. When a USB drive is recognized as a separate boot disk, the BIOS will change the list according to which GRUB writes off data from the media one by one. The first disk will be a USB drive, the remaining hard drives will be accessible via hdl and hd2. If necessary, you can change /boot/grub/devices.map before GRUB install.

If everything is done correctly, installing GRUB from external media will be more than successful. GRUB recognizes the flash drive as hdn+1, where n is the number corresponding to the last internal hard drive. Subsequent installation of GRUB in the MBR via an external storage device requires executing the command below:

root# grub grub> root (hd1,12)

grub> setup (hd2) (installation in MBR flash drive) grub> quit

A further reboot of the PC should allow GRUB to appear in the MBR and start all existing systems that are contained in menu.lst. If errors occur, you should go through the bootloader menu into interactive mode by pressing the C button. Activating the command consisting of the word cat and pressing the tab key helps the user learn about the names that the bootloader has assigned to all hard drives. Using the Esc key you can go back to the menu, and the E button will help you change previously written commands for loading and execute them again.

If the Linux OS is stored on a flash drive or external hard drive that can be connected to the computer exclusively via a USB port, the user should be aware of several important issues. The fact is that GRUB install may not be carried out the first time; most likely, you will have to change the BIOS settings and drive designations several times. It will be better if all the properties stored in the menu.lst file are configured only manually.

Additionally, all important USB modules should be stored in the Initrd file. When working with Ubuntu, in the /etc/fstab section and the kernel line located in menu.lst, you need to specify not the device names themselves, since they can be changed after a system reboot, but the UUID numbers. The user can independently specify in menu.lst using uuid exactly the directory in which the kernel and the Initrd file will subsequently be placed.

Conclusion

Despite its apparent complexity, anyone can do a GRUB install. Support with newfangled motherboards provides for simple and trouble-free operation of any operating system, including Linux, which can be installed directly on the USB drive itself. It is not easy to configure all the parameters correctly and create all the conditions for the uninterrupted existence of two different systems; in addition to free time and knowledge, the user must have considerable experience, which those who are just starting to get acquainted with the Linux environment do not have.

Various PEtoUSB, there are more universal ones like in this topic. A bunch of utilities essentially install the grub, isolinux bootloader (less often BCDW or lilo, even less often your own like Win7), and then put the files offered to it (Windows7,WindowsXP, Ubuntu, etc.) into folders. This is where the demand for images comes from (as they wrote in the comments to this topic).

Meanwhile, the vast majority of disks posted on the Internet (especially USB) use isolinux and grub, what prevents them from simply being combined? nothing!

I will try with examples tell you how to make a bootable, installation, and just a Live flash drive, all in one without utilities tailored for a specific distribution. And be able, if necessary, to easily add something else to the flash drive, without reformatting it again.

Not all of the antivirus images were successfully “attached” to a flash drive, if someone can and will share their experience, I will be glad (I haven’t downloaded them for a long time, perhaps in the latest versions this is already made much easier). The image from Dr.Web, for example, even contains instructions for installation on flash drives.
For reference, Live images of antiviruses:
Dr.Web
BitDefender
Avast! already paid :(
Symantec NAV
Panda
Avira

8. DOS. It’s worth dividing here: if we need DOS for some serious work, then it makes sense to find DOS-Live images, for example this one, and load it as in step 3. We run DOS so that we can then launch the installation of Windows XP from it. From DOS we need:
AUTOEXEC.BAT
COMMAND.COM
CONFIG.SYS
EMM386.EXE
HIMEM.SYS
IO.SYS
SMARTDRV.EXE

Preferred, but not required:
Mouse.com
MOUSE.INI
OAKCDROM.SYS

We copy all this to the root of the flash drive, and in menu.lst add
title DOS (Install WinXP?)
root(hd0,0)
makeactive
chainloader/io.sys
Here you can either enjoy DOS, or in advance in AUTOEXEC.BAT register (the answer file is of course optional):
smartdrv
cd\WinXP\i386
winnt /U:\WinXP\i386\winnt.sif

9. Installing Windows 7. As I wrote above, just unzip the ISO to the root of the flash drive, and menu.lst add (already with hd0.0)
root(hd0,0)
chainloader/bootmgr
boot

10. Well, just for good measure, I’ll tell you about one more type of utility. Some (not all!) ISO images can be loaded directly from grub. Among these I found: Acronis True Image, Acronis Disk Director, Active Password Changer. These are specially prepared images (not a simple copy from a CD), they can be loaded as follows:
title Active Password Changer
map (hd0,0)/Pwdchanger.iso (hd32)
map --hook
chainloader (hd32)

Removal

What to do if you accidentally installed grub in the MBR of the main disk, and not the flash drive, or you need to remove it from the flash drive? You can use the utility bootsect.exe as I wrote above.
If you have not rebooted yet (if you have rebooted, then use grub to load Windows using the method described above), and run bootsect.exe
To restore Windows XP bootsect /nt52 c: /mbr
To restore Windows Vista/7 bootsect /nt60 c: /mbr
bootsect is in the folder boot Windows disk, and is also in my posted archive at the end of the article.
It's easy enough to format a flash drive.

Conclusion

I hope that the examples will help someone figure it out, and someone will be interested in this bootloader, and the utilities for creating bootable flash drives will make you smile (I don’t want to offend anyone, I respect all developers, moreover, I started with such utilities myself). And of course, I highly recommend studying grub itself in more detail, and GRUB4DOS, for example here