当前位置:首页 > 技术 > LINUX > 正文内容

从零开始构建 RISC-V 架构下的 Debian 根文件镜像

Watrt2年前 (2023-10-24)LINUX11100

主机配置:Ubuntu 18.04

配置基本服务

下载安装依赖

sudo apt install debootstrap qemu qemu-user-static qemu-system qemu-utils qemu-system-misc binfmt-support dpkg-cross debian-ports-archive-keyring --no-install-recommends

生成目标镜像,配置环境

dd if=/dev/zero of=rootfs.img bs=1M count=4096
mkdir rootfs
mkfs.ext4 rootfs.img
sudo mount rootfs.img rootfs

执行下debootstrap

sudo debootstrap --arch=riscv64 --foreign --keyring /usr/share/keyrings/debian-ports-archive-keyring.gpg --include=debian-ports-archive-keyring sid ./rootfs http://deb.debian.org/debian-ports

如果遇到GPG error: E852514F5DF312F6,需要更新下本地钥匙串。

wget http://ftp.cn.debian.org/debian/pool/main/d/debian-ports-archive-keyring/debian-ports-archive-keyring_2022.02.15_all.deb
sudo dpkg -i debian-ports-archive-keyring_2022.02.15_all.deb

基本文件系统就准备好了

编译安装最新版的QEMU

安装依赖。

sudo apt-get install -y pkg-config git libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev

下载,配置QEMU并编译

wget https://download.qemu.org/qemu-7.0.0.tar.xz
tar -xf qemu-7.0.0.tar.xz
cd qemu-7.0.0/
./configure --static --target-list=riscv64-linux-user
make

将QEMU打包成 DEB 并安装

sudo apt-get install checkinstall
sudo checkinstall make install
sudo apt-get install ./*.deb

或直接安装

sudo make install

配置binfmt

/usr/bin/qemu-riscv64-static必须能够在chroot的目的地执行。 已准备好binfmt,riscv64可以运行。

先复制一份

将qemu-riscv64-static放在./riscv/usr/bin/QEMU-riscv 64-static上,如果是为了这次的目的,请使用/usr/bin/qemu-riscv64-static 只要在chroot的前端存在/usr/bin/qemu-riscv64-static二进制文件即可。

sudo cp -rf /usr/bin/qemu-riscv64-static rootfs/usr/bin/

配置binfmt的magic和mask

cat > /tmp/riscv64 <<- EOF
package qemu-user-static
type magic
offset 0
magic \x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00
mask \xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff
interpreter /usr/bin/qemu-riscv64-static
EOF

导入binfmt

sudo update-binfmts --import /tmp/riscv64

检查一下有没有配置成功

ls /proc/sys/fs/binfmt_misc/riscv64
-> /proc/sys/fs/binfmt_misc/riscv64

(如果没有输出,sudo systemctl restart binfmt-support 一下)

进入chroot环境

sudo chroot rootfs/

配置目标rootfs

先让debootstrap把事情干完。

/debootstrap/debootstrap --second-stage

再配置下软件源

cat >/etc/apt/sources.list <<EOF
deb http://ftp.ports.debian.org/debian-ports sid main
deb http://ftp.ports.debian.org/debian-ports unstable main
deb http://ftp.ports.debian.org/debian-ports unreleased main
deb http://ftp.ports.debian.org/debian-ports experimental main
EOF

安装软件包

apt-get update
apt-get install -y util-linux haveged openssh-server systemd kmod initramfs-tools conntrack ebtables ethtool iproute2 iptables mount socat ifupdown iputils-ping vim neofetch sudo chrony pciutils

配置网络

mkdir -p /etc/network
cat >/etc/network/interfaces <<EOF
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
EOF
cat >/etc/resolv.conf <<EOF
nameserver 1.1.1.1
nameserver 8.8.8.8
EOF

配置分区

cat >/etc/fstab <<EOF
LABEL=rootfs/ext4user_xattr,errors=remount-ro01
EOF

配置root密码

echo "root:riscv" | chpasswd

清理缓存

apt-get clean
rm -rf /var/cache/apt/

退出chroot,解除挂载

exit
sudo umount rootfs

输出得到的rootfs.img就是目标根文件。


打赏 支付宝打赏 微信打赏
分享给朋友:

相关文章

Deepin Linux修复grub引导

Deepin Linux修复grub引导

环境说明:一直使用的是Win7+Deepin 15.5。后来全新安装了Win 10,需要修复grub第一步:在Windows操作系统下使用深度官方的U盘启动制作器 制作U盘第二步:开机U盘启动进入Deepin linux安装界面,待进入到安装界面选择语言时,按住Crtl+Alt+F2/F1进入Linux tty终端。并执行以下命令完成修复sudo fdisk -l/*根据查询结果确定deepin 的/目录和/boot目录所在的分区编号*/sudo mount&nbs...

