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

snapshots / disposable VMs #2688

Closed
ThomasWaldmann opened this issue Jul 29, 2021 · 25 comments
Closed

snapshots / disposable VMs #2688

ThomasWaldmann opened this issue Jul 29, 2021 · 25 comments
Labels
enhancement New feature or request

Comments

@ThomasWaldmann
Copy link

ThomasWaldmann commented Jul 29, 2021

I'm used to use Qubes OS on my other machine, especially using disposable VMs for random web surfing or potentially dangerous stuff (like working with files from untrusted sources).

A disposable VM is a VM created from a given state (template VM), executes normally, but when shut down, all changes get thrown away. E.g. if you do web surfing, you do not have to worry about getting tracked long-term by cookies or similar mechanisms - or if you try installing random software just to have a quick look, you do not have to worry about spoiling your system somehow, because all state will get thrown away automatically at shutdown time. Also malware does not have a chance to persist.

Such a dispVM could be implemented with qemu temporary snapshots.

Normal snapshots would be also useful as a safety net, e.g. before running OS upgrades or critical SW installations inside your VMs. If anything goes wrong, one can just revert to a known-good state in a snapshot.

@ThomasWaldmann ThomasWaldmann added the enhancement New feature or request label Jul 29, 2021
@ThomasWaldmann
Copy link
Author

BTW, oracle virtualbox has a GUI for managing snapshots.

@juanandresgs
Copy link

Looks like #3067 is inching us closer. Any chance we can get a snapshot management view? This would be hugely valuable.
Willing to donate to support dev.

@ktprograms
Copy link
Contributor

Hi @juanandresgs, what do you mean by a snapshot management view?

BTW the PR is only for temporary snapshots, not qcow2 snapshots with backing files.

@ThomasWaldmann
Copy link
Author

@ktprograms if you have virtualbox installed somewhere, just have a look at its snapshots dialogues.

One can create (permanent) snapshots there, go back to the state of some snapshot, delete/merge snapshots, etc.

@ktprograms
Copy link
Contributor

I just realised, QEMU seems to have 3 kinds of snapshots.

  1. Using the -snapshot option for a temporary disposable VM.
  2. qcow2 backing files to have multiple images based on a single 'parent' image.
  3. qcow2 save states which you can create and revert back to using the qemu-img snapshot subcommand.

If I understand it, you would like (3) to be implemented, right?

@ThomasWaldmann
Copy link
Author

Well, guess we need 1 and 3.

2 would be also nice to have as a space saver maybe.

@ktprograms
Copy link
Contributor

@osy as I understand from the Git history, directly using qemu-img as a dylib was removed due to some problem on iOS, right? These snapshot features would be a lot easier to implement by calling qemu-img instead of implementing it from scratch. What was the problem on iOS and is there any solution?

@juanandresgs
Copy link

Definitely thinking (3). I've added the picture of the snapshot manager from VMWare Fusion for reference.
Screen Shot 2021-09-12 at 11 29 13 PM

@jimmont
Copy link

jimmont commented Nov 27, 2021

@ktprograms I'm looking to use "2." using snapshot against a backing file and "3." save states (I assume this is like virtualbox, or perhaps I need to read up on it). I attempted to setup 2 manually using qemu-img and UTM's image structure and when changing the settings from the parent to the snapshot the parent image is automatically deleted losing my setup entirely.

@ktprograms
Copy link
Contributor

ktprograms commented Nov 28, 2021

@jimmont I'm sorry to hear that it deleted your disk images, that happened to me when I was testing (2) as well. It seems that if you mess with the drives (create new ones or move/resize old ones) manually from the command line while UTM is still open, then it deletes the drives. If you have closed UTM first, then you can try and create the new disk images with backing files, but I find the other problem is that the backing file can't be properly accessed if it isn't in the same folder as the new image, so the (temporary) solution I came up with is to hard link the backing file into each VM folder.

However, please note that this is not a supported configuration and (as you have found out) runs the risk of you losing data.

