<!--
{
  "availability" : [
    "macOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "DiskImageKit",
  "identifier" : "/documentation/DiskImageKit/DiskImage",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "DiskImageKit"
    ],
    "preciseIdentifier" : "s:12DiskImageKit0aB0C"
  },
  "title" : "DiskImage"
}
-->

# DiskImage

The representation of an open disk image

```
class DiskImage
```

## Overview

To use a disk image as storage for virtual machine, use this object with the Virtualization API method
<doc://com.apple.documentation/documentation/Virtualization/VZDiskImageStorageDeviceAttachment/init(diskImage:cachingMode:synchronizationMode:)>.
In addition, it contains properties that describe the disk image and operations to manipulate it.

An image can either be standalone or part of a stack. For more information on stacked disk image, see [`StackedImage`](/documentation/DiskImageKit/StackedImage).

The following example demonstrates how to create a stacked disk image with 3 layers:

```
// Open the base image.
let baseImage = try DiskImage(opening: .open(url: baseImageURL))

// Append a new cache layer,
var stackedImage = try baseImage.appending(.asifLayer(url: cacheURL, type: .cache))

// Append an existing overlay layer,
let overlayImage = try DiskImage(opening: .open(url: overlayURL))
stackedImage = try stackedImage.appending(overlayImage)

// Append a new overlay layer.
stackedImage = try stackedImage.appending(.asifLayer(url: overlayURL, type: .overlay))
```

The example demonstrates how to create a standalone, 512 GB (1 billion block) ASIF disk image:

```
_ = try DiskImage(creating: .asif(url: imageURL, blockCount: 1000000000, blockSize: .bytes512))
```

## Relationships

### Inherited By

[`StackedImage`](/documentation/DiskImageKit/StackedImage)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)