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

Riscv64创建ubuntu文件系统

Watrt2个月前 (08-01)LINUX208130

UBUNTU系统内核必须要开启的支持模块:

CONFIG_CGROUPS=y
CONFIG_CGROUP_FREEZER=y
CONFIG_CGROUP_PIDS=y
CONFIG_CGROUP_DEVICE=y
CONFIG_CPUSETS=y
CONFIG_PROC_PID_CPUSET=y
CONFIG_CGROUP_CPUACCT=y
CONFIG_PAGE_COUNTER=y
CONFIG_MEMCG=y
CONFIG_CGROUP_SCHED=y
CONFIG_NAMESPACES=y
CONFIG_OVERLAY_FS=y
CONFIG_AUTOFS4_FS=y
CONFIG_SIGNALFD=y
CONFIG_TIMERFD=y
CONFIG_EPOLL=y
CONFIG_IPV6=y
CONFIG_FANOTIFY
CONFIG_CGROUP_BPF=y
CONFIG_TMPFS=y
CONFIG_TMPFS_POSIX_ACL=y

# optional (开启 zram 内存压缩):
CONFIG_ZSMALLOC=y
CONFIG_ZRAM=y

文件系统创建:

Important: to reduce ram usage follow point n.2 of the ![faq](https://github.com/milkv-duo/duo-buildroot-sdk/tree/develop#faqs),

to increase the rootfs partition size you can edit ```duo-buildroot-sdk/milkv/genimage-milkv-duo.cfg```

at line 16 replace ```size = 256M``` with ```size = 1G``` or higher as desired

then follow the ![instructions](https://github.com/milkv-duo/duo-buildroot-sdk#step-by-step-compilation) to manually compile buildroot and the kernel and pack it.


## Creating the rootfs

```bash

# install prerequisites

sudo apt install debootstrap qemu qemu-user-static binfmt-support dpkg-cross --no-install-recommends

# generate minimal bootstrap rootfs

sudo debootstrap --arch=riscv64 --foreign jammy ./temp-rootfs http://ports.ubuntu.com/ubuntu-ports

# chroot into the rootfs we just created

sudo chroot temp-rootfs /bin/bash

# run 2nd stage of deboostrap

/debootstrap/debootstrap --second-stage

# add package sources

cat >/etc/apt/sources.list <<EOF
deb http://ports.ubuntu.com/ubuntu-ports jammy main restricted

deb http://ports.ubuntu.com/ubuntu-ports jammy-updates main restricted

deb http://ports.ubuntu.com/ubuntu-ports jammy universe
deb http://ports.ubuntu.com/ubuntu-ports jammy-updates universe

deb http://ports.ubuntu.com/ubuntu-ports jammy multiverse
deb http://ports.ubuntu.com/ubuntu-ports jammy-updates multiverse

deb http://ports.ubuntu.com/ubuntu-ports jammy-backports main restricted universe multiverse

deb http://ports.ubuntu.com/ubuntu-ports jammy-security main restricted
deb http://ports.ubuntu.com/ubuntu-ports jammy-security universe
deb http://ports.ubuntu.com/ubuntu-ports jammy-security multiverse
EOF

# update and install some 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

# optional for zram

apt-get install zram-config
systemctl enable zram-config

# Create base config files


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

# write text to fstab (this is with swap enabled if you want to disable it just put a # before the swap line)

cat >/etc/fstab <<EOF
# <file system>	<mount pt>	<type>	<options>	<dump>	<pass>
/dev/root	/		ext2	rw,noauto	0	1
proc		/proc		proc	defaults	0	0
devpts		/dev/pts	devpts	defaults,gid=5,mode=620,ptmxmode=0666	0	0
tmpfs		/dev/shm	tmpfs	mode=0777	0	0
tmpfs		/tmp		tmpfs	mode=1777	0	0
tmpfs		/run		tmpfs	mode=0755,nosuid,nodev,size=64M	0	0
sysfs		/sys		sysfs	defaults	0	0
/dev/mmcblk0p3  none            swap    sw              0       0
EOF

# set hostname

echo "milkvduo-ubuntu" > /etc/hostname

# set root passwd

echo "root:riscv" | chpasswd

# enable root login through ssh

sed -i "s/#PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config

# exit chroot


exit
sudo tar -cSf Ubuntu-jammy-rootfs.tar -C temp-rootfs .
gzip Ubuntu-jammy-rootfs.tar
rm -rf temp-rootfs

上面生成的文件系统有问题下面更新后的:

# 安装依赖


sudo apt install debootstrap qemu qemu-user-static binfmt-support --no-install-recommends

# 构建目录

mkdir -p temp-rootfs
sudo debootstrap --arch=riscv64 --foreign jammy ./temp-rootfs http://ports.ubuntu.com/ubuntu-ports

# 【关键】挂载虚拟文件系统


sudo mount -t proc none temp-rootfs/proc
sudo mount -t sysfs none temp-rootfs/sys
sudo mount -o bind /dev temp-rootfs/dev
sudo mount -o bind /dev/pts temp-rootfs/dev/pts

# 进入chroot

sudo chroot temp-rootfs /bin/bash

## ========== chroot 内部开始 ==========

/debootstrap/debootstrap --second-stage

cat >/etc/apt/sources.list <<EOF
deb http://ports.ubuntu.com/ubuntu-ports jammy main restricted
deb http://ports.ubuntu.com/ubuntu-ports jammy-updates main restricted
deb http://ports.ubuntu.com/ubuntu-ports jammy universe
deb http://ports.ubuntu.com/ubuntu-ports jammy-updates universe
deb http://ports.ubuntu.com/ubuntu-ports jammy multiverse
deb http://ports.ubuntu.com/ubuntu-ports jammy-updates multiverse
deb http://ports.ubuntu.com/ubuntu-ports jammy-backports main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports jammy-security main restricted
deb http://ports.ubuntu.com/ubuntu-ports jammy-security universe
deb http://ports.ubuntu.com/ubuntu-ports jammy-security multiverse
EOF

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 sudo chrony

# 可选 zram


apt-get install -y zram-config
systemctl enable zram-config

# 网络配置


mkdir -p /etc/network
cat >/etc/network/interfaces <<EOF
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
EOF

# fstab 适配ext4


cat >/etc/fstab <<EOF
# <file system> <mount pt> <type> <options> <dump> <pass>
/dev/root       /       ext4    defaults        0 1
proc            /proc   proc    defaults        0 0
devpts          /dev/pts devpts defaults,gid=5,mode=620,ptmxmode=0666 0 0
tmpfs           /dev/shm tmpfs  mode=0777       0 0
tmpfs           /tmp    tmpfs   mode=1777       0 0
tmpfs           /run    tmpfs   mode=0755,nosuid,nodev,size=64M 0 0
sysfs           /sys    sysfs   defaults        0 0
/dev/mmcblk0p3  none    swap    sw              0 0
EOF

echo "milkvduo-ubuntu" > /etc/hostname
echo "root:riscv" | chpasswd

# SSH配置,同时开启密码登录


sed -i "s/#PermitRootLogin.*/PermitRootLogin yes/" /etc/ssh/sshd_config
sed -i "s/#PasswordAuthentication.*/PasswordAuthentication yes/" /etc/ssh/sshd_config

# 开启串口终端


systemctl enable serial-getty@ttyS0.service

# 清理缓存缩小镜像

apt autoremove -y
apt clean

## ========== chroot 内部结束 ==========


exit

# 务必卸载!!


sudo umount temp-rootfs/dev/pts
sudo umount temp-rootfs/dev
sudo umount temp-rootfs/sys
sudo umount temp-rootfs/proc

# 打包


sudo tar -cpf Ubuntu-jammy-rootfs.tar -C temp-rootfs .
gzip Ubuntu-jammy-rootfs.tar
sudo rm -rf temp-rootfs

SD 卡部署操作


# 1.挂载root分区,替换为你的设备

sudo mount /dev/sdb2 /mnt/sdroot

# 2.清空分区

sudo rm -rf /mnt/sdroot/*

# 3.直接解压rootfs

sudo tar -xf Ubuntu-jammy-rootfs.tar -C /mnt/sdroot

# 4.卸载

sudo umount /mnt/sdroot



打赏 支付宝打赏 微信打赏

相关文章

[转]Linux内核配置和编译过程详解

[转]Linux内核配置和编译过程详解

一、引言: 本文档的内容大部份内容都是从网上收集而来,然后配合一些新的截 图(内核版本:V2.4.19)。在每一配置项后会有一个选择指南的部份,用来指导大家怎么样 根据自己的情况来做相应的选择;还有在每一个大项和文档的最后会有一个经验谈,它是一些高手们在应对问题和处理特有硬件时的一些经验(这个还得靠各位)。 文档最后会发到网上,到时会根据网友们的回复随时进行更新。 我们的目的是让我们有一个全面的、简单明了内核编译帮手。#make mrproper -----删除不必要的文件和...

LINUX 使用sendmail邮件备份

LINUX 使用sendmail邮件备份

首先安装:sudo apt-get install sendmail然后在终端可以使用mail来发邮件echo "ESP32固件"|mail -s "esp32" -A "./fw.bin" -r "bak@xxx.com" xb100@qq.com注意很有可能收到的邮件在垃圾箱里面。把发件地址加到白 名单中...

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

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

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

利用BusyBox ~私人定制 My LINUX~

利用BusyBox ~私人定制 My LINUX~

前言  我在今天在这里跟大家详细地探讨一下Linux系统的定制过程和实现例如、用户能够远程登录;和Nginx能够稳定地运行在我们私人定制的LINUX系统上、一步一步从头开始定制属于我们自己的系统。正文   首先我们先来简单的介绍一下我们这里定制属于自己的Linux系统的基本元素.   一个定制的linux内核+一个定制的busybox就可以定制一个小型的Linux操作系统了,安装Dropbear和Nginx,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...

[转]《保姆级教程》全志F1C100S/F1C200S spi-flash 启动全流程适配烧录及踩坑指南

[转]《保姆级教程》全志F1C100S/F1C200S spi-flash 启动全流程适配烧录及踩坑指南

转自哇酷网=丨晋丨通过参考荔枝派nano官方和论坛大佬的帖子,总结了烧录 spi-flash 启动的方法。通过搜寻资料,把其中有错误或者做了多余的操作的步骤做了修正,以免大家再次踩坑,耗费青春。以下包括 uboot、kernel、buildroot 和 烧录的详细步骤和需要注意的问题,尽量精简方法,以期容易上手和理解。各种配置项也做了详细注释,要知其然,也知其所以然。最理想的状态应该是是:有的坑,踩的人多了,也便没有了坑。论坛不太好排版,有需要的也可以去我的博客看:P:全志F1C100S/F1C...

修改U-BOOT,输出信息在LCD上显示,并使用USB连接键盘使用控制台

修改U-BOOT,输出信息在LCD上显示,并使用USB连接键盘使用控制台

修改方法:一:修改U-BOOT   include/configs/suniv.h#define CONFIG_BOOTCOMMAND"fatload mmc 0:1 0x80800000 zImage; "  \              &nb...

控制台终端输出颜色

控制台终端输出颜色

在使用putty、secureCRT、XShell等终端仿真器连接linux系统时,ls、vim等工具的输出都含有各种颜色,这些颜色的输出大大地增强了文本的可读性。一、终端文本颜色输出的一般示例在bash中,通常我们可以使用echo命令加-e选项输出各种颜色的文本,例如:echo -e "\033[31mRed Text\033[0m" echo -e "\033[32mGreen Text\033[0m...