制作riscv架构的ubuntu文件系统(rootfs)
命令 lsb_release -a
No LSB modules are available. Distributor ID:Ubuntu Description:Ubuntu 20.04.6 LTS Release:20.04 Codename:focal
制作的根文件系统为
RISC-V 64 Ubuntu 22.04 LTS
1 主机安装需要的程序和生成最小 bootstrap rootfs
# 安装需要的程序
sudo apt install debootstrap qemu qemu-user-static binfmt-support dpkg-cross --no-install-recommends
# 生成最小 bootstrap rootfs
sudo debootstrap --arch=riscv64 --foreign jammy ./temp-rootfs http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports
2 生成文件夹temp-rootfs的内容 chroot 和 debootstrap
# chroot 和 debootstrap sudo chroot temp-rootfs /bin/bash /debootstrap/debootstrap --second-stage
3 添加 package sources
# 添加 package sources
cat >/etc/apt/sources.list <<EOF # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse # deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse # deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse # deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse # deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse # # deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse deb http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse # deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse # 预发布软件源,不建议启用 # deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-proposed main restricted universe multiverse # # deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-proposed main restricted universe multiverse EOF
简洁内容
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse
4 安装 essential packages
apt-get update apt-get install --no-install-recommends -y util-linux haveged openssh-server systemd kmod initramfs-tools conntrack ebtables ethtool iproute2 iptables mount socat ifupdown iputils-ping vim dhcpcd5 neofetch sudo chrony
如果要安装其他包
先挂载,再安装
sudo mount -t proc /proc temp-rootfs/proc sudo mount -t sysfs /sys temp-rootfs/sys sudo mount -o bind /dev temp-rootfs/dev sudo mount -o bind /dev/pts temp-rootfs/dev/pts sudo chroot temp-rootfs /bin/bash
apt install rsyslog apt install language-pack-en-base apt install language-pack-zh-hans apt install net-tools apt install resolvconf apt install network-manager apt install usbutils apt install sysstat apt install bash-completion
安装完成全卸载
sudo umount /dev/pts/ /dev/ /proc/ /sys
5 基本配置
cat >>/etc/network/interfaces <<EOF auto lo iface lo inet loopback auto eth0 iface eth0 inet dhcp EOF cat >/etc/resolv.conf <<EOF nameserver 114.114.114.114 nameserver 8.8.8.8 EOF echo 'riscv-ubuntu2204' > /etc/hostname echo "127.0.0.1 localhost" > /etc/hosts echo "127.0.0.1 riscv-ubuntu2204" >> /etc/hosts #一个大于号是覆盖写,两个大于号是追加写 #添加用户和设置密码 useradd -s '/bin/bash' -m -G adm,sudo flyfish passwd flyfish passwd root sed -i "s/#PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config #分区配置 cat >/etc/fstab <<EOF # <file system><mount pt><type><options><dump><pass> /dev/root/ext2rw,noauto01 proc/procprocdefaults00 devpts/dev/ptsdevptsdefaults,gid=5,mode=620,ptmxmode=066600 tmpfs/dev/shmtmpfsmode=077700 tmpfs/tmptmpfsmode=177700 tmpfs/runtmpfsmode=0755,nosuid,nodev00 sysfs/syssysfsdefaults00 EOF
6 文件夹 打包为tar或者gz
sudo tar -cSf rootfs_ubuntu_riscv.tar -C temp-rootfs . gzip rootfs_ubuntu_riscv.tar
7 制作ext镜像的完整脚本
ext4格式
echo "making image..." dd if=/dev/zero of=rootfs_ubuntu_riscv.ext4 bs=1M count=4096 mkfs.ext4 rootfs_ubuntu_riscv.ext4 mkdir -p tmpfs echo "copy data into rootfs..." sudo mount -t ext4 rootfs_ubuntu_riscv.ext4 tmpfs/ -o loop sudo cp -af temp-rootfs/* tmpfs/ sudo umount tmpfs chmod 777 rootfs_ubuntu_riscv.ext4
ext2格式
echo "making image..." dd if=/dev/zero of=rootfs_ubuntu_riscv.ext2 bs=1M count=1024 mkfs.ext2 rootfs_ubuntu_riscv.ext2 mkdir -p tmpfs echo "copy data into rootfs..." sudo mount -t ext2 rootfs_ubuntu_riscv.ext2 tmpfs/ -o loop sudo cp -af temp-rootfs/* tmpfs/ sudo umount tmpfs chmod 777 rootfs_ubuntu_riscv.ext2
安装内核模块到RISCV架构的根文件系统
在编译完成的linux内核目录中执行
如果是buildroot则目录是buildroot/output/build/linux-origin_master
sudo make ARCH=riscv INSTALL_MOD_PATH=/mnt/temp-rootfs modules_install