Skip to content

Commit c4b92cf

Browse files
committed
support resize GuestOS disk
Signed-off-by: Songpon Srisawai <songpon.ssw@gmail.com>
1 parent cd9d260 commit c4b92cf

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

cmd/limactl/edit.go

+8
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ func editAction(cmd *cobra.Command, args []string) error {
157157
if err != nil {
158158
return err
159159
}
160+
161+
// Apply config from .ymal to store.instance
162+
inst, err = store.Inspect(inst.Name)
163+
164+
if err := inst.ResizeGuestOSDisk(); err != nil {
165+
return err
166+
}
167+
160168
return instance.Start(ctx, inst, "", false)
161169
}
162170

pkg/store/instance.go

+24
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"io"
1111
"os"
12+
"os/exec"
1213
"path/filepath"
1314
"runtime"
1415
"strconv"
@@ -131,6 +132,7 @@ func Inspect(instName string) (*Instance, error) {
131132
}
132133
disk, err := units.RAMInBytes(*y.Disk)
133134
if err == nil {
135+
// logrus.Infof("Inst:%s changing size %d to %d \n", inst.Name, inst.Disk, disk)
134136
inst.Disk = disk
135137
}
136138
inst.AdditionalDisks = y.AdditionalDisks
@@ -437,3 +439,25 @@ func (inst *Instance) Unprotect() error {
437439
inst.Protected = false
438440
return nil
439441
}
442+
443+
func (inst *Instance) ResizeGuestOSDisk() error {
444+
fName := filepath.Join(inst.Dir, filenames.DiffDisk)
445+
446+
cmd := exec.Command("limactl", "disk", "add", inst.Name, "--filename", fName)
447+
if err := cmd.Run(); err != nil {
448+
logrus.Fatalf("Failed to add disk: %v", err)
449+
}
450+
451+
cmd = exec.Command("limactl", "disk", "resize", inst.Name, "--size", string(units.BytesSize(float64(inst.Disk))))
452+
if err := cmd.Run(); err != nil {
453+
logrus.Fatalf("Failed to resize disk: %v", err)
454+
}
455+
456+
cmd = exec.Command("limactl", "disk", "delete", inst.Name)
457+
if err := cmd.Run(); err != nil {
458+
logrus.Fatalf("Failed to remove disk: %v", err)
459+
}
460+
461+
logrus.Infof("Edit GuestOS size to %s", units.BytesSize(float64(inst.Disk)))
462+
return nil
463+
}

0 commit comments

Comments
 (0)