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