0

After creating the boot loader, if I copy the bytes of the boot loader and paste it on the 1st 512 bytes of the pen drive using a hex editor, will it work? (Actually I want to learn creating an operating system from scratch.)

Kara
  • 6,115
  • 16
  • 50
  • 57
Nafis Abdullah Khan
  • 2,062
  • 3
  • 22
  • 39

2 Answers2

0

I'm not entirely sure I understand your question, but to answer the title: yes. You can write to any part of the drive with an appropriately-designed hex editor with appropriate permissions (usually "sudo" access is required on Linux).

For instance, writing to the boot sector of a flash drive is necessary for automating booting of the CHDK system.

Not all hex editors are designed to access drives, some can only work with files. For instance, the NCurses Hexeditor normally works only with files, but can be made to access disks as files in Linux/Unix environment by employing the -d flag.

The Linux dd command also enables low-level writing to drives. This may be useful in your case as it can be used to perform byte-by-byte copies of drive contents, including MBR sections.

Richard
  • 56,349
  • 34
  • 180
  • 251
  • Hi Richard, thanks for your answer. I am actually more interested working on Windows rather than Linux although I know Linux is better for OS development. And I also am familiar with the dd command although I never tried it. In windows I am experienced with a free hex editor named [HxD]: http://mh-nexus.de/en/hxd/. It would be more helpful if you tell me whether I can do it in windows and which file system is good for doing this (NTFS of FAT32). Any tutorial link would be more preferable. – Nafis Abdullah Khan Aug 31 '12 at 16:58
  • I'm sorry, @NafisAbdullahKhan, I'm not very familiar with Windows development tools. – Richard Aug 31 '12 at 17:28
0

Do not know about HEX editors, but looks like on Windows you can try to CreateFile with name like this \\.\PHYSICALDRIVE0 or just \\PHYSICALDRIVE0. And alter them with WriteFile (with caution!!! otherwise you can damage your OS install or other data).

You can probably figure out device name with WinObj. Also take a look at this project and this question.

Community
  • 1
  • 1
denis-bu
  • 3,426
  • 1
  • 17
  • 11