Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix accidental application of msdos quirks to gpt #475

Merged
merged 2 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
72 changes: 64 additions & 8 deletions tests/partitioning/expected.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
34 changes: 31 additions & 3 deletions tests/partitioning/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down