Move WSL (Bash on Windows) root filesystem to another hard drive?

前端 未结 3 1701
天命终不由人
天命终不由人 2021-01-29 19:03

I\'ve just upgraded the Windows 10 in my laptop to Redstone 1. So I had a test of the Linux subsystem (aka. WSL, LXSS or Bash on Windows). Basically, everything is fine, but the

3条回答
  •  别那么骄傲
    2021-01-29 19:29

    If you are using Windows 10 version 1903 (April 2019 Update) or later, you can try the WSL command line tool with the export and import options. If you are using an older Windows 10 version, you can move the distribution to another drive using lxRunOffline.


    Using the WSL command line tool

    In Windows 10 version 1903 (April 2019 Update) or later, you can use the wsl.exe command line tool.

    1. Export the distribution. Create a .tar file with the distribution to move using wsl.exe --export

    wsl.exe --export  
    

    For instance, to export an Ubuntu distribution, you can use

    C:\> wsl.exe --export Ubuntu c:\data\ubuntu.tar
    

    2. Import the distribution into the target folder. Then, you can import the exported distribution into another folder

    wsl.exe --import   
    

    For instance, to import the exported Ubuntu into a new UbuntuCustom distribution, you can use

    C:\> wsl.exe --import UbuntuCustom d:\wsl\UbuntuCustom c:\data\ubuntu.tar
    

    NOTE: You may check an script for moving WSL distros that use these commands at https://github.com/pxlrbt/move-wsl


    Using LxRunOffline

    In any Windows 10 version, you can move the distribution to another drive using lxRunOffline.

    1. Set permissions to the target folder. First, I think you must set some permissions to the folder where the distribution will be moved. You may use icacls

    /grant ":(OI)(CI)(F)" to set the proper permissions.

    C:\> whoami
    test\jaime
    
    C:\> icacls D:\wsl /grant "jaime:(OI)(CI)(F)"
    

    NOTE: In addition to the above permissions, I have activated the long path names in Windows.

    2. Move the distribution. Using lxrunoffline move.

    C:\wsl> lxrunoffline move -n Ubuntu-18.04 -d d:\wsl\installed\Ubuntu-18.04
    

    You may check the installation folder using

    C:\wsl> lxrunoffline get-dir -n Ubuntu-18.04
    d:\wsl\installed\Ubuntu-18.04
    

    3. Run the distribution. after moving the distribution, you can run the distribution using wsl or the same lxrunoffline

    C:\wsl> lxrunoffline run -n Ubuntu-18.04 -w
    user@test:~$ exit
    logout
    
    C:\wsl> wsl
    user@test:/mnt/c/wsl$ exit
    logout
    

提交回复
热议问题