How to copy Bootloader to first sector of USB Flash Drive.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Muazzam
Member
Member
Posts: 543
Joined: Mon Jun 16, 2014 5:59 am
Location: Shahpur, Layyah, Pakistan

How to copy Bootloader to first sector of USB Flash Drive.

Post by Muazzam »

I want to make a boot loader to load files from USB Stick. How do I copy bootloader to first sector of USB flash?
"dd if=bootload.bin of=/dev/sdb" not working on real hardware.
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: How to copy Bootloader to first sector of USB Flash Driv

Post by Nable »

It's very unlikely that `dd' is not working. IMHO, it actually works (i.e. writes your file to block device `sdb') but something goes wrong at a further stage: BIOS wrongly detects boot type emulation for your flash drive (USB-HDD vs USB-FDD == superfloppy) or your bootloader is doing something wrong.
User avatar
Muazzam
Member
Member
Posts: 543
Joined: Mon Jun 16, 2014 5:59 am
Location: Shahpur, Layyah, Pakistan

Re: How to copy Bootloader to first sector of USB Flash Driv

Post by Muazzam »

Nable wrote:It's very unlikely that `dd' is not working. IMHO, it actually works (i.e. writes your file to block device `sdb') but something goes wrong at a further stage: BIOS wrongly detects boot type emulation for your flash drive (USB-HDD vs USB-FDD == superfloppy) or your bootloader is doing something wrong.
My bootloader simply prints something. I know hot to emulate USB-Floppy, But How do i emulate USB-HDD or USB CD or DVD.
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: How to copy Bootloader to first sector of USB Flash Driv

Post by Nable »

muazzam wrote:My bootloader simply prints something. I know hot to emulate USB-Floppy, But How do i emulate USB-HDD or USB CD or DVD.
I mean that BIOS emulates FDD/HDD for you so you can read from USB devices via INT 0x13 interface. As I've seen in some BIOSes, by default they choose emulation types for flash drives depending on drive size. So if you attach ~large flash stick then BIOS may set emulation type to USB-HDD and then refuse to boot from it if 0th sector doesn't contain valid MBR with 1 bootable partition entry. Forcing the correct mode (HDD if you have MBR and partitions, FDD if filesystem begins from 0th sector) helped me several times.
User avatar
staringlizard
Posts: 15
Joined: Wed Aug 13, 2014 1:15 pm
Contact:

Re: How to copy Bootloader to first sector of USB Flash Driv

Post by staringlizard »

If using linux:
1. Find your output device (usb flash drive in your case) by looking into /dev while inserting and removing drive
2. 'dd if=<path to your mbr flat binary file> of=<path to the usb drive e.g. /dev/sdb> bs=512 count=1'

If you are using VMware emulating Linux on a Windows machine:
1. Forget about it, just brings you pain.

If you are using windows:
1. Download dd for windows here http://uranus.chrysocome.net/linux/rawwrite/
2. Find your output device (usb flash drive in your case) by using 'dd --list'
3. 'dd if=<path to your mbr flat binary file> of=<path to the usb drive e.g. \\.\PhysicalDrive2> bs=512 count=1 conv=notrunc'

Be very careful when using dd !

Regards,
StaringL
Post Reply