feat: custom distro root filesystem type and mount options#14377
feat: custom distro root filesystem type and mount options#14377artiga033 wants to merge 20 commits intomicrosoft:masterfrom
Conversation
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Pull request overview
This PR adds support for custom root filesystem types and mount options when importing or installing WSL2 distributions. It addresses issue #9339, which requested support for filesystems other than ext4 (specifically btrfs and xfs). The feature allows specifying --fs-type and --fs-mount-options on --import and --install commands, plus --manage --set-fs-mount-options for existing distributions.
Changes:
- Adds
--fs-type(ext4/btrfs/xfs) and--fs-mount-optionsarguments to--importand--install, and--set-fs-mount-optionsto--manage - Stores fs type and mount options in the distribution registry, and passes them through to the Linux init at startup and during import
- Adds btrfs subvolume auto-creation during import when
subvol=is specified in mount options - Renames the default VHD filename from
ext4.vhdxtodistro.vhdx
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
src/windows/service/inc/wslservice.idl |
Adds FsType/FsMountOptions parameters to RegisterDistribution/RegisterDistributionPipe, new SetFsMountOptions method, default constants, renames VHD default name |
src/windows/service/exe/LxssUserSession.cpp/h |
Implements SetFsMountOptions, threads fs type/mount options through registration pipeline |
src/windows/service/exe/DistributionRegistration.cpp/h |
Persists FsType/FsMountOptions to registry, applies fs-specific default mount options |
src/windows/service/exe/LxssCreateProcess.h |
Adds FsType/FsMountOptions fields to LXSS_DISTRO_CONFIGURATION |
src/windows/service/exe/WslCoreVm.cpp |
Passes configuration's FsType/FsMountOptions to init message |
src/windows/service/exe/WslCoreInstance.cpp |
Removes EINVAL from disk corruption detection |
src/windows/common/svccomm.cpp/hpp |
Exposes FsType/FsMountOptions on RegisterDistribution, adds SetFsMountOptions |
src/windows/common/WslClient.cpp |
Parses --fs-type/--fs-mount-options/--set-fs-mount-options CLI args |
src/windows/common/WslInstall.cpp/h |
Threads fs type/mount options through installation flow |
src/windows/inc/wsl.h |
Defines CLI argument constants |
src/linux/init/main.cpp |
Implements FormatDevice for btrfs/xfs, adds CreateBtrfsSubvolumeOnDevice |
localization/strings/en-US/Resources.resw |
Adds help text for new arguments |
localization/strings/zh-CN/Resources.resw |
Adds Chinese translations, inadvertently removes UTF-8 BOM |
test/windows/UnitTests.cpp |
Adds three new test methods; existing tests not updated for VHD rename |
| { | ||
| // N.B. EUCLEAN (117) can be returned if the disk's journal is corrupted. | ||
| if ((result.Result == EINVAL || result.Result == 117) && result.FailureStep == LxInitCreateInstanceStepMountDisk) | ||
| if ((result.Result == 117) && result.FailureStep == LxInitCreateInstanceStepMountDisk) |
There was a problem hiding this comment.
Removing EINVAL (22) from the disk-corruption check is a behavioral regression. Mounting an empty VHD (no filesystem) returns EINVAL, which previously mapped to WSL_E_DISK_CORRUPTED. The existing CorruptedDisk unit test at line 2550 creates a VHD without a filesystem and expects WSL_E_DISK_CORRUPTED; with this change that test will now fail because EINVAL no longer triggers the WSL_E_DISK_CORRUPTED path. Either restore the EINVAL check or update the test to expect the new error message.
|
@benhillis I have done the reviews. There's one remaining discussion https://github.com/microsoft/WSL/pull/14377/changes#r2901401367 As support for custom mount options is added, it's hard to distinguish between corrupted vhdx and invalid mount options. So I think maybe we should just give an EINVAL in both condition |
It is hard to distinguish between a corrupted disk and bad fsType/fsMountOptions for failures of mounting the rootfs. This change renamed the WSL_E_DISK_CORRUPTED into WSL_E_MOUNT_FAILED, and changed the error message to inform the user the possible causes of the failure.
dae9b08 to
0a29cae
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 18 out of 18 changed files in this pull request and generated 7 comments.
You can also share your feedback on Copilot code review. Take the survey.
Summary of the Pull Request
#9339 , allows to use custom filesystem and mount options for the
/mount point.Depends on WSLg changes to add the corrosponding filesystem userspace progs microsoft/wslg#1426.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Features Included:
--fs-typeand--fs-mount-optionswhen importing or installing a distro, to change the fs type and mount options for/mountpoint. Supported filesystems areext4,btrfsandxfssubvol=mount option, it will be automatically created. This enables customizing the subvolume layout. E.g. using ubuntu layout(@and@home) for apps liketimeshiftto work properly. It is auto-created because normally in WSL we don't have a way (for the end user) to create such subvolumes before the distro is imported.fs-mount-optionsis not supplied, as defined in /src/windows/service/inc/wslservice.idl--manage --set-fs-mount-optionsto change the mount options of exsting distro.Validation Steps Performed
New unit tests has been added and can be run via
.\run-tests.ps1 -Fast --% /select:"@Name='UnitTests::UnitTests::ImportDistroWithFsType' OR @Name='UnitTests::UnitTests::ImportDistroWithFsMountOptions' OR @Name='UnitTests::UnitTests::ManageSetFsMountOptions'"Also there are screenshots I and other community users posted in the related issue #9339 .
Moreover, here are some quick commands to give it a try in realworld
default to ext4 like current behavior:
use xfs with default mount options:
use btrfs with custom mount options:
migrate existing ext4 distro: