Skip to content

Conversation

@ashwat287
Copy link
Contributor

@ashwat287 ashwat287 commented Dec 2, 2025

Fixes #4418
Ensure diffDisk is converted to the requested format instead of staying sparse.

return fmt.Errorf("failed to create sparse diff disk %q: %w", diffDisk, err)
}
return diffDiskF.Close()
diffDiskF.Close()
Copy link
Member

Choose a reason for hiding this comment

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

How did you test this PR?
The diffDisk created in L43 will be overwritten by a new disk converted from baseDisk in L57, no?

Copy link
Contributor Author

@ashwat287 ashwat287 Dec 2, 2025

Choose a reason for hiding this comment

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

Yes diffDisk would get converted in L57 when the base image is ISO.
I have include the tests to verify the conditions when base image is ISO and non-ISO
Can you please clarify on what should be the desired behaviors in each test cases?

Copy link
Member

Choose a reason for hiding this comment

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

When the base disk is an ISO9660 image, the diff disk has to be a new empty disk.
("diff" is misnomer here)

Copy link
Contributor Author

@ashwat287 ashwat287 Dec 3, 2025

Choose a reason for hiding this comment

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

The diff disk when created as a sparse file in L49 is empty and has size 0 bytes.
On debugging, I find that after conversion the diffdisk size becomes equal to diskSizeInBytes.

To keep the diffDisk empty we can either:

  1. not convert the diffDisk and leave it as a sparse file and eventually ignore diskImageFormat when the base disk is ISO. or,
  2. convert the diffDisk to the available formats while keeping diskSizeInBytes=0 in case of ISO base disk. The problem here arises when the disk is being converted to asif format, the following error gets thrown specified size 0 is smaller than the original image size because of
    if size != nil && *size < srcImg.Size() {
    return fmt.Errorf("specified size %d is smaller than the original image size (%d) of %q", *size, srcImg.Size(), source)
    }

@ashwat287 ashwat287 force-pushed the Issue4418 branch 2 times, most recently from efb2779 to ea17ac7 Compare December 2, 2025 17:18
Copy link
Contributor

@norio-nomura norio-nomura left a comment

Choose a reason for hiding this comment

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

This PR does not fix #4418:

$ limactl start ./hack/test-templates/alpine-iso-9p-writable.yaml --vm-type vz --set .vmOpts.vz.diskimageFormat=\"asif\" --set .mountType=null --tty=false --log-level fatal
$ limactl stop alpine-iso-9p-writable
INFO[0000] Sending SIGINT to hostagent process 62151    
INFO[0000] Waiting for the host agent and the driver processes to shut down 
INFO[0000] [hostagent] Received SIGINT, shutting down the host agent 
INFO[0000] [hostagent] Shutting down the host agent     
INFO[0000] [hostagent] Shutting down VZ                 
INFO[0003] [hostagent] [VZ] - vm state change: stopped  
ERRO[0003] [hostagent] accept tcp 127.0.0.1:58662: use of closed network connection 
INFO[0004] Waiting for the instance to shut down        
INFO[0004] The instance alpine-iso-9p-writable has shut down 
$ diskutil image info ~/.lima/alpine-iso-9p-writable/diffdisk
Image Format: RAW
Format Description: RAW read-write image

	Size Info:
		Empty Bytes: 0
		Min Size Bytes: 512
		Sector Count: 209715200
		Total Bytes: 107374182400

	Encryption Info:
		Is Encrypted: 0

	Partitions
		0:
			content-hint: GUID_partition_scheme
			total-space: 107374182400
			used-space: N/A
			volume-name: N/A
		1:
			content-hint: Microsoft Basic Data
			total-space: 167936
			used-space: N/A
			volume-name: N/A
		2:
			content-hint: EFI
			total-space: 1474560
			used-space: N/A
			volume-name: NO NAME
		3:
			content-hint: Microsoft Basic Data
			total-space: 81270784
			used-space: N/A
			volume-name: N/A
$ limactl --version
limactl version 2.0.2-25-gea17ac7c.m

@norio-nomura
Copy link
Contributor

This PR does not fix #4418:

updated console log to add missing --set .mountType=null on limactl start

@ashwat287 ashwat287 force-pushed the Issue4418 branch 5 times, most recently from e7cdb60 to 2951d80 Compare December 6, 2025 22:54
@ashwat287
Copy link
Contributor Author

$ limactl start ./hack/test-templates/alpine-iso-9p-writable.yaml --vm-type vz --set .vmOpts.vz.diskImageFormat=\"asif\" --set .mountType=null --tty=false --log-level fatal
$ diskutil image info ~/.lima/alpine-iso-9p-writable/diffdisk                                                                                                                     
Image Format: ASIF
Format Description: Apple sparse image

	Identity Info:
		Stable UUID: F240DA64-A9D1-44B2-841C-1BABD6F3CE17
		UUID: 8C2D97C2-80AE-4545-979D-FC4DE3DCF943

	Size Info:
		Empty Bytes: 107303096320
		Max Size Bytes: 4503599626321920
		Min Size Bytes: 1048576
		Sector Count: 209715200
		Total Bytes: 107374182400

	Encryption Info:
		Is Encrypted: 0

	ASIF Info:
		Bitmapped Entries: 83
		Chunk Size: 1048576
		Dir Pointer Version: 4
		Full Entries: 62
		Is Cache: 0
		Max Sector Count: 8796093022208
		Num Tables: 2
		Uninitialized Entries: 155647
		Unmapped Entries: 102256

	Partitions
		0:
			content-hint: FDisk_partition_scheme
			total-space: 107374182400
			used-space: N/A
			volume-name: N/A
		1:
			content-hint: Linux
			total-space: 107373133824
			used-space: N/A
			volume-name: N/A

Copy link
Contributor

@norio-nomura norio-nomura left a comment

Choose a reason for hiding this comment

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

Confirmed that #4418 will be corrected.
I don't know if the call to MakeSparse needs to be left, but I don't think it's a problem.

}

err = diskUtil.MakeSparse(ctx, diffDiskF, 0)
err = diskUtil.MakeSparse(ctx, diffDiskF, diskSizeInBytes)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this MakeSparse still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, just an empty volume is enough. I have removed it in the amended commit.

…ty volume for diff disk so Convert executes.

Ensure diffDisk is converted to the requested format instead of staying sparse.

Signed-off-by: ashwat287 <ashwatpas@gmail.com>
Add pkg/driverutil/disk_test.go covering:
 - Base image is ISO: EnsureDisk creates/keeps diffdisk and converts to asif and raw; base ISO remains unchanged (content hash and ISO signature).
 - Base image is non-ISO: EnsureDisk converts diffdisk to raw and asif.

Signed-off-by: ashwat287 <ashwatpas@gmail.com>
Copy link
Contributor

@norio-nomura norio-nomura left a comment

Choose a reason for hiding this comment

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

LGTM! 👍🏻

@ashwat287 ashwat287 requested a review from AkihiroSuda December 9, 2025 05:12
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.

pkg/driverutil.EnsureDisk: diskImageFormat is ignored for ISO mode

3 participants