grub

Command line shell tool for multi-boot program grub

Supplementary instructions

grub command is the command line shell tool for the multi-boot program grub.

grammar

grub(options)

Options

--batch: Turn on batch mode;
--boot-drive=<drive>: Specify the boot drive of stage2;
--config-file<configuration file>: Specify the configuration file of stage2;
--device-map=<file>: Specify the mapping file of the device;
--help: display help information;
--install-partition=<partition>: Specify the stage2 installation partition;
--no-config-file: Do not use the configuration file;
--no-pager: Do not use the internal pager;
--preset-menu: Use the preset menu;
--probe-second-floppy: detect the second floppy drive;
--read-only: read-only mode.

Example

Use the grub command to start a damaged Linux system. Maybe your computer is damaged and cannot start automatically due to some reasons. Of course there are many reasons and many possible phenomena.

Here is how to deal with this situation, that is: the screen prompts grub>, but the data on your hard disk is not lost and all partitions are good. In this case, your grub information is damaged, but more seriously, the system cannot start.

Of course, under normal startup conditions, you can also enter the grub> state by pressing the c key when the grub startup item selection menu appears on the screen. At this time we need to use the grub command to manually start the system.

Only four commands, boot, kernel, initrd, and boot, are needed.

But grub itself has many commands, such as cat to view the file content. You can get it by typing help.

First, enter "root (hd", and then press the TAB key twice; /* This will list the possible disk devices on your computer, the hard disk is hd0/hd1 or sd0/sd1, etc. */

Then, select the hard disk where you install the Linux system, such as hd0, enter "root (hd0, " and press the TAB key twice; /* This will list the partitions on your first hard disk, and you will know which one is swap swap partition, 0x82, which is the Linux partition 0x83 */

Select the partition where you think the possible /boot directory is located, enter root (hd0, 1) and press Enter;

Then, enter cat /boot/vm and press the TAB key twice. If there are some files starting with vm, such as vmlinuz-2.6.15-26-386, it means that this is the partition where /boot is located.

Delete the last input, then enter cat /boot/initrd, and press the TAB key twice. If there are some files starting with initrd, such as initrd.img-2.6.15-26-386, it means that the partition where /boot is located has initrd, the ramdisk image;

Delete the last input, then enter cat /sbin/init, and press the TAB key twice. If there are some files starting with init, such as /sbin/init, it means that this partition is the partition where / is located;

If the /sbin/init file does not appear, it means that the (hd0,1) partition is only the /boot partition and not the / partition. Re-enter the root (hd0,N) command, where N is a Linux partition, and then try cat /sbin/init again until /sbin/init appears on the screen, indicating that you have found the / partition , strictly speaking, it should be the partition where the /sbin directory is located;

Enter the commands in sequence:

root (hd0,1) /* Assume /dev/hda2 is the partition where your /boot is located */
kernel /boot/vmlinuz-2.6.15-26-386 ro dev=/dev/hda3 /* Assume /dev/hda3 is the partition where your / is */
initrd /boot/initrd.img-2.6.15-26-386
boot

The system can be started.

The key issue here is how to determine the several partitions of the system: /boot / /sbin

References