From a23bd9238749586a1aa4ea473baa3642bf2cc54b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sat, 29 Apr 2023 13:29:30 +0200 Subject: [PATCH] Add mkfs args to additional disks format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For instance when running glusterfs, it needs xfs args. Signed-off-by: Anders F Björklund --- pkg/cidata/cidata.TEMPLATE.d/boot/05-lima-disks.sh | 3 ++- pkg/cidata/cidata.TEMPLATE.d/lima.env | 3 +++ pkg/cidata/cidata.go | 1 + pkg/cidata/template.go | 1 + pkg/limayaml/limayaml.go | 7 ++++--- pkg/limayaml/load_test.go | 5 +++++ 6 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/cidata/cidata.TEMPLATE.d/boot/05-lima-disks.sh b/pkg/cidata/cidata.TEMPLATE.d/boot/05-lima-disks.sh index a4802e0299f5..6c2a7205a8d7 100644 --- a/pkg/cidata/cidata.TEMPLATE.d/boot/05-lima-disks.sh +++ b/pkg/cidata/cidata.TEMPLATE.d/boot/05-lima-disks.sh @@ -14,6 +14,7 @@ for i in $(seq 0 $((LIMA_CIDATA_DISKS - 1))); do DEVICE_NAME="$(get_disk_var "$i" "DEVICE")" FORMAT_DISK="$(get_disk_var "$i" "FORMAT")" FORMAT_FSTYPE="$(get_disk_var "$i" "FSTYPE")" + FORMAT_FSARGS="$(get_disk_var "$i" "FSARGS")" test -n "$FORMAT_DISK" || FORMAT_DISK=true test -n "$FORMAT_FSTYPE" || FORMAT_FSTYPE=ext4 @@ -22,7 +23,7 @@ for i in $(seq 0 $((LIMA_CIDATA_DISKS - 1))); do if [[ ! -b "/dev/disk/by-label/lima-${DISK_NAME}" ]]; then if $FORMAT_DISK; then echo 'type=linux' | sfdisk --label gpt "/dev/${DEVICE_NAME}" - mkfs.$FORMAT_FSTYPE -L "lima-${DISK_NAME}" "/dev/${DEVICE_NAME}1" + mkfs.$FORMAT_FSTYPE $FORMAT_FSARGS -L "lima-${DISK_NAME}" "/dev/${DEVICE_NAME}1" fi fi diff --git a/pkg/cidata/cidata.TEMPLATE.d/lima.env b/pkg/cidata/cidata.TEMPLATE.d/lima.env index 44db5aa636bb..16ac9594375e 100644 --- a/pkg/cidata/cidata.TEMPLATE.d/lima.env +++ b/pkg/cidata/cidata.TEMPLATE.d/lima.env @@ -15,6 +15,9 @@ LIMA_CIDATA_DISK_{{$i}}_FORMAT={{$disk.Format}} {{- if $disk.FSType}} LIMA_CIDATA_DISK_{{$i}}_FSTYPE={{$disk.FSType}} {{- end}} +{{- if $disk.FSArgs}} +LIMA_CIDATA_DISK_{{$i}}_FSARGS={{range $j, $arg := $disk.FSArgs}}{{if $j}} {{end}}{{$arg}}{{end}} +{{- end}} {{- end}} {{- if .Containerd.User}} LIMA_CIDATA_CONTAINERD_USER=1 diff --git a/pkg/cidata/cidata.go b/pkg/cidata/cidata.go index 7642df100806..ffedb8540675 100644 --- a/pkg/cidata/cidata.go +++ b/pkg/cidata/cidata.go @@ -216,6 +216,7 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort Device: diskDeviceNameFromOrder(i), Format: format, FSType: fstype, + FSArgs: d.FSArgs, }) } diff --git a/pkg/cidata/template.go b/pkg/cidata/template.go index 32a38616590e..d980a1e71bc0 100644 --- a/pkg/cidata/template.go +++ b/pkg/cidata/template.go @@ -50,6 +50,7 @@ type Disk struct { Device string Format bool FSType string + FSArgs []string } type TemplateArgs struct { Name string // instance name diff --git a/pkg/limayaml/limayaml.go b/pkg/limayaml/limayaml.go index 0c47462ca521..c83b8b2f0944 100644 --- a/pkg/limayaml/limayaml.go +++ b/pkg/limayaml/limayaml.go @@ -77,9 +77,10 @@ type Image struct { } type Disk struct { - Name string `yaml:"name" json:"name"` // REQUIRED - Format *bool `yaml:"format,omitempty" json:"format,omitempty"` - FSType *string `yaml:"fsType,omitempty" json:"fsType,omitEmpty"` + Name string `yaml:"name" json:"name"` // REQUIRED + Format *bool `yaml:"format,omitempty" json:"format,omitempty"` + FSType *string `yaml:"fsType,omitempty" json:"fsType,omitEmpty"` + FSArgs []string `yaml:"fsArgs,omitempty" json:"fsArgs,omitEmpty"` } type Mount struct { diff --git a/pkg/limayaml/load_test.go b/pkg/limayaml/load_test.go index 351e79bd6d4d..0a7c09fe5142 100644 --- a/pkg/limayaml/load_test.go +++ b/pkg/limayaml/load_test.go @@ -42,6 +42,7 @@ additionalDisks: assert.Equal(t, y.AdditionalDisks[0].Name, "name") assert.Assert(t, y.AdditionalDisks[0].Format == nil) assert.Assert(t, y.AdditionalDisks[0].FSType == nil) + assert.Assert(t, y.AdditionalDisks[0].FSArgs == nil) } func TestLoadDiskStruct(t *testing.T) { @@ -50,6 +51,7 @@ additionalDisks: - name: "name" format: false fsType: "xfs" + fsArgs: ["-i","size=512"] ` y, err := Load([]byte(s), "disk.yaml") assert.NilError(t, err) @@ -59,4 +61,7 @@ additionalDisks: assert.Equal(t, *y.AdditionalDisks[0].Format, false) assert.Assert(t, y.AdditionalDisks[0].FSType != nil) assert.Equal(t, *y.AdditionalDisks[0].FSType, "xfs") + assert.Assert(t, len(y.AdditionalDisks[0].FSArgs) == 2) + assert.Equal(t, y.AdditionalDisks[0].FSArgs[0], "-i") + assert.Equal(t, y.AdditionalDisks[0].FSArgs[1], "size=512") }