---
title: "init(diskImage:cachingMode:synchronizationMode:)"
framework: virtualization
role: symbol
role_heading: Initializer
path: "virtualization/vzdiskimagestoragedeviceattachment/init(diskimage:cachingmode:synchronizationmode:)"
---

# init(diskImage:cachingMode:synchronizationMode:)

Initializes the attachment from a disk image.

## Declaration

```swift
convenience init(diskImage: DiskImage, cachingMode: VZDiskImageCachingMode = .automatic, synchronizationMode: VZDiskImageSynchronizationMode = .full) throws
```

## Parameters

- `diskImage`: A diskImage object created using the doc://com.apple.documentation/documentation/DiskImageKit framework. It supports both single and stacked disk images.
- `cachingMode`: The host-level doc://com.apple.virtualization/documentation/Virtualization/VZDiskImageCachingMode policy for the disk image. This is independent of cache layers in the disk image stack.
- `synchronizationMode`: How the disk image synchronizes with the underlying storage when the guest operating system flushes data, described by one of the available doc://com.apple.virtualization/documentation/Virtualization/VZDiskImageSynchronizationMode modes.

## Discussion

Discussion This initializer enables the use of DiskImage objects created with the DiskImageKit framework, including stacked images with cache and overlay layers. The following example shows how to initialize a storage attachment object using a disk image.     import Virtualization          let imageURL = // A `URL` that references a disk image.     let diskImage = try DiskImage(opening: .init(url: imageURL))     let storageAttachment = try VZDiskImageStorageDeviceAttachment(diskImage: diskImage)
