This was written when latest release version of UTM was v4.5.3.
NOTE: Snapshots using qemu-img is not supported for macOS VMs due to .img image format as other pre-configured non-macOS VMs are using .qcow2 as the storage backend, which is well-supported.
Credit goes to lnxbil for mentioning this workaround
-
Run
brew install qemuon macOS with Homebrew installed already. -
Right-click the VM on the left pane of the UTM window app and select Show in Finder.
-
The easiest way to determine the location of the
.utmVM file (really, it's a folder) is to right-click it then select New Terminal at Folder to open the Terminal, and it'd take you directly to that directory as your$PWD. We'll use the same Terminal for the subsequent steps. -
Run
cd Data.Assuming there's only one
.qcow2file listed in theDatadirectory as it would be conveniently manageable dealing with just one. Here are the syntaxes you'd only need to know to perform the snapshots usingqemu-imgcommand:PLEASE NOTE: Snapshots cannot be created, applied, listed, or deleted while the VM is running. It must be in either in
suspendedorstoppedstate.Command syntax: snapshot [--object objectdef] [--image-opts] [-U] [-q] [-l | -a snapshot | -c snapshot | -d snapshot] filename Parameters to snapshot subcommand: 'snapshot' is the name of the snapshot to create, apply or delete '-a' applies a snapshot (revert disk to saved state) '-c' creates a snapshot '-d' deletes a snapshot '-l' lists all snapshots in the given image -
To create the snapshot, run:
qemu-img snapshot F8793221-25FF-47CE-8163-347DD16963E6.qcow2 -c fresh_install
It's a strong recommendation to use a unique (unused names in the list of snapshots) descriptive
TAGname in the last argument even though you can reuse the same name. If you attempt to reuse the same name, the new snapshot would be created with higherIDvalue than the original or previous snapshots with the same name, which means you would not be able to conveniently delete the latest snapshot as the original or previous snapshots have the higher priority. -
To list the snapshot, run:
qemu-img snapshot F8793221-25FF-47CE-8163-347DD16963E6.qcow2 -l
Output of the command (ex. containing 2 snapshots with same name):
Snapshot list: ID TAG VM_SIZE DATE VM_CLOCK ICOUNT 1 fresh_install 0 B 2024-06-26 21:45:02 0000:00:00.000 0 2 fresh_install 0 B 2024-06-26 21:45:14 0000:00:00.000 0
-
To apply the snapshot, run:
You can only apply the change to the VM if it's in a
suspendedorstoppedstate.qemu-img snapshot F8793221-25FF-47CE-8163-347DD16963E6.qcow2 -a fresh_install
Although, please note that the above command would use the oldest snapshot if the
TAGname is the same.To reference the snapshot by its
IDinstead (regardless of the duplicatedTAGnames), use the following command:qemu-img snapshot F8793221-25FF-47CE-8163-347DD16963E6.qcow2 -a 2
-
To delete the snapshot, run:
You can only delete the snapshot if the associated VM is in a
suspendedorstoppedstate.qemu-img snapshot F8793221-25FF-47CE-8163-347DD16963E6.qcow2 -d fresh_install
Just like the apply command in the previous step, the command would delete the oldest snapshot if the
TAGname is the same. However, the snapshot cannot be deleted by itsIDvalue as shown in the snapshot list. So, it's strongly encouraged to give snapshot name a uniqueTAGname. -
To view the actual disk size versus the virtual size along with a list of associated snapshots, you can use the command:
qemu-img info F8793221-25FF-47CE-8163-347DD16963E6.qcow2
Please remember, you cannot list snapshots while the VM is running due to
.qcow2file being locked during use, preventing write operations.