Own bootloader to make a bootable USB stick in Linux
Posted: Tue Dec 17, 2019 3:07 am
Hi.
I am trying to write my own bootloader, after having done all of the operating system coding and testing based on the GRUB's mulitiboot bootloader. Now it is the time to touch the bootloader stuff from scratch.
I have a USB thumb drive which ultimately will be bootable and contained the necessary bootloader and kernel files to be booted by BIOS.
In windows, I have used RUFUS to make my USB drive bootable. I have simply a 2-stage bootloader where the first stage contains a FAT 12 bios-parameter-block and is only responsible to load the second stage bootloader which finally loads the kernel at the upper memory address (i.e. >1MB). Having used RUFUS, the OS is booted and no problem has been encountered.
But in Linux, which is my main developing operating system, I faced some problems. To make my USB drive bootable I used DD and MKFS utilities as below:
1.Create a blank floppy image
2.Format the floppy image
3.Writes your bootsector and other files to the image file
4.Write the floppy image into the USB device
5.reboot and see if the operating system is booted. NO!
The second try:
Directly writes things on the USB device:
1.Writes your bootsector and other files to the USB
2.reboot and see if the operating system is booted. NO!
In another failed try, I did:
1.Create a blank floppy image
2.Format the floppy image
3.Cerate a virtual floppy device and mount it
4.Writes your bootsector and other files to the image file
5.Writes your image file to the floppy drive
6.Writes all the floppy drive to your USB
Here the last command cannot be executed since it cannot operate to load a directory (/media/floppy/) to the USB device.
I am wondering what would be the procedure to do it in Linux, and what is wrong with my first and second tries in Linux which will not be ended up to booting.
Any other suggestions are highly welcomed.
Best regards.
Iman.
I am trying to write my own bootloader, after having done all of the operating system coding and testing based on the GRUB's mulitiboot bootloader. Now it is the time to touch the bootloader stuff from scratch.
I have a USB thumb drive which ultimately will be bootable and contained the necessary bootloader and kernel files to be booted by BIOS.
In windows, I have used RUFUS to make my USB drive bootable. I have simply a 2-stage bootloader where the first stage contains a FAT 12 bios-parameter-block and is only responsible to load the second stage bootloader which finally loads the kernel at the upper memory address (i.e. >1MB). Having used RUFUS, the OS is booted and no problem has been encountered.
But in Linux, which is my main developing operating system, I faced some problems. To make my USB drive bootable I used DD and MKFS utilities as below:
1.Create a blank floppy image
Code: Select all
dd bs=512 count=2880 if=/dev/zero of=floppy.imgCode: Select all
mkfs.msdos floppy.imgCode: Select all
dd if=BOOT1.bin of=floppy.img bs=512 count=1
cp BOOT2.bin floppy.img
cp KERNEL.bin floppy.imgCode: Select all
dd if=floppy.img of=/dev/sdb/ bs=512 count=2880The second try:
Directly writes things on the USB device:
1.Writes your bootsector and other files to the USB
Code: Select all
dd if=BOOT1.bin of=/dev/sdb/ bs=512 count=1
cp BOOT2.bin /dev/sdb/
cp KERNEL.bin /dev/sdb/In another failed try, I did:
1.Create a blank floppy image
Code: Select all
dd bs=512 count=2880 if=/dev/zero of=floppy.imgCode: Select all
mkfs.msdos floppy.imgCode: Select all
sudo mkdir /media/floppy/
sudo mount -o loop floppy.img /media/floppy/Code: Select all
dd if=BOOT1.bin of=floppy.img bs=512 count=1
cp BOOT2.bin floppy.img
cp KERNEL.bin floppy.imgCode: Select all
dd if=floppy.img of=/media/floppy bs=512 count=2880Code: Select all
dd if=/media/floppy/ of=/dev/sdb/ bs=512 count=2880I am wondering what would be the procedure to do it in Linux, and what is wrong with my first and second tries in Linux which will not be ended up to booting.
Any other suggestions are highly welcomed.
Best regards.
Iman.