Skip to content

Commit b136eaf

Browse files
committed
Add initial WSL2 VM support in Lima
1 parent 0b59d3a commit b136eaf

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,9 @@ There is no way to use file system mounts in Podman with QEMU on Windows hosts.
263263

264264
Additional work is required to bring AF_UNIX port forwarding (same applied to Unix socket to named pipe forwarding)
265265

266-
### 2. WSL driver is currently broken
266+
### 2. Containers in WSL2 machine are not operational
267267

268-
Lima supprot is in prototype stage and numerous features from original version are broken, this includes support for provisioning
269-
WSL2 VMs using Lima. Only QEMU driver is supported in this rebuild.
268+
Rootless containerd is not installing and rootful containerd lacks networking connectivity.
270269

271270
### 3. Key pairs created with official Lima instance will lack Unix permissions and will be rejected
272271

patches/AlpineWSL/0002-Add-Lima-customizations.patch

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
From 7df9651f4e754513c3578e97b64e6eeac1515373 Mon Sep 17 00:00:00 2001
1+
From 9ef3ad3959d37b6d78c51f8fe9c212ae7c6f9526 Mon Sep 17 00:00:00 2001
22
From: Arthur Sengileyev <[email protected]>
33
Date: Tue, 28 Jan 2025 14:55:26 +0200
44
Subject: [PATCH] Add Lima customizations
55

66
---
7-
src_x64/Makefile | 9 ++++++---
7+
src_x64/Makefile | 10 +++++++---
88
src_x64/cygpath | 5 +++++
99
src_x64/oobe.sh | 8 ++++++++
1010
src_x64/wsl-distribution.conf | 4 ++++
1111
src_x64/wsl.conf | 10 ++++++++++
12-
5 files changed, 33 insertions(+), 3 deletions(-)
12+
5 files changed, 34 insertions(+), 3 deletions(-)
1313
create mode 100755 src_x64/cygpath
1414
create mode 100755 src_x64/oobe.sh
1515
create mode 100644 src_x64/wsl-distribution.conf
1616
create mode 100644 src_x64/wsl.conf
1717

1818
diff --git a/src_x64/Makefile b/src_x64/Makefile
19-
index ead99a0..de75b76 100644
19+
index ead99a0..f734975 100644
2020
--- a/src_x64/Makefile
2121
+++ b/src_x64/Makefile
2222
@@ -3,7 +3,7 @@ LNCR_EXE=Alpine.exe
@@ -28,13 +28,14 @@ index ead99a0..de75b76 100644
2828
ROOTFS_TARBALL_CKSM_URL=${BASE_URL}.sha512
2929
LNCR_ZIP_URL=https://github.com/yuk7/wsldl/releases/download/23072600/icons.zip
3030
LNCR_ZIP_EXE=Alpine.exe
31-
@@ -43,9 +43,12 @@ rootfs: base.tar.gz profile
31+
@@ -43,9 +43,13 @@ rootfs: base.tar.gz profile
3232
sudo cp -f /etc/resolv.conf rootfs/etc/resolv.conf
3333
sudo cp -f profile rootfs/etc/profile
3434
sudo chroot rootfs /sbin/apk update
3535
- sudo chroot rootfs /sbin/apk add bash
3636
- echo "# This file was automatically generated by WSL. To stop automatic generation of this file, remove this line." | sudo tee rootfs/etc/resolv.conf
37-
+ sudo chroot rootfs /sbin/apk add bash openssh openssh-client-krb5 socat
37+
+ sudo chroot rootfs /sbin/apk add bash openssh openssh-client-krb5 socat libdeflate-utils
38+
+ sudo chroot rootfs /bin/ln -s /usr/bin/libdeflate-gzip /usr/local/bin/gzip # https://github.com/microsoft/WSL/issues/12523
3839
sudo rm -rf `sudo find rootfs/var/cache/apk/ -type f`
3940
+ sudo cp -f oobe.sh rootfs/etc/oobe.sh
4041
+ sudo cp -f wsl.conf rootfs/etc/wsl.conf
@@ -56,7 +57,7 @@ index 0000000..975a36f
5657
+/bin/wslpath "$@"
5758
diff --git a/src_x64/oobe.sh b/src_x64/oobe.sh
5859
new file mode 100755
59-
index 0000000..c9ab254
60+
index 0000000..f1f14ca
6061
--- /dev/null
6162
+++ b/src_x64/oobe.sh
6263
@@ -0,0 +1,8 @@

patches/lima/0001-Add-QEMU-driver-support-on-Windows-hosts.patch

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From f97d2c5d7968e6172b9b542a78351854f8e983dd Mon Sep 17 00:00:00 2001
1+
From cd7ce15a7838fb45e618f445a39599b1ac21c557 Mon Sep 17 00:00:00 2001
22
From: Arthur Sengileyev <[email protected]>
33
Date: Wed, 22 Jan 2025 17:24:01 +0200
44
Subject: [PATCH] Add QEMU driver support on Windows hosts
@@ -13,20 +13,20 @@ Signed-off-by: Arthur Sengileyev <[email protected]>
1313
contrib/bundle-wsl/wsllinks.ini | 2 ++
1414
pkg/cidata/cidata.go | 11 ++++++++++-
1515
pkg/hostagent/hostagent.go | 7 ++++++-
16-
pkg/hostagent/mount.go | 21 ++++++++++++++++++---
16+
pkg/hostagent/mount.go | 23 ++++++++++++++++++++---
1717
pkg/ioutilx/ioutilx.go | 3 ++-
1818
pkg/iso9660util/iso9660util.go | 6 ------
1919
pkg/osutil/user.go | 2 +-
2020
pkg/qemu/qemu.go | 2 ++
2121
pkg/sshutil/sshutil.go | 19 ++++++++++---------
2222
templates/default.yaml | 2 +-
23-
15 files changed, 83 insertions(+), 24 deletions(-)
23+
15 files changed, 85 insertions(+), 24 deletions(-)
2424
create mode 100644 contrib/bundle-wsl/go-wsllinks.exe
2525
create mode 100644 contrib/bundle-wsl/sftp-server.ini
2626
create mode 100644 contrib/bundle-wsl/wsllinks.ini
2727

