I have built a Linux From Scratch system onto a flash drive with the kernel and everything. When I boot into it via the GRUB instance on the host computer's hard drive, it works fine. I would like to install. GRUB on the flash. drive, as to not need the host computer's instance of GRUB. There is a /boot folder on the USB that contains a working grub config file, and it seems that the only thing missing is grub itself. (I also would like to have it Legacy BIOS compatible as for it to be bootable on more types of systems)
1 Answer
Dangerous commands ahead, you may hurt your system. You can do this from a live cd to be on the safe side.
- Mount the USB, say under
/mnt. - Take note of the USB device, say
/dev/sdb, which will be used in the commands below. - Install
grub-efi-amd64. - Mark
/dev/sdb1as bootable, you can use a disk utility. - Execute
$ dirs=(dev etc usr lib lib64 bin sbin sys proc) $ for dir in ${dirs[@]}; do mkdir /mnt/$dir && sudo mount --bind /$dir /mnt/$dir; done $ sudo chroot /mnt/ # grub-install --force --removable --target=x86_64-efi --efi-directory=/ /dev/sdb1 # grub-install --force --removable --target=i386-pc --boot-directory=/ /dev/sdb # exit $ for dir in ${dirs[@]}; do sudo umount /mnt/$dir && rm -r /mnt/$dir; done Now both efi and legacy GRUB will be installed, the bootable grub.cfg is under /boot/grub. If the file already exists make a backup.
- Thanks, this works on a different flash drive I have. Before I do it on the real one, I would like to know, does this erase/modify dev/sdb1 because that's where the actual LFS system is built and I do not want to ruin it.Matthias Lee– Matthias Lee2022-02-01 21:05:24 +00:00Commented Feb 1, 2022 at 21:05
- @MatthiasLee I think not, it's been a while since I been doing this. Can you make a backup of the USB?schrodingerscatcuriosity– schrodingerscatcuriosity2022-02-01 21:07:00 +00:00Commented Feb 1, 2022 at 21:07
- Yeah, I can. Also, do I still need to mount the drive if I only am doing the non-efi (--target=i386-pc)? Edit: I don't need EFIMatthias Lee– Matthias Lee2022-02-01 21:19:18 +00:00Commented Feb 1, 2022 at 21:19
- @MatthiasLee If you don't need efi just don't execute
grub-install --force --removable --target=x86_64-efi.... The rest stays the same.schrodingerscatcuriosity– schrodingerscatcuriosity2022-02-01 21:46:00 +00:00Commented Feb 1, 2022 at 21:46 - Ok, thanks! Will do once my backup completesMatthias Lee– Matthias Lee2022-02-01 21:58:09 +00:00Commented Feb 1, 2022 at 21:58