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

Riscv64创建ubuntu文件系统

Watrt4个月前 (08-01)LINUX436670

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 压缩解压命令备忘

01-.tar格式解包:[*******]$ tar xvf FileName.tar 打包:[*******]$ tar cvf FileName.tar DirName(注:tar是打包,不是压缩!) 02-.gz格式 解压1:[*******]$ gunzip FileName.gz 解压2:[*******]$ gzip -d FileName.gz 压 缩:[*******]$ gzip...

mpalqyer 播放命令

mpalqyer 播放命令

mplayer -vo fbdev2 -vf scale=1366:768 film.avi /usr/bin/mplayer -x 800 -y 480 -zoom -framedrop aa.avi...

mkfs 参数

mkfs 参数

#mkfs.jffs2 -r rootfs -o fs.jffs2 -e 0x20000 --pad=0x500000 -s 0x800 –n -l即可生成 rootfs.jffs2Mkfs.jffs2各参数的意义如下:-r:指定要做成image的目录名。-o:指定输出image的文件名。-e:每一块要擦除的block size,默认是64KB.要注意,不同的flash, 其block size会不一样,三星的K9F2G08U0A的block size为0x20000(从其datasheet里可...

使用buildroot构建根文件系统

使用buildroot构建根文件系统

使用buildroot构建根文件系统buildroot可用于构建小型的linux根文件系统。大小最小可低至2M,与内核一起可以放入最小8M的spi flash中。buildroot中可以方便地加入第三方软件包(其实已经内置了很多),省去了手工交叉编译的烦恼。下载安装首先安装一些依赖,比如linux头文件:apt-get install linux-headers-$(uname -r)然后下载安装:wget https://buildroot.org/do...

关于CentOS 下 httpd 修改默认的目录后 403 错误的 解决

关于CentOS 下 httpd 修改默认的目录后 403 错误的 解决

step 1 : 首先改你要设置的目录权限       chmod -R 755 /home/html          -------------->>  /home/html   是你存放你的页面的目录   这里我顺便记录下关于selinux 的命令吧    getenforce=>查看 selinux的状态&nbs...

licheepi_zero开发板 buildroot配置 一键编译

licheepi_zero开发板 buildroot配置 一键编译

开贴记录配置最新buildroot-2018.08.使用buildroot自带工具链一键编译生成uboot,kernel,dtb和rootfs.最新稳定版buildroot下载:buildroot-2018.08.02稳定版我配置好的config文件:配置好的.config本人的开发环境是vmware workstation 15 pro+ubuntu 16.04_x64参照沉鱼的帖子荔枝派Zero V3s开发板入坑记录 (TF/SD卡启动)(主线Linux,主线u-boot)做如下配置:1.t...

制作荔枝派Zero开发板(全志V3s) TF/SD卡启动盘

制作荔枝派Zero开发板(全志V3s) TF/SD卡启动盘

0. 前言近几天买了一块荔枝派0开发板,以及官方配的480×272的屏幕。让我记录一下入坑与采坑过程。1. u-boot的编译git clone https://github.com/Lichee-Pi/u-boot -b v3s-current cd u-boot make ARCH=arm LicheePi_Zero_480x272LCD_defconfig make ARCH=arm CROSS...

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注意很有可能收到的邮件在垃圾箱里面。把发件地址加到白 名单中...