Skip to content

Commit

Permalink
partitioning: Avoid msdos special cases for other types
Browse files Browse the repository at this point in the history
The extended partition handling for msdos accidentally got applied to
all partition types. Ensure and be more defensive against msdos special
handling getting applied to other partition types

Fixes: #473
  • Loading branch information
sjoerdsimons committed Jan 20, 2024
1 parent 463b97d commit 7870756
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions actions/image_partition_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,7 @@ func (i ImagePartitionAction) Run(context *debos.DebosContext) error {
}

var name string
if i.PartitionType == "gpt" {
name = p.PartLabel
} else {
if i.PartitionType == "msdos" {
if len(i.Partitions) <= 4 {
name = "primary"
} else {
Expand All @@ -494,6 +492,8 @@ func (i ImagePartitionAction) Run(context *debos.DebosContext) error {
name = "logical"
}
}
} else {
name = p.PartLabel
}

command := []string{"parted", "-a", "none", "-s", "--", context.Image, "mkpart", name}
Expand Down Expand Up @@ -671,30 +671,32 @@ func (i ImagePartitionAction) PostMachineCleanup(context *debos.DebosContext) er

func (i *ImagePartitionAction) Verify(context *debos.DebosContext) error {

for idx, _ := range i.Partitions {
p := &i.Partitions[idx]

if idx == 3 && len(i.Partitions) > 4 {
var name string
var part Partition

name = "extended"
part.number = idx+1
part.Name = name
part.Start = p.Start
tmp_n := len(i.Partitions)-1
tmp := &i.Partitions[tmp_n]
part.End = tmp.End
part.FS = "none"

i.Partitions = append(i.Partitions[:idx+1], i.Partitions[idx:]...)
i.Partitions[idx] = part

num := 1
for idx, _ := range i.Partitions {
p := &i.Partitions[idx]
p.number = num
num++
if i.PartitionType == "msdos" {
for idx, _ := range i.Partitions {
p := &i.Partitions[idx]

if idx == 3 && len(i.Partitions) > 4 {
var name string
var part Partition

name = "extended"
part.number = idx + 1
part.Name = name
part.Start = p.Start
tmp_n := len(i.Partitions) - 1
tmp := &i.Partitions[tmp_n]
part.End = tmp.End
part.FS = "none"

i.Partitions = append(i.Partitions[:idx+1], i.Partitions[idx:]...)
i.Partitions[idx] = part

num := 1
for idx, _ := range i.Partitions {
p := &i.Partitions[idx]
p.number = num
num++
}
}
}
}
Expand Down

0 comments on commit 7870756

Please sign in to comment.