1

I want to try and see how the BIOS detects boot device using the magic number (0xaa55) by writing

e9 fd ff 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*
00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa

to the first sector of my pendrive as said in the experiment in the book "Writing a Simple Operating System — from Scratch" (pg-4).

Can this be achieved by using dd command alone? I am using Ubuntu 20.04 LTS

1 Answer 1

0

I would use printf to produce the raw bytes and redirect it to dd for writing to the device.

You need to know the device name of your pendrive, but if it were /dev/sdf for example you could accomplish this in 3 steps.

Make sure you use the correct device name for your pendrive!

  1. Zero out the first 512 byte sector:
printf '\x00%.0s' {1..512} | sudo dd of=/dev/sdf
  1. Write the first 3 bytes to the start of the sector:
printf '\xe9\xfd\xff' | sudo dd of=/dev/sdf
  1. Write the last 2 bytes to the end of the sector:
printf '\x55\xaa' | sudo dd seek=510 oflag=seek_bytes of=/dev/sdf
5
  • You don't technically have to zero the sector first. Just use conv=sync with dd to pad with NUL to the block size.
    – CR.
    Commented Mar 11, 2022 at 1:23
  • @CR. wouldn't that zero the entire device and not just the first 512 bytes? Commented Mar 11, 2022 at 1:49
  • No, sync only pads the input data to the size of a block.
    – CR.
    Commented Mar 11, 2022 at 3:58
  • @fuzzydrawings I tried the above method, but while booting, my PC doesn't seem to recognize my flash drive as a boot media, it directly boots to grub menu Also, why do we have to zero out the first 512 bytes? Commented Mar 11, 2022 at 19:03
  • @user13675319 The boot issue is a separate question. The reason for zeroing out the first 512 bytes is the example you give (and link to) shows a 512 byte block that is all zeroes between the e9 fd ff and 55 aa. Commented Mar 12, 2022 at 0:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .