The Boot Code of linux boot disk self-built by using vmware implemented by nasm

Source: Internet
Author: User

When the computer power is turned on, it will first perform power-on self-check (POST), and then find the boot disk, if you choose to start from a floppy disk, the computer will find the 0-side 0-side 0-side track 1 Sector of the floppy disk. If it is found to end with 0xAA55, the BIOS considers it as a boot sector, then, the BIOS copies the Boot Code of the first 512 bytes of the boot sector to the 0000: 7c00 of the memory and completely delivers the Controller to this boot code.

The Simple Guide code is as follows:

Copy codeThe Code is as follows: org 07c00h; tells the compiler to load to 07c00h

Mov ax, cs
Mov ds, ax
Mov es, ax

Call DispStr; call the display string Function

Jmp $; infinite loop

DispStr:
Mov ax, BootMessge
Mov bp, ax
Mov cx, 16
Mov ax, 01301 h
Mov bx, 000ch
Mov dl, 0
Int 10 h
Ret
BootMessge: db "hello, OS world! "
Times 510-($-$) db 0
Dw 0aa55h

This code is written in nasm, which is similar to the masm language. The org 07c00h command is to add 07c00h to the offset address in the code after the command, so that the program will be executed at 0000: 7c00. As mentioned in the book, use the nasm bootsector command. asm-o boot. bin to generate boot code. bin, and then. bin write to the floppy disk with 0 sides and 0 tracks and 1 sector. The problem is that I don't have a floppy disk. However, in the wmware virtual machine, it seems that I can start it with an image file of a floppy disk. So I want to create an image file instead of a floppy disk as the boot disk, but how to create this image file?

Remember to useDd commands in linux have been used as linux boot disks. dd should be ready for production.So I found dd on the Internet to create an image file. The method is as follows:

1. First create an empty floppy disk image file diska. img (1.44Mb floppy disk image file ):

Dd if =/dev/zero of = diska. img bs = 512 count = 2880

2. Create an image file boot. img that contains boot. bin:

Dd if = boot. bin of = boot. img bs = 512 count = 1

3. copy the data after one slice in diska. img to the end of boot. img.

Dd if = diska. img of = boot. img skip = 1 seek = 1 bs = 512 count = 2879

In this way, an image file with a boot code of 1.44Mb is created.

The next thing is easy to do. directly create an empty Virtual Machine in wmware, and set the Floppy path to the path of the created Boot Sector in the settings, as shown in the following figure:

Set Floppy connection, disconnect the CD/DVD connection, and start the virtual machine to see the following picture:

 

Conclusion: Writing and running this small code can give you a deeper understanding of system startup, but what you don't understand isHow to start with an ISO image file and write the boot code to an ISO Image File, There is still no good solution.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.