1

Anybody tried to migrate Ubuntu (in this particular case 21.10 in use) from virtual machine (powered by VirtualBox, if this concerns) to WSL? Migration within one single host.

How well could imaging source (v.m.) then restoring to target (WSL) work? Hardware layer has a good chance to differ.

Fifi Cek
  • 309
  • 1
    Your VM's Linux kernel and systemd init won't work on WSL. WSL uses a proprietary Microsoft kernel and init. By all means, do the experiment, and let us know what you discover. – user535733 Jan 23 '22 at 15:08
  • 1
    @user535733 Strongly agree on the Systemd init being something to watch out for. While it's true that the VM's kernel isn't going to work, I'm not sure I'd call WSL2's kernel "proprietary". Sure, it's a fork of the mainline kernel, but (a) the primary differences, to my knowledge, are just driver-based, (b) it's open-sourced, (c) as far as I know, changes in it are often contributed back upstream – NotTheDr01ds Jan 23 '22 at 17:13
  • @NotTheDr01ds thanks for the refinement. I have learned something new today. – user535733 Jan 23 '22 at 18:03

1 Answers1

3

In general, if you can get a tarball'd rootfs of the VM, it should (in theory) be pretty straightforward, although I haven't tried it. The main trick will be getting the rootfs.tar "just right". Considerations:

  • It will need to include all "normal" filesystems from the VM, but you can, of course, ignore things like /proc, /sys, /dev, etc.

  • You should include the --xattrs flag to tar to make sure you pick up any extended attributes. This is not the default.

Once you have a valid rootfs tarball, importing in WSL is easy:

wsl --import Ubuntu2110 <directory> <tarball> --version 2

The first argument (distribution name) can be whatever you prefer, although I'd recommend avoiding Ubuntu as this is the name of the default WSL distro and could cause a conflict.

I tend to set up my WSL "directory":

  • Somewhere easy to get to from PowerShell, such as ~\Documents\WSL
  • Have ~\Documents\WSL\instances\Ubuntu2110 (and others) for my distributions
  • Have ~\Documents\WSL\images\Ubuntu2110.tar (and others) for my rootfs images.

Hardware layer has a good chance to differ.

Not really the issue you might think. WSL2 instances are actually more "containers" than VMs. There is a VM running, but you can't access it. The VM itself is what handles the import and running of the distros/instances/containers. All WSL2 instances share the same kernelspace, virtual hardware, network, etc., but each has its own PID namespace, chroot, etc (to oversummarize).


Differences between WSL and your VM

  • System startup

    The biggest difference you are going to find is that the VM does all of its configuration via Systemd, of course. That's not going to happen on WSL2, as Systemd isn't supported. Instead, WSL uses its own /init for bootstrapping the interoperability with the system VM and Windows.

    That means that, when you start up the WSL2 instance from the imported VM, pretty much nothing is going to be running.

    You'll need to start each service manually. Or use other techniques to start automatically.

  • Other Systemd issues

    While you can start many services in Ubuntu without Systemd, more and more are relying on Systemd. Those can be problematic under WSL. Although there are workarounds to run Systemd in WSL, they tend to be "hacky" at present.

  • GUI Apps

    Also, remember that WSL is primarily a command-line environment. To run GUI apps, you'll need to run either:

    • Windows 11
    • A third-party X server in Windows
    • Or xrdp
  • Desktop Environments

    Finally, desktop environments can be even more challenging, for a combination of the above reasons and more:

    • Some require Systemd
    • Running full-screen Linux GUI apps in Windows can present key-binding challenges (e.g. Alt+Tab will be intercepted by Windows and shift away from your DE).
    • WSLg in Windows 11 utilizes Weston, which provides its own window manager
NotTheDr01ds
  • 17,888