actions/image-partition: allow extended and logical

This commit allows us to create extended or logical
partitions on MBR partition table (msdos) in order to
address the following issues:

* Because part-type for parted is hardcoded with primary,
we cannot create more than 4 partitions using extended and
logical.

* Even if we manage to create extended and logical partitions,
the verificaton step fails because the Verify function assumes
that the partition number is always sequetially incremental.

This commit makes it possible that if the number of partitions
is more than 4, 3 of them are automatically created as primary,
1 of them is extended, and the remaining partitions are logical.

Signed-off-by: Daniel Sangorrin <daniel.sangorrin@toshiba.co.jp>
Signed-off-by: Daichi Fukui <daichi1.fukui@toshiba.co.jp>
This commit is contained in:
Daichi Fukui
2021-09-14 10:40:14 +09:00
committed by Sjoerd Simons
parent 03ec3cbfab
commit da773ccbc8

View File

@@ -479,7 +479,17 @@ func (i ImagePartitionAction) Run(context *debos.DebosContext) error {
if i.PartitionType == "gpt" {
name = p.PartLabel
} else {
name = "primary"
if cap(i.Partitions) <= 4 {
name = "primary"
} else {
if idx < 3 {
name = "primary"
} else if idx == 3 {
name = "extended"
} else {
name = "logical"
}
}
}
command := []string{"parted", "-a", "none", "-s", "--", context.Image, "mkpart", name}
@@ -656,6 +666,35 @@ 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 && cap(i.Partitions) > 4 {
var name string
var part Partition
name = "extended"
part.number = idx+1
part.Name = name
part.Start = p.Start
tmp_n := cap(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 len(i.GptGap) > 0 {
log.Println("WARNING: special version of parted is needed for 'gpt_gap' option")
if i.PartitionType != "gpt" {