制作ubuntu-base-23.10-base-armhf的根文件系统rootfs

1、创建一台同版本的ubuntu23的虚拟机

2、下载

ubuntu-base-23.10-base-armhf.tar.gz

3、上传到虚拟机里,解压到rootfs文件夹下

mkdir /opt/rootfs
cd /opt/
tar -xf /opt/ubuntu-base-23.10-base-armhf.tar.gz -C /opt/rootfs

4、安装 qemu,对任何机器运行操作系统的全系统仿真。

qemu 是一个通用的、开源的机器仿真器和虚拟机,拷贝它是为了可以模拟 arm cpu 进行文件系统的配置。

sudo apt-get install qemu-user-static
sudo cp /usr/bin/qemu-arm-static rootfs/usr/bin/

5、复制虚拟机的dns文件到rootfs系统内

echo 'nameserver 114.114.114.114' >> rootfs/etc/resolv.conf
echo 'nameserver 8.8.8.8' >> rootfs/etc/resolv.conf
echo 'DNS=114.114.114.114 8.8.8.8' >> rootfs/etc/systemd/resolved.conf

6、更新源

vim rootfs/etc/apt/sources.list

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic main restricted
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic-updates main restricted
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic universe
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic-updates universe
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic-updates multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic-backports main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic-backports main restricted universe multiverse

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic-security main restricted
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic-security universe
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic-security multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ mantic-security multiverse

7、挂载ubuntu-base

编写挂载脚本

#!/bin/bash
mnt() {
	echo "MOUNTING"
	sudo mount -t proc /proc ${2}proc
	sudo mount -t sysfs /sys ${2}sys
	sudo mount -o bind /dev ${2}dev
	sudo mount -o bind /dev/pts ${2}dev/pts
	sudo chroot ${2}
}
umnt() {
	echo "UNMOUNTING"
	sudo umount ${2}proc
	sudo umount ${2}sys
	sudo umount ${2}dev/pts
	sudo umount ${2}dev
}
 
if [ "$1" == "-m" ] && [ -n "$2" ] ;
then
	mnt $1 $2
elif [ "$1" == "-u" ] && [ -n "$2" ];
then
	umnt $1 $2
else
	echo ""
	echo "Either 1'st, 2'nd or both parameters were missing"
	echo ""
	echo "1'st parameter can be one of these: -m(mount) OR -u(umount)"
	echo "2'nd parameter is the full path of rootfs directory(with trailing '/')"
	echo ""
	echo "For example: ch-mount -m /media/sdcard/"
	echo ""
	echo 1st parameter : ${1}
	echo 2nd parameter : ${2}
fi

增加脚本执行权限

sudo chmod +x mount.sh

运行脚本挂载根文件系统

bash mount.sh -m rootfs/

**卸载则运行

bash mount.sh -u rootfs/

8、装软件

apt update
#安装系统工具
apt install -y rsyslog systemd
apt install -y sudo language-pack-en-base htop vim bash-completion
#安装网络工具
apt install -y ssh net-tools ethtool  ifupdown iputils-ping wireless-tools 
#安装蓝牙工具
apt install -y rfkill bluez*
#安装大数库
apt install -y libgmp-dev
#安装usb工具
apt install -y usbutils
#安装桌面
apt install -y lxqt
#安装Qt开发环境
apt install -y build-essential qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools qt5* qtcreator libqt5serialport5-dev libqt5multimedia5-plugins libqt5bluetooth5  qtmultimedia5-dev qtconnectivity5-dev

9、用户配置

设置密码、添加用户

passwd root
adduser xyy
usermod -G sudo  xyy

chmod u+s /bin/ping

设置主机名称和本机IP

echo "xyy" > /etc/hostname
echo "127.0.0.1 localhost" >> /etc/hosts
echo "127.0.0.1 xyy" >> /etc/hosts

10、创建开机自启动脚本

1.创建rc-local.service文件

cp /lib/systemd/system/rc-local.service /etc/systemd/system/

然后修改/etc/systemd/system/rc-local.service,在文件最下方添加如下两行:

vim /etc/systemd/system/rc-local.service

[Install]   
WantedBy=multi-user.target   
Alias=rc-local.service

设置开机自启

systemctl enable rc-local.service

2.创建rc.local文件

创建/etc/rc.local,里边写自己想要运行的命令。例:

vim /etc/rc.local

#!/usr/bin/bash

resize2fs /dev/mmcblk2p7
rfkill unblock all
hciconfig hci0 up

exit 0

给/etc/rc.local加上可执行权限

chmod +x /etc/rc.local

11、打包镜像

先创建一个空镜像文件,大小为4096MB

exit

bash mount.sh -u rootfs/

dd if=/dev/zero of=ubuntu_rootfs.img bs=1M count=10240

将该文件格式化成ext4文件系统

mkfs.ext4 ubuntu_rootfs.img

将该镜像文件挂载到一个空的文件夹上,然后将ubuntu_rootfs的文件复制到该空文件夹中

mkdir ubuntu_base_rootfs
sudo mount ubuntu_rootfs.img ubuntu_base_rootfs
sudo cp -rfp rootfs/* ubuntu_base_rootfs/

复制完后用e2fsck修复及检测镜像文件系统,resize2fs 减小镜像文件的大小

sudo umount ubuntu_base_rootfs/
e2fsck -p -f ubuntu_rootfs.img
resize2fs -M ubuntu_rootfs.img
相关推荐
cuisidong199715 分钟前
如何在 Kali Linux 上安装 Google Chrome 浏览器
linux·运维·chrome
光通信学徒1 小时前
ubuntu图形界面右上角网络图标找回解决办法
linux·服务器·ubuntu·信息与通信·模块测试
wusam1 小时前
螺蛳壳里做道场:老破机搭建的私人数据中心---Centos下Docker学习03(网络及IP规划)
运维·服务器·网络·docker·容器
南种北李1 小时前
Linux自动化构建工具Make/Makefile
linux·运维·自动化
一直在进步的派大星1 小时前
Docker 从安装到实战
java·运维·docker·微服务·容器
小飞猪Jay1 小时前
面试速通宝典——10
linux·服务器·c++·面试
哲伦贼稳妥2 小时前
一天认识一个硬件之电源
运维·其他·电脑·硬件工程
暗恋 懒羊羊2 小时前
Linux 生产者消费者模型
linux·开发语言·ubuntu
安红豆.3 小时前
Linux基础入门 --13 DAY(SHELL脚本编程基础)
linux·运维·操作系统
..空空的人3 小时前
linux基础指令的认识
linux·运维·服务器