Contents

VZDiskImageStorageDeviceAttachment

A device that stores content in a disk image.

Declaration

class VZDiskImageStorageDeviceAttachment

Overview

Use a VZDiskImageStorageDeviceAttachment object to manage the storage for a disk in a virtual machine (VM). The guest operating system sees the storage as a disk, and when the guest operating system writes files to the disk, the virtual machine stores the files in the disk image you provide.

The virtualization framework supports two disk image formats:

RAW disk images

A file that’s the requested size of the VM disk, this format results in a 1-to-1 mapping between the offsets in the file and the offsets in the VM disk.

ASIF disk images

Apple Sparse Image Format (ASIF) files transfer more efficiently between hosts or disks because their intrinsic structure doesn’t depend on the host file system’s capabilities. The size the ASIF file takes on the file system is proportional to the actual data stored in the disk image.

Create the disk image

Create disk images using diskutil, a command-line utility you can access through the Terminal app. The diskutil utility performs a number of functions. The command uses a specific structure that tells the app what function it’s performing, including many arguments documented in its online manual page documents. For more information, see the diskutil manual page by using the command man diskutil in Terminal.

The command to creates disk image files you use with VMs starts with diskutil image create blank, followed by three required arguments that describe the structure, size, and location of the disk image. The general format of the command follows the pattern shown here:

diskutil image create blank --fs none --format FORMAT --size SIZE IMAGE_PATH

Use these parameters to specify the configuration of the disk image:

--format

An argument that describes the specific file-system format to use, either RAW or ASIF. diskutil supports other file-system formats as well, not all of which Virtualization supports. For more information, see the diskutil manual page by using the command man diskutil in Terminal.

--fs

An argument that specifies the file system to use when creating the disk image.

--size

An argument that describes the size of the file system to create, usually specified in gigabytes with the suffix GiB; for example, 256GiB specifies a 256 GB image file size. You can also specify sizes in megabytes, using the MiB notation; for example, 256MiB.

IMAGE_PATH

The file system path that represents the location where diskutil creates the RAW or ASIF file.

To create a RAW disk image in the file system of the host computer, open Terminal and run the following command, replacing the placeholder values with your own, for example:

diskutil image create blank --fs none --format RAW --size SIZE IMAGE_PATH

A best practice is to give disk images a common and easily recognizable file extension, such as .img; for example VM_Image.img.

To create an ASIF image, replace RAW with ASIF, as shown here:

diskutil image create blank --fs none --format ASIF --size SIZE IMAGE_PATH

You can execute diskutil commands under app control to create disk images programmatically.

You can also create ASIF or RAW disk images interactively using Disk Utility, a utility app that Apple provides with macOS. To create volumes with Disk Utility, open the app, then select File > New Image > Blank Image. Configure the form by selecting the disk format (either ASIF or RAW), volume size, and location for the new volume, and then click Save. For more information on using Disk Utility, see Disk Utility User Guide.

Alternatively, you can create a raw disk image programmatically using the UNIX open() and truncate() standard library functions as shown here:

Initialize the disk image

After creating the disk image, you use it to initialize a VM’s VZDiskImageStorageDeviceAttachment object. Use the attachment object to configure the VZVirtioBlockDeviceConfiguration object that you add to your virtual machine’s configuration, as shown here:

Topics

Creating the attachment point

Getting the disk image details

Initializers

See Also

Attachment points