Skip to content

Fix: resize GuestOS disk #3437

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

songponssw
Copy link
Contributor

Try to fix: #1448

How Lima edit disk

  • The limactl edit updates the disk value to the store. It does not resize disk image. Users have to manually resize by qemu-img
  • Does not support --shrink (fails to start instance)

What I did

  • create a limactl disk add command to add an existing qcow2 disk to Lima.
  • To update GuestOS disk, before start instance, It adds a diffdisk of the instance to Lima, resize, and delete.

@songponssw songponssw marked this pull request as ready for review April 17, 2025 05:34
@songponssw songponssw marked this pull request as draft April 17, 2025 05:34
func (inst *Instance) ResizeGuestOSDisk() error {
fName := filepath.Join(inst.Dir, filenames.DiffDisk)

cmd := exec.Command("limactl", "disk", "add", inst.Name, "--filename", fName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

limactl shouldn't invoke limactl itself unless it is inevitable or there is a significant benefit

@songponssw songponssw force-pushed the feat-edit-disk branch 2 times, most recently from b3f95e5 to a0800cf Compare April 17, 2025 09:18
@songponssw songponssw closed this Apr 25, 2025
Signed-off-by: Songpon Srisawai <songpon.ssw@gmail.com>
@songponssw songponssw reopened this Apr 25, 2025
@songponssw
Copy link
Contributor Author

This implementation works fine for increasing the disk size.
However, it returns an error when shrinking, as disk shrinking is not supported.

@AkihiroSuda
Copy link
Member

Needs rebase

@@ -157,6 +157,12 @@ func editAction(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}

inst, err = store.Inspect(inst.Name)
Copy link
Member

@AkihiroSuda AkihiroSuda May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason to inspect the instance twice should be explained as a code comment

format := string(img.Type())

if inst.Disk == diskSize {
logrus.Infof("diffDisk size does not changed")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This debug message can be removed

return errors.New("diffDisk: Shrinking is currently unavailable")
}

tmpDiskDir := filepath.Join(filenames.DisksDir, inst.Name+"-tmp")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DisksDir is dedicated for additional disks, and should not be used for the main disk

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's the case, it would make sense to implement a separate ResizeDiffDisk() function specifically for resizing the diffDisk in the instance directory (e.g., ~/.lima/default/diffdisk)?

This implementation tries to reuse ResizeDataDisk(), which was originally intended for additional disks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changing the disk size in lima.yaml should resize the disk
2 participants