1
00:00:01,480 --> 00:00:08,320
Ok, let’s first create the fat16 image. In this example, we use the free dos to format the image to fat16 image

2
00:00:08,320 --> 00:00:09,120
.

3
00:00:09,730 --> 00:00:17,200
So we need free dos. To download free dos image, we search free dos and click free dos project, 

4
00:00:19,400 --> 00:00:25,610
in the free dos page, we go to download section and click download free dos 1.2.

5
00:00:28,050 --> 00:00:31,320
In the download page, we choose standard cd rom. 

6
00:00:32,630 --> 00:00:35,780
Once the file is downloaded, we can go to next step.

7
00:00:38,750 --> 00:00:46,100
As you see, I havedownloaded free dos image here, now we create a new folder called test.

8
00:00:48,240 --> 00:00:51,050
And copy free dos image to this folder.

9
00:00:56,850 --> 00:01:03,420
Next we create another image, os image file, which is used as the image for the operating system in the following lectures. 

10
00:01:03,420 --> 00:01:08,570
The boot image file in the previous lectures is discarded. 

11
00:01:09,330 --> 00:01:10,500
So in the terminal,

12
00:01:13,650 --> 00:01:15,480
we navigate to the test folder.

13
00:01:18,380 --> 00:01:21,770
and create an image file by the command bximage, 

14
00:01:24,110 --> 00:01:26,840
the settings are the same as we did with boot image. 

15
00:01:30,740 --> 00:01:36,800
The difference is that we set the image file to 100mb.  

16
00:01:36,800 --> 00:01:39,740
100mb is enough to store and test our projects in this section. 

17
00:01:40,190 --> 00:01:42,590
And the name of the image is called os.img

18
00:01:42,620 --> 00:01:43,730
.

19
00:01:45,350 --> 00:01:45,860
Alright,

20
00:01:45,860 --> 00:01:48,260
We have created the os.img

21
00:01:49,560 --> 00:01:59,190
The last file we need is bochs configuration file where we add the free dos image and os image.  So we run bochs

22
00:01:59,640 --> 00:02:00,600
and select edit options.

23
00:02:02,220 --> 00:02:08,560
The option is 12 edit disk and boot options. In the channel 0, 

24
00:02:09,360 --> 00:02:13,680
we add the two image files. We choose 4 to set the first device 

25
00:02:14,850 --> 00:02:16,310
and the type of device is disk. 

26
00:02:18,050 --> 00:02:21,590
The name of the image file is os.img we just created. 

27
00:02:24,670 --> 00:02:28,240
As for the chs value, we use the value here.

28
00:02:30,740 --> 00:02:35,270
So we type  203 16 63. 

29
00:02:37,270 --> 00:02:38,950
We use default settings.

30
00:02:42,740 --> 00:02:44,390
OK, move to the second device.

31
00:02:45,450 --> 00:02:47,220
So we choose option 5.

32
00:02:49,110 --> 00:02:57,300
The type of device is cd rom and the name of the file is  dos image we just downloaded. 

33
00:03:03,630 --> 00:03:13,110
we change the status to inserted, and we leave other settings unchanged. 

34
00:03:13,110 --> 00:03:20,340
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. 

35
00:03:22,860 --> 00:03:24,600
OK, return to the top menu.

36
00:03:27,950 --> 00:03:30,440
Select option f4 to save options.

37
00:03:34,970 --> 00:03:35,370
Alright,

38
00:03:35,400 --> 00:03:41,990
The preparation is finished, we run bochs.  We type c to continue.

39
00:03:43,370 --> 00:03:45,650
As you can see, the free dos is running.

40
00:03:47,090 --> 00:03:48,290
select the language 

41
00:03:49,880 --> 00:03:51,530
and continue with the installation. 

42
00:03:53,060 --> 00:03:55,610
Partition drive c, press enter. 

43
00:03:57,730 --> 00:03:59,770
Ok now we can reboot the computer. 

44
00:04:03,500 --> 00:04:05,720
At this point, we return to dos 

45
00:04:07,310 --> 00:04:10,700
and in the dos prompt, we format the os.img. 

46
00:04:12,190 --> 00:04:15,640
So we format c drive and press enter. 

47
00:04:16,920 --> 00:04:18,450
We proceed with the format.

48
00:04:21,470 --> 00:04:24,530
The volume label in this example is set to os.

49
00:04:27,830 --> 00:04:32,600
Ok the os image is finally created. We close it out. 

50
00:04:33,950 --> 00:04:39,530
In ubuntu, we can simply mount the fat16 image by typing 

51
00:04:43,410 --> 00:04:46,140
gnome disk image mounter writable 

52
00:04:49,920 --> 00:04:54,420
and the image file, os.img in this case, press enter. 

53
00:04:56,250 --> 00:05:02,270
As you can see  the os folder is showing here.   Because we didn’t copy files into it after we format the image, 

54
00:05:02,280 --> 00:05:07,680
there is no files in the folder. To dismount the partition is simple, 

55
00:05:08,340 --> 00:05:09,810
all we need to do is click unmount here

56
00:05:11,180 --> 00:05:12,290
.

57
00:05:16,210 --> 00:05:22,750
After we create the image file, we can inspect the os image. The command we use is hexdump 

58
00:05:25,870 --> 00:05:33,360
the option we need here is -C which means we want to see the characters, and the name of the image file os.img

59
00:05:33,370 --> 00:05:34,910
.

60
00:05:35,620 --> 00:05:36,460
we hit enter.

