制作ubuntu18.04根文件系统

目标平台:ARM64

制作平台:PC、x86_64、ubuntu18.04虚拟机

一、获取源码

源码地址:Index of /ubuntu-base/releases

在此选择18.04.5.

二、开始构建文件系统

2.1 解压根文件系统

创建一个文件夹并解压下载的ubuntu-base-18.04.5-base-arm64.tar.gz

mkdir ubuntu18.04-arm64-rootfs 
cd ubuntu18.04-arm64-rootfs 
mkdir rootfs
cd rootfs
tar -vzxf ubuntu-base-18.04.5-base-arm64.tar.gz
mv ./ubuntu-base-18.04.5-base-arm64.tar.gz ../

2.2 安装qemu

在PC机的Ubuntu下安装qemu工具:

sudo apt-get install qemu-user-static

然后将安装的qemu-user-static拷贝到我们新建的根文件系统的文件夹下:

sudo cp /usr/bin/qemu-arm-static ./usr/bin/

2.3 设置软件源

 先将PC Ubuntu主机下的DNS配置文件拷贝过来:

sudo cp /etc/resolv.conf ./etc/

然后在根文件系统文件夹下的/ubuntu_rootfs/etc/apt/sources.list文件后面添加软件源,如下为中科大的软件源,直接添加失去即可:

deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
vim ./etc/apt/sources.list

在ubuntu18.04-arm64-rootfs目录下创建mount.sh挂载脚本文件,输入如下内容:

#!/bin/bash
echo "MOUNTING"
sudo mount -t proc /proc /home/fenton/ubuntu18.04-arm64-rootfs/rootfs/proc
sudo mount -t sysfs /sys /home/fenton/ubuntu18.04-arm64-rootfs/rootfs/sys
sudo mount -o bind /dev /home/fenton/ubuntu18.04-arm64-rootfs/rootfs/dev
sudo mount -o bind /dev/pts /home/fenton/ubuntu18.04-arm64-rootfs/rootfs/dev/pts
sudo chroot /home/fenton/ubuntu18.04-arm64-rootfs/rootfs

还有unmount.sh卸载脚本文件,输入如下内容:

#!/bin/bash
echo "UNMOUNTING"
sudo umount /home/fenton/ubuntu18.04-arm64-rootfs/rootfs/proc
sudo umount /home/fenton/ubuntu18.04-arm64-rootfs/rootfs/sys
sudo umount /home/fenton/ubuntu18.04-arm64-rootfs/rootfs/dev
sudo umount /home/fenton/ubuntu18.04-arm64-rootfs/rootfs/dev/pts

给予其可执行权限:

chmod 777 mount.sh unmount.sh

然后执行挂载脚本:

./mount.sh -m ubuntu18.04-rootfs/

卸载脚本

./unmount.sh -u ubuntu18.04-rootfs/

此时就可以看到进入挂在的根文件系统中

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一日风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值