Write the operating system by yourself, successfully write the boot program into the USB flash drive, and start the computer

Original: http://freesoftman.iteye.com/blog/629598

input the command:

nasm boot.asm -o boot.bin

 

After a while, an image file boot.bin is generated. This file is what I call the operating system. Ha ha! In fact, it is just a boot sector. But this is the first step for us to step into the operating system. After this step, we will have a bright future.

In theory, it only took about 10 minutes to complete the writing.

 

But, annoyingly, the book describes writing that image to floppy. My books do not have floppy driver. Then even you must understand the concept of bootloader.

 

So, it took 1 week to understand the concept, and imagine whether it can be booted with a USB flash drive, and write my own boot loader program into the MBR of the USB flash drive. So I asked the company's elders, haha, effortless effort. Let me know a tool to write Image to MBR of U disk.

 

Here, I would like to recommend the dd tool. This tool is originally a tool that comes with Linux and is used to write image files to any storage device. You can type dd for window in google, then you can get the window version of dd.

 

Next, I will explain step by step how to write boot.bin to the MBR of the USB flash drive:

1. Open cmd and enter the directory where dd.exe is located. The path is C:\NASM. As shown in the figure:

 

 

 2. Since dd is a small tool on the command line, first call the command --list to check the Partition of the U disk. As shown in the figure:

3. As you can see from the picture, the partition of my U disk is K, the name is \\.\Volume{66b36b20-3a85-11df-b4e4-005056c00008 }

4. Now that the partition address is found, we can write our boot.bin to the MBR of the U disk.

 

5,命令 dd if=c:\nasm\boot.bin of=\\.\Volume{66b36b20-3a85-11df-b4e4-005056c00008} count=1

Just this command, you can write your boot loader to the U disk.

Parameter meaning:

if, the absolute address of the file you want to write + file name

of, the address you want to write to.

bs, the block size for each write, the default is 512 bytes.

count, to write the specified block of the specified of device.

 

Then the above command is to write the 512 bytes in my boot.bin file to sector 0 of the U disk. That is MBR.

 

OK, after the above simple processing, then you can see the effect. So, even restart the computer, set the BIOS to boot from the U disk.

 

Haha, Hello, OS world! is displayed on the interface, and I am extremely happy.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325369938&siteId=291194637