Cross-Platform VM Support - Implementation Notes
Completed Tasks
All 8 tasks have been implemented and committed:
- ✅
is_linux_package_format(): Detect Linux package formats (renamed from should_enable_libkrun) - ✅ virtiofs Windows: Support POSIX permissions via NTFS Extended Attributes
- ✅ virtiofs Windows: Support special file types via NTFS Reparse Points
- ✅ unpack_package()/link_packages(): Set file metadata via NTFS EA on Windows (deferred)
- ✅ Windows: Detect symlink permission and fall back to Hardlink
- ✅ init.rs: Download epkg-linux-$arch on Windows/macOS for VM usage
- ✅ create_applet_symlinks(): Link to correct epkg binary based on env distro
- ✅ Run Linux scriptlets in VM when installing on Windows/macOS
- ✅ libkrun on Windows:宿主 Windows 构建启用
libkrunCargo feature 时,与 macOS 一样可作为IsolateMode::Vm后端(virtiofs、NTFS EA、sandbox-kernel 等依赖见docs/design-notes/sandbox-vmm.md)
Additional Fix: cfg Hygiene
Removed #[cfg(unix)] and #[cfg(target_os = "linux")] restrictions that were incorrectly
used as business boundaries. The actual boundary is the package format, not the OS.
- transaction.rs: deb_triggers, hooks, scriptlets now work on all platforms
- hooks.rs: all hook functions available on all platforms
- scriptlets.rs: all scriptlet functions available on all platforms
- install.rs: unified run_transaction_batch() for all platforms
Pending Items
1. Split NTFS EA Code
The NTFS Extended Attributes code in git/libkrun/src/devices/src/virtio/fs/windows/passthrough.rs
should be split into a separate .rs file for better reuse by epkg.
Status: User confirmed OK to defer
2. Add libloading Dependency for EA Support in epkg
User confirmed: YES, should add libloading as a Windows dependency to epkg
so that package extraction can set EA permissions directly.
Note: Currently we rely on postinst scripts running in VM to set correct permissions. This works but is slower than setting EA during extraction.
Architecture Summary
┌─────────────────────────────────────────────────────────────────────┐
│ Windows/macOS Host (Native epkg) │
├─────────────────────────────────────────────────────────────────────┤
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Native Formats │ │ Linux Formats │ │ Self Install │ │
│ │ (conda/brew/ │ │ (deb/rpm/arch/ │ │ downloads both │ │
│ │ msys2) │ │ apk) │ │ binaries │ │
│ └────────┬────────┘ └────────┬────────┘ └─────────────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Direct exec │ │ fork_and_execute│ │
│ │ (native speed) │ │ IsolateMode::Vm │ │
│ │ skip_namespace │ │ (libkrun) │ │
│ └─────────────────┘ └────────┬────────┘ │
└─────────────────────────────────┼───────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────┐
│ Linux VM (libkrun) │
├─────────────────────────────────────────────────────────────────────┤
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ epkg-linux-$arch│ │ virtiofs + NTFS │ │ Scriptlets run │ │
│ │ (as /usr/bin/ │ │ EA for POSIX │ │ with correct │ │
│ │ init) │ │ permissions │ │ permissions │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────────────┘
Commits Made
epkg
run: add should_enable_libkrun() for auto VM sandbox on Windows/macOSlfs: add can_create_symlinks() for Windows symlink capability detectioninit: download epkg-linux-$arch on Windows/macOS for VM usagebusybox: link applets to correct epkg binary based on env distroinstall: run Linux scriptlets in VM on Windows/macOS hostsenable hooks/scriptlets on all platforms for VM executionrun: rename should_enable_libkrun() to is_linux_package_format()
libkrun
virtiofs: add NTFS Extended Attributes for POSIX metadata on Windowsvirtiofs: implement mknod for special file types on Windows