Page 1 of 1

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

Posted: Sat Aug 02, 2014 5:11 am
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.

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

Posted: Sat Aug 02, 2014 7:41 am
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.

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

Posted: Sat Aug 02, 2014 8:25 am
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.

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

Posted: Sat Aug 02, 2014 10:59 am
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.

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

Posted: Thu Aug 14, 2014 11:05 am
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