btrfs icon indicating copy to clipboard operation
btrfs copied to clipboard

VHDX storage

Open woachk opened this issue 6 years ago • 1 comments

Hi,

Trying to store a sparse VHDX on a BTRFS volume makes the virtual disk unusable. (Windows 10 version 1809).

Is that expected?

woachk avatar Dec 02 '18 15:12 woachk

Encountered this with VHDX on NTFS. Sparse file VHDX made by non-windows tools, cannot be mounted by windows. Windows probably does not like the way in which the file is sparsified. I think VHDX with spare property is not the same as a compacted VHDX, which is thin provisioning. Solution: Ensure VHDX file is not sparse at creation time.

Some collected links.

Copying the file once in windows seems to fix the VHDX and inflates it to makes it larger. https://www.mail-archive.com/[email protected]/msg04963.html

"things are as bad as they seem: Making VHD Files in QEMU That Work with Hyper-V (xenotrope.blogspot.com)" https://xenotrope.blogspot.com/2020/04/making-vhd-files-in-qemu-that-work-with.html

fsutil sparse queryflag my_disk.vhd
This file is set as sparse

fsutil sparse setflag my_disk.vhd 0
fsutil sparse queryflag my_disk.vhd
This file is NOT set as sparse

Though the above approach seems to inflate the VHDX, for me, it resulted in VHDX corruption.

"guestfish (libguestfs.org)" https://libguestfs.org/guestfish.1.html#disk-create

"linux - How to create a qcow2 file that is not thin provisioned? - Server Fault" https://serverfault.com/questions/841031/how-to-create-a-qcow2-file-that-is-not-thin-provisioned qemu-img create -o preallocation=full -f qcow2 /var/lib/libvirt/images/urb-dat0.qcow2 10G

Previously my pre kernel-5.15 system was using NTFS3g-FUSE driver, on which guestfish created sparse files by default. With kernel-5.15, I recently switched to new NTFS3 kernel-mode paragon driver, the VHDX created using guestfish did not become a sparse file. So I wonder what could be the reason. Either the NTFS3g-FUSE driver is buggy and responsible for badly created sparse file, or luckily when the filesystem driver is paragon ntfs it does not support or automatically create a sparse file. With the NTFS3 kernel-mode paragon driver, just a simple chkdsk /f /v, seemed to fix some trivial errors and windows-10 was able to mount the VHDX file. This needs more close investigation.

https://www.infradead.org/~mchehab/kernel_docs/filesystems/ntfs.html

If it is true that the handling of sparse files is the problem, then for your <win10,BTRFS,WinBTRFS> case, guest-fish, qemu needs to have options so as to not create sparse files. I don't find the current options satisfactory, as I interpret full-allocation as meaning not thinly provisioned. For such dedicated use cases, maybe winbtrfs can have a mount option that disables sparse files altogether.

Some <operating system, filesystem, filesystem driver> tuple have a feature to disable the sparse file feature all together. Ex <linux, ntfs, ntf3>. But, one does not wish to disable that as sparse files are useful in applications that can use it. Its only windows, that doesn't seem to like it if the VHDX file is sparse.

hgkamath avatar Sep 27 '21 21:09 hgkamath

Closing old issues

maharmstone avatar Nov 30 '23 01:11 maharmstone

Just adding for future reader.

Some of the issues in my comment may have also been caused by bugs present in wnbd, qemu-6, kernel-5.15 NTFS code at the time (20210928), which since then and are either resolved in qemu-8.1+, kernel-6,2+ or have work-arounds.

If using qemu to generate VHDX, see bugs

  • 727 (fixed) bug in VHDX
    VHDX is corrupted on expansion
    https://gitlab.com/qemu-project/qemu/-/issues/727
  • 136 (caution) care with regard to sparse using qemu-img
    windows qemu-img create vpc/vhdx error
    https://gitlab.com/qemu-project/qemu/-/issues/136
  • 1605 (workaround) use aio-native threads
    On windows, 2nd kind vhdx-dyn bug, crash on Unexpected error in bdrv_check_qiov_request() in io.c
    https://gitlab.com/qemu-project/qemu/-/issues/1605
  • 806 (workaround) Use qemu-img create option -o subformat=fixed,block_state_zero=off
    Fixed VHDX inflates beyond its fixed size when data is copied onto it and also corrupts
    https://gitlab.com/qemu-project/qemu/-/issues/806

Also, if using qemu-storage-daemon+wnbd to attach vhdx to storport

  • 63 disable WinOS-kernel page-caching for vhdx-file using cache.direct=on
    wnbd driver and qemu-nbd - DriveIO lockup and corruption https://github.com/cloudbase/wnbd/issues/63

hgkamath avatar Nov 30 '23 05:11 hgkamath