2828
diff --git a/Makefile b/Makefile
29-
index 71bea6e4..afde990b 100644
29+
index 71bea6e4..3d77640f 100644
3030
--- a/Makefile
3131
+++ b/Makefile
3232
@@ -551,6 +551,20 @@ artifacts-misc: | _artifacts
@@ -36,7 +36,7 @@ index 71bea6e4..afde990b 100644
3636
+.PHONY: add-bundles
3737
+add-bundles: add-bundle-wsl
3838
+
39-
+add-bundle-wsl: _output/bin/bundle-wsl/wsllinks.ini _output/bin/bundle-wsl/sftp-server.ini _output/bin/bundle-wsl/cygpath.exe _output/bin/bundle-wsl/id.exe _output/bin/bundle-wsl/realpath.exe _output/bin/bundle-wsl/sftp-server.exe _output/bin/bundle-wsl/ssh.exe _output/bin/bundle-wsl/ssh-keygen.exe
39+
+add-bundle-wsl: _output/bin/bundle-wsl/wsllinks.ini _output/bin/bundle-wsl/sftp-server.ini _output/bin/bundle-wsl/cygpath.exe _output/bin/bundle-wsl/id.exe _output/bin/bundle-wsl/realpath.exe _output/bin/bundle-wsl/sftp-server.exe _output/bin/bundle-wsl/ssh.exe _output/bin/bundle-wsl/ssh-keygen.exe _output/bin/bundle-wsl/gzip.exe
4040
+
4141
+
4242
+_output/bin/bundle-wsl/%.ini: contrib/bundle-wsl/%.ini | _output/bin/bundle-wsl
@@ -105,15 +105,15 @@ index 00000000..47d2814a
105105
--- /dev/null
106106
+++ b/contrib/bundle-wsl/sftp-server.ini
107107
@@ -0,0 +1 @@
108-
+binary = /usr/lib/ssh/sftp-server
108+
+binary = /usr/lib/ssh/sftp-server
109109
diff --git a/contrib/bundle-wsl/wsllinks.ini b/contrib/bundle-wsl/wsllinks.ini
110110
new file mode 100644
111111
index 00000000..60b0c8e8
112112
--- /dev/null
113113
+++ b/contrib/bundle-wsl/wsllinks.ini
114114
@@ -0,0 +1,2 @@
115-
+distro = lima-infra
116-
+user = lima
115+
+distro = lima-infra
116+
+user = lima
117117
diff --git a/pkg/cidata/cidata.go b/pkg/cidata/cidata.go
118118
index 2030a9a8..bdbca881 100644
119119
--- a/pkg/cidata/cidata.go
@@ -179,21 +179,22 @@ index 396401a4..212f0c35 100644
179179

180180
if err := cidata.GenerateCloudConfig(inst.Dir, instName, inst.Config); err != nil {
181181
diff --git a/pkg/hostagent/mount.go b/pkg/hostagent/mount.go
182-
index 646dc5d4..d7ef289f 100644
182+
index 646dc5d4..9a59f25c 100644
183183
--- a/pkg/hostagent/mount.go
184184
+++ b/pkg/hostagent/mount.go
185-
@@ -4,7 +4,10 @@ import (
185+
@@ -4,7 +4,11 @@ import (
186186
"errors"
187187
"fmt"
188188
"os"
189+
+ "os/exec"
189190
+ "path"
190191
+ "runtime"
191192

192193
+ "github.com/lima-vm/lima/pkg/ioutilx"
193194
"github.com/lima-vm/lima/pkg/limayaml"
194195
"github.com/lima-vm/lima/pkg/localpathutil"
195196
"github.com/lima-vm/sshocker/pkg/reversesshfs"
196-
@@ -36,13 +39,22 @@ func (a *HostAgent) setupMount(m limayaml.Mount) (*mount, error) {
197+
@@ -36,13 +40,22 @@ func (a *HostAgent) setupMount(m limayaml.Mount) (*mount, error) {
197198
if err != nil {
198199
return nil, err
199200
}
@@ -219,12 +220,13 @@ index 646dc5d4..d7ef289f 100644
219220
}
220221
// NOTE: allow_other requires "user_allow_other" in /etc/fuse.conf
221222
sshfsOptions := "allow_other"
222-
@@ -64,6 +76,9 @@ func (a *HostAgent) setupMount(m limayaml.Mount) (*mount, error) {
223+
@@ -64,6 +77,10 @@ func (a *HostAgent) setupMount(m limayaml.Mount) (*mount, error) {
223224
Readonly: !(*m.Writable),
224225
SSHFSAdditionalArgs: []string{"-o", sshfsOptions},
225226
}
226-
+ if runtime.GOOS == "windows" {
227-
+ rsf.OpensshSftpServerBinary = "sftp-server" // using wrapper
227+
+ serverPath, err := exec.LookPath("sftp-server")
228+
+ if err == nil {
229+
+ rsf.OpensshSftpServerBinary = serverPath
228230
+ }
229231
if err := rsf.Prepare(); err != nil {
230232
return nil, fmt.Errorf("failed to prepare reverse sshfs for %q on %q: %w", location, mountPoint, err)

0 commit comments

Comments
 (0)