(3) would be implemented by either directly using qemu-img snapshot ... or by using whatever internal mechanism qemu-img snapshot ... uses.

@rvaliev
Copy link

rvaliev commented Dec 1, 2021

The ability of making snapshots will be very nice feature for the users whose workflow relies on on VirtualBox and want to move to the M1 devices. (both UI and command line functionality)

@juanandresgs
Copy link

Is there a dev interested in implementing this? We can start a donation drive 🆘

@ghost
Copy link

ghost commented Dec 18, 2021

+1 from me. This is a highly important feature, especially when you want to install software that is non-trivial to install and highly probable to fail. You can then revert back to a safe state, and retry.

From Parallels and VirtualBox I know their handling, and that's what should be provided here as well (as described above with the screenshot from @juanandresgs .

In the meantime: I tried to use qemu directly to create snapshots, but for unknown reasons this did not work (qemu does not recognize the machine). Am I doing something wrong, or is there an incompatibility?

@ktprograms
Copy link
Contributor

Hi @innoreq, can you please share the debug log / error alert because I don't understand what you mean by qemu does not recognise the machine?

The reason why this feature isn't very easy to implement is because, for iOS compatibility, the qemu-img command cannot be used.

Manually replicating the qemu-img snapshot command wouldn't be simple and would be highly likely to be incorrect in some way and corrupt the disk image.

Currently, the best solution is to Clone your VMs, and because they are copied using APFS Copy on Write clones, it will not use extra space until you start changing one of the VMs, at which point the amount of space used will be the delta between the original and the second VM. For more information you can look at man 2 clonefile and the -c option of the macOS cp command.

Note that even though it's a Copy on Write clone, you can freely use either VM (it won't break if you start using / modifying the original VM, even if you use both at the same time).

@marcelloromani
Copy link

marcelloromani commented Jan 6, 2022

I ended up here as I was also looking for something similar to VBox's snapshot management.
I realised with the current UTM functionality it's pretty easy to get the same end result.
I created a new Ubuntu machine, installed all the basic packages I needed for my tests and other files (public keys for passwordless logins, etc.). I named this machine "Template".

Whenever I need to test something on the machine, I simply clone the Template machine into what I consider a disposabile test machine (e.g. "Test1"), start it work on it. The only thing to lookout for is ensuring I don't accidentally start the Template machine (which would change the state of the disk image).

When I'm done, I simply delete the Test1 machine and create a new clone.

@ktprograms
Copy link
Contributor

Now that qemu-img is being built as a shared library and is usable from code on macOS (see b65c9f6), it should be possible to implement this.

@osy Can you confirm that this is correct?

@osy
Copy link
Contributor

osy commented Jan 11, 2022

Yes I plan to add other qemu-info functionalities as well. But right now it only works on macOS because we can launch new processes. On iOS you can call it once but if you run it again it errors.

@ktprograms
Copy link
Contributor

@osy I can work on implementing save states using qemu-img snapshot this week, but FYI my other suggestion for multiple qcow2 images based off a backing file won't be doable yet until #3227 is merged (that will allow the backing file to just be stored as a bookmark file for each VM while the real backing image can be stored elsewhere).

@ktprograms
Copy link
Contributor

On iOS you can call it once but if you run it again it errors.

What exactly is the error? Just wondering.

@osy
Copy link
Contributor

osy commented Jan 11, 2022

Don't remember you can try it. It basically doesn't like main called multiple times.

@henry2man
Copy link

Hi there. Does anybody tried this project? https://github.com/Metamogul/UTM-Snapshot-Manager

@gitsnaf
Copy link

gitsnaf commented Jun 17, 2023

Hi there, is there any progress regarding a snapshot manager? I would also very much appreciate it if there was such a functionality.

@juanandresgs
Copy link

Plez?

@dataprolet
Copy link

Plez?

What do you mean?

@osy
Copy link
Contributor

osy commented Jul 21, 2023

Disposable VMs have been available for QEMU backend for multiple releases now. #5484 will track the feature request for snapshots.

@osy osy closed this as completed Jul 21, 2023
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

10 participants