qemu 源码分析(Qemu搭建龙芯LoongArch的LinuxCLFS环境)
qemu 源码分析(Qemu搭建龙芯LoongArch的LinuxCLFS环境)#拷贝到刚解压的bin目录下 cp qemu-loongarch64 /mnt/e/work-qemu/loongarch/bin/qemu-loongarch64 chroot /mnt/e/work-qemu/loongarchchroot命令 用来在指定的根目录下运行指令。chroot,即 change root directory (更改 root 目录)。在 linux 系统中,系统默认的目录结构都是以/,即是以根 (root) 开始的。而在使用 chroot 之后,系统的目录结构将以指定的位置作为/位置。binfmt_misc是Linux内核的一项功能,其使得内核可识别任意类型的可执行文件格式并传递至特定的用户空间应用程序,如模拟器和虚拟机。类似Windows根据文件扩展名选择打开程序。https://learn.microsoft.com/en-us/windows/wsl/
基于以下五种技术快速搭建LoongArch的Linux开发环境
- WSL(Windows Subsystem for Linux)
- qemu-user-static
- binfmt_misc(Miscellaneous Binary Format)
- clfs(Cross Linux From ScratchMiscellaneous Binary Format)
- chroot
WSL(Windows Subsystem for Linux)适用于 Linux 的 Windows 子系统可让开发人员按原样运行 GNU/Linux 环境 - 包括大多数命令行工具、实用工具和应用程序 - 且不会产生传统虚拟机或双启动设置开销。
您可以:
- 在 Microsoft Store 中选择你偏好的 GNU/Linux 分发版。
- 运行常用的命令行软件工具(例如 grep、sed、awk)或其他 ELF-64 二进制文件。
- 运行 Bash shell 脚本和 GNU/Linux 命令行应用程序,包括:工具:vim、emacs、tmux语言:NodeJS、Javascript、Python、Ruby、C/C 、C# 与 F#、Rust、Go 等服务:SSHD、MySQL、Apache、lighttpd、MongoDB、PostgreSQL。
- 使用自己的 GNU/Linux 分发包管理器安装其他软件。
- 使用类似于 Unix 的命令行 shell 调用 Windows 应用程序。
- 在 Windows 上调用 GNU/Linux 应用程序。
- 运行直接集成到 Windows 桌面的 GNU/Linux 图形应用程序
- 将 GPU 加速用于机器学习、数据科学场景等
参考在windows上使用WSL安装linux教程:
https://learn.microsoft.com/en-us/windows/wsl/install
下载预编译包和loongarch qemu
下载地址:
https://github.com/sunhaiyong1978/CLFS-for-LoongArch/releases
启动WSL,并注册Binfmt
在Binfmt注册LoongArch可执行文件的信息了
sudo passwd #添加root密码
su # 需要root用户
echo ":qemu-loongarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02\x01:\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/bin/qemu-loongarch64:" > /proc/sys/fs/binfmt_misc/register
以上命令注册了LoongArch可执行文件“头信息”,并指定符合条件的文件会使用"/bin/qemu-loongarch64"命令来执行,所以这个"/bin/qemu-loongarch64"命令必须真实有效。
binfmt_misc是Linux内核的一项功能,其使得内核可识别任意类型的可执行文件格式并传递至特定的用户空间应用程序,如模拟器和虚拟机。类似Windows根据文件扩展名选择打开程序。
解压LoongArch系统包,并执行chroot#拷贝到刚解压的bin目录下
cp qemu-loongarch64 /mnt/e/work-qemu/loongarch/bin/qemu-loongarch64
chroot /mnt/e/work-qemu/loongarch
chroot命令 用来在指定的根目录下运行指令。chroot,即 change root directory (更改 root 目录)。在 linux 系统中,系统默认的目录结构都是以/,即是以根 (root) 开始的。而在使用 chroot 之后,系统的目录结构将以指定的位置作为/位置。