将 WSL(Windows 上的 Bash)根文件系统移动到另一个硬盘驱动器? [英] Move WSL (Bash on Windows) root filesystem to another hard drive?
问题描述
我刚刚将笔记本电脑中的 Windows 10 升级到 Redstone 1.所以我对 Linux 子系统(也就是 Windows 上的 WSL、LXSS 或 Bash)进行了测试.基本上一切正常,但是有一个问题是WSL的RootFS位于%LocalAppData%
路径下(例如C:\Users\xyz\AppData\Local
),这也是我的 Windows 操作系统所在的地方.它消耗了我笔记本电脑中的大量 SSD 硬盘空间,我希望我可以将它移到我的外置硬盘上.
还有一个问题.由于其他硬盘分区挂载为DriveFS,因此不支持chmod
等一些Linux文件系统功能,而且我的一些Linux项目构建脚本仅适用于VoIFS,它仅位于/
和 /home
.
所以我尝试将整个 WSL RootFS 移动到另一个硬盘驱动器.首先,我尝试为 C:\Users\xyz\AppData\Local\lxss
创建一个 NTFS 连接(硬链接).我已经完全卸载了 WSL 并将 RootFS 的 mklink
运行到另一个硬盘驱动器,当我再次重新安装 WSL 时,它无法创建新用户,并报告错误代码 0x80070003.
然后我四处搜索,我得到了这个:移动 Linux 文件系统 - 问题 #449.WSL RootFS 的移动和制作硬链接似乎只在 Windows 10 Build 14388 之前有效,它在 Windows 10 Build 14393 RTM 中不起作用. 唯一的方法是移动整个 %LocalAppData%
到外部硬盘驱动器,但我不能这样做,因为我是笔记本电脑用户,我不能随身携带外部硬盘驱动器!
所以我想问一下,有没有其他方法可以将 WSL 移出我的系统分区?如果我不能这样做,我可以在其他地方创建一个额外的 VoIFS 工作目录并编译我的东西吗?
谢谢和问候,杰克逊
如果您使用的是 Windows 10 版本 1903(2019 年 4 月更新)或更高版本,您可以尝试带有 export
和 import
选项.如果您使用的是较旧的 Windows 10 版本,您可以使用 lxRunOffline 将分发版移动到另一个驱动器.><小时>
使用 WSL 命令行工具
在 Windows 10 版本 1903(2019 年 4 月更新)或更高版本中,您可以使用 wsl.exe
命令行工具.
1.导出分发版. 使用 wsl.exe --export
.tar
文件和分发版一起移动wsl.exe --export <分发名称><Tar-文件名>
例如,要导出 Ubuntu
发行版,您可以使用
C:\>wsl.exe --export Ubuntu c:\data\ubuntu.tar
2.将发行版导入到目标文件夹中. 然后,您可以将导出的发行版导入到另一个文件夹中
wsl.exe --import <分发名称><安装文件夹><Tar-文件名>
例如,要将导出的 Ubuntu
导入到新的 UbuntuCustom
发行版中,您可以使用
C:\>wsl.exe --import UbuntuCustom d:\wsl\UbuntuCustom c:\data\ubuntu.tar
注意:您可以在 https://github.com/pxlrbt/move-wsl
<小时>使用 LxRunOffline
在任何 Windows 10 版本中,您都可以使用 lxRunOffline 将分发版移动到另一个驱动器.
1.为目标文件夹设置权限. 首先,我认为您必须为将要移动分发的文件夹设置一些权限.您可以使用 icacls <dir>/grant "
设置适当的权限.
C:\>我是谁测试\海梅C:\>icacls D:\wsl/grant "jaime:(OI)(CI)(F)"
注意:除了上述权限,我还激活了Windows 中的长路径名.
2.移动分发版. 使用 lxrunoffline move
.
C:\wsl>lxrunoffline move -n Ubuntu-18.04 -d d:\wsl\installed\Ubuntu-18.04
您可以使用
检查安装文件夹C:\wsl>lxrunoffline get-dir -n Ubuntu-18.04d:\wsl\installed\Ubuntu-18.04
3.运行发行版. 移动发行版后,您可以使用 wsl
或相同的 lxrunoffline
C:\wsl>lxrunoffline 运行 -n Ubuntu-18.04 -wuser@test:~$ 退出登出C:\wsl>WSluser@test:/mnt/c/wsl$ 退出登出
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 there is a problem that the RootFS of WSL is located in the %LocalAppData%
path (e.g. C:\Users\xyz\AppData\Local
), which is also the place where my Windows OS located. It consumes a lot of the SSD hard drive space in my laptop and I hope I can move it to my external hard drive.
There is an another problem. Since the other hard drive partitions are mounted as DriveFS, it does not support some Linux filesystem features like chmod
, and some of my Linux project build scripts only works in VoIFS, which only located in /
and /home
.
So I tried to move the whole WSL RootFS to another hard drive. Firstly I've tried to make a NTFS Junction (hard link) for C:\Users\xyz\AppData\Local\lxss
. I've uninstalled the WSL completely and run mklink
for the RootFS to another hard drive, and when I reinstall the WSL again, it couldn't create the new user, and it reports error with code 0x80070003.
Then I searched around, and I got this: moving Linux filesystem - issue #449. It seems that moving and making hard link for WSL RootFS only works before Windows 10 Build 14388, it does not work in the Windows 10 Build 14393 RTM. The only way is moving the whole %LocalAppData%
to the external hard drive, but I cannot do that since I'm a laptop user and I can't bring an external hard drive everywhere!
So I would like to ask that, is there any other ways to move WSL out of my system partition? If I can't do that, can I create an extra VoIFS work directory in some other places and compile my stuff?
Thanks and regards, Jackson
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 <DistributionName> <Tar-FileName>
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 <DistributionName> <Folder-To-Install> <Tar-FileName>
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 <dir> /grant "<user>:(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
这篇关于将 WSL(Windows 上的 Bash)根文件系统移动到另一个硬盘驱动器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!