您的位置:首页 > 其它

编译更新 WSL2 内核至4.19.57,增加 Squashfs 支持

2019-07-16 13:52 746 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/weixin_44008092/article/details/96125560

编译更新 WSL2 内核至4.19.57,增加 Squashfs 支持

前言

WSL是WIN10中内置的Linux子系统,WSL2是WSL技术的第二版。今天在WSL2环境中测试Singularity时遇到问题,无法启动sif格式镜像。经分析,原因是内核中没有squashfs文件系统所致。

当前内核版本:

root@DESKTOP-ASI6ES4:~# uname -r
4.19.43-microsoft-standard

错误表现:

root@DESKTOP-ASI6ES4:/opt/singularity# singularity shell busybox_latest.sif
FATAL: container creation failed: mount /proc/self/fd/3/usr/local/var/singularity/mnt/session/rootfs error: can’t mount image /proc/self/fd/3: failed to mount squashfs filesystem: no such device

准备编译环境

微软商店获取 Ubuntu(我使用的是16.04), 并运行

wsl.exe --list -v
NAME STATE VERSION
Ubuntu-16.04 Running 2

获取WSL2 Kernel最新代码

微软已经在GITHUB上开源了内核代码,GITHUB

git clone https://github.com/microsoft/WSL2-Linux-Kernel

安装依赖

sudo install build-essential flex bison libssl-dev libelf-dev

编译内核

查看 modules.builtin 文件,发现最新代码中已经增加了squashfs支持

kernel/fs/squashfs/squashfs.ko

查看git log,发现是6月14日增加的支持

commit 051a2e8171ec05d9d42035f79b1b207e1fe00e6c
Author: Sasha Levin alexander.levin@microsoft.com
Date: Fri Jun 14 23:07:02 2019 +0000
Update WSL config
Enable squashfs, NF conntrack, etc
TAG_MSFT: wsl
Signed-off-by: Sasha Levin alexander.levin@microsoft.com

所以直接编译

make KCONFIG_CONFIG=Microsoft/config-wsl

编译成功后,项目根目录会产生 vmlinux,把该文件复制到 windows 文件系统中,例如 c:\tmp

cp ./vmlinux /mnt/c/tmp/

替换内核

WIN10中以管理员身份运行 PowerShell

  1. 停止所有 WSL 实例

wsl.exe --shutdown

  1. 备份原内核
    cd C:\Windows\System32\lxss\tools
    move kernel kernel.back
  2. 复制编译好的内核
    cp c:\tmp\vmlinux .\kernel

重新启动 WSL2, 验证singularity

最新内核版本:

root@DESKTOP-ASI6ES4:/opt/singularity# uname -r
4.19.57-microsoft-standard+

重启ubuntu16.04

wsd.exe -d Ubuntu-16.04

再次运行singularity

root@DESKTOP-ASI6ES4:/opt/singularity# singularity shell busybox_latest.sif
Singularity>

工作正常

延伸阅读

WSL2 Announcing: https://devblogs.microsoft.com/commandline/announcing-wsl-2/
WSL2 使用入门: https://www.geek-share.com/detail/2711221107.html
Singularity3.3手册: https://sylabs.io/guides/3.3/user-guide/

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: