Installing a Linux Distribution without internet connection
You can (1) download the installer from the Windows Store or (2) download a distribution file and install it using tools such as lxRunOffline. If you have the distribution file you can make the installation copying the files using a USB drive or something else.
Downloading the installer from the Windows Store
You can download the installers from the Windows Store using Powershell. For instance, you can download the Ubuntu 16 version using the following command
PS> Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1604 -OutFile Ubuntu.appx -UseBasicParsing
In the above command, the output file is Ubuntu.appx
. It must be named in that way. You can run that application to install the Ubuntu.
PS> Ubuntu.appx
Using LxRunOffline
First, you must download some distribution file. There are many distribution files available in the lxRunOffline wiki.
For instance, to install the same Ubuntu 16 from the Microsoft Windows Store, you can download the file at
https://lxrunoffline.apphb.com/download/UbuntuFromMS/16
Then, you can install the linux distribution using lxRunOffline
# lxrunoffline install -n <name> -d <folder> -f <distribution file>
C:\wsl> lxrunoffline install -n copy -d c:\wsl\copy -f 16.04.2-server-cloudimg-amd64-root.tar.gz
To run the distribution, you may use the same lxRunOffline
C:\wsl> lxrunoffline run -n copy -w
Using a DistroLauncher
You can use some DistroLauncher. There are many versions based on the Microsoft example to create custom linux distributions for WSL. For instance, you can use the Yuk7 version.
You must download a distribution file and the launcher.exe
. You must rename the distribution file to rootfs.tar.gz
and the launcher to the distribution name you want. Later you must run the launcher as an Administrator (I got errors running it as a normal user)
PS> ren launcher.exe mydistro.exe
PS> ren .\16.04.2-server-cloudimg-amd64-root.tar.gz rootfs.tar.gz
PS> .\mydistro
The first time you run the launcher, it installs and run the distribution. The next time, it runs the linux distribution.
After installing, you can manage the distributions using the wslconfig
or the lxrunoffline
commands.
Microsoft has recently added comprehensive support for this, and it should be generally available in the April 2019 (19H1) update. Once it's ready, a 9P server will run in the background whenever a Linux distro is running. The 9P server will be able to handle Linux filesystem metadata, and Windows will be able to treat it as a network drive so it can access it safely. You can read about it at https://blogs.msdn.microsoft.com/commandline/2019/02/15/whats-new-for-wsl-in-windows-10-version-1903/.
With the new feature, you'll be able to safely access both Windows and Linux filesystem files from Windows, as long as you go through the 9P server. This will be handled natively from within WSL. For example, from the WSL command line you'll be able to type code /mnt/c/Users/username/src/windows-file.txt
to open a Windows file in VS Code, or type code /home/username/src/linux-file.txt
to open a Linux file in VS Code.
If you're not part of the Windows Insider Program, you won't have access to this yet so you'll still have to use an older method, such as wslpath.
wslpath will convert between Windows- and Linux-style paths so you can easily open Windows files from the WSL command line. As per https://github.com/Microsoft/WSL/issues/3146#issuecomment-388118689, it will refuse to convert Linux filesystem paths (i.e. %AppData%\lxss), because without 9P it's unsafe to modify these files from Windows. This means you can't open /home/username/src/linux-file.txt
, but you can use code "$(wslpath -aw /mnt/c/Users/username/src/windows-file.txt)"
.
In the past, there were a number of third-party tools to perform the same conversion but wslpath does it natively-- in fact, ls -l /bin/wslpath
shows that it's just a link to /init.
Best Answer
I understand that you have the root folder of your distribution, but you cannot run it using
bash
orwsl
. I think you may try to register again your old installation folder using lxRunOfflineRegistering an existing installation
I think that the
BasePath
is the parent of yourrootfs
folder. For instance, if the root folder isThe base path must be