The diskimage_builder.block_device.level1.mbr Module

The diskimage_builder.block_device.level1.mbr Module

class diskimage_builder.block_device.level1.mbr.MBR(name, disk_size, alignment)

Bases: object

MBR Disk / Partition Table Layout

Primary partitions are created first - and must also be passed in first.

The extended partition layout is done in the way, that there is one entry in the MBR (the last) that uses the whole disk. EBR (extended boot records) are used to describe the partitions themselves. This has the advantage, that the same procedure can be used for all partitions and arbitrarily many partitions can be created in the same way (the EBR is placed as block 0 in each partition itself).

In conjunction with a fixed and ‘fits all’ partition alignment the major design focus is maximum performance for the installed image (vs. minimal size).

Because of the chosen default alignment of 1MiB there will be (1MiB - 512B) unused disk space for the MBR and also the same size unused in every partition.

Assuming that 512 byte blocks are used, the resulting layout for extended partitions looks like (blocks offset in extended partition given):

Offset Description
0 MBR - 2047 blocks unused
2048 EBR for partition 1 - 2047 blocks unused
4096 Start of data for partition 1
X EBR for partition N - 2047 blocks unused
X+2048 Start of data for partition N

Direct (native) writing of MBR, EBR (partition table) is implemented - no other partitioning library or tools is used - to be sure to get the correct CHS and alignment for a wide range of host systems.

MBR_offset_disk_id = 440
MBR_offset_first_partition_table_entry = 446
MBR_offset_signature = 510
MBR_partition_type_extended_chs = 5
MBR_partition_type_extended_lba = 15
MBR_signature = 43605
add_extended_partition(bootflag, size, ptype)
add_partition(primaryflag, bootflag, size, ptype)

Adds a partition with the given type and size

add_primary_partition(bootflag, size, ptype)
align(blockno)

Align the blockno to next alignment count

bytes_per_sector = 512
compute_partition_lbas(abs_start, size)
encode_chs(cylinders, heads, sectors)

Encodes a CHS triple into disk format

free()

Returns the free (not yet partitioned) size

heads_per_cylinder = 254
lba2chs(lba)

Converts a LBA block number to CHS

If the LBA block number is bigger than the max (1023, 63, 254) the maximum is returned.

max_cylinders = 1023
sectors_per_track = 63
write_mbr()

Write MBR

This method writes the MBR to disk. It creates a random disk id as well that it creates the extended partition (as first partition) which uses the whole disk.

write_mbr_signature(blockno)

Writes the MBR/EBR signature to a block

The signature consists of a 0xAA55 in the last two bytes of the block.

write_partition_entry(bootflag, blockno, entry, ptype, lba_start, lba_length)

Writes a partition entry

The entries are always the same and contain 16 bytes. The MBR and also the EBR use the same format.

Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.