1 00:00:00,210 --> 00:00:08,160 To create the fat16 image, we need free dos image and then the free dos is used to format our image to fat16 format 2 00:00:08,160 --> 00:00:08,670 . 3 00:00:09,660 --> 00:00:17,910 So let’s go ahead and download free dos image. We search free dos and click the free dos project, 4 00:00:20,060 --> 00:00:21,380 in the free dos page, 5 00:00:23,690 --> 00:00:26,720 we click download free dos 1.2. 6 00:00:29,140 --> 00:00:30,370 In the download page, 7 00:00:31,740 --> 00:00:33,540 we choose standard cd rom. 8 00:00:35,290 --> 00:00:42,190 As you can see, I have downloaded the free dos image here, after you download the file, we can 9 00:00:42,190 --> 00:00:43,750 copy it to the new folder. 10 00:00:45,100 --> 00:00:47,320 So here we create a new folder. 11 00:00:49,220 --> 00:00:54,080 called test and we move free dos image to it. 12 00:00:56,030 --> 00:00:57,890 Next, we create another image 13 00:00:58,960 --> 00:01:05,710 os image file, which is used as the image for the operating system. 14 00:01:05,710 --> 00:01:08,470 The boot image file that we used in the previous lectures is discarded. 15 00:01:09,810 --> 00:01:13,500 To create an image file, we opened the command prompt. 16 00:01:15,820 --> 00:01:17,860 And we navigate to the test folder. 17 00:01:22,240 --> 00:01:24,910 We run the command bximage, 18 00:01:26,840 --> 00:01:32,850 the settings are the same as we did with boot image. The difference is that 19 00:01:32,850 --> 00:01:34,700 we set the image file to 100mb. 20 00:01:37,010 --> 00:01:43,310 100mb is enough to store and test our projects in this section. And the name of the image file 21 00:01:43,310 --> 00:01:45,230 is called OS.image. 22 00:01:46,280 --> 00:01:48,440 OK, we have a new image. 23 00:01:49,710 --> 00:01:52,880 The last file we need is bochs configuration file 24 00:01:52,930 --> 00:01:55,950 where we add the free dos image and os image. 25 00:01:56,990 --> 00:02:01,840 We open bochs and edit disk and boot options. 26 00:02:06,190 --> 00:02:13,830 In the channel 0, we add the two image files here. We navigate to the first device and select disk 27 00:02:13,900 --> 00:02:14,410 . 28 00:02:16,760 --> 00:02:21,230 The name of the image file is os.img we just created. 29 00:02:25,900 --> 00:02:28,620 As for the chs value, we use the value here 30 00:02:28,660 --> 00:02:29,470 . 31 00:02:33,160 --> 00:02:38,200 We type 203 16 63. 32 00:02:41,260 --> 00:02:43,510 OK, we move to the next one. 33 00:02:44,850 --> 00:02:48,090 As for the second device, we choose cdrom 34 00:02:49,990 --> 00:02:52,360 add the dos image we just downloaded. 35 00:03:01,080 --> 00:03:06,570 Notice that the status here is ejected, we change it to inserted. 36 00:03:07,590 --> 00:03:14,460 Since we want to boot the dos image and format the os image file, so in the boot option, 37 00:03:15,640 --> 00:03:18,220 we select cd rom to boot first. 38 00:03:19,510 --> 00:03:19,960 OK. 39 00:03:21,450 --> 00:03:22,470 And save the file. 40 00:03:25,210 --> 00:03:25,950 Click save. 41 00:03:27,470 --> 00:03:29,470 Alright, the preparation is finished. 42 00:03:30,430 --> 00:03:31,450 We exit it out. 43 00:03:32,480 --> 00:03:33,710 Now we can run bochs. 44 00:03:36,500 --> 00:03:37,790 we double click it. 45 00:03:41,790 --> 00:03:43,560 As you see, free dos is running, 46 00:03:45,500 --> 00:03:49,160 select the language and continue with the installation. 47 00:03:52,350 --> 00:03:55,020 Partition drive c and press enter. 48 00:03:56,490 --> 00:03:58,500 OK, now we can reboot the computer. 49 00:04:03,500 --> 00:04:05,540 At this point, we return to dos. 50 00:04:06,870 --> 00:04:15,120 and in the dos prompt, we format the os.img. So we type format c drive and press enter. 51 00:04:16,709 --> 00:04:18,540 And we proceed with the format. 52 00:04:20,690 --> 00:04:25,610 The volume label, we name it, for example, os and press enter. 53 00:04:27,020 --> 00:04:29,930 Ok now the os image is finally created. 54 00:04:31,170 --> 00:04:32,520 We exit out the bochs. 55 00:04:34,390 --> 00:04:39,610 In windows environment, we can mount the fat16 image using osfmount. 56 00:04:40,550 --> 00:04:43,550 So we search osfmount 57 00:04:48,150 --> 00:04:53,340 and in the page, we go to download section and download 64-bit version. 58 00:04:54,520 --> 00:04:58,240 After we download it, we open the package to install it. 59 00:04:59,420 --> 00:05:05,780 The installation is simple. Click next and install. 60 00:05:08,220 --> 00:05:12,540 When the installation is done, we can mount the image. So we open 61 00:05:14,270 --> 00:05:15,140 osfmount 62 00:05:19,430 --> 00:05:22,190 To mount the image, we first click mount new. 63 00:05:24,460 --> 00:05:28,060 In this dialogue, we select the os image we just created. 64 00:05:31,620 --> 00:05:32,700 and click next. 65 00:05:35,000 --> 00:05:41,360 Here you can see the type of image is fat16 and size is 100mb, which is the correct image 66 00:05:41,360 --> 00:05:41,750 . 67 00:05:42,290 --> 00:05:45,200 So we select the image and click next. 68 00:05:46,610 --> 00:05:51,320 If you want to copy the file in the image, you need to uncheck read only drive. 69 00:05:52,330 --> 00:05:53,800 Then we mount the image. 70 00:05:56,700 --> 00:06:02,030 Right now, we can see the image is os.img and the drive of the image is d 71 00:06:02,040 --> 00:06:02,790 . 72 00:06:03,740 --> 00:06:05,390 In the Windows Explorer. 73 00:06:07,220 --> 00:06:08,720 the drive D is showing here. 74 00:06:10,360 --> 00:06:16,000 Since we don’t copy files into it after we format the image, there is no files in the drive D. 75 00:06:18,980 --> 00:06:25,370 To unmount the partition is simple, all we need to do is select the drive and click dismount. 76 00:06:29,370 --> 00:06:34,770 Alright, after we create the image file, let's see what we have in os image. 77 00:06:35,850 --> 00:06:42,900 The software we use to inspect the image file is hex editor. So first off, we download the hxd and install it. 78 00:06:42,900 --> 00:06:45,300 So we search 79 00:06:45,750 --> 00:06:46,590 hxd 80 00:06:51,810 --> 00:06:53,620 and go to the download section. 81 00:06:55,150 --> 00:06:56,650 we click download page. 82 00:06:59,070 --> 00:07:04,860 As you see, the download links are listed here. Once the package is downloaded, you can install it 83 00:07:04,860 --> 00:07:05,070 . 84 00:07:06,480 --> 00:07:10,220 The process of installation is pretty much the same. 85 00:07:10,330 --> 00:07:11,850 Click next and install. 86 00:07:15,670 --> 00:07:19,570 After you install it, we open hxd, 87 00:07:23,580 --> 00:07:27,240 and in this window we click file and open 88 00:07:31,020 --> 00:07:32,760 Then we choose os file. 89 00:07:33,860 --> 00:07:34,610 click open. 90 00:07:37,270 --> 00:07:43,890 As you see, the image is pretty much filled with 0s. The data which is important to us 91 00:07:43,900 --> 00:07:49,880 is the data located in the offset 0x1be. Remember when we write the boot loader in the lecture the first program, 92 00:07:49,960 --> 00:07:56,140 we talked about the partition entries and constructed a valid looking partition entr 93 00:07:56,140 --> 00:07:56,530 . 94 00:07:56,980 --> 00:07:59,460 At that time, we don’t want to mount the image, 95 00:07:59,470 --> 00:08:03,940 so the partition entry we set doesn’t correctly represent the partitions. 96 00:08:04,540 --> 00:08:10,140 But, in this section, because we want to mount this partition and transfer data between the operating systems, 97 00:08:10,690 --> 00:08:14,920 we need correct partition entry info, which is the data here. 98 00:08:16,300 --> 00:08:22,390 As you can see, we only have one partition entry. The starting and ending chs values are included 99 00:08:22,420 --> 00:08:23,710 in these 6 bytes. 100 00:08:24,910 --> 00:08:31,630 The starting sector is stored here. They will be written in the boot file and then write into the image 101 00:08:31,630 --> 00:08:33,940 which will represent the correct partition. 102 00:08:34,780 --> 00:08:36,730 The starting sector is 3f 103 00:08:37,630 --> 00:08:44,020 and each sector assumes to be 512 in our system. So the first partition is located 104 00:08:44,300 --> 00:08:50,560 at the offset 3f*512. We get the result 7e00. 105 00:08:51,460 --> 00:08:53,890 If we go to the address 7e00, 106 00:09:00,090 --> 00:09:02,340 we can see we have a small block of data. 107 00:09:03,240 --> 00:09:07,020 In the right column, you see the characters fat16. 108 00:09:09,400 --> 00:09:15,220 Ok, the next thing we are going to do is we are going to change the boot code and write it in the image. 109 00:09:16,280 --> 00:09:17,780 So we open the boot folder. 110 00:09:22,020 --> 00:09:27,140 in boot.asm, we change the value of the partition entry accordingly. 111 00:09:32,670 --> 00:09:35,390 The data is starting chs value, 112 00:09:38,700 --> 00:09:39,930 the partition type, 113 00:09:42,240 --> 00:09:44,100 the ending chs value, 114 00:09:46,840 --> 00:09:48,340 the starting lba 115 00:09:50,660 --> 00:09:57,740 and the sectors of the partition. Note that the data is 4 bytes stored in the little-endian order 116 00:09:57,740 --> 00:10:01,170 which means the low byte of the data is stored in the low memory address. 117 00:10:04,360 --> 00:10:07,900 So the value is 03 1f 11. 118 00:10:09,580 --> 00:10:16,840 We will also change the loader file which loads the image in the memory. 119 00:10:16,840 --> 00:10:20,750 The size of loader file is increased to 15 sectors. 120 00:10:20,850 --> 00:10:27,250 and we will change the loader file in the next video. Since the boot file is still used to do the same task, 121 00:10:27,250 --> 00:10:28,330 we leave other parts of the file unchanged. 122 00:10:28,870 --> 00:10:29,700 OK, that's it. 123 00:10:30,400 --> 00:10:36,580 Now, we write the boot file in the os image to see if it works. Because we want to test the boot code, 124 00:10:36,670 --> 00:10:43,260 we change the build script to assemble only boot.asm and write it into the image file. 125 00:10:43,960 --> 00:10:46,030 So we comment out other commands. 126 00:10:49,780 --> 00:10:51,150 OK, let's test it out. 127 00:10:55,880 --> 00:10:56,930 We open the terminal. 128 00:10:59,260 --> 00:11:06,700 Since we want to write the boot code into os.img, we copy the os image file to the boot folder 129 00:11:06,700 --> 00:11:07,090 . 130 00:11:12,450 --> 00:11:16,050 And also, we change the boot.img to os.img. 131 00:11:20,430 --> 00:11:21,770 Now, let's run the build script. 132 00:11:25,610 --> 00:11:27,290 Let's reexamine the image. 133 00:11:33,380 --> 00:11:40,010 As you see, the boot code is written into the first sector and the partition entry remains unchanged. 134 00:11:41,240 --> 00:11:44,410 OK, let's try to mount the image to see if it works. 135 00:11:57,120 --> 00:12:01,770 In the Explorer, we can see the partition is showing here. 136 00:12:03,840 --> 00:12:09,510 So, the image file is still recognized by Windows after we writes boot code into the image. 137 00:12:10,410 --> 00:12:17,460 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 138 00:12:17,460 --> 00:12:19,320 flash drive and open rufus. 139 00:12:20,250 --> 00:12:27,420 Choose the image we want to write to the disk, the os.img in this case, checks the device is the correct one 140 00:12:27,420 --> 00:12:29,010 and we click start. 141 00:12:33,380 --> 00:12:39,380 If everything goes well, you will see that USB flash drive is recognized as a 100mb fat16 partition 142 00:12:39,380 --> 00:12:40,010 . 143 00:12:40,250 --> 00:12:48,590 So let's open Windows Explorer and a 100mb fat16 partition is showing here. In the following lectures, 144 00:12:48,610 --> 00:12:50,660 We will parse the data and implement a file module. 145 00:12:50,690 --> 00:12:53,390 See you in the next video