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 can see, I have downloaded the free dos image, now we create a new folder.
test and move dos image to this folder.
The another image file we need is 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.
In the terminal,
first we navigate to the test folder.
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.
And the name of the image, we set it to os.img
100mb is enough to store and test our projects in this section. With the new image created,
we will format it with free dos image.
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 3 edit options.
The option we want is disk boot options, we select 12
In the channel 0, we add the two image files here. We set the first device
the type of the 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.
As for other settings, we use default ones.
Then we go to the second device.
the type of the device is cd rom.
And the name of the file is free dos image.
we change 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 change boot drive from floppy disk to cd rom.
Alright, we return to the top menu.
and save the options
to the bochs configuration file.
OK, the preparation is done, now we can run the bochs.
type c to continue.
As you see, free dos is running,
select the language
and continue with the installation.
Partition drive c and press enter.
now we can reboot the computer.
At this point, we return to dos
and in the dos prompt, we format the image file. So we format c drive.
And proceed with format.
The volume label is set to os and press enter.
OK, the os image is finally created.
we exit out the bochs. In macos, we can simply mount the fat16 image
by right clicking the os image
and open with disk image mounter.
If everything goes as expected, we can see the image is mounted as 100mb fat16 image.
Because we didn't copy files into it after we format the image, there is no files in the folder.
To unmount the partition is simple, all we need to do is
click unmount here.
OK, after we create an image file, we can inspect the image.
So in the terminal, we type hex dump.
The option we need is -C which means we want to see the characters.
and then the name of the image file,
os.img in this case, hit enter.
As you can see, the image is pretty much filled with zeros.
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.
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 look at the address 7e00, we can see we have a small block of data. In the right column,
the characters fat16 is there.
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 we open the boot folder.
in boot.asm,
we change the value of the partition entry accordingly.
The data is the starting chs value,
the partition type,
the ending chs value,
the starting lba value
then 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 value is
03 1f 11
We will change the loader file which loads the image in the memory.
So the size of loader in this section 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.
Now, we write the boot file in the os image to see if it works.
So we navigate to the boot folder.
Because we just want to test the boot code,
we change the build script
we comment out other commands
The output file is changed to os.img. We copy os.img to the boot folder.
In the terminal, we build the project.
Now, let's re-examine the os image.
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 mount the image to see if it works.
So we right click os image
and choose disk image mounter.
OK, you can see
the image is still recognized by the macos.
What are we going to do next is we are going to write the image file into the USB flash drive.
Just as we did in the previous lectures, we insert a USB flash drive and in the terminal, we type
command diskutil
list to list disks.
The name of the device in this example is dev disk3
So we type sudo
dd, the input file
os.img and output file
dev disk3. Once again make sure that the output file is the correct device and press enter.
Alright, we're done.
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.