From da773ccbc899d2f5b236f80db303062693f6f2b6 Mon Sep 17 00:00:00 2001 From: Daichi Fukui Date: Tue, 14 Sep 2021 10:40:14 +0900 Subject: [PATCH] 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 Signed-off-by: Daichi Fukui --- actions/image_partition_action.go | 41 ++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/actions/image_partition_action.go b/actions/image_partition_action.go index e2a81ff..0797ecc 100644 --- a/actions/image_partition_action.go +++ b/actions/image_partition_action.go @@ -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" {