基于Ubuntu Base构建根文件系统

1. 什么是Ubuntu Base

Ubuntu 针对不同的 CPU 架构提供相应的 ubuntu base 根文件系统,目前提供的架构有amd64、arm64、armhf、i386、s390x、ppc64el、riscv64


2. 构建根文件系统

2.1 下载Ubuntu Base

到官网下载自己需要的版本:

http://cdimage.ubuntu.com/ubuntu-base/releases/ 

如下图:
在这里插入图片描述
此次为arm设备,计划采用ubuntu 22.04,故下载ubuntu-base-22.04.3-base-arm64.tar.gz

在这里插入图片描述

2.3 配置根文件系统

2.3.1 新建ext4文件系统

dd if=/dev/zero of=ubuntu-22.04.3-base.ext4 bs=1M count=1024
mkfs.ext4 -O 64bit ubuntu-22.04.3-base.ext4
mkdir -p ubuntu-22.04.3-base
mount -o loop ubuntu-22.04.3-base.ext4 ubuntu-22.04.3-base

2.3.2 解压文件系统

tar -xvf ubuntu-base-22.04.3-base-arm64.tar.gz -C ubuntu-22.04.3-base

2.3.3 配置dns

cd  ubuntu-22.04.3-base
echo "nameserver 223.5.5.5"  > ./etc/resolv.conf

2.3.4 配置sources.list

vim ./etc/apt/sources.list
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy main restricted
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-updates main restricted
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-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.aliyun.com/ubuntu-ports/ jammy universe
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy universe
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-updates universe
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-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.aliyun.com/ubuntu-ports/ jammy multiverse
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy multiverse
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-updates multiverse
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-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.aliyun.com/ubuntu-ports/ jammy-backports main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-backports main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-security main restricted
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-security main restricted
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-security universe
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-security universe
deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-security multiverse
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-security multiverse

2.3.5 安装软件包

chroot安装包需要先执行:

cd ..
mount --bind /dev ubuntu-22.04.3-base/dev
cd - 

防止没有权限
安装基础软件包:

chroot ./
apt update
apt install vim sudo kmod net-tools ethtool ifupdown language-pack-en-base rsyslog htop iputils-ping gcc make libfdt-dev wget  -y

设置root的密码

passwd root

2.3.6 拷贝kvmtool等

cp -r kvmtool ubuntu-22.04.3-base/opt/
cp cirros-0.6.0-aarch64-disk.img ubuntu-22.04.3-base/opt/

2.3.8 修改sh

cd bin
ln -sf bash sh
cd -

2.3.9 配置完成

配置完成后

exit
cd ..
umount ubuntu-22.04.3-base/dev
umount ubuntu-22.04.3-base

2.3 启动根文件系统

需要提前准备好Image和kvmtools工具,然后通过lkvm启动根文件如下

lkvm run linux-6.6.2/arch/arm64/boot/Image --disk ubuntu-22.04.3-base.ext4 --console serial  --name vm1

在这里插入图片描述

3. 问题记录

  • chroot cannot create /dev/null: Permission denied
    chroot执行apt update时,报如下错误:
Get:1 http://mirrors.aliyun.com/ubuntu-ports jammy InRelease [270 kB]
0% [Working]/usr/bin/apt-key: 95: cannot create /dev/null: Permission denied
/usr/bin/apt-key: 95: cannot create /dev/null: Permission denied
/usr/bin/apt-key: 95: cannot create /dev/null: Permission denied
E: gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
Err:1 http://mirrors.aliyun.com/ubuntu-ports jammy InRelease
  gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
Get:2 http://mirrors.aliyun.com/ubuntu-ports jammy-updates InRelease [119 kB]
0% [Working]/usr/bin/apt-key: 95: cannot create /dev/null: Permission denied
/usr/bin/apt-key: 95: cannot create /dev/null: Permission denied
/usr/bin/apt-key: 95: cannot create /dev/null: Permission denied
E: gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
Err:2 http://mirrors.aliyun.com/ubuntu-ports jammy-updates InRelease
  gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
Get:3 http://mirrors.aliyun.com/ubuntu-ports jammy-backports InRelease [109 kB]
0% [Working]/usr/bin/apt-key: 95: cannot create /dev/null: Permission denied
/usr/bin/apt-key: 95: cannot create /dev/null: Permission denied
/usr/bin/apt-key: 95: cannot create /dev/null: Permission denied
E: gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
Err:3 http://mirrors.aliyun.com/ubuntu-ports jammy-backports InRelease
  gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
Get:4 http://mirrors.aliyun.com/ubuntu-ports jammy-security InRelease [110 kB]
0% [Working]/usr/bin/apt-key: 95: cannot create /dev/null: Permission denied
/usr/bin/apt-key: 95: cannot create /dev/null: Permission denied
/usr/bin/apt-key: 95: cannot create /dev/null: Permission denied
E: gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
Err:4 http://mirrors.aliyun.com/ubuntu-ports jammy-security InRelease
  gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
Reading package lists... Done
W: GPG error: http://mirrors.aliyun.com/ubuntu-ports jammy InRelease: gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
E: The repository 'http://mirrors.aliyun.com/ubuntu-ports jammy InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://mirrors.aliyun.com/ubuntu-ports jammy-updates InRelease: gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
E: The repository 'http://mirrors.aliyun.com/ubuntu-ports jammy-updates InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://mirrors.aliyun.com/ubuntu-ports jammy-backports InRelease: gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
E: The repository 'http://mirrors.aliyun.com/ubuntu-ports jammy-backports InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://mirrors.aliyun.com/ubuntu-ports jammy-security InRelease: gpgv, gpgv2 or gpgv1 required for verification, but neither seems installed
E: The repository 'http://mirrors.aliyun.com/ubuntu-ports jammy-security InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

解决方法:

mount --bind /dev ubuntu-22.04.3-base/dev

4. 参考文献

https://doc.embedfire.com/lubancat/build_and_deploy/zh/latest/building_image/ubuntu_rootfs/ubuntu_rootfs.html
https://cloud.tencent.com/developer/ask/sof/116426316

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值