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 1


Dangerous commands ahead, you may hurt your system. You can do this from a live cd to be on the safe side.

  1. Mount the USB, say under /mnt.
  2. Take note of the USB device, say /dev/sdb, which will be used in the commands below.
  3. Install grub-efi-amd64.
  4. Mark /dev/sdb1 as bootable, you can use a disk utility.
  5. 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. 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? 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 EFI 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. Feb 1, 2022 at 21:46
  • Ok, thanks! Will do once my backup completes Feb 1, 2022 at 21:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .