其他分享
首页 > 其他分享> > 编译更新 WSL2 内核至4.19.57,增加 Squashfs 支持

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

作者:互联网

编译更新 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), 并转换成 VERSION2 (WSL2)模式

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

获取WSL2 Kernel最新代码

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

安装依赖

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

编译内核

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

kernel/fs/squashfs/squashfs.ko

所以直接编译

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://linux.cn/article-10972-1.html
Singularity3.3手册: https://sylabs.io/guides/3.3/user-guide/

标签:4.19,57,Squashfs,DESKTOP,编译,内核,singularity,WSL2,squashfs
来源: https://blog.csdn.net/weixin_44008092/article/details/96125560