![installing grub on usb installing grub on usb](https://hakin9.org/wp-content/uploads/2020/02/Screen-Shot-2020-02-10-at-11.35.00.png)
![installing grub on usb installing grub on usb](https://i.stack.imgur.com/y5ta1.jpg)
Today, I'm going to use Linux, because my attempts to try to build the latest Grub 2 using either MinGW32 or cygwin failed miserably (crypto compilation issue for MinGW, Python issue for cygwin on top of the usual CRLF annoyances for shell scripts due to the lack of a. With the above in mind, it's time to get our hands dirty. Thus, if you try to follow the myriad of quick Grub 2 guides you'll find floating around, you'll end up nowhere in terms of booting a FAT or NTFS USB Flash Drive, that should be isolated of everything else. This is because the Grub installer is designed to try to boot the OS it is running from, rather than try to boot a random target in generic fashion.
![installing grub on usb installing grub on usb](https://i.imgur.com/rRLin8c.jpg)
INSTALLING GRUB ON USB PLUS
For a BIOS/USB boot, Grub 2 basically works on the principle of a standard MBR ( boot.img), that calls a custom second stage ( core.img), which usually sits right after the MBR (sector 1, or 0x200 on the UFD) and which is a flat compressed image containing the Grub 2 kernel plus a user hand-picked set of modules (.I'll also assume that you know nothing about the intricacies of Grub 2 with regards to the creation of a bootable USB, so let me start with a couple of primers:
INSTALLING GRUB ON USB DRIVER
Also, on newer machines with USB3 controllers it is necessary to add the xhci_hcd driver (built into the kernel or as a module).The goal here, is to produce the necessary set of files, to be written to an USB Flash Drive using dd (rather than using the Grub installer), so that it will boot through Grub 2.x and be able to process an existing grub.cfg that sits there.Īs usual, we start from nothing. When there are lots of modules booting takes a long time so it probably does not matter, but if there are only a few modules loaded then it is important, because the system could have booted before the kernel detects the USB device. Also important for USB booting is the scandelay option, as USB devices need a little time to be detected by the kernel that is what this option is for.root=LABEL=GENTOO_USB_ROOT will use the label of the disk instead of /dev/sdb2 which is important because these device numbers move around depending on the number of hard disks in the computer or number of USB disk drives.The lines after image are all easy but the append line contains some interesting options. Timeout=20 # Time to wait before default selectionĭefault="Gentoo-352" # Default selection after timeout # remove when there are problems with booting This is important because it will be how the root file system is detected later as the USB stick can be booted on systems where the drive letter allocation is completely different.įILE /etc/nf Configure nf boot=/dev/sdb # The location of the USB Stick (currently)Ĭompact # boot quickly by loading lots of blocks Notice that during the formatting operation, a label is assigned to the partitions. In the example we use the ext2 file system but another file system for the / partition can be used if it is supported in the kernel. Make sure that the first partition is bootable ( a command toggles the boot flag). I/O size (minimum/optimal): 512 bytes / 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes Root # fdisk /dev/sdb Command (m for help): d