diff --git a/examples/default.yaml b/examples/default.yaml index 4fb77a50c2d9..276b01965c31 100644 --- a/examples/default.yaml +++ b/examples/default.yaml @@ -109,6 +109,8 @@ additionalDisks: # - "data" # or a list of disk objects with extra parameters, for example: # - name: "data" +# format: true +# fsType: "ext4" ssh: # A localhost port of the host. Forwarded to port 22 of the guest. 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 eef49937f85b..a4802e0299f5 100644 --- a/pkg/cidata/cidata.TEMPLATE.d/boot/05-lima-disks.sh +++ b/pkg/cidata/cidata.TEMPLATE.d/boot/05-lima-disks.sh @@ -12,14 +12,20 @@ get_disk_var() { for i in $(seq 0 $((LIMA_CIDATA_DISKS - 1))); do DISK_NAME="$(get_disk_var "$i" "NAME")" DEVICE_NAME="$(get_disk_var "$i" "DEVICE")" + FORMAT_DISK="$(get_disk_var "$i" "FORMAT")" + FORMAT_FSTYPE="$(get_disk_var "$i" "FSTYPE")" + + test -n "$FORMAT_DISK" || FORMAT_DISK=true + test -n "$FORMAT_FSTYPE" || FORMAT_FSTYPE=ext4 # first time setup if [[ ! -b "/dev/disk/by-label/lima-${DISK_NAME}" ]]; then - # TODO: skip if disk is tagged as "raw" - echo 'type=linux' | sfdisk --label gpt "/dev/${DEVICE_NAME}" - mkfs.ext4 -L "lima-${DISK_NAME}" "/dev/${DEVICE_NAME}1" + if $FORMAT_DISK; then + echo 'type=linux' | sfdisk --label gpt "/dev/${DEVICE_NAME}" + mkfs.$FORMAT_FSTYPE -L "lima-${DISK_NAME}" "/dev/${DEVICE_NAME}1" + fi fi mkdir -p "/mnt/lima-${DISK_NAME}" - mount -t ext4 "/dev/${DEVICE_NAME}1" "/mnt/lima-${DISK_NAME}" + mount -t $FORMAT_FSTYPE "/dev/${DEVICE_NAME}1" "/mnt/lima-${DISK_NAME}" done diff --git a/pkg/cidata/cidata.TEMPLATE.d/lima.env b/pkg/cidata/cidata.TEMPLATE.d/lima.env index 941286c85192..44db5aa636bb 100644 --- a/pkg/cidata/cidata.TEMPLATE.d/lima.env +++ b/pkg/cidata/cidata.TEMPLATE.d/lima.env @@ -11,6 +11,10 @@ LIMA_CIDATA_DISKS={{ len .Disks }} {{- range $i, $disk := .Disks}} LIMA_CIDATA_DISK_{{$i}}_NAME={{$disk.Name}} LIMA_CIDATA_DISK_{{$i}}_DEVICE={{$disk.Device}} +LIMA_CIDATA_DISK_{{$i}}_FORMAT={{$disk.Format}} +{{- if $disk.FSType}} +LIMA_CIDATA_DISK_{{$i}}_FSTYPE={{$disk.FSType}} +{{- end}} {{- end}} {{- if .Containerd.User}} LIMA_CIDATA_CONTAINERD_USER=1 diff --git a/pkg/cidata/cidata.go b/pkg/cidata/cidata.go index ddba61775ad6..7642df100806 100644 --- a/pkg/cidata/cidata.go +++ b/pkg/cidata/cidata.go @@ -203,9 +203,19 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort } for i, d := range y.AdditionalDisks { + format := true + if d.Format != nil { + format = *d.Format + } + fstype := "" + if d.FSType != nil { + fstype = *d.FSType + } args.Disks = append(args.Disks, Disk{ Name: d.Name, Device: diskDeviceNameFromOrder(i), + Format: format, + FSType: fstype, }) } diff --git a/pkg/cidata/template.go b/pkg/cidata/template.go index dff7a0a3ebe1..32a38616590e 100644 --- a/pkg/cidata/template.go +++ b/pkg/cidata/template.go @@ -48,6 +48,8 @@ type BootCmds struct { type Disk struct { Name string Device string + Format bool + FSType string } type TemplateArgs struct { Name string // instance name diff --git a/pkg/limayaml/limayaml.go b/pkg/limayaml/limayaml.go index 419a9ce207e7..0c47462ca521 100644 --- a/pkg/limayaml/limayaml.go +++ b/pkg/limayaml/limayaml.go @@ -78,6 +78,8 @@ 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"` } type Mount struct { diff --git a/pkg/limayaml/load_test.go b/pkg/limayaml/load_test.go index 30323c643d45..351e79bd6d4d 100644 --- a/pkg/limayaml/load_test.go +++ b/pkg/limayaml/load_test.go @@ -40,15 +40,23 @@ additionalDisks: assert.NilError(t, err) assert.Equal(t, len(y.AdditionalDisks), 1) assert.Equal(t, y.AdditionalDisks[0].Name, "name") + assert.Assert(t, y.AdditionalDisks[0].Format == nil) + assert.Assert(t, y.AdditionalDisks[0].FSType == nil) } func TestLoadDiskStruct(t *testing.T) { s := ` additionalDisks: - name: "name" + format: false + fsType: "xfs" ` y, err := Load([]byte(s), "disk.yaml") assert.NilError(t, err) assert.Assert(t, len(y.AdditionalDisks) == 1) assert.Equal(t, y.AdditionalDisks[0].Name, "name") + assert.Assert(t, y.AdditionalDisks[0].Format != nil) + assert.Equal(t, *y.AdditionalDisks[0].Format, false) + assert.Assert(t, y.AdditionalDisks[0].FSType != nil) + assert.Equal(t, *y.AdditionalDisks[0].FSType, "xfs") }