12

If I use a MBR partitioning scheme and create a primary or extended partition with fdisk(version 2.20.1), then it starts on sector 2048. If I remember correctly, then older versions of fdisk started the first partition on sector 63. If MBR needs only 512 bytes, then why doesn't the first partition start on sector 2? What is kept on those 2047 sectors? Some stage of the boot-loader?

2
  • 1
    FYI the 1 MiB (2048 sector) alignment was introduced to Linux fdisk in util-linux-ng-2.17.1/fdisk/fdisk.c, function update_sector_offset(void), released on 2010-02-22. Windows Vista was released in 2006-11.
    – pts
    Commented Jan 5, 2018 at 14:45
  • Related questions and answers: superuser.com/q/352572/19956, superuser.com/q/565577/19956.
    – pts
    Commented Jan 5, 2018 at 14:46

2 Answers 2

19

The old 32KiB gap between MBR and first sector of file system is called DOS compatibility region or MBR gap, because DOS required that the partitions started at cylinder boundaries (and each cylinder had 64 sectors i.e. 64 sectors * 512 bytes/sector= 32KiB space).

enter image description here

Legacy GRUB (GRUB1) could've used it to install GRUB1 1.5-stage bootloader there: http://www.gnu.org/software/grub/manual/grub.html#BIOS-installation.

Additional links:

  1. http://www.pixelbeat.org/docs/disk/
  2. https://superuser.com/questions/107235/how-do-boot-sectors-and-multiple-drives-works/108152#108152
  3. http://www.dedoimedo.com/computers/grub.html
3
  • 1
    Ok, thanks for explaining this! Looks that GRUB2 uses the same area between the MBR and before the partition for it's boot code. According to grub-install -v I have GRUB2 installed and if I execute dd if=/dev/sda obs=1 ibs=1 skip=512 count=2047 2>/dev/null | strings -n4 then there are "loading", "Geom", "Read", "Error" in this area and they should belong to GRUB2.
    – Martin
    Commented Jul 4, 2013 at 20:01
  • @Martin Hm, interesting observation. I've got only "^@"s there, grub2, too. Seems my stage 2 is right in the file system. :) Commented Jul 4, 2013 at 21:04
  • 1
    @Martin: If you previously had GRUB 0.99 installed, it might still be in that area, even if your current bootloader is GRUB 2.x and not using it.
    – Ben Voigt
    Commented Aug 6, 2014 at 21:02
6

This is a performance optimization and not related to Linux at all, just to the hardware. Modern disks (so called "4K" disks) use physical sectors of 4096 byte instead of 512. You still can address single 512-byte sectors but that may severely impact performance if the partitions (or rather: file systems) are not aligned to 4K.

Start sector 64 would be enough for this requirement. The increase to 2048 seems to be preventive (e.g. allowing to put an UEFI boot partition there if the disk should be converted to GPT later).

2
  • By performance optimization you mean that if the file-system starts at the middle of the 4K sector, then all the data within this file system is also misaligned and this would mean that if one changes even a byte in a file on file-system, then two physical 4K sectors needs to be read and modified? If file-system is aligned, then only one 4K sector needs to be modified as long as all the bytes are on the same 4K physical sector?
    – Martin
    Commented Jul 4, 2013 at 23:20
  • 2
    @Martin The problem is that the kernel always writes 4K blocks (page size) to the disk (because pages are cached). In contrast to a single sector a 4K page can be part of two sectors. In that case not 4K but 8K must be written. And even worse: It may be that one or even both 4K blocks on disk must be read first. Commented Jul 4, 2013 at 23:48

You must log in to answer this question.

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