Linux没有最小只有更小----迷你Linux版本大集合

Linux没有最小只有更小----迷你Linux版本大集合

    自从去年到现在已经收集了上百种版本的Linux和Unix,至于Unix就不想说了,没有Linux的功底是很难驾驭Unix的,我在这里只把小于360M的Linux以及一些非Linux但是很像Linux的版本也发布一下,我本人喜欢安静,如果你想要这些迷你版本的Linux光盘的话,建议去官网下载就OK了。英语不行的话随时带个字典。有些没有桌面,想知道哪些没有桌面的话请自己网上查资料!下面就是绝大部分小于361M的Linux及其非Linux名单,参考时间为...

 Debian 9.9 (stretch) 文件系统制作

Debian 9.9 (stretch) 文件系统制作

0. 准备工作:sudo apt install qemu-user-static -y sudo apt install debootstrap -y mkdir rootfs1. debootstrapdebootstrap --foreign --verbose --arch=armhf  stretch rootfs http...

Configure & Build

Configure & Build

Configure and build Linux kernel for Surface RTEditing kernel build configurationFirst run the command make ARCH=arm tegra_defconfigThis will create a standard kernel config for tegra SoC's.Open the file .config in the kernel source directory wit...

f1c100s编译启动所需的uboot,kernel,rootfs

f1c100s编译启动所需的uboot,kernel,rootfs

 https://github.com/Icenowy/linux.git 有f1c100s-480272lcd-test和f1c100s分支, 然后自己手动修复一个 USB 问题,驱动就比较全了https://github.com/Lichee-Pi/linux.git 有nano-4.14-exp和nano-5.2-flash分支,用哪个合适个人画了块没有连接任何其他模块的F1C100S开发板,没有链接任何外设,本文是编译所有启动所需的三大件。(只要编...

从Ubuntu-base构建ubuntu rootfs系统

从Ubuntu-base构建ubuntu rootfs系统

1.介绍ubuntu-base 是Ubuntu官方构建的ubuntu最小文件系统,包含debain软件包管理器,基础包大小通常只有几十兆,其背后有整个ubuntu软件源支持,ubuntu软件一般稳定性比较好,基于ubuntu-base按需安装Linux软件,深度可定制…,常用于嵌入式rootfs构建。嵌入式常见的几种文件系统构建方法:busybox、yocto、builroot,我觉得它们都不如Ubuntu方便,强大的包管系统,有强大的社区支持,可以直接apt-get install来安装新软件...

Ubuntu+Openbox_还原_安装_脚本

Ubuntu+Openbox_还原_安装_脚本

第一步:安装UBUNTU基本系统安装基本的命令行系统,选英文。装好重启后马上把系统tar备份(只有186M),下次重装1分钟就可以解压第二步:执行脚本#!/bin/bash #联网----------->卸载DHCP、配置拨号、解决掉线、网络接口 sudo apt-get -y purge isc-dhcp-client && sudo pppoeconf && s...

如何使用 Ubuntu 安装和配置 Openbox

如何使用 Ubuntu 安装和配置 Openbox

Openbox是一个相当简单的窗口管理器,我们可以根据需要构建和自定义。本教程向我们展示了在 Ubuntu 中设置 Openbox 的基础知识、如何更改菜单、如何添加扩展坞以及如何设置墙纸。安装 Openbox要安装 Openbox,请同时打开终端窗口(按 CTRL 、 ALT 和 T )或者在破折号中搜索“TERM”并选择图标。输入以下命令:sudo apt install openbox obconf单击右上角的图标,然后注销。如何切换到 Openbo...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。