当前位置: 首页 > news >正文

debootstrap 构建 RISC-V 64 Ubuntu 根文件系统

debootstrap 构建 Ubuntu RISC-V Linux 根文件系统

flyfish

主机信息
命令 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

生成文件夹temp-rootfs的内容
在这里插入图片描述

2 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 multiversedeb 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

在这里插入图片描述

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
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 loopbackauto eth0
iface eth0 inet dhcp
EOFcat >/etc/resolv.conf <<EOF
nameserver 114.114.114.114
nameserver 8.8.8.8
EOFecho '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

6 文件夹 打包为tar或者gz

sudo tar -cSf rootfs_ubuntu_riscv.tar -C temp-rootfs .gzip rootfs_ubuntu_riscv.tar

7 制作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

以下为可选

8 虚拟机共享文件夹

为了防治物理机被破坏可以将主机放到虚拟机尝试

物理机配置
在这里插入图片描述
虚拟机配置

vmware-hgfsclient
sudo vmhgfs-fuse .host:/ /mnt -o nonempty -o allow_other

第一行命令是查看共享有没有成功
第二行命令是将物理机的共享文件夹挂载到虚拟机的/mnt目录

参考

https://wiki.ubuntu.com/DebootstrapChroot
https://wiki.ubuntu.com/ARM/RootfsFromScratch/
Ubuntu Ports 软件仓库镜像使用帮助

http://www.lryc.cn/news/64862.html

相关文章:

  • 腾讯云轻量应用服务器(Lighthouse)怎么样?
  • 学习 AI 常用的一些专业词汇
  • IP协议基础
  • Redis主从复制、哨兵实战
  • README.md编写
  • 软件设计证书倒计时28天
  • 程序员基础的硬件知识(cpu、主板、显卡、内存条等)
  • 优化Google Cloud Storage大文件上传和内存溢出
  • chatGPT的prompt技巧
  • 【华为OD机试 2023最新 】统一限载货物数最小值(C语言题解 100%)
  • ios 在windows chrome 联调
  • 干翻Mybatis源码系列之第六篇:Mybatis可选缓存概述
  • 如何调教ChatGPT
  • 记一次我的漏洞挖掘实战——某公司的SQL注入漏洞
  • 代码随想录二刷复习 day1 704二分查找 27 移除元素 977 有序数组的平方
  • 第16章 指令级并行与超标量处理器
  • JavaWeb ( 三 ) Web Server 服务器
  • 2.6 浮点运算方法和浮点运算器
  • 第一次找实习, 什么项目可以给自己加分(笔记)
  • FPGA/Verilog HDL/AC620零基础入门学习——8*8同步FIFO实验
  • shell脚本
  • 不部署服务端调用接口,前端接口神器json-server
  • 国产化:复旦微JFM7K325T +华为海思 HI3531DV200 的综合视频处理平台
  • Ceph入门到精通- stderr raise RuntimeError(‘Unable to create a new OSD id‘)
  • AWSFireLens轻松实现容器日志处理
  • Java程序设计入门教程--案例:自由落体
  • Qt音视频开发44-本地摄像头推流(支持分辨率/帧率等设置/实时性极高)
  • SpringCloud学习(七)——统一网关Gateway
  • 《花雕学AI》31:ChatGPT--用关键词/咒语/提示词Prompt激发AI绘画的无限创意!
  • 计算机组成原理9控制单元的结构