61
00:05:38,470 --> 00:05:41,740
as you see, the image is pretty much filled with 0s. 

62
00:05:43,120 --> 00:05:48,100
The data which is important to us is the data located in the offset 1be in the first sector. 

63
00:05:49,350 --> 00:05:52,150
Remember when we write the boot loader in the lecture the first program,

64
00:05:52,170 --> 00:05:58,260
we talked about the partition entries and constructed a valid looking partition entry.

65
00:05:58,260 --> 00:05:59,960
At that time,

66
00:06:00,270 --> 00:06:02,030
we don’t want to mount the image, 

67
00:06:02,040 --> 00:06:06,430
so the partition entry we set doesn’t correctly represent the partitions. 

68
00:06:07,200 --> 00:06:12,860
But, in this section,  we want to mount this partition and transfer data between the operating systems, 

69
00:06:13,470 --> 00:06:17,490
so we need correct partition entry info, which is the data here. 

70
00:06:18,430 --> 00:06:24,400
As you can see, we only have one partition entry. They will be written in the boot file 

71
00:06:24,400 --> 00:06:27,820
and then write it into the image which will represent the correct partition.

72
00:06:28,750 --> 00:06:34,680
As you can see here, the starting sector is 3f and each sector assumes to be 512 in our system

73
00:06:34,680 --> 00:06:35,760
,

74
00:06:36,250 --> 00:06:43,390
so the first partition is located at the offset 3f*512. We get the result 7e00

75
00:06:43,390 --> 00:06:44,650
.

76
00:06:45,250 --> 00:06:52,060
If we go to the address 7e00, we can see we have a small block of data. In the right column, 

77
00:06:52,570 --> 00:06:54,640
the characters fat16 is here.

78
00:06:55,520 --> 00:07:01,370
Ok, once we create the fat16 image, the next thing we are going to do is we are going to change the boot code

79
00:07:01,370 --> 00:07:03,890
and write it in the image. 

80
00:07:04,960 --> 00:07:06,520
So in the boot folder,

81
00:07:08,980 --> 00:07:10,660
we open boot.asm

82
00:07:19,170 --> 00:07:25,530
In this file, we change the value of the partition entry accordingly. The data here is 

83
00:07:25,530 --> 00:07:26,070
the starting chs value

84
00:07:26,250 --> 00:07:26,700
,

85
00:07:31,300 --> 00:07:32,530
the partition type, 

86
00:07:34,480 --> 00:07:36,040
the ending chs value, 

87
00:07:39,820 --> 00:07:41,530
the starting lba value 

88
00:07:42,900 --> 00:07:44,660
and the sectors of the partition.  

89
00:07:45,780 --> 00:07:52,910
Note that the data is 4 bytes stored in the little-endian order which means the low byte is in the low memory address.

90
00:07:53,790 --> 00:08:00,210
so the count of the partition is 03 1f 11

91
00:08:04,590 --> 00:08:09,240
Also, we will change the size of the loader to 15 sectors.

92
00:08:10,250 --> 00:08:12,760
in the next video we will change the loader file.

93
00:08:13,490 --> 00:08:15,770
That’s it for the boot.asm.

94
00:08:18,540 --> 00:08:24,580
With the partition entry adjusted to the correct value, we can build product in the terminal. Before we build the project,

95
00:08:24,600 --> 00:08:28,160
in the build script,

96
00:08:31,660 --> 00:08:36,970
we need to comment out other commands because we only want to test the boot code.

97
00:08:41,799 --> 00:08:45,190
The output file is changed to os.img.

98
00:08:47,470 --> 00:08:47,790
OK.

99
00:08:50,590 --> 00:08:52,630
Now we copy os.img

100
00:08:54,950 --> 00:08:55,880
to the boot folder.

101
00:08:59,080 --> 00:09:00,250
Let's build the project.

102
00:09:05,210 --> 00:09:07,880
OK, let's rexamine the os.img

103
00:09:11,580 --> 00:09:17,640
As you can see, the boot code is written into the first sector of the image and the partition entry remains

104
00:09:17,640 --> 00:09:18,260
unchanged.

105
00:09:19,800 --> 00:09:22,610
Now, let's try to mount the image to see if it works.

106
00:09:23,740 --> 00:09:24,930
So we mount the image.

107
00:09:26,950 --> 00:09:32,860
Alright, you can see the image is still recognized as 100mb fat16 partition.

108
00:09:35,930 --> 00:09:40,490
The next thing we are going to do is we are going to write the image file into the USB flash drive.

109
00:09:41,490 --> 00:09:48,360
Just as we did in the previous lectures, we insert the USB flash drive and in the terminal, we type

110
00:09:49,670 --> 00:09:51,200
sudo fdisk

111
00:09:52,880 --> 00:09:54,620
-l to list the partitions.

112
00:09:59,540 --> 00:10:04,520
The name of device in my computer is sdb. We write sudo 

113
00:10:06,000 --> 00:10:08,520
dd, the input file 

114
00:10:09,620 --> 00:10:13,910
is os.img and the name of the output file

115
00:10:15,240 --> 00:10:16,920
is dev sdb

116
00:10:17,990 --> 00:10:22,130
we need to check out the output file is correct one and press enter.

117
00:10:24,720 --> 00:10:30,930
You can see the usb flash drive is recognized as 100mb fat16 partition.

118
00:10:32,600 --> 00:10:36,710
In the following lectures, we will parse the data and implement the file module. 

119
00:10:37,790 --> 00:10:38,960
See you in the next video.

