Why does the WSL2 import command in PowerShell output "Access is denied"?
Asked Answered
H

6

6

On Windows 10 Pro and 11 Pro I have installed and activated Ubuntu-20.04 and Debian. Using the documentation from MS on switching those distros to a secondary drive, everything seemed to work fine. Until the WSL import command. It outputs "Access is denied". I've tried Windows Terminal, PowerShell, and even WebStorm; I get the same output.

I am running with elevated privileges but to no avail. The export works fine, I use a different name as the source file to ensure I restore the name to its original name. The wsl.conf editing looks good, everything lines up... until the import command.

I am at a loss. I've exhausted all research. Can anyone help me resolve this so I can run these from my F: drive?

Cheers,

RN

Hellish answered 23/8, 2021 at 9:1 Comment(4)
Please share the exact command you're runningFlimsy
I forgot to paste the link, it is here: learn.microsoft.com/en-us/windows/wsl/wsl-configHellish
That is absolutely hideous. Let me clean that up: From memory, along the lines of: $ cd /etc/ # sudo nano wsl.conf [or vim]--add file commits - open powershell # wsl --shutdown # wsl -l -v # wsl --export Debian C:\temp\Dibian.tar # wsl unregister Debian # wsl -l -v to verify deregistration # wsl --import Dibian.tar F:\wsl C:\temp\Dibian !output --> Access is denied. I follow the same process with Ubuntu-20.04, but export to Ubintu.tar, then export to original name Ubuntu-20.04.Hellish
Please edit your question with the exact commands you ran and the output you got. Best to do it over again rather than trying to write it from memory. It's really difficult to help otherwise.Moslem
M
22

You just have to put a filename in the end, like:

wsl --export Ubuntu C:\Users\Desktop\OneDrive\Documents\ubuntu.tar
Menendez answered 19/9, 2021 at 1:35 Comment(0)
A
7

Suppose you want to import an exported distribution "ubuntu.tar".

Try to cd at the location of the .tar file before executing the wsl --import command in PowerShell (running as standard user), for example:

PS X:\> cd D:\
PS D:\> wsl --import Ubuntu_copy .\Ubuntu_copy ubuntu.tar

Executing the wsl --import command with an absolute path didn't work for me, but the above mentioned method did.

Assimilable answered 4/1, 2022 at 12:31 Comment(0)
I
0

Just in case this is an ongoing issue for anyone, you need to run wsl --import not just from an Administrator account, but you need to run Powershell/cmd as Administrator, for example by right-clicking a pwsh.exe icon/shortcut and clicking "Run as administrator". If you're running as a standard user and "Run as administrator", the import will install the distro for the admin user you've chosen to run as.

The full syntax is:

wsl --import <Distro name> <Install folder> <Source .tar file>
Impaste answered 27/3, 2022 at 20:6 Comment(0)
Q
0

wsl -h

The import syntax is as following, you should be carefull about install dir and imported tar file's arguments order:

--import <Distro> <InstallLocation> <FileName> [Options]                                                            
    Imports the specified tar file as a new distribution.                                                                   
    The filename can be - for standard input.                                                                                                                                                                                                       
    Options:                                                                                                                    
    --version <Version>                                                                                                         
        Specifies the version to use for the new distribution. 
Quadrate answered 2/10, 2022 at 14:0 Comment(0)
C
0

Unfortunately, this can happen for a lot of reasons. In my case, I wasn't sure what to put for the <InstallLocation>. The official documentation says Ubuntu is installed on the "C:" drive, so I mistakenly put C: for that value and it gave me the same error.

When I used C:\WSL as the <InstallLocation>, the command worked as expected.

Colmar answered 25/1 at 7:2 Comment(0)
M
0

I had to cd to the file location before using wsl --import ubuntu .\ ubuntu.tar

Mongolia answered 16/2 at 12:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.