<!--
{
  "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))
```

## Topics

### Protocols

[`protocol CreationConfiguration`](/documentation/DiskImageKit/DiskImage/CreationConfiguration)

A marker protocol for disk image creation configurations.

[`protocol StackableLayer`](/documentation/DiskImageKit/DiskImage/StackableLayer)

A marker protocol that stackable disk image layer configuration objects conform to.

### Structures

[`struct LayerType`](/documentation/DiskImageKit/DiskImage/LayerType-swift.struct)

An enumeration that defines the type of a layer in a stacked disk image.

### Initializers

[`convenience init(creating: some DiskImage.CreationConfiguration) throws`](/documentation/DiskImageKit/DiskImage/init(creating:))

Creates a new, empty disk image.

[`convenience init(opening: some OpenConfigurationProtocol) throws`](/documentation/DiskImageKit/DiskImage/init(opening:))

Opens an existing disk image using the specified image URL.

### Instance Properties

[`var blockCount: Int`](/documentation/DiskImageKit/DiskImage/blockCount)

The number of blocks in the disk image.

[`var blockSize: DiskImage.BlockSize`](/documentation/DiskImageKit/DiskImage/blockSize-swift.property)

The block size, either 512 bytes or 4 KB.

[`var format: DiskImage.Format`](/documentation/DiskImageKit/DiskImage/format-swift.property)

The format of the disk image.

[`var layerType: DiskImage.LayerType?`](/documentation/DiskImageKit/DiskImage/layerType-swift.property)

The layer type of the disk image.

[`var layerUUID: UUID?`](/documentation/DiskImageKit/DiskImage/layerUUID)

A UUID of the image that the framework uses to validate its compatibility with the layer above it in the stack

[`var openMode: OpenConfiguration.Mode`](/documentation/DiskImageKit/DiskImage/openMode)

The open mode of the disk image, read-only or read-write.

[`var parentUUID: UUID?`](/documentation/DiskImageKit/DiskImage/parentUUID)

A UUID of the image that must be equal to the layer UUID of the layer beneath it in the stack.

[`var size: Int`](/documentation/DiskImageKit/DiskImage/size)

The logical size of the disk image in bytes.

[`let url: URL`](/documentation/DiskImageKit/DiskImage/url)

The URL of the disk image.

### Instance Methods

[`func appending(any DiskImage.CreationConfiguration & DiskImage.StackableLayer) throws -> any StackedImage`](/documentation/DiskImageKit/DiskImage/appending(_:)-3pfqg)

Appends a new layer to this disk image, creating or extending a stack

[`func appending(consuming DiskImage) throws -> any StackedImage`](/documentation/DiskImageKit/DiskImage/appending(_:)-4wifj)

Appends a layer to this disk image, creating or extending a stack.

[`func truncate(blockCount: Int) throws`](/documentation/DiskImageKit/DiskImage/truncate(blockCount:))

Truncate or extend the disk image to a new size.

### Enumerations

[`enum BlockSize`](/documentation/DiskImageKit/DiskImage/BlockSize-swift.enum)

Values that represent the block size of a disk image.

[`enum Format`](/documentation/DiskImageKit/DiskImage/Format-swift.enum)

Values that describe the disk image formats DiskImageKit supports.

## 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)