Ok, let’s first create the fat16 image. In this example, we use the free dos to format the image to fat16 image
.
So we need free dos. To download free dos image, we search free dos and click free dos project,
in the free dos page, we go to download section and click download free dos 1.2.
In the download page, we choose standard cd rom.
Once the file is downloaded, we can go to next step.
As you see, I havedownloaded free dos image here, now we create a new folder called test.
And copy free dos image to this folder.
Next we create another image, os image file, which is used as the image for the operating system in the following lectures.
The boot image file in the previous lectures is discarded.
So in the terminal,
we navigate to the test folder.
and create an image file by the command bximage,
the settings are the same as we did with boot image.
The difference is that we set the image file to 100mb.
100mb is enough to store and test our projects in this section.
And the name of the image is called os.img
.
Alright,
We have created the os.img
The last file we need is bochs configuration file where we add the free dos image and os image. So we run bochs
and select edit options.
The option is 12 edit disk and boot options. In the channel 0,
we add the two image files. We choose 4 to set the first device
and the type of device is disk.
The name of the image file is os.img we just created.
As for the chs value, we use the value here.
So we type 203 16 63.
We use default settings.
OK, move to the second device.
So we choose option 5.
The type of device is cd rom and the name of the file is dos image we just downloaded.
we change the status to inserted, and we leave other settings unchanged.
Since we want to boot the dos image and format the os image file, in the boot option, we set the boot drive from floppy drive to cd rom.
OK, return to the top menu.
Select option f4 to save options.
Alright,
The preparation is finished, we run bochs. We type c to continue.
As you can see, the free dos is running.
select the language
and continue with the installation.
Partition drive c, press enter.
Ok now we can reboot the computer.
At this point, we return to dos
and in the dos prompt, we format the os.img.
So we format c drive and press enter.
We proceed with the format.
The volume label in this example is set to os.
Ok the os image is finally created. We close it out.
In ubuntu, we can simply mount the fat16 image by typing
gnome disk image mounter writable
and the image file, os.img in this case, press enter.
As you can see the os folder is showing here. Because we didn’t copy files into it after we format the image,
there is no files in the folder. To dismount the partition is simple,
all we need to do is click unmount here
.
After we create the image file, we can inspect the os image. The command we use is hexdump
the option we need here is -C which means we want to see the characters, and the name of the image file os.img
.
we hit enter.
as you see, the image is pretty much filled with 0s.
The data which is important to us is the data located in the offset 1be in the first sector.
Remember when we write the boot loader in the lecture the first program,
we talked about the partition entries and constructed a valid looking partition entry.
At that time,
we don’t want to mount the image,
so the partition entry we set doesn’t correctly represent the partitions.
But, in this section, we want to mount this partition and transfer data between the operating systems,
so we need correct partition entry info, which is the data here.
As you can see, we only have one partition entry. They will be written in the boot file
and then write it into the image which will represent the correct partition.
As you can see here, the starting sector is 3f and each sector assumes to be 512 in our system
,
so the first partition is located at the offset 3f*512. We get the result 7e00
.
If we go to the address 7e00, we can see we have a small block of data. In the right column,
the characters fat16 is here.
Ok, once we create the fat16 image, the next thing we are going to do is we are going to change the boot code
and write it in the image.
So in the boot folder,
we open boot.asm
In this file, we change the value of the partition entry accordingly. The data here is
the starting chs value
,
the partition type,
the ending chs value,
the starting lba value
and the sectors of the partition.
Note that the data is 4 bytes stored in the little-endian order which means the low byte is in the low memory address.
so the count of the partition is 03 1f 11
Also, we will change the size of the loader to 15 sectors.
in the next video we will change the loader file.
That’s it for the boot.asm.
With the partition entry adjusted to the correct value, we can build product in the terminal. Before we build the project,
in the build script,
we need to comment out other commands because we only want to test the boot code.
The output file is changed to os.img.
OK.
Now we copy os.img
to the boot folder.
Let's build the project.
OK, let's rexamine the os.img
As you can see, the boot code is written into the first sector of the image and the partition entry remains
unchanged.
Now, let's try to mount the image to see if it works.
So we mount the image.
Alright, you can see the image is still recognized as 100mb fat16 partition.
The next thing we are going to do is we are going to write the image file into the USB flash drive.
Just as we did in the previous lectures, we insert the USB flash drive and in the terminal, we type
sudo fdisk
-l to list the partitions.
The name of device in my computer is sdb. We write sudo
dd, the input file
is os.img and the name of the output file
is dev sdb
we need to check out the output file is correct one and press enter.
You can see the usb flash drive is recognized as 100mb fat16 partition.
In the following lectures, we will parse the data and implement the file module.
See you in the next video.