Category: Booting

  • BogoMIPS. What does it mean?

    Considering Linux OS, we can see a text “BogoMIPS”. It also displays a number. What does it mean?

    BogoMips is an unscientific measurement of CPU speed made by the Linux Kernel when it boots to calibrate an internal busy-loop. The value can be used to verify whether the processor being used is in proper range of similiar processors.

    BogoMips is Linus’s own invention. His kernel version 0.99.11 needed a timing loop (the time is too short and/or needs to be too exact for a non-busy-loop method of waiting), which must be calibrated to the processor speed of machine. Hence the kernel measures at boot time how fast a certain kind of busy loop runs on a computer. This is unscientific method of measurement of MIPS so is called Bogus (fake).

  • How many drive partitions can we assign?

    Generally in a computer system we can assign 4 primary partitions, or we can assign 3 primary partitions and 1 extended partition with as many logical partitions as you want but withing the range of A – Z and assign any drive letter to the drives in windows. Similarly in linux its from sda-sdz. In the deeper level, to MBR we can describe more detailed and quite understanding way for why only 4 partitions. A MBR stored in 512 bytes of code in first sector of storage device.

    The above is the memory map of MBR. This shows how many bytes are allocated in the code and which part of the code does what specific task.

    In this section our concern is about the partition table only. That is at address 01BE,  which is of 64 bytes. The complete MBR code would look like below.

    MBR_Pic

    The highlighted code is the partition table code which is 64 bytes long. Each 16 bytes of code represents 4 partitions.

    Partition 1:80 20 21 00 83 FE FF FF 00 08 00 00 00 F8 5F 02 
    Partition 2:00 FE FF FF 05 FE FF FF FE 07 60 02 02 F0 1F 00 
    Partition 3:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Partition 4:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

    In the first partition from above
    80: The first byte represents the bootable or non-bootable status of the partition. If the value is 80 the partition is bootable else if value is 00 it is not.
    20 21 00: (Cylinder-Head-Sector Address) The first byte is represents head, Second represents “almost the head” and the last byte represents the Cylinder
    83: Represents Partition type in our case XX means
    FE FF FF: Cylinder Head Sector Address of the last absolute sector in partition
    00 08 00 00: Logical block addressing of first absolute sector in the partition
    00 F8 5F 02 : number of sectors in partition in our case (sectors-in decimal)

    You can simple do the following:

    $file <EXTRACTED_MBR_FILE>

    Doing this you will the extracted data with partition info displayed.

  • Writing MBR

    There are different ways for doing that. You can take reference to www.osdev.org for details.

    The easy way for me was going with linux and extracting MBR for drives:

    1. Backup first

      dd if=/dev/sda of=~/[original_bootloader.bin] bs=512 count=1

      2. Disassemble the bootloader

      ndisasm -b16 -o7C00h ~/[original_bootloader.bin] > ~/[original_bootloader.asm]

      3. Make your modifications and reassemble

      nasm ~/[original_bootloader.asm] -f bin ~/[modified_bootloader.bin]

      4. Overwrite the bootloader

        dd if=~/[modified_bootloader.bin] of=/dev/sda bs=512 count=1

        ‘sda’ is your default primary (bootable) drive. You can modify the .bin file and test in your development enviroment and deploy the successfully edited bootloader  to system.