Disabling a USB flash drive from being used to boot

bootusb

Is there a way to make a USB flash drive not detected on a reboot, to avoid the PC trying to use it to boot from? Assuming you only have control over the flash drive and are not administering the PC. I know you can to disable it from the PC, and that there are ways to make the flash drive boot up an OS.

My problem, I have a portable apps drive full of useful stuff, but when I reboot I have to unplug and plug it back in or whatever PC I am working on at the time hangs.

A software solution would be best, but if anyone knows of a USB device that only becomes powered some time after boot up that would be interesting as well.

Best Answer

Summary

Boot into Linux (Live or installed) and run sudo grub-install /dev/sdX where sdX is the file connected to your USB drive. To find the location of your USB drive use sudo parted -l or sudo fdisk -l [1] (I am not sure how this will work with UEFI firmware)

Main

My issue was I have a portable USB hard drive that I use for backups. I set my BIOS to first boot from USB because, sometimes I have to boot a live OS image from USB. When I would reboot my system, the system would try to boot the portable hard drive and hang.

  • First, I tried clearing the boot flag of the partition. The boot flag had no effect as most modern boot loaders are indifferent to it and it is mostly used by legacy OS's.[2]
  • Second, I tried zeroing out the first 446 bytes of the USB drive in the hopes that the BIOS would see nothing and just move on to the next drive.[3] Turns out the BIOS does not work that way. As near as I can tell, you (the user) set your boot order in the BIOS config. If the BIOS detects media where you told it to look, it will "connect" to the device, copy the first sector (512 bytes) into ram and start executing code. If the area is zeroed out the machine will just hang.
  • Finally, I tried the method detailed in the summary section. grub-install was able to find all of my OS's and now I do not have to unplug the USB to boot.


[1] https://askubuntu.com/q/180023
[2] https://unix.stackexchange.com/a/23588/183350
[3] The first sector (512 bytes) is the Master Boot Record (MBR). The MBR has two sections: the Master Partition Table and the Master Boot Code. The Master Boot Code goes from byte 0-446 and contains the code that the system will use to boot the specified partition. Bytes 447-512 contain the actual partition table. If this is damaged or zeroed the system may not be able to read the partitions. http://www.dewassoc.com/kbase/hard_drives/master_boot_record.htm
[4] https://unix.stackexchange.com/questions/259143/how-does-grub-stage1-exactly-access-load-stage-2

Related Question