Designing a simple "Hello world" bootloader

/
0 Comments
Now this one is highly technical stuff.....

I just designed a simple bootloader which will display "Hello world!" on your screen at the time of boot.

I have tested following steps very well on my sysstem but still you are at your own risk.

1) Download following two file:
bootsect.s file contains assembly code for boot-loader which will be compiled using Makefile. 

2) Now copy these files in any empty folder. 


3) Open terminal & go to this folder using "cd" command and fire "make" command. 

You should be getting following o/p : 

$ make
as -a bootsect.s -o bootsect.o >bootsect.map
ld --oformat binary -N -e start -Ttext 0x7c00 -o bootsect bootsect.o
mv bootsect final.img
4) Now you are having your boot-loader in final.img file. Size of the final.img file must be 512 MB since BIOS assumes sector size=512 MB for any boot device.

5) Now it's time to load this boot-loader in first sector of your boot device. You can take floppy disk, USB drive , CD or DVD as boot device. I used USB stick for that so following steps are for USB stick.

6) Now we need to find out device file of your pen-drive in /dev directory. In my case it was /dev/sdb1


To identify this device file of your pendrive plugin your pendrive & fire dmesg command which will give o/p shown in this screen shot. Now blue circled area in the screenshot will give you your device file. Here in my case it was sdb1. 

(Make sure you detect this file accurately because otherwise you may loose data of other device.

7) After detecting device format your pendrive. Then open terminal & go to directory of "final.img" file & fire following command: 

dd if=final.img bs=512 of=/dev/sdb1  

Replace sdb1 with your usb device file name.
(This command will destroy the existing file system of your pendive. I'll tell the command to fix it back in final step.)

8) Now restart your computer and go to BIOS setting. In BIOS setting in boot menu make sure that following 2 options are enabled 1)"USB boot" & 2) "Boot from USB device first". 
9) Save BIOS configuration & restart your system (Make sure that your USB stick is plugged in). If you have followed steps properly then you should get "Hello world!" message printed on your screen. If you have received this message then you have successfully booted from your pendrive. 
 
10) Now again restart your system & disable "boot from USB device first" option.  And restart again.

11) Now it's time to fix filesystem of your pendrive. 
For that plug in your pendrive and fire following command:
sudo mkfs.vfat /dev/sdb1
  
(Replace sdb1 with your usb device file name.)

 Fill free to comment for any doubts and suggestions......:)


You may also like

Popular Posts