From 2ebacf6a3a6ada08885977c601d97a536829d749 Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Sun, 4 May 2014 12:16:25 +0200 Subject: [PATCH] Fix MBR offset and add some comments to explain --- bootstrapvz/base/fs/partitionmaps/gpt.py | 4 ++-- bootstrapvz/base/fs/partitionmaps/msdos.py | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bootstrapvz/base/fs/partitionmaps/gpt.py b/bootstrapvz/base/fs/partitionmaps/gpt.py index ffc0343..1e5d952 100644 --- a/bootstrapvz/base/fs/partitionmaps/gpt.py +++ b/bootstrapvz/base/fs/partitionmaps/gpt.py @@ -48,12 +48,12 @@ class GPTPartitionMap(AbstractPartitionMap): # We need to move the first partition to make space for the gpt offset gpt_offset = Bytes('17KiB') - self.partitions[0].offset = gpt_offset + self.partitions[0].offset += gpt_offset if hasattr(self, 'grub_boot'): # grub_boot should not increase the size of the volume, # so we reduce the size of the succeeding partition. - # gpt_offset is included here, because of the offset we added above + # gpt_offset is included here, because of the offset we added above (grub_boot is partition[0]) self.partitions[1].size -= self.grub_boot.get_end() else: # Avoid increasing the volume size because of gpt_offset diff --git a/bootstrapvz/base/fs/partitionmaps/msdos.py b/bootstrapvz/base/fs/partitionmaps/msdos.py index d21ec64..c6e1a64 100644 --- a/bootstrapvz/base/fs/partitionmaps/msdos.py +++ b/bootstrapvz/base/fs/partitionmaps/msdos.py @@ -40,11 +40,17 @@ class MSDOSPartitionMap(AbstractPartitionMap): # Mark boot as the boot partition, or root, if boot does not exist getattr(self, 'boot', self.root).flags.append('boot') - # If we are using the grub bootloader, we will need to create a 2 MB offset at the beginning - # of the partitionmap and steal it from the first partition + # If we are using the grub bootloader, we will need to add a 2 MB offset + # at the beginning of the partitionmap and steal it from the first partition. + # The MBR offset is included in the grub offset, so if we don't use grub + # we should reduce the size of the first partition and move it by only 512 bytes. if bootloader == 'grub': - self.partitions[0].offset = Bytes('2MiB') - self.partitions[0].size -= self.partitions[0].offset + offset = Bytes('2MiB') + else: + offset = Bytes('512B') + + self.partitions[0].offset += offset + self.partitions[0].size -= offset super(MSDOSPartitionMap, self).__init__(bootloader)