The previous section mentioned differencing images and how they are used with snapshots, immutable images, and multiple disk attachments. This section describes in more detail how differencing images work.
A differencing image is a special disk image that only holds the differences to another image. A differencing image by itself is useless, it must always refer to another image. The differencing image is then typically referred to as a child, which holds the differences to its parent.
When a differencing image is active, it receives all write operations from the virtual machine instead of its
parent. The differencing image only contains the sectors of the virtual hard disk that have changed since the
differencing image was created. When the machine reads a sector from such a virtual hard disk, it looks into the
differencing image first. If the sector is present, it is returned from there. If not,
Differencing images can be chained. If another differencing image is created for a virtual disk that already has
a differencing image, then it becomes a grandchild of the original parent. The first differencing image
then becomes read-only as well, and write operations only go to the second-level differencing image. When reading
from the virtual disk,
There can be an unlimited number of differencing images, and each image can have more than one child. As a
result, the differencing images can form a complex tree with parents, siblings, and children, depending on how
complex your machine configuration is. Write operations always go to the one active differencing image that
is attached to the machine, and for read operations,
In all of these situations, from the point of view of the virtual machine, the virtual hard disk behaves like any
other disk. While the virtual machine is running, there is a slight runtime I/O overhead because
Differencing images are used in the following situations:
Snapshots. When you create a
snapshot, as explained in the previous section,
In the above screenshot, you see that the original disk image is now attached to a snapshot, representing the state of the disk when the snapshot was taken.
If you restore a snapshot, and want to go back to the exact machine state that was stored in the snapshot, the following happens:
If the snapshot was taken while the machine was running, it contains a saved machine state, and that state is restored as well. After restoring the snapshot, the machine will then be in Saved state and resume execution from there when it is next started. Otherwise the machine will be in Powered Off state and do a full boot.
For each disk image attached to the machine, the differencing image holding all the write operations since the current snapshot was taken is thrown away, and the original parent image is made active again. If you restored the root snapshot, then this will be the root disk image for each attachment. Otherwise, some other differencing image descended from it. This effectively restores the old machine state.
If you later delete a snapshot in order to free disk space, for each disk attachment, one of the
differencing images becomes obsolete. In this case, the differencing image of the disk attachment cannot
simply be deleted. Instead,
Immutable images. When an image is switched to immutable mode, a differencing image is created as well. As with snapshots, the parent image then becomes read-only, and the differencing image receives all the write operations. Every time the virtual machine is started, all the immutable images which are attached to it have their respective differencing image thrown away, effectively resetting the virtual machine's virtual disk with every restart.