disk: use bytes instead of sectors in all code
Use bytes internally everywhere and convert to sectors only when writing the options for the stages. Changed the AlignUp() method to not do the alignment if the input is already aligned. This changes the behaviour when the size is 0, but that's not a realistic use case. Updated unit tests to match. Manifests are unaffected. Co-Authored-By: Christian Kellner <christian@kellner.me>
This commit is contained in:
parent
abaadf95ed
commit
dec5a3850c
15 changed files with 115 additions and 113 deletions
|
|
@ -33,16 +33,14 @@ func CreatePartitionTable(
|
|||
table := basePartitionTable.Clone()
|
||||
|
||||
for _, m := range mountpoints {
|
||||
sectors := table.BytesToSectors(m.MinSize)
|
||||
|
||||
// if we already have a partition ensure that the
|
||||
// size is at least the requested size, otherwise
|
||||
// create a new filesystem with that size
|
||||
part := table.FindPartitionForMountpoint(m.Mountpoint)
|
||||
if part != nil {
|
||||
part.EnsureSize(sectors)
|
||||
part.EnsureSize(m.MinSize)
|
||||
} else {
|
||||
err := table.CreateFilesystem(m.Mountpoint, sectors)
|
||||
err := table.CreateFilesystem(m.Mountpoint, m.MinSize)
|
||||
if err != nil {
|
||||
return PartitionTable{}, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ type PartitionTable struct {
|
|||
}
|
||||
|
||||
type Partition struct {
|
||||
Start uint64 // Start of the partition in sectors
|
||||
Size uint64 // Size of the partition in sectors
|
||||
Start uint64 // Start of the partition in bytes
|
||||
Size uint64 // Size of the partition in bytes
|
||||
Type string // Partition type, e.g. 0x83 for MBR or a UUID for gpt
|
||||
Bootable bool // `Legacy BIOS bootable` (GPT) or `active` (DOS) flag
|
||||
// ID of the partition, dos doesn't use traditional UUIDs, therefore this
|
||||
|
|
@ -61,12 +61,15 @@ type Filesystem struct {
|
|||
FSTabPassNo uint64
|
||||
}
|
||||
|
||||
// AlignUp will align the given sectors to next aligned sector
|
||||
func (pt *PartitionTable) AlignUp(sectors uint64) uint64 {
|
||||
|
||||
grain := pt.BytesToSectors(DefaultGrainBytes)
|
||||
|
||||
return ((sectors + grain) / grain) * grain
|
||||
// AlignUp will align the given bytes to next aligned grain if not already
|
||||
// aligned
|
||||
func (pt *PartitionTable) AlignUp(size uint64) uint64 {
|
||||
grain := DefaultGrainBytes
|
||||
if size%grain == 0 {
|
||||
// already aligned: return unchanged
|
||||
return size
|
||||
}
|
||||
return ((size + grain) / grain) * grain
|
||||
}
|
||||
|
||||
// Convert the given bytes to the number of sectors.
|
||||
|
|
@ -279,7 +282,7 @@ func (pt *PartitionTable) BootFilesystem() *Filesystem {
|
|||
}
|
||||
|
||||
// Create a new filesystem within the partition table at the given mountpoint
|
||||
// with the given minimum size in sectors.
|
||||
// with the given minimum size in bytes.
|
||||
func (pt *PartitionTable) CreateFilesystem(mountpoint string, size uint64) error {
|
||||
filesystem := Filesystem{
|
||||
Type: "xfs",
|
||||
|
|
@ -346,7 +349,8 @@ func (pt *PartitionTable) GenerateUUIDs(rng *rand.Rand) {
|
|||
func (pt *PartitionTable) updatePartitionStartPointOffsets(size uint64) uint64 {
|
||||
|
||||
// always reserve one extra sector for the GPT header
|
||||
header := uint64(1)
|
||||
|
||||
header := pt.SectorsToBytes(1)
|
||||
footer := uint64(0)
|
||||
|
||||
if pt.Type == "gpt" {
|
||||
|
|
@ -359,14 +363,13 @@ func (pt *PartitionTable) updatePartitionStartPointOffsets(size uint64) uint64 {
|
|||
parts = 128
|
||||
}
|
||||
|
||||
nBytes := uint64(parts * 128)
|
||||
header += pt.BytesToSectors(nBytes)
|
||||
header += uint64(parts * 128)
|
||||
|
||||
footer = header
|
||||
}
|
||||
|
||||
start := pt.AlignUp(header)
|
||||
size = pt.SectorsToBytes(pt.AlignUp(pt.BytesToSectors(size) - 1))
|
||||
size = pt.AlignUp(size)
|
||||
|
||||
var rootIdx = -1
|
||||
for i := range pt.Partitions {
|
||||
|
|
@ -376,21 +379,21 @@ func (pt *PartitionTable) updatePartitionStartPointOffsets(size uint64) uint64 {
|
|||
continue
|
||||
}
|
||||
partition.Start = start
|
||||
partition.Size = pt.AlignUp(partition.Size - 1)
|
||||
partition.Size = pt.AlignUp(partition.Size)
|
||||
start += partition.Size
|
||||
}
|
||||
|
||||
root := &pt.Partitions[rootIdx]
|
||||
root.Start = start
|
||||
|
||||
// add the extra pedding specified in the partition table
|
||||
// add the extra padding specified in the partition table
|
||||
footer += pt.ExtraPadding
|
||||
|
||||
// If the sum of all partitions is bigger then the specified size,
|
||||
// we use that instead. Grow the partition table size if needed.
|
||||
end := pt.AlignUp(root.Start + footer + root.Size - 1)
|
||||
if endBytes := pt.SectorsToBytes(end); endBytes > size {
|
||||
size = endBytes
|
||||
end := pt.AlignUp(root.Start + footer + root.Size)
|
||||
if end > size {
|
||||
size = end
|
||||
}
|
||||
|
||||
if size > pt.Size {
|
||||
|
|
@ -398,7 +401,7 @@ func (pt *PartitionTable) updatePartitionStartPointOffsets(size uint64) uint64 {
|
|||
}
|
||||
|
||||
// If there is space left in the partition table, grow root
|
||||
root.Size = pt.BytesToSectors(pt.Size) - root.Start
|
||||
root.Size = pt.Size - root.Start
|
||||
|
||||
// Finally we shrink the last partition, i.e. the root partition,
|
||||
// to leave space for the footer, e.g. the secondary GPT header.
|
||||
|
|
|
|||
|
|
@ -12,20 +12,23 @@ import (
|
|||
func TestDisk_AlignUp(t *testing.T) {
|
||||
|
||||
pt := disk.PartitionTable{}
|
||||
firstAligned := pt.BytesToSectors(disk.DefaultGrainBytes)
|
||||
firstAligned := disk.DefaultGrainBytes
|
||||
|
||||
tests := []struct {
|
||||
size uint64
|
||||
want uint64
|
||||
}{
|
||||
{0, firstAligned},
|
||||
{0, 0},
|
||||
{1, firstAligned},
|
||||
{firstAligned - 1, firstAligned},
|
||||
{firstAligned, firstAligned}, // grain is already aligned => no change
|
||||
{firstAligned / 2, firstAligned},
|
||||
{firstAligned + 1, firstAligned * 2},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
got := pt.AlignUp(tt.size)
|
||||
assert.Equal(t, tt.want, got)
|
||||
assert.Equal(t, tt.want, got, "Expected %d, got %d", tt.want, got)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ const (
|
|||
// for the secondary GPT header, but it was too much and
|
||||
// also done for MBR. Since image definitions are frozen,
|
||||
// we keep this extra padding around.
|
||||
ExtraPaddingGPT = uint64(67)
|
||||
ExtraPaddingMBR = uint64(100)
|
||||
ExtraPaddingGPT = uint64(34304)
|
||||
ExtraPaddingMBR = uint64(51200)
|
||||
)
|
||||
|
||||
var defaultBasePartitionTables = distro.BasePartitionTableMap{
|
||||
|
|
@ -22,13 +22,13 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
|
|||
ExtraPadding: ExtraPaddingGPT,
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 2048,
|
||||
Size: 1048576,
|
||||
Bootable: true,
|
||||
Type: disk.BIOSBootPartitionGUID,
|
||||
UUID: disk.BIOSBootPartitionUUID,
|
||||
},
|
||||
{
|
||||
Size: 204800,
|
||||
Size: 104857600,
|
||||
Type: disk.EFISystemPartitionGUID,
|
||||
UUID: disk.EFISystemPartitionUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -60,7 +60,7 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
|
|||
ExtraPadding: ExtraPaddingGPT,
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 204800,
|
||||
Size: 104857600,
|
||||
Type: disk.EFISystemPartitionGUID,
|
||||
UUID: disk.EFISystemPartitionUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -92,7 +92,7 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
|
|||
ExtraPadding: ExtraPaddingMBR,
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 8192,
|
||||
Size: 4194304,
|
||||
Type: "41",
|
||||
Bootable: true,
|
||||
},
|
||||
|
|
@ -133,7 +133,7 @@ var ec2BasePartitionTables = distro.BasePartitionTableMap{
|
|||
ExtraPadding: ExtraPaddingGPT,
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 2048,
|
||||
Size: 1048576,
|
||||
Bootable: true,
|
||||
Type: disk.BIOSBootPartitionGUID,
|
||||
UUID: disk.BIOSBootPartitionUUID,
|
||||
|
|
@ -158,7 +158,7 @@ var ec2BasePartitionTables = distro.BasePartitionTableMap{
|
|||
ExtraPadding: ExtraPaddingGPT,
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 409600,
|
||||
Size: 209715200,
|
||||
Type: disk.EFISystemPartitionGUID,
|
||||
UUID: disk.EFISystemPartitionUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -171,7 +171,7 @@ var ec2BasePartitionTables = distro.BasePartitionTableMap{
|
|||
},
|
||||
},
|
||||
{
|
||||
Size: 1048576,
|
||||
Size: 536870912,
|
||||
Type: disk.FilesystemDataGUID,
|
||||
UUID: disk.FilesystemDataUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -205,13 +205,13 @@ var edgeBasePartitionTables = distro.BasePartitionTableMap{
|
|||
ExtraPadding: ExtraPaddingGPT,
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 2048, // 2MB
|
||||
Size: 1048576,
|
||||
Bootable: true,
|
||||
Type: disk.BIOSBootPartitionGUID,
|
||||
UUID: disk.BIOSBootPartitionUUID,
|
||||
},
|
||||
{
|
||||
Size: 260096, // 127 MB
|
||||
Size: 133169152,
|
||||
Type: disk.EFISystemPartitionGUID,
|
||||
UUID: disk.EFISystemPartitionUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -225,7 +225,7 @@ var edgeBasePartitionTables = distro.BasePartitionTableMap{
|
|||
},
|
||||
},
|
||||
{
|
||||
Size: 786432, // 384 MB
|
||||
Size: 402653184,
|
||||
Type: disk.FilesystemDataGUID,
|
||||
UUID: disk.FilesystemDataUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -257,7 +257,7 @@ var edgeBasePartitionTables = distro.BasePartitionTableMap{
|
|||
ExtraPadding: ExtraPaddingGPT,
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 260096, // 127 MB
|
||||
Size: 133169152,
|
||||
Type: disk.EFISystemPartitionGUID,
|
||||
UUID: disk.EFISystemPartitionUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -271,7 +271,7 @@ var edgeBasePartitionTables = distro.BasePartitionTableMap{
|
|||
},
|
||||
},
|
||||
{
|
||||
Size: 786432, // 384 MB
|
||||
Size: 402653184,
|
||||
Type: disk.FilesystemDataGUID,
|
||||
UUID: disk.FilesystemDataUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
|
|||
|
|
@ -955,13 +955,12 @@ func simplifiedInstallerBootISOTreePipeline(archivePipelineName, kver string) *o
|
|||
},
|
||||
))
|
||||
|
||||
var sectorSize uint64 = 512
|
||||
pt := disk.PartitionTable{
|
||||
Size: 20971520,
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Start: 0,
|
||||
Size: 20971520 / sectorSize,
|
||||
Size: 20971520,
|
||||
Filesystem: &disk.Filesystem{
|
||||
Type: "vfat",
|
||||
Mountpoint: "/",
|
||||
|
|
@ -1275,8 +1274,8 @@ func mkfsStages(pt *disk.PartitionTable, device *osbuild.Device) []*osbuild2.Sta
|
|||
stageDevice := osbuild.NewLoopbackDevice(
|
||||
&osbuild.LoopbackDeviceOptions{
|
||||
Filename: devOptions.Filename,
|
||||
Start: p.Start,
|
||||
Size: p.Size,
|
||||
Start: pt.BytesToSectors(p.Start),
|
||||
Size: pt.BytesToSectors(p.Size),
|
||||
},
|
||||
)
|
||||
switch p.Filesystem.Type {
|
||||
|
|
|
|||
|
|
@ -375,8 +375,8 @@ func sfdiskStageOptions(pt *disk.PartitionTable) *osbuild.SfdiskStageOptions {
|
|||
for idx, p := range pt.Partitions {
|
||||
partitions[idx] = osbuild.Partition{
|
||||
Bootable: p.Bootable,
|
||||
Size: p.Size,
|
||||
Start: p.Start,
|
||||
Start: pt.BytesToSectors(p.Start),
|
||||
Size: pt.BytesToSectors(p.Size),
|
||||
Type: p.Type,
|
||||
UUID: p.UUID,
|
||||
}
|
||||
|
|
@ -419,8 +419,8 @@ func copyFSTreeOptions(inputName, inputPipeline string, pt *disk.PartitionTable,
|
|||
devices[name] = *osbuild.NewLoopbackDevice(
|
||||
&osbuild.LoopbackDeviceOptions{
|
||||
Filename: devOptions.Filename,
|
||||
Start: p.Start,
|
||||
Size: p.Size,
|
||||
Start: pt.BytesToSectors(p.Start),
|
||||
Size: pt.BytesToSectors(p.Size),
|
||||
},
|
||||
)
|
||||
var mount *osbuild.Mount
|
||||
|
|
@ -488,7 +488,7 @@ func grub2InstStageOptions(filename string, pt *disk.PartitionTable, platform st
|
|||
return &osbuild.Grub2InstStageOptions{
|
||||
Filename: filename,
|
||||
Platform: platform,
|
||||
Location: pt.Partitions[0].Start,
|
||||
Location: pt.BytesToSectors(pt.Partitions[0].Start),
|
||||
Core: core,
|
||||
Prefix: prefix,
|
||||
}
|
||||
|
|
@ -502,7 +502,7 @@ func ziplInstStageOptions(kernel string, pt *disk.PartitionTable) *osbuild.ZiplI
|
|||
|
||||
return &osbuild.ZiplInstStageOptions{
|
||||
Kernel: kernel,
|
||||
Location: pt.Partitions[bootPartIndex].Start,
|
||||
Location: pt.BytesToSectors(pt.Partitions[bootPartIndex].Start),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
|
|||
Type: "gpt",
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 2048,
|
||||
Size: 1048576,
|
||||
Bootable: true,
|
||||
Type: disk.BIOSBootPartitionGUID,
|
||||
UUID: disk.BIOSBootPartitionUUID,
|
||||
},
|
||||
{
|
||||
Size: 204800,
|
||||
Size: 104857600,
|
||||
Type: disk.EFISystemPartitionGUID,
|
||||
UUID: disk.EFISystemPartitionUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -48,7 +48,7 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
|
|||
Type: "gpt",
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 204800,
|
||||
Size: 104857600,
|
||||
Type: disk.EFISystemPartitionGUID,
|
||||
UUID: disk.EFISystemPartitionUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -79,7 +79,7 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
|
|||
Type: "dos",
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 8192,
|
||||
Size: 4194304,
|
||||
Type: "41",
|
||||
Bootable: true,
|
||||
},
|
||||
|
|
@ -118,7 +118,7 @@ var ec2BasePartitionTables = distro.BasePartitionTableMap{
|
|||
Type: "gpt",
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 2048,
|
||||
Size: 1048576,
|
||||
Bootable: true,
|
||||
Type: disk.BIOSBootPartitionGUID,
|
||||
UUID: disk.BIOSBootPartitionUUID,
|
||||
|
|
@ -142,7 +142,7 @@ var ec2BasePartitionTables = distro.BasePartitionTableMap{
|
|||
Type: "gpt",
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 409600,
|
||||
Size: 209715200,
|
||||
Type: disk.EFISystemPartitionGUID,
|
||||
UUID: disk.EFISystemPartitionUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -155,7 +155,7 @@ var ec2BasePartitionTables = distro.BasePartitionTableMap{
|
|||
},
|
||||
},
|
||||
{
|
||||
Size: 1048576,
|
||||
Size: 536870912,
|
||||
Type: disk.FilesystemDataGUID,
|
||||
UUID: disk.FilesystemDataUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -188,13 +188,13 @@ var edgeBasePartitionTables = distro.BasePartitionTableMap{
|
|||
Type: "gpt",
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 2048, // 2MB
|
||||
Size: 1048576,
|
||||
Bootable: true,
|
||||
Type: disk.BIOSBootPartitionGUID,
|
||||
UUID: disk.BIOSBootPartitionUUID,
|
||||
},
|
||||
{
|
||||
Size: 260096, // 127 MB
|
||||
Size: 133169152, // 127 MB
|
||||
Type: disk.EFISystemPartitionGUID,
|
||||
UUID: disk.EFISystemPartitionUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -208,7 +208,7 @@ var edgeBasePartitionTables = distro.BasePartitionTableMap{
|
|||
},
|
||||
},
|
||||
{
|
||||
Size: 786432, // 384 MB
|
||||
Size: 402653184, // 384 MB
|
||||
Type: disk.FilesystemDataGUID,
|
||||
UUID: disk.FilesystemDataUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -239,7 +239,7 @@ var edgeBasePartitionTables = distro.BasePartitionTableMap{
|
|||
Type: "gpt",
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 260096, // 127 MB
|
||||
Size: 133169152, // 127 MB
|
||||
Type: disk.EFISystemPartitionGUID,
|
||||
UUID: disk.EFISystemPartitionUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -253,7 +253,7 @@ var edgeBasePartitionTables = distro.BasePartitionTableMap{
|
|||
},
|
||||
},
|
||||
{
|
||||
Size: 786432, // 384 MB
|
||||
Size: 402653184, // 384 MB
|
||||
Type: disk.FilesystemDataGUID,
|
||||
UUID: disk.FilesystemDataUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
|
|||
|
|
@ -692,13 +692,13 @@ func simplifiedInstallerBootISOTreePipeline(archivePipelineName, kver string) *o
|
|||
},
|
||||
))
|
||||
|
||||
var sectorSize uint64 = 512
|
||||
pt := disk.PartitionTable{
|
||||
Size: 20971520,
|
||||
Size: 20971520,
|
||||
SectorSize: 512,
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Start: 0,
|
||||
Size: 20971520 / sectorSize,
|
||||
Size: 20971520,
|
||||
Filesystem: &disk.Filesystem{
|
||||
Type: "vfat",
|
||||
Mountpoint: "/",
|
||||
|
|
@ -998,8 +998,8 @@ func mkfsStages(pt *disk.PartitionTable, device *osbuild.Device) []*osbuild.Stag
|
|||
stageDevice := osbuild.NewLoopbackDevice(
|
||||
&osbuild.LoopbackDeviceOptions{
|
||||
Filename: devOptions.Filename,
|
||||
Start: p.Start,
|
||||
Size: p.Size,
|
||||
Start: pt.BytesToSectors(p.Start),
|
||||
Size: pt.BytesToSectors(p.Size),
|
||||
},
|
||||
)
|
||||
switch p.Filesystem.Type {
|
||||
|
|
|
|||
|
|
@ -416,8 +416,8 @@ func sfdiskStageOptions(pt *disk.PartitionTable) *osbuild.SfdiskStageOptions {
|
|||
for idx, p := range pt.Partitions {
|
||||
partitions[idx] = osbuild.Partition{
|
||||
Bootable: p.Bootable,
|
||||
Size: p.Size,
|
||||
Start: p.Start,
|
||||
Start: pt.BytesToSectors(p.Start),
|
||||
Size: pt.BytesToSectors(p.Size),
|
||||
Type: p.Type,
|
||||
UUID: p.UUID,
|
||||
}
|
||||
|
|
@ -460,8 +460,8 @@ func copyFSTreeOptions(inputName, inputPipeline string, pt *disk.PartitionTable,
|
|||
devices[name] = *osbuild.NewLoopbackDevice(
|
||||
&osbuild.LoopbackDeviceOptions{
|
||||
Filename: devOptions.Filename,
|
||||
Start: p.Start,
|
||||
Size: p.Size,
|
||||
Start: pt.BytesToSectors(p.Start),
|
||||
Size: pt.BytesToSectors(p.Size),
|
||||
},
|
||||
)
|
||||
var mount *osbuild.Mount
|
||||
|
|
@ -529,7 +529,7 @@ func grub2InstStageOptions(filename string, pt *disk.PartitionTable, platform st
|
|||
return &osbuild.Grub2InstStageOptions{
|
||||
Filename: filename,
|
||||
Platform: platform,
|
||||
Location: pt.Partitions[0].Start,
|
||||
Location: pt.BytesToSectors(pt.Partitions[0].Start),
|
||||
Core: core,
|
||||
Prefix: prefix,
|
||||
}
|
||||
|
|
@ -543,7 +543,7 @@ func ziplInstStageOptions(kernel string, pt *disk.PartitionTable) *osbuild.ZiplI
|
|||
|
||||
return &osbuild.ZiplInstStageOptions{
|
||||
Kernel: kernel,
|
||||
Location: pt.Partitions[bootPartIndex].Start,
|
||||
Location: pt.BytesToSectors(pt.Partitions[bootPartIndex].Start),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
|
|||
Type: "gpt",
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 2048, // 1MB
|
||||
Size: 1048576, // 1MB
|
||||
Bootable: true,
|
||||
Type: disk.BIOSBootPartitionGUID,
|
||||
UUID: disk.BIOSBootPartitionUUID,
|
||||
},
|
||||
{
|
||||
Size: 409600, // 200 MB
|
||||
Size: 209715200, // 200 MB
|
||||
Type: disk.EFISystemPartitionGUID,
|
||||
UUID: disk.EFISystemPartitionUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -31,7 +31,7 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
|
|||
},
|
||||
},
|
||||
{
|
||||
Size: 1024000, // 500 MB
|
||||
Size: 524288000, // 500 MB
|
||||
Type: disk.FilesystemDataGUID,
|
||||
UUID: disk.FilesystemDataUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -62,7 +62,7 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
|
|||
Type: "gpt",
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 409600, // 200 MB
|
||||
Size: 209715200, // 200 MB
|
||||
Type: disk.EFISystemPartitionGUID,
|
||||
UUID: disk.EFISystemPartitionUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -76,7 +76,7 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
|
|||
},
|
||||
},
|
||||
{
|
||||
Size: 1024000, // 500 MB
|
||||
Size: 524288000, // 500 MB
|
||||
Type: disk.FilesystemDataGUID,
|
||||
UUID: disk.FilesystemDataUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -107,12 +107,12 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
|
|||
Type: "dos",
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 8192,
|
||||
Size: 4194304,
|
||||
Type: "41",
|
||||
Bootable: true,
|
||||
},
|
||||
{
|
||||
Size: 1024000, // 500 MB
|
||||
Size: 524288000, // 500 MB
|
||||
Filesystem: &disk.Filesystem{
|
||||
Type: "xfs",
|
||||
Mountpoint: "/boot",
|
||||
|
|
@ -138,7 +138,7 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
|
|||
Type: "dos",
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 1024000, // 500 MB
|
||||
Size: 524288000, // 500 MB
|
||||
Filesystem: &disk.Filesystem{
|
||||
Type: "xfs",
|
||||
Mountpoint: "/boot",
|
||||
|
|
@ -168,13 +168,13 @@ var edgeBasePartitionTables = distro.BasePartitionTableMap{
|
|||
Type: "gpt",
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 2048, // 1MB
|
||||
Size: 1048576, // 1MB
|
||||
Bootable: true,
|
||||
Type: disk.BIOSBootPartitionGUID,
|
||||
UUID: disk.BIOSBootPartitionUUID,
|
||||
},
|
||||
{
|
||||
Size: 260096, // 127 MB
|
||||
Size: 133169152, // 127 MB
|
||||
Type: disk.EFISystemPartitionGUID,
|
||||
UUID: disk.EFISystemPartitionUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -188,7 +188,7 @@ var edgeBasePartitionTables = distro.BasePartitionTableMap{
|
|||
},
|
||||
},
|
||||
{
|
||||
Size: 786432, // 384 MB
|
||||
Size: 402653184, // 384 MB
|
||||
Type: disk.FilesystemDataGUID,
|
||||
UUID: disk.FilesystemDataUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -219,7 +219,7 @@ var edgeBasePartitionTables = distro.BasePartitionTableMap{
|
|||
Type: "gpt",
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 260096, // 127 MB
|
||||
Size: 133169152, // 127 MB
|
||||
Type: disk.EFISystemPartitionGUID,
|
||||
UUID: disk.EFISystemPartitionUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -233,7 +233,7 @@ var edgeBasePartitionTables = distro.BasePartitionTableMap{
|
|||
},
|
||||
},
|
||||
{
|
||||
Size: 786432, // 384 MB
|
||||
Size: 402653184, // 384 MB
|
||||
Type: disk.FilesystemDataGUID,
|
||||
UUID: disk.FilesystemDataUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
|
|||
|
|
@ -683,7 +683,6 @@ func simplifiedInstallerBootISOTreePipeline(archivePipelineName, kver string, rn
|
|||
},
|
||||
))
|
||||
|
||||
var sectorSize uint64 = 512
|
||||
// TODO: handle error
|
||||
volid, err := disk.NewRandomVolIDFromReader(rng)
|
||||
if err != nil {
|
||||
|
|
@ -694,7 +693,7 @@ func simplifiedInstallerBootISOTreePipeline(archivePipelineName, kver string, rn
|
|||
Partitions: []disk.Partition{
|
||||
{
|
||||
Start: 0,
|
||||
Size: 20971520 / sectorSize,
|
||||
Size: 20971520,
|
||||
Filesystem: &disk.Filesystem{
|
||||
Type: "vfat",
|
||||
Mountpoint: "/",
|
||||
|
|
@ -995,8 +994,8 @@ func mkfsStages(pt *disk.PartitionTable, device *osbuild.Device) []*osbuild.Stag
|
|||
stageDevice := osbuild.NewLoopbackDevice(
|
||||
&osbuild.LoopbackDeviceOptions{
|
||||
Filename: devOptions.Filename,
|
||||
Start: p.Start,
|
||||
Size: p.Size,
|
||||
Start: pt.BytesToSectors(p.Start),
|
||||
Size: pt.BytesToSectors(p.Size),
|
||||
},
|
||||
)
|
||||
switch p.Filesystem.Type {
|
||||
|
|
|
|||
|
|
@ -417,8 +417,8 @@ func sfdiskStageOptions(pt *disk.PartitionTable) *osbuild.SfdiskStageOptions {
|
|||
for idx, p := range pt.Partitions {
|
||||
partitions[idx] = osbuild.Partition{
|
||||
Bootable: p.Bootable,
|
||||
Size: p.Size,
|
||||
Start: p.Start,
|
||||
Start: pt.BytesToSectors(p.Start),
|
||||
Size: pt.BytesToSectors(p.Size),
|
||||
Type: p.Type,
|
||||
UUID: p.UUID,
|
||||
}
|
||||
|
|
@ -461,8 +461,8 @@ func copyFSTreeOptions(inputName, inputPipeline string, pt *disk.PartitionTable,
|
|||
devices[name] = *osbuild.NewLoopbackDevice(
|
||||
&osbuild.LoopbackDeviceOptions{
|
||||
Filename: devOptions.Filename,
|
||||
Start: p.Start,
|
||||
Size: p.Size,
|
||||
Start: pt.BytesToSectors(p.Start),
|
||||
Size: pt.BytesToSectors(p.Size),
|
||||
},
|
||||
)
|
||||
var mount *osbuild.Mount
|
||||
|
|
@ -530,7 +530,7 @@ func grub2InstStageOptions(filename string, pt *disk.PartitionTable, platform st
|
|||
return &osbuild.Grub2InstStageOptions{
|
||||
Filename: filename,
|
||||
Platform: platform,
|
||||
Location: pt.Partitions[0].Start,
|
||||
Location: pt.BytesToSectors(pt.Partitions[0].Start),
|
||||
Core: core,
|
||||
Prefix: prefix,
|
||||
}
|
||||
|
|
@ -544,7 +544,7 @@ func ziplInstStageOptions(kernel string, pt *disk.PartitionTable) *osbuild.ZiplI
|
|||
|
||||
return &osbuild.ZiplInstStageOptions{
|
||||
Kernel: kernel,
|
||||
Location: pt.Partitions[bootPartIndex].Start,
|
||||
Location: pt.BytesToSectors(pt.Partitions[bootPartIndex].Start),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ const (
|
|||
// for the secondary GPT header, but it was too much and
|
||||
// also done for MBR. Since image definitions are frozen,
|
||||
// we keep this extra padding around.
|
||||
ExtraPaddingGPT = uint64(67)
|
||||
ExtraPaddingMBR = uint64(100)
|
||||
ExtraPaddingGPT = uint64(34304)
|
||||
ExtraPaddingMBR = uint64(51200)
|
||||
)
|
||||
|
||||
var defaultBasePartitionTables = distro.BasePartitionTableMap{
|
||||
|
|
@ -22,13 +22,13 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
|
|||
ExtraPadding: ExtraPaddingGPT,
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 2048,
|
||||
Size: 1048576,
|
||||
Bootable: true,
|
||||
Type: disk.BIOSBootPartitionGUID,
|
||||
UUID: disk.BIOSBootPartitionUUID,
|
||||
},
|
||||
{
|
||||
Size: 204800,
|
||||
Size: 104857600,
|
||||
Type: disk.EFISystemPartitionGUID,
|
||||
UUID: disk.EFISystemPartitionUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -60,7 +60,7 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
|
|||
ExtraPadding: ExtraPaddingGPT,
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 204800,
|
||||
Size: 104857600,
|
||||
Type: disk.EFISystemPartitionGUID,
|
||||
UUID: disk.EFISystemPartitionUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -92,7 +92,7 @@ var defaultBasePartitionTables = distro.BasePartitionTableMap{
|
|||
ExtraPadding: ExtraPaddingMBR,
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 8192,
|
||||
Size: 4194304,
|
||||
Type: "41",
|
||||
Bootable: true,
|
||||
},
|
||||
|
|
@ -133,7 +133,7 @@ var ec2BasePartitionTables = distro.BasePartitionTableMap{
|
|||
ExtraPadding: ExtraPaddingGPT,
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 2048,
|
||||
Size: 1048576,
|
||||
Bootable: true,
|
||||
Type: disk.BIOSBootPartitionGUID,
|
||||
UUID: disk.BIOSBootPartitionUUID,
|
||||
|
|
@ -158,7 +158,7 @@ var ec2BasePartitionTables = distro.BasePartitionTableMap{
|
|||
ExtraPadding: ExtraPaddingGPT,
|
||||
Partitions: []disk.Partition{
|
||||
{
|
||||
Size: 409600,
|
||||
Size: 209715200,
|
||||
Type: disk.EFISystemPartitionGUID,
|
||||
UUID: disk.EFISystemPartitionUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
@ -171,7 +171,7 @@ var ec2BasePartitionTables = distro.BasePartitionTableMap{
|
|||
},
|
||||
},
|
||||
{
|
||||
Size: 1048576,
|
||||
Size: 536870912,
|
||||
Type: disk.FilesystemDataGUID,
|
||||
UUID: disk.FilesystemDataUUID,
|
||||
Filesystem: &disk.Filesystem{
|
||||
|
|
|
|||
|
|
@ -1085,8 +1085,8 @@ func mkfsStages(pt *disk.PartitionTable, device *osbuild.Device) []*osbuild.Stag
|
|||
stageDevice := osbuild.NewLoopbackDevice(
|
||||
&osbuild.LoopbackDeviceOptions{
|
||||
Filename: devOptions.Filename,
|
||||
Start: p.Start,
|
||||
Size: p.Size,
|
||||
Start: pt.BytesToSectors(p.Start),
|
||||
Size: pt.BytesToSectors(p.Size),
|
||||
},
|
||||
)
|
||||
switch p.Filesystem.Type {
|
||||
|
|
|
|||
|
|
@ -354,8 +354,8 @@ func sfdiskStageOptions(pt *disk.PartitionTable) *osbuild.SfdiskStageOptions {
|
|||
for idx, p := range pt.Partitions {
|
||||
partitions[idx] = osbuild.Partition{
|
||||
Bootable: p.Bootable,
|
||||
Size: p.Size,
|
||||
Start: p.Start,
|
||||
Start: pt.BytesToSectors(p.Start),
|
||||
Size: pt.BytesToSectors(p.Size),
|
||||
Type: p.Type,
|
||||
UUID: p.UUID,
|
||||
}
|
||||
|
|
@ -398,8 +398,8 @@ func copyFSTreeOptions(inputName, inputPipeline string, pt *disk.PartitionTable,
|
|||
devices[name] = *osbuild.NewLoopbackDevice(
|
||||
&osbuild.LoopbackDeviceOptions{
|
||||
Filename: devOptions.Filename,
|
||||
Start: p.Start,
|
||||
Size: p.Size,
|
||||
Start: pt.BytesToSectors(p.Start),
|
||||
Size: pt.BytesToSectors(p.Size),
|
||||
},
|
||||
)
|
||||
var mount *osbuild.Mount
|
||||
|
|
@ -462,7 +462,7 @@ func grub2InstStageOptions(filename string, pt *disk.PartitionTable, platform st
|
|||
return &osbuild.Grub2InstStageOptions{
|
||||
Filename: filename,
|
||||
Platform: platform,
|
||||
Location: pt.Partitions[0].Start,
|
||||
Location: pt.BytesToSectors(pt.Partitions[0].Start),
|
||||
Core: core,
|
||||
Prefix: prefix,
|
||||
}
|
||||
|
|
@ -476,7 +476,7 @@ func ziplInstStageOptions(kernel string, pt *disk.PartitionTable) *osbuild.ZiplI
|
|||
|
||||
return &osbuild.ZiplInstStageOptions{
|
||||
Kernel: kernel,
|
||||
Location: pt.Partitions[bootPartIndex].Start,
|
||||
Location: pt.BytesToSectors(pt.Partitions[bootPartIndex].Start),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue