Skip to content

Commit

Permalink
Add mkfs args to additional disks format
Browse files Browse the repository at this point in the history
For instance when running glusterfs, it needs xfs args.

Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed Jul 25, 2023
1 parent 5db82ac commit 2abdc61
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion pkg/cidata/cidata.TEMPLATE.d/boot/05-lima-disks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,7 +23,8 @@ 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"
# shellcheck disable=SC2086
mkfs.$FORMAT_FSTYPE $FORMAT_FSARGS -L "lima-${DISK_NAME}" "/dev/${DEVICE_NAME}1"
fi
fi

Expand Down
1 change: 1 addition & 0 deletions pkg/cidata/cidata.TEMPLATE.d/lima.env
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ LIMA_CIDATA_DISK_{{$i}}_NAME={{$disk.Name}}
LIMA_CIDATA_DISK_{{$i}}_DEVICE={{$disk.Device}}
LIMA_CIDATA_DISK_{{$i}}_FORMAT={{$disk.Format}}
LIMA_CIDATA_DISK_{{$i}}_FSTYPE={{$disk.FSType}}
LIMA_CIDATA_DISK_{{$i}}_FSARGS={{range $j, $arg := $disk.FSArgs}}{{if $j}} {{end}}{{$arg}}{{end}}
{{- end}}
LIMA_CIDATA_GUEST_INSTALL_PREFIX={{ .GuestInstallPrefix }}
{{- if .Containerd.User}}
Expand Down
1 change: 1 addition & 0 deletions pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
Device: diskDeviceNameFromOrder(i),
Format: format,
FSType: fstype,
FSArgs: d.FSArgs,
})
}

Expand Down
1 change: 1 addition & 0 deletions pkg/cidata/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Disk struct {
Device string
Format bool
FSType string
FSArgs []string
}
type TemplateArgs struct {
Name string // instance name
Expand Down
7 changes: 4 additions & 3 deletions pkg/limayaml/limayaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,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 {
Expand Down
5 changes: 5 additions & 0 deletions pkg/limayaml/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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")
}

0 comments on commit 2abdc61

Please sign in to comment.