Score:1

Ubuntu to migrate from virtual machine to WSL

ve flag

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.

user535733 avatar
cn flag
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.
NotTheDr01ds avatar
vn flag
@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
user535733 avatar
cn flag
@NotTheDr01ds thanks for the refinement. I have learned something new today.
Score:2
vn flag

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
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.