To create the fat16 image, we need free dos image and then the free dos is used to format our image to fat16 format
.
So let’s go ahead and download free dos image. We search free dos and click the free dos project,
in the free dos page,
we click download free dos 1.2.
In the download page,
we choose standard cd rom.
As you can see, I have downloaded the free dos image here, after you download the file, we can
copy it to the new folder.
So here we create a new folder.
called test and we move free dos image to it.
Next, we create another image
os image file, which is used as the image for the operating system.
The boot image file that we used in the previous lectures is discarded.
To create an image file, we opened the command prompt.
And we navigate to the test folder.
We run 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 file
is called OS.image.
OK, we have a new image.
The last file we need is bochs configuration file
where we add the free dos image and os image.
We open bochs and edit disk and boot options.
In the channel 0, we add the two image files here. We navigate to the first device and select disk
.
The name of the image file is os.img we just created.
As for the chs value, we use the value here
.
We type 203 16 63.
OK, we move to the next one.
As for the second device, we choose cdrom
add the dos image we just downloaded.
Notice that the status here is ejected, we change it to inserted.
Since we want to boot the dos image and format the os image file, so in the boot option,
we select cd rom to boot first.
OK.
And save the file.
Click save.
Alright, the preparation is finished.
We exit it out.
Now we can run bochs.
we double click it.
As you see, free dos is running,
select the language and continue with the installation.
Partition drive c and 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 type format c drive and press enter.
And we proceed with the format.
The volume label, we name it, for example, os and press enter.
Ok now the os image is finally created.
We exit out the bochs.
In windows environment, we can mount the fat16 image using osfmount.
So we search osfmount
and in the page, we go to download section and download 64-bit version.
After we download it, we open the package to install it.
The installation is simple. Click next and install.
When the installation is done, we can mount the image. So we open
osfmount
To mount the image, we first click mount new.
In this dialogue, we select the os image we just created.
and click next.
Here you can see the type of image is fat16 and size is 100mb, which is the correct image
.
So we select the image and click next.
If you want to copy the file in the image, you need to uncheck read only drive.
Then we mount the image.
Right now, we can see the image is os.img and the drive of the image is d
.
In the Windows Explorer.
the drive D is showing here.
Since we don’t copy files into it after we format the image, there is no files in the drive D.
To unmount the partition is simple, all we need to do is select the drive and click dismount.
Alright, after we create the image file, let's see what we have in os image.
The software we use to inspect the image file is hex editor. So first off, we download the hxd and install it.
So we search
hxd
and go to the download section.
we click download page.
As you see, the download links are listed here. Once the package is downloaded, you can install it
.
The process of installation is pretty much the same.
Click next and install.
After you install it, we open hxd,
and in this window we click file and open
Then we choose os file.
click open.
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 0x1be. 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 entr
.
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, because we want to mount this partition and transfer data between the operating systems,
we need correct partition entry info, which is the data here.
As you can see, we only have one partition entry. The starting and ending chs values are included
in these 6 bytes.
The starting sector is stored here. They will be written in the boot file and then write into the image
which will represent the correct partition.
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, you see the characters fat16.
Ok, the next thing we are going to do is we are going to change the boot code and write it in the image.
So we open the boot folder.
in boot.asm, we change the value of the partition entry accordingly.
The data is starting chs value,
the partition type,
the ending chs value,
the starting lba
and the sectors of the partition. Note that the data is 4 bytes stored in the little-endian order
which means the low byte of the data is stored in the low memory address.
So the value is 03 1f 11.
We will also change the loader file which loads the image in the memory.
The size of loader file is increased to 15 sectors.
and we will change the loader file in the next video. Since the boot file is still used to do the same task,
we leave other parts of the file unchanged.
OK, that's it.
Now, we write the boot file in the os image to see if it works. Because we want to test the boot code,
we change the build script to assemble only boot.asm and write it into the image file.
So we comment out other commands.
OK, let's test it out.
We open the terminal.
Since we want to write the boot code into os.img, we copy the os image file to the boot folder
.
And also, we change the boot.img to os.img.
Now, let's run the build script.
Let's reexamine the image.
As you see, the boot code is written into the first sector and the partition entry remains unchanged.
OK, let's try to mount the image to see if it works.
In the Explorer, we can see the partition is showing here.
So, the image file is still recognized by Windows after we writes boot code into the image.
OK, what we are going to do next is we are going to write the image to the USB flash drive, so we insert usb
flash drive and open rufus.
Choose the image we want to write to the disk, the os.img in this case, checks the device is the correct one
and we click start.
If everything goes well, you will see that USB flash drive is recognized as a 100mb fat16 partition
.
So let's open Windows Explorer and a 100mb fat16 partition is showing here. In the following lectures,
We will parse the data and implement a file module.
See you in the next video