Score:2

Migrating from VirtualBox to WSL

jp flag

I've been using Ubuntu on VirtualBox for about a year now, but I recently learned about WSL, and it seems a lot more useful for my purposes. I've been trying to migrate all my data out of the VirtualBox VM, but I'm unable to find any resources online that tell me how to do so. I was able to migrate my VM and all the data within to Hyper-V in the hopes that migration from Hyper-V to WSL2 would be simpler, but so far that process eludes me too.

Right now all I want is access to all the files that are in my VM, from outside the VM (i.e. accessible from WSL).

Any advice would be much appreciated!

Nmath avatar
ng flag
WSL is considerably different than a VM installation. You will need to install Ubuntu from the Windows store. You can then manually copy any files to your WSL installation
user535733 avatar
cn flag
See https://askubuntu.com/questions/19430/mount-a-virtualbox-drive-image-vdi for how to mount a Virtualbox .vdi virtual hard drive in your WSL Ubuntu. I suggest you make a backup copy before trying to modify virtual drives -- when trying something new, something might go wrong.
arenay avatar
jp flag
Thanks! I've already installed Ubuntu, and created a copy of the original - the copy is what I'm using to get the files from, not the original.I wouldn't mind copying the files over manually, I'm just not able to figure out where those files are located.
NotTheDr01ds avatar
vn flag
Welcome again! Thanks for reposting this here rather than Stack Overflow. The idea from @user535733 is just the type of thing I was hoping to see from the expertise here, and why I recommended coming to Ask Ubuntu rather than Super User for this particular question.
Score:1
vn flag

You can go several routes here:

  • As mentioned in the comments, this question covers how to directly mount the VirtualBox disk image directly in Ubuntu. While I haven't tried it, I can't see any reason that this won't work on WSL2 (but it will not on WSL1).

    One thing to keep in mind will be size and performance. I'm assuming that the .vdi is on a Windows drive at the moment, so you'll need to access it using /mnt/c/path/to/vdi (or /mnt/d, etc.). The performance when accessing files on Windows drives under WSL2 is quite a bit degraded, but that's generally only a problem when dealing with a lot of smaller files. I'm not sure, but I think performance will be okay with a single large .vdi. It's a "one-time-only" thing anyway, so I'm sure that degraded performance won't be a total showstopper, at least.

    Alternatively, if you choose to copy your .vdi into WSL before mounting, realize that it will grow the size of the WSL virtual disk, and the space that is consumed won't be reclaimed when you delete the .vdi (or move it back "out" of WSL2. See my answer here on Super User for details on how to reclaim the space if you end up in this situation.

  • Alternatively, you might choose to use a network share/copy from VirtualBox to WSL. The trick here is making sure that the network is accessible, but I don't think that's going to be a problem when attempting to contact your VirtualBox VM from WSL2. If you have trouble connecting, let me know, and we can work on that part.

    Assuming that you have ssh set up inside the existing VM, you can always use sftp or scp to copy files over manually to WSL.

    Or, if you have Samba installed in the VM, you can simply mount the CIFS share from inside WSL2. See this answer on Stack Overflow (also off-topic since it's not programming-related, but some of them slip through) along with the other answers to that question about mounting Samba shares.

arenay avatar
jp flag
This worked, thanks! I used the first method, which let me mount the .vdi image directly in Ubuntu. I appreciate your help!
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.