I have read that my partition table is stored in the MBR. And write operations are performed sector-wise i.e, even if you want to change just a few bytes of a sector you need to overwrite entire contents of the sector. So when installing GRUB on MBR, why doesn't it destroy my partition table?


The software reads the original sector; updates it in memory; then writes out the updated sector.

On Linux, this is actually done by the OS itself, so GRUB doesn't need to worry about sectors – it can just issue a 440-byte write, and the OS will read/modify/write the whole 512-byte sector accordingly. (The job of an OS is to abstract away the inconvenient hardware details.) But if the OS didn't do this, then GRUB could still do the same read/modify/write thing on its own.

This "read/modify/write" pattern is not limited to just the MBR – it's also how you're able to change individual bytes within a file, even though they're also stored in disk sectors. The OS will read the corresponding sector from disk, update it with your changes, then write the new sector back.

  • Isn't read-modify-write done by the hard drive firmware, not software on the OS?
    – forest
    Feb 21 at 1:01
  • 13
    Both. The disk interface only has commands for writing whole logical sectors, so writes smaller than a sector have to be r/m/w'd by the OS – it literally has no way to issue a byte-level write to the disk. (At least this is true for ATA and SCSI, as far as I know.) On the other hand, if you have a disk which has e.g. 4K physical sectors but still emulates traditional 512b logical sectors, then yes, the disk's firmware will r/m/w the whole physical 4K sector when it needs to handle the emulated 512b write operation.
    – user1686
    Feb 21 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.