Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to make Linux GRUB Boot on USB disk

Shulou Source: shulou.com Published: 2022-06-01 15:20:15 09月24日 Update

This article mainly explains "how to make Linux GRUB boot on USB disk". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to make Linux GRUB boot on USB disk".

GNU GRUB (GRand Unified Bootloader referred to as "GRUB") is a multi-operating system startup program from the GNU project. GRUB is an implementation of the multi-boot specification, which allows users to have multiple operating systems in the computer at the same time and choose which operating system they want to run when the computer starts. GRUB can be used to select different kernels on operating system partitions or to pass boot parameters to those kernels.

When booting from a hard disk, the BIOS usually turns to the first sector of the first hard disk, the master boot record (MBR).

The process of loading GRUB and operating system includes the following steps:

Load record-the only thing the basic bootloader does is load the second bootloader.

Loading Grub--, the second bootloader, actually leads to more advanced features that allow users to load a specific operating system.

Load the system-- such as the linux kernel. GRUB transfers control of the machine to the operating system.

The difference is that Microsoft operating systems are booted using a boot method called chain loading, and the master boot record simply points to the first sector of the operating system partition.

Many distributions support usb startup, so can we make a usb startup tool tray ourselves? the answer is yes!

First, make the following assumptions

Usb device is / dev/sdb

Usb disk mount point / mnt/usbdisk

Let's briefly describe the steps for installing the grub bootstrap on the USB disk.

Determine the location of the usb disk, usually / dev/sdb

The code is as follows:

[root@localhost] # fdisk-l

Clear the mbr boot byte using the following command

The code is as follows:

[root@localhost] # dd if=/dev/zero of=/dev/sdb bs=512 count=1

Use mbr.bin in syslinux to load onto USB disk

The code is as follows:

[root@localhost] # locate mbr.bin

[root@localhost] # cat / somepath/share/syslinux/mbr.bin > / dev/sdb

Using fdisk to partition the USB disk, the similar result is as follows:

The code is as follows:

Device Boot Start End Blocks Id System

/ dev/sdb1 * 1 1018 993537 + 83 Linux

Create an ext3 file system on the partition and hang it on the USB disk

The code is as follows:

[root@localhost] # mkfs.ext3 / dev/sdb1

[root@localhost] # mkdir-p / mnt/usbdisk

[root@localhost] # mount / dev/sdb1 / mnt/usbdisk

Install GRUB boot loader to USB disk

The code is as follows:

[root@localhost] # grub-install-- no-floppy-- root-directory=/mnt/usbdisk / dev/sdb

Create a grub.conf profile

The code is as follows:

[root@localhost] #

Cat > / mnt/usbdisk/boot/grub/grub.conf

Tags: System load operating system code disk production program kernel learning different previous generation content that is files steps user hard disk computer choice can not Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MySQL OPPO Reno MariaDB Xiaomi