一、下载并解压ubuntu-base版本

1,从ubuntu官方下载最小系统Ubuntu Base 18.04.5 LTS (Bionic Beaver)CD images for Ubuntu Base 18.04.5 LTS (Bionic Beaver)http://cdimage.ubuntu.com/ubuntu-base/releases/18.04.5/release/

2,解压 

tar -xvf ubuntu-base-18.04.5-base-arm64.tar.gz
bin   dev  home  media  oem  proc  run   srv  tmp       usr
boot  etc  lib   mnt    opt  root  sbin  sys  userdata  var

二、安装Qemu-User-Static工具

1,QEMU是专门模拟不同机器架构的软件,在ubuntu中对其支持良好,若需要挂载ubuntu arm64版本的文件,必须安装qemu-user-static工具。

sudo apt-get install qemu-user-static

2,将安装好的qemu-user-static工具拷贝到ubuntu文件系统中

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

三、设置软件源和域名解析配置

1,设置软件下载源

vim ./binary/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

2,Ubuntu安装软件是通过名apt-get从网上下载安装的。我们需要指定软件源。
为了制作成功的根文件系统能够联网,可以直接拷贝本机的dns配置文件到根文件系统的相应位置,使用命令“cp /etc/resolv.conf ./etc/resolv.conf”

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

四、挂载根文件系统并chroot

1,首先在本机挂载刚刚下载好的文件系统,需要挂载proc, sys, dev, dev/pts等文件系统。使用命令“vi mount.sh”添加挂载脚本

mount -t proc /proc binary/proc
mount -t sysfs /sys binary/sys
mount -o bind /dev binary/dev
mount -o bind /dev/pts binary/dev/pts

chroot binary
chmod 777 /tmp/
apt-get update
apt-get upgrade

五、安装需要的软件和环境

apt-get install ssh
apt-get install net-tools
apt-get install ethtool
apt-get install ifupdown
apt-get install psmisc
apt-get install nfs-common
apt-get install htop
apt-get install vim
apt-get install rsyslog
apt-get install iputils-ping
apt-get install language-pack-en-base
apt-get install sudo
apt-get install network-manager

然后使用命令“passwd root”设置root用户密码

passwd root

创建用户

adduser username

接下来使用如下命令设置主机名称和本机IP

echo "ubuntu 18.04" > /etc/hostname
echo "127.0.0.1 localhost" >> /etc/hosts
echo "127.0.0.1 ubuntu 18.04" >> /etc/hosts

设置好后exit退出 

六、卸载文件系统并制作镜像

1,卸载ubuntu文件系统

umount binary/dev/pts
umount binary/dev
umount binary/sys
umount binary/proc

2,制作文件系统镜像

./mk-image.sh

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