home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / BOOT2C.ZIP / BOOT2C.DOC < prev   
Text File  |  1993-02-26  |  18KB  |  359 lines

  1. BOOT2C.COM & BOOTPW.COM (VERSION 1.0)   Copyright (c) 1993 Douglas Boling
  2. -------------------------------------------------------------------------
  3.                 First Published in PC Magazine March 30, 1993 (Utilities)
  4. -------------------------------------------------------------------------
  5.  
  6. BOOT2C & BOOTPW:
  7.                 BOOT2C lets you force a boot from your hard disk even if
  8. you have left a floppy in a disk drive. BOOT2C does this not only for
  9. DOS-based PCs, but for machines that run under OS/2 as well. BOOTPW lets
  10. you password-protect a floppy or hard disk. Once protected, your disks
  11. won't be recognized as valid disks by either DOS or OS/2.
  12.  
  13.  
  14.      How often do you forget that you've left a floppy disk in drive
  15. A: when you boot up your PC?  Don't you wish that instead of giving you
  16. an annoying ``Non-System disk or disk error'' message and making you
  17. unlock drive A:, your machine would simply go to drive C: and boot up
  18. from there directly?
  19.  
  20.     BOOT2C, eliminates the forgotten-disk syndrome.  By installing a tiny
  21. bit of code in the boot sector of the drive A: floppy disk, BOOT2C
  22. automatically forces the machine to load the operating system files from
  23. the hard disk.  BOOT2C does this not only for DOS-based PCs, but for
  24. machines that run under OS/2 as well.
  25.  
  26.     Indeed, with a BOOT2C-modified disk in drive A:, your machine will
  27. actually boot faster.  That's because your PC won't receive and process
  28. an error when it attempts to read the A: drive.  Normally, a PC retries
  29. its initial floppy disk read up to five times before giving up and
  30. booting from the hard drive.
  31.  
  32.     If you're running under OS/2, BOOT2C can actually redirect its boot-up
  33. instruction to another physical disk--drive D:, for example. Unfortunately,
  34. current releases of DOS don't support this feature, but in a future DOS
  35. version you may not have to be limited to booting from drive A: or C:.
  36.  
  37.     The second utility, BOOTPW, a program that will password protect
  38. either a floppy or a hard disk.  Once protected, the disk won't be
  39. recognized as a valid disk by either DOS or OS/2.
  40.  
  41.     You won't subsequently need the BOOTPW program to unprotect the disk.
  42. Just start the machine with the password-protected floppy disk in the
  43. A: drive, and the BOOTPW code will ask for the proper password.  Note
  44. that once the password is entered, the protection is removed; to reprotect
  45. the disk BOOTPW must be reinstalled.
  46.  
  47. USING BOOT2C
  48.  
  49.      BOOT2C is a simple program with a simple interface.  Its full syntax is
  50.  
  51.                                  BOOT2C d: [n]
  52.  
  53. where d: is the disk drive on which the redirection code is to be installed
  54. and the optional n parameter (to be explained below) is the number of the
  55. disk that holds the boot-up files (OS/2 only).  For the normal case,
  56. assuming that the BOOT2C.COM program is on your path, you can install
  57. the necessary code on the floppy disk in the A: drive by entering
  58.  
  59.                                   BOOT2C A:
  60.  
  61. You can then leave the floppy disk in drive A:, and you'll never have to
  62. see that irritating ``Non-System disk'' error message again.
  63.  
  64.     The redirection code written by BOOT2C is not a file you'll find with
  65. the DIR command; it resides in the boot sector of the disk.  You can write
  66. the code to a floppy disk located in drive B: by entering
  67.  
  68.                                   BOOT2C B:
  69.  
  70. Obviously, since a PC can't boot from the B: drive, a modified disk in
  71. the B: drive won't force a hard disk boot.  Such a command is useful,
  72. however, if you want to prepare the disk in your drive B: for use in
  73. another machine's drive A:.  It might be,  for example, that you need
  74. to put BOOT2C on a 3.5-inch floppy disk and your 3.5-inch drive is
  75. drive B:.
  76.  
  77.     By using the n parameter, BOOT2C can also modify a floppy disk so it
  78. will boot the second hard disk of the system.  By the ``second hard disk''
  79. here I mean a second physical hard disk, not a secondary partition on the
  80. first hard disk.  Again, this will not work with current DOS, but OS/2
  81. users may wish to try it. To modify a floppy disk in the A: drive to boot
  82. the second hard disk, you use the command
  83.  
  84.                                   BOOT2C A: 81
  85.  
  86.     In the above command, 81 represents the physical disk number the BIOS
  87. uses to address the disk.  According to the BIOS numbering scheme, 0 is
  88. the first floppy disk, 1 is the second floppy disk, and so on.  Hard disks
  89. are numbered starting with 80 hex, so the first hard disk is 80, the second
  90. is 81.  Thus, to force a floppy disk in the A: drive to boot the disk in
  91. the B: drive on systems where the B: drive is bootable, the command is
  92.  
  93.                                    BOOT2C A: 1
  94.  
  95.     BOOT2C must use the BIOS number instead of the drive letter because
  96. at the point in the boot-up sequence at which the BOOT2C boot program is
  97. executed, the operating system isn't available to tell BOOT2C which
  98. physical drives it calls the A:, B:, and C: drives!  The drive letters
  99. with which we are familiar don't exist at the BIOS level when a PC is
  100. booted.
  101.  
  102.     Once the new BOOT2C boot record has been installed, the floppy disk
  103. will act like any other.  Files can be read and written to the disk and
  104. programs executed from the disk.  The only difference occurs when you
  105. boot the system with a BOOT2C-modified floppy disk in the A: drive.
  106. In that case the floppy disk displays a message indicating that BOOT2C
  107. is present and then continues by booting the files on the hard disk.
  108.  
  109.     Removing BOOT2C from a disk requires executing either the DOS SYS
  110. or FORMAT commands on the disk.  Although this may seem to be a drastic
  111. step to take just to remove a program, there really isn't a reason for
  112. removing BOOT2C unless you want to make the disk bootable.  The SYS
  113. command puts the DOS system files onto the disk and replaces the boot
  114. record--including any BOOT2C code.  FORMAT erases all information on the
  115. disk and writes a new DOS boot record.
  116.  
  117. USING BOOTPW
  118.  
  119.      Using BOOTPW is just as simple as BOOT2C.  Just type BOOTPW along
  120. with the drive letter of the disk to protect.  For example, to protect
  121. a floppy disk in the A: drive, you enter the command
  122.  
  123.                                    BOOTPW A:
  124.  
  125.     Once started, BOOTPW will ask you for a password.  The password, which
  126. can be up to eight characters long, is not displayed on the screen as you
  127. enter it.  BOOTPW then asks for the password again to ensure that you
  128. entered the password correctly.  The disk should then be removed from the
  129. drive.  If you now place the floppy disk in the drive again and try a DIR
  130. (or any other disk-related) command, DOS will respond with a ``General
  131. failure'' message.
  132.  
  133.     The password protection can be removed in either of two ways.  First,
  134. if you run BOOTPW on a drive that is already password-protected, BOOTPW
  135. will ask you to enter in the password for the disk.  If you enter the
  136. proper password, BOOTPW will unprotect the disk, restoring it to its
  137. original state.
  138.  
  139.     Since you might not always have BOOTPW available, a floppy disk can
  140. be unprotected by a second method.  Simply place the disk in the A: drive
  141. and reboot your machine.  Instead of booting the operating system, the
  142. disk will ask you for the password for the disk.  If you enter it correctly,
  143. the password protection will be removed and the disk will continue to boot
  144. as if it had never been protected.  That's to say, if the disk is not a
  145. bootable disk you'll get the standard Non-System disk error message.
  146. When this happens, all you need to do is remove the floppy disk and reboot
  147. your system.
  148.  
  149.     How much actual protection does BOOTPW provide?  As with all password
  150. schemes, BOOTPW can be broken.  Its protection is at the operating system
  151. level; the data on the disk is not modified in any way, and an intrepid
  152. programmer can remove the password with a few hours' work.  So, using
  153. BOOTPW won't absolutely prevent people from reading your data, but it will
  154. deter them--at least for a while.
  155.  
  156. REVEILLE
  157.  
  158.     When a PC first wakes up or is reset, it goes through a built-in
  159. series of Power-On Self Tests (POST) designed to initialize the system
  160. components and ensure memory integrity.  Only after the machine has been
  161. tested and initialized does it look to the outside world for a program
  162. to run.  Normally, this first program is an operating system, such as
  163. DOS or OS/2. BOOTPW and BOOT2C are exceptions to the general rule, for
  164. they take control of the machine before DOS or OS/2.
  165.  
  166.     To load its first program, the PC reads the first sector of the first
  167. floppy disk in the system and loads the information there at segment 0,
  168. offset 7C00 hex.  If the data in that sector contains the word value
  169. AA55 hex (known as the signature word) at offset 510 of the block, the
  170. sector is assumed to contain valid code and the BIOS jumps to the first
  171. byte of the block (address 0:7C00).  At this point, all the microprocessor
  172. registers are undefined with the exceptions of the following:  the code
  173. segment register (CS), which contains 0; the instruction pointer (IP),
  174. which contains 7C00 hex; and DL, which contains the number of the drive
  175. where the boot sector was found.
  176.  
  177.     If the first floppy disk sector does not have the correct signature
  178. word--because there isn't a floppy disk in the drive or there isn't a
  179. drive at all--the BIOS attempts to load the first sector of the first
  180. hard disk in the system.  The process is the same as when reading the
  181. floppy disk:  The first sector is placed at address 0:7C00 and the
  182. signature word is checked.  If a valid signature is not found, the PC
  183. assumes that there isn't an external program to load.  In this case,
  184. an IBM PC will start its ROM BASIC program.  Machines that lack ROM
  185. BASIC simply wait for the user to place a proper floppy disk in the
  186. system.
  187.  
  188.     The DOS boot sector has two components that are vital to DOS and
  189. OS/2 FAT drives. The first component is the BIOS Parameter Block (BPB),
  190. which is located immediately following a Jump opcode and the OEM
  191. identification field.  The figure below shows the layout of the first
  192. 60 bytes of a DOS boot record.
  193.  
  194. The DOS Boot Record
  195.  
  196. Offset    Name             Size       Description
  197. ---------------------------------------------------------------------------
  198.  
  199.  0      jump opcode        3 bytes     Long jump or short jump followed
  200.                                        by a NOP
  201.  
  202.  3      OEM field          8 bytes     Identifies the DOS that formatted
  203.                                        the disk
  204.  
  205. **11    Bytes per sector   Word        Sector size in bytes
  206.  
  207. **13    Sectors per        Byte        Number of sectors per allocation unit
  208.         cluster
  209.  
  210. **14    Reserved Sectors    Word        Number of sectors reserved after the
  211.                                         boot record
  212.  
  213. **16    Number of FATs      Byte        Number of file allocation tables
  214.                                         on-disk
  215.  
  216. **17    Root entries        Word        Number of entries in the root
  217.                                         directory
  218.  
  219. **19    Total sectors       Word        Total sectors on disk 0 if number over
  220.                                         65,535
  221.  
  222. **21    Media descriptor    Byte        Indicates the type of media
  223.  
  224. **22    Sectors per FAT     Word        Size in sectors of each FAT
  225.  
  226. **24    Sectors per track   Word        Number of sectors on each track on
  227.                                         the disk
  228.  
  229. **26    Number of heads     Word        Number of heads on-disk
  230.  
  231. **28    *Hidden Sectors     Word        Number of hidden sectors on-disk 
  232.  
  233. ***32   Huge Sectors        DWord       Total sectors if over 65,535 
  234.  
  235. ***34   Drive number        Byte        BIOS drive number
  236.  
  237. ***35                       Byte        Reserved
  238.  
  239. ***36   Boot signature      Byte        Must be 29 hex for extended boot
  240.                                         record
  241.  
  242. ***37   Volume ID           DWord       Volume ID for disk
  243.  
  244. ***41   Volume label        11 bytes    Copy of volume label
  245.  
  246. ***52   File system label   8 bytes     Identifies file system type (FAT12
  247.                                         or FAT16)
  248.  
  249. * In DOS 3.3 this field was extended to a double word.
  250.  
  251. ** BIOS Parameter Block
  252.  
  253. *** Added in DOS 4
  254.  
  255. Figure:  This table shows the layout of the data at the start of the first
  256.           60 bytes of a DOS boot record.
  257. -----------------------------------------------------------------------------
  258.  
  259.  
  260.     The second important part of a DOS boot record is the boot program
  261. itself, which finds and loads the DOS system files.  The boot program is
  262. a simple routine that uses the data in the BPB to locate the root
  263. directory on the disk.  The directory is then read into memory and its
  264. entries are checked for the two DOS system programs:  IO.SYS and
  265. MSDOS.SYS (for MS-DOS), or IBMBIO.COM and IBMDOS.COM (for PC-DOS).
  266. If these files are not in their proper place on the disk, the boot sector
  267. code prints its infamous ``Non-System disk or disk error'' message.
  268.  
  269.     If these files are found, the boot routine reads the first few sectors
  270. of IO.SYS (or IBMBIO.COM) into memory and then jumps to the newly loaded
  271. code.  From that point on, the machine is controlled by the DOS system
  272. programs.  By using a slightly different boot program and loading the
  273. file OS2LDR instead, the machine will run OS/2 instead of DOS.  In the
  274. case of the programs BOOT2C and BOOTPW, the boot record takes a different
  275. path still.
  276.  
  277. HOW BOOT2C AND BOOTPW WORK
  278.  
  279.      Both BOOT2C and BOOTPW work by modifying the boot record on the
  280. target floppy disk.  Although both BOOT2C and BOOTPW contain code
  281. necessary for installation (and removal, in the case of BOOTPW), the
  282. replacement boot records of these programs are of primary interest.
  283.  
  284.     When BOOT2C is run, it replaces the original boot record on the
  285. floppy disk with the BOOT2C boot record.  Before the BOOT2C boot record
  286. is written to the disk, the fields in the BIOS Parameter Block are filled
  287. in with the information from the original boot record.
  288.  
  289.     The boot sector code is quite simple.  The first instruction is the
  290. required JMP opcode.  This is followed by an empty area that is filled in
  291. with the BIOS Parameter Block from the original boot record during the
  292. installation.  After the BPB comes the byte that holds the drive number
  293. toward which BOOT2C will redirect the boot.  The boot code that follows
  294. is relatively short and can be described straightforwardly.
  295.  
  296.     First, the stack segment (SS) and stack pointer (SP) must be
  297. initialized.  Since the POST procedure initializes only the CS, IP, and
  298. DL registers, all the other registers must be initialized before they
  299. are used.  Once the registers are initialized, the boot code must be
  300. relocated, for the boot record that BOOT2C is to load must occupy the
  301. place that BOOT2C has taken over. BOOT2C therefore moves its own code up
  302. by 512 bytes, to address 0:7A00 hex, and then uses a far return to jump
  303. to the new location.  Once relocated, BOOT2C prints a short message to
  304. indicate where it is and then proceeds to read the boot sector on the
  305. redirection disk.
  306.  
  307.     Since DOS has yet to be loaded, however, BOOT2C must use the BIOS
  308. disk services.  In order to read a sector via the BIOS, a program must
  309. encode the cylinder, head, and sector information in the CX and DX
  310. registers.  ES:BX points to the buffer for the data and AL is loaded
  311. with the number of sectors to be read.  Finally, AH is loaded with a 2
  312. to indicate a disk read, and an Interrupt 13h is performed.
  313.  
  314.     Specifically to read the boot sector of the disk, the registers are
  315. loaded so that BX contains 7C00, CX is equal to 1, DH is 0, and register
  316. DL contains the disk number.
  317.  
  318.     Following the procedure of the BIOS routine, BOOT2C checks to see
  319. whether the sector read has the proper AA55 boot flag located at offset
  320. 510.  If not, or if an error occurred during the read, BOOT2C displays
  321. an error message and halts the machine.  If the boot record is valid,
  322. BOOT2C loads DL with the new boot drive number and jumps to the new
  323. boot code.
  324.  
  325.     The boot code for BOOTPW performs a very similar litany, except
  326. extra code is added to query the user for the password.  The tasks of
  327. the BOOTPW boot record are to ensure that the user enters the proper
  328. password, then to find and read the original boot record, write the
  329. original boot record back to its proper place, and finally to reboot
  330. the machine.  Once the original boot record code has been rewritten
  331. to the boot sector, the reboot will cause the machine to continue the
  332. boot process as if BOOTPW had never existed.  Of course, if there are
  333. no system files on the floppy disk, the reboot of the original boot
  334. record will display the ``Non-System disk'' message.
  335.  
  336.     The protection provided to the disk is actually quite simple.
  337. The BOOTPW boot record does not conform to the DOS requirement for a
  338. BIOS Parameter Block located at the start of the disk.  Thus, when DOS
  339. attempts to read the protected disk, it does not see a proper BPB and
  340. consequently reports a General Error back to the user.  Until the
  341. correct boot sector is replaced, DOS is not able to access the disk.
  342.  
  343.     BOOTPW can also unprotect a disk without requiring a machine reboot.
  344. To do this the BOOTPW program reads and writes the protected disk with
  345. DOS interrupt 25 (Absolute Sector Read) and DOS interrupt 26
  346. (Absolute Sector Write).  These functions can read the boot record of
  347. a protected disk even with a BOOTPW boot record installed.
  348.  
  349.     Both BOOTPW and BOOT2C show what can be done with no more than the
  350. limited 512 bytes of a boot record.  By modifying the boot record
  351. structure, BOOTPW confuses DOS so that the disk becomes inaccessible.
  352. On the other hand, BOOT2C's almost trivial code frees us from the
  353. frustration of that silly ``Non-System or disk error'' message.  If you
  354. use a lot of floppy disks, you'll rejoice that the full use of your
  355. A: drive has been returned to you.
  356. ------------------------------------------------------------------------
  357.  
  358. DOUGLAS BOLING IS A CONTRIBUTING EDITOR TO PC MAGAZINE.
  359.