Skip to content

Conversation

@nagypeterjob
Copy link
Contributor

@nagypeterjob nagypeterjob commented Aug 28, 2025

Which issue(s) this PR fixes:

Not an issue but discussion:
#189

Additional documentation

The PR adds support for the new Apple Sparse Image Format introduced by Tahoe (still beta). Currently the only known way of creating ASIF images is via diskutil.

Tested on:

$ sw_vers
ProductName:            macOS
ProductVersion:         26.0
BuildVersion:           25A5346a

Testing evidence:

// installing in the "old" way, resulting in a plain raw image file
$ ./virtualization -install
install has been completed

$ diskutil image info ~/VM.bundle/Disk.img
Image Format: RAW
Format Description: RAW read-write image
// rest of the output is omitted

// installing with `-asif` flag, resulting in an ASIF disk image
$ ./virtualization -install -asif
install has been completed

$ diskutil image info ~/VM.bundle/Disk.img
Image Format: ASIF
Format Description: Apple sparse image
// rest of the output is omitted

The VM runs with ASIF disk as well:
Screenshot 2025-08-28 at 12 44 48

I don't think we need to update any header files, as the VZDiskImageStorageDeviceAttachment and VZVirtioBlockDeviceConfiguration interfaces did not change.

Let me know if you need anything else to accept the PR 🙇🏻

Copy link
Owner

@Code-Hex Code-Hex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! I've only made one comment. It's mostly LGTM.

//
// Note that ASIF is only available from macOS Tahoe, so the function will return error
// on earlier versions.
func CreateSparseDiskImage(ctx context.Context, pathname string, size int64) error {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nagypeterjob Could you add test for this function?

A simple test to verify these points is sufficient:

  • Whether a disk image file is created
  • Whether the format is ASIF
  • Whether it is created at the specified size

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will do it in a day or two 🙇🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There you go @Code-Hex, let me know if you need any changes 🙇🏻


var sizeStr string
for _, line := range strings.Split(string(output), "\n") {
if strings.Contains(line, "Total Bytes") {
Copy link
Contributor Author

@nagypeterjob nagypeterjob Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to get the total "logical" size from the diskutil image info <image_path> output, otherwise stat.Size and even syscall.Stat_t returns the "real" size of the disk, which is close to 0 given currently empty

Copy link
Owner

@Code-Hex Code-Hex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left 1 comment 🙇

path := filepath.Join(dir, "sparse_disk.img")

ctx := context.Background()
size := int64(1024 * 1024 * 1024) // 1 GiB
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Occupying 1 GB for testing is not good - can't you do something like 1 KB, 1 MB?

Copy link
Contributor

@cfergeau cfergeau Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The image is supposed to be sparse, so I’d expect it will use a few MBs on disk at most.

Copy link
Contributor Author

@nagypeterjob nagypeterjob Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cfergeau thats right, de "real" disk size the image claims is negligible, given its empty

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nagypeterjob I see Thanks!

@Code-Hex
Copy link
Owner

Code-Hex commented Sep 4, 2025

I merge this PR. Thanks! @nagypeterjob

@Code-Hex Code-Hex merged commit f6c8b99 into Code-Hex:main Sep 4, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants