<!--
{
  "availability" : [
    "macOS: 14.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Virtualization",
  "identifier" : "/documentation/Virtualization/VZDiskBlockDeviceStorageDeviceAttachment",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Virtualization"
    ],
    "preciseIdentifier" : "c:objc(cs)VZDiskBlockDeviceStorageDeviceAttachment"
  },
  "title" : "VZDiskBlockDeviceStorageDeviceAttachment"
}
-->

# VZDiskBlockDeviceStorageDeviceAttachment

A storage device attachment that uses a disk to store data.

```
class VZDiskBlockDeviceStorageDeviceAttachment
```

## Overview

The disk block device implements a storage attachment by using an actual disk rather than a disk image on a file system.

> Warning:
> Handle the disk passed to this attachment with caution. If the disk has a file system formatted on it, the guest can destroy data in a way that isn’t recoverable.

In the following example, a disk device at `/dev/rdisk42` executes the I/O operations directly on that disk rather than through a file system:

```objc
NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:@"/dev/rdisk42"];
    if (!fileHandle) {
        // Handle errors.
    }

    NSError *error;
    VZDiskBlockDeviceStorageDeviceAttachment *attachment =
        [[VZDiskBlockDeviceStorageDeviceAttachment alloc] initWithFileHandle:fileHandle
                                                          readOnly:YES
                                                          synchronizationMode:VZDiskSynchronizationModeFull
                                                          error:error];
    if (!attachment) {
        // Handle errors.
    }
```

By default, only the `root` user can access the disk file handle. Running virtual machines as `root` isn’t recommended. The best practice is to open the file in a separate process that has `root` privileges, then pass the open file descriptor using XPC or a Unix socket to a non-`root` process running Virtualization. For more information about Unix sockets, see <doc://com.apple.documentation/documentation/Foundation/streams-sockets-and-ports>; for more information on XPC services, see the <doc://com.apple.documentation/documentation/XPC> framework documentation.

> Important:
> You can’t use this method of privilege escalation in apps distributed on the Mac App Store.

## Topics

### Initializers

[`init(fileHandle:readOnly:synchronizationMode:)`](/documentation/Virtualization/VZDiskBlockDeviceStorageDeviceAttachment/init(fileHandle:readOnly:synchronizationMode:))

Creates a new block storage device attachment from a file handle and with the specified access mode, synchronization mode, and error object that you provide.

### Getting the block storage device details

[`fileHandle`](/documentation/Virtualization/VZDiskBlockDeviceStorageDeviceAttachment/fileHandle)

A file handle to a block device.

[`isReadOnly`](/documentation/Virtualization/VZDiskBlockDeviceStorageDeviceAttachment/isReadOnly)

A Boolean value that indicates whether this disk attachment is read-only; otherwise, if the file handle allows writes, the device can write data into it.

[`synchronizationMode`](/documentation/Virtualization/VZDiskBlockDeviceStorageDeviceAttachment/synchronizationMode)

The value that defines how the disk synchronizes with the underlying storage when the guest operating system flushes data.

## See Also

[`VZVirtioBlockDeviceConfiguration`](/documentation/Virtualization/VZVirtioBlockDeviceConfiguration)

The configuration object that requests the creation of a virtual storage device in the guest system.



---

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)