From 7870756d9c65ea26fd6ee3d7482aaa5338472d9c Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 20 Jan 2024 10:49:49 +0100 Subject: [PATCH 1/2] partitioning: Avoid msdos special cases for other types 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 --- actions/image_partition_action.go | 56 ++++++++++++++++--------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/actions/image_partition_action.go b/actions/image_partition_action.go index ba675e18..61ac62bb 100644 --- a/actions/image_partition_action.go +++ b/actions/image_partition_action.go @@ -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 { @@ -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} @@ -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++ + } } } } From 325c8f76c70453c6a360a76bf787284d091e725d Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 20 Jan 2024 10:43:54 +0100 Subject: [PATCH 2/2] Expand gpt partitioning tests to more then 4 partitions The msdos partitioning now handles more then 4 partitions by inserting an extended partition. To test this doesn't confuse the gpt partitioning expand that test to more then 4 partitions as well. --- tests/partitioning/expected.json | 72 ++++++++++++++++++++++++++++---- tests/partitioning/test.yaml | 34 +++++++++++++-- 2 files changed, 95 insertions(+), 11 deletions(-) diff --git a/tests/partitioning/expected.json b/tests/partitioning/expected.json index 3b2a9bdb..a2dcc6aa 100644 --- a/tests/partitioning/expected.json +++ b/tests/partitioning/expected.json @@ -1,14 +1,70 @@ { "partitiontable": { - "label":"gpt", - "id":"12345678-1234-1234-1234-123456789012", - "device":"test.img", - "unit":"sectors", - "firstlba":34, - "lastlba":7812466, - "sectorsize":512, + "label": "gpt", + "id": "12345678-1234-1234-1234-123456789012", + "device": "test.img", + "unit": "sectors", + "firstlba": 34, + "lastlba": 15624966, + "sectorsize": 512, "partitions": [ - {"node":"test.img1", "start":34, "size":7812433, "type":"0FC63DAF-8483-4772-8E79-3D69D8477DE4", "uuid":"87654321-1234-5678-9012-345678901234", "name":"system"} + { + "node": "test.img1", + "start": 34, + "size": 499967, + "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4", + "uuid": "7BA1B99D-7942-450A-921B-F394A0A065AF", + "name": "boot" + },{ + "node": "test.img2", + "start": 500001, + "size": 3406250, + "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4", + "uuid": "87654321-1234-5678-9012-345678901234", + "name": "system" + },{ + "node": "test.img3", + "start": 3906251, + "size": 1953125, + "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4", + "uuid": "713CA942-5DB4-41F8-A365-E8F1CA967D7A", + "name": "data0" + },{ + "node": "test.img4", + "start": 5859376, + "size": 1953125, + "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4", + "uuid": "05D13CA0-7EA3-48D2-9824-8C94263E5692", + "name": "data1" + },{ + "node": "test.img5", + "start": 7812501, + "size": 1953125, + "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4", + "uuid": "C86924DB-49D2-47D8-BBB7-BB56426A8934", + "name": "data2" + },{ + "node": "test.img6", + "start": 9765626, + "size": 1953125, + "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4", + "uuid": "B0F4D633-B66A-44B6-933A-E77A0144B275", + "name": "data3" + },{ + "node": "test.img7", + "start": 11718751, + "size": 1953125, + "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4", + "uuid": "8BDAE85E-E473-4D77-B09D-43E1D6F741DA", + "name": "data4" + },{ + "node": "test.img8", + "start": 13671876, + "size": 1953091, + "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4", + "uuid": "F9272482-3F7E-44E3-8D99-C24023EB3317", + "name": "data5" + } ] } } diff --git a/tests/partitioning/test.yaml b/tests/partitioning/test.yaml index 3a03bfc2..0638d908 100644 --- a/tests/partitioning/test.yaml +++ b/tests/partitioning/test.yaml @@ -4,18 +4,46 @@ actions: - action: image-partition description: Partition the image imagename: test.img - imagesize: 4G + imagesize: 8G partitiontype: gpt diskid: 12345678-1234-1234-1234-123456789012 mountpoints: - mounpoint: / partition: system partitions: + - name: boot + fs: ext2 + start: 0% + end: 256M - name: system + fs: ext4 + start: 256m + end: 2G partuuid: 87654321-1234-5678-9012-345678901234 + - name: data0 fs: ext4 - start: 0% - end: 100% + start: 2G + end: 3G + - name: data1 + fs: ext4 + start: 3G + end: 4G + - name: data2 + fs: ext4 + start: 4G + end: 5G + - name: data3 + fs: ext4 + start: 5G + end: 6G + - name: data4 + fs: ext4 + start: 6G + end: 7G + - name: data5 + fs: ext4 + start: 7G + end: 8G - action: run chroot: false