Skip to content
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

Add snapshotting functionality #368

Open
cweagans opened this issue Oct 29, 2021 · 8 comments
Open

Add snapshotting functionality #368

cweagans opened this issue Oct 29, 2021 · 8 comments
Labels
enhancement New feature or request

Comments

@cweagans
Copy link

I would like to be able to create one or more snapshots of a lima vm and be able to roll back to some specified snapshot. I'm thinking this would be a copy of the qcow2 images stored in the ~/.lima/machine-name/ directory. It would be totally fine (and probably desirable) to shut the machine down before making a copy of the images.

This would be useful for e.g. testing a provisioning script. I could set up the machine with a base install of ubuntu, take a snapshot, and then be able to quickly roll back to the base state of the machine without necessarily re-doing the machine from scratch. It could also be useful for testing potentially destructive operations inside the VM.

@afbjorklund
Copy link
Member

@vsoch
Copy link

vsoch commented Dec 17, 2023

Silly question - I saved a snapshot, e.g.,:

$ limactl snapshot create flux-0 --tag flux-instance-gcp-12-17-2023

And I'm wondering where it saves to?

$ limactl snapshot list flux-0
WARN[0000] `limactl snapshot` is experimental           
INFO[0000] Sending HMP info command                     
ID        TAG               VM SIZE                DATE     VM CLOCK     ICOUNT
--        flux-instance-gcp-12-17-2023 3.84 GiB 2023-12-17 12:29:02 00:44:35.838  

I see it uses qemu-img here: https://github.com/lima-vm/lima/pull/1054/files#diff-25a805e06b16efefb1e5acb2009e512cca20865126e3a6afa52df59dcb4cf0fbR158 but I'm not experienced enough to know how to get it. I'd like to be able to export the VM and then, for example, import it into a cloud via storage. Or do I not need a snapshot (which is a diff) and just want one of these files here?

$ ls /home/vanessa/.lima/flux-0/
basedisk    diffdisk  ha.pid   ha.stderr.log  lima.yaml  qmp.sock    serial.sock  serialv.sock  ssh.sock
cidata.iso  ga.sock   ha.sock  ha.stdout.log  qemu.pid   serial.log  serialv.log  ssh.config

If the basedisk is some format I can use, or I can load the iso into a VM image (which I think I know how to do) that might fit the bill - just trying to figure out the right (or recommended) path. Thanks for the help!

@afbjorklund
Copy link
Member

afbjorklund commented Dec 18, 2023

The snapshots, like the normal contents, are stored in the diffdisk. The basedisk is the readonly cloud image.

Both are normally in the QCOW2 file format, unless using lima-alpine in which case the basedisk is an ISO image.

You can learn this, using the regular file tool.

The diffdisk has the basedisk, as a "backing file".

https://www.qemu.org/docs/master/system/images.html

You need both files, but the basedisk is the same as in cache.


The qemu-img tool can combine the files into one image, and export into various different formats.

It also allows for manipulating the snapshots, but requires that the virtual machine using it is offline.

@vsoch
Copy link

vsoch commented Dec 18, 2023

You can learn this, using the regular file tool.

Great, thank you! Any reason they don't have an extension so it's obvious to the untrained eye?

@afbjorklund
Copy link
Member

afbjorklund commented Dec 18, 2023

Any reason they don't have an extension so it's obvious to the untrained eye?

No particular reason, just UNIX. Like "README", versus "README.txt"?

Think I had to add DOS extensions like .img and .iso, for VirtualBox to work
ff5238c
It would crash without them... Added some symlinks, for the old names.
(which of course probably wouldn't work on actual Windows, but anyway)

@vsoch
Copy link

vsoch commented Dec 18, 2023

Gotcha! And super cool - thanks for giving me this nugget of info. I know about file but didn't consider trying it here (I was going to try opening it in vim to see if there was an identifable header, like with ELF, haha).

$ file basedisk 
basedisk: QEMU QCOW2 Image (v2), 2361393152 bytes
$ file diffdisk 
diffdisk: QEMU QCOW2 Image (v3), has backing file (path /home/vanessa/.lima/flux-0/basedisk), 268435456000 bytes

@afbjorklund
Copy link
Member

You can also use qemu-img info, if you want the details.

@vsoch
Copy link

vsoch commented Dec 19, 2023

Even better!

image

I was able to load this into GCP and (soon) am going to boot it up. So far no issues!

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

No branches or pull requests

4 participants