1

I'm new to the WSL2 and wondering if it's possible to run the same WSL2 ubuntu instance on both my desktop and laptop.

Now I am able to use wsl --export and wsl --import method to save and load the system to/from my portable hard drive. But these methods takes a long time.

I notice that wsl --import load a file named ext4.vhdx. Is there a way to load straightly from this file?

Update v2.0:

I was able to get a workaround and it works great.

Thanks to Booting from vhdx here, I was able to load straightly from my vhdx file on my portable hard disk. Windows track down its subsystem with regedit, So we can write our own(p.s: make sure to get BasePath right, it starts with "\\\\?", or you will not be able to access the subsystem' filesystem on your host system.):

 Windows Registry Editor Version 5.00

 [HKEY_USERS\【your SID here】\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\{【UUID here】}]

"State"=dword:00000001

"DistributionName"="distribution name"

"Version"=dword:00000002

"BasePath"="vhdx folder path" 【 e.g. "\\\\?\\E:\\S061\\WSL\\ubuntu-20"】

"Flags"=dword:0000000f

"DefaultUid"=dword:000003e8
古今中
  • 333
  • 1
  • 2
  • 8

2 Answers2

1

I suppose the best way to do this would be to store ext4.vhd on a network storage device accessible to both devices.

I have previosly mentioned how to move ext4.vhd. You can check that out here Basically you need to export from one machine and import it while making sure the vhd file is configured for wsl to access from the network storage

Since this should *officially* not supported expect some performance hits

Another way would be to run WSL on one computer and ssh/remote desktop to it from another device on the network

zwxi
  • 782
  • 7
  • 9
0

I'm of the strong belief that sharing the same ext4 vhd between two VM's simultaneously would be a bad idea. See this and this Unix & Linux StackExchange, including the part about ...

note that sharing LVs/partitions on a single disk between the servers at the same time is NOT very safe. You should only access whole disks from any of the servers at one time.

However, as dopewind's answer mentioned, you can access the WSL instance on one computer (probably the desktop) from another (e.g. the laptop). There are several techniques you can use:

  • If you have Windows 10 Professional or Enterprise on one of the computers, you can enable Remote Desktop, which allows you to access pretty much everything on one computer from another. RDP ("Remote Desktop Protocol") even works from other devices such as an iPad or Android tablet (or even a phone, although that's a bit of a small screen for a "desktop"). That said, there are better, more idiomatic solutions for WSL ...

  • You could enable SSH server on the Windows 10 computer with the WSL instance (instructions). This may sound counterintuitive to some people, since Linux itself running in the WSL instance also includes an SSH server (by default). But by SSH'ing from (for example) your laptop into your desktop's Windows 10, you can then launch any WSL instance you have installed (if you choose to install more than one) via wsl -d <distroName>. You also avoid a lot of the network unpleasantness in the next option ...

  • You could, as mentioned above, enable SSH on the WSL instance (usually something like sudo service ssh start) and then ssh directly into it. However, note that WSL2 instances are NAT'd, so there's a whole lot more hackery that you have to do to get access to the network interface. There's a whole huge thread on the WSL Github about it. Personally, I'd recommend the "Windows SSH Server" option mentioned about to start out with, then you can worry about direct SSH access later if you need it.

    Side note: Even though I have SSH enabled on my WSL instances, I still use Windows SSH to proxy to them, to avoid these networking issues.

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70
  • Thanks a lot! Does the SSH remote connection requires a public network ip address? Btw, I am not planning to access the file system simultaneously, but rather, say, access it on the laptop at day and desktop at night? – 古今中 Dec 21 '20 at 02:13
  • Ah, if it is only accessed on one device at a time (and the WSL instance is terminated `wsl --terminate` on one machine before the other), then it's more than likely *possible* to share the vhd, but probably *very* slow. – NotTheDr01ds Dec 21 '20 at 03:29
  • And ssh can be done without requiring a public IP, purely on your internal network. – NotTheDr01ds Dec 21 '20 at 03:31