昇腾社区首页
中文
注册

定制Ubuntu 22.04文件系统

由于当前Ubuntu 22.04的公共镜像源没有自带常用工具包,无法通过挂载本地源方式进行文件系统配置,所以需要通过配置网络源手动下载常用Linux组件,定制Sample-root-filesystem-soc_ubuntu-22.04-aarch64.img。

前提条件

  • 制作环境为Arm架构的Ubuntu操作系统的服务器。
  • 已获取Ubuntu 22.04镜像“ubuntu-22.04-live-server-arm64.iso”,并上传到部署环境的任意目录。

操作步骤

  1. 登录制作Sample-root-filesystem-soc_ubuntu-22.04-aarch64.img的服务器,详细操作请参见使用PuTTY登录设备(网口方式)
  2. 获取最小文件系统。
    1. 在Ubuntu 22.04镜像所在目录下执行以下命令,挂载镜像到“/mnt”目录。

      mount ubuntu-22.04-live-server-arm64.iso /mnt

    2. 执行以下命令复制ubuntu-server-minimal.squashfs到当前目录。

      cp /mnt/casper/ubuntu-server-minimal.squashfs ./

    3. 执行以下命令,解挂载“/mnt”目录。

      umount /mnt

  3. 执行以下命令,解压镜像,生成“squashfs-root”目录。

    unsquashfs ubuntu-server-minimal.squashfs

  4. 配置Ubuntu的网络源。

    执行以下命令,在当前目录创建sources.list文件。

    vim sources.list

    网络源配置参考如下。

    deb https://repo.huaweicloud.com/ubuntu-ports/ bionic main restricted universe multiverse
    deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic main restricted universe multiverse
    deb https://repo.huaweicloud.com/ubuntu-ports/ bionic-security main restricted universe multiverse
    deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic-security main restricted universe multiverse
    deb https://repo.huaweicloud.com/ubuntu-ports/ bionic-updates main restricted universe multiverse
    deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic-updates main restricted universe multiverse
    deb https://repo.huaweicloud.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
    deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
    ## Not recommended
    # deb https://repo.huaweicloud.com/ubuntu-ports/ bionic-proposed main restricted universe multiverse
    # deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic-proposed main restricted universe multiverse

    保存配置文件并退出。

    执行以下命令,将sources.list文件复制到“squashfs-root/etc/apt”目录下。

    cp sources.list squashfs-root/etc/apt/

  5. 切换根系统。

    执行如下命令,切换根系统。

    chroot squashfs-root

  6. 执行以下命令,更新源。

    apt-get update

    若执行命令后报错“The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32”,请参见更新网络源时签名不可用

  7. 执行以下命令,安装Linux组件。

    apt-get install unzip -y

    apt-get install vim -y

    apt-get install sysstat -y

    apt-get install libnuma1 -y

    apt-get install dmidecode -y

    apt-get install rsync -y

    apt-get install net-tools -y

    apt-get install psmisc -y

    apt-get install parted -y

    apt-get install arping -y

    apt-get install ntpdate -y

    apt-get install iproute2 -y

    apt-get install iputils-ping -y

    apt-get install mawk -y

    apt-get install cracklib-runtime -y

    apt-get install ethtool -y

    apt-get install ntp -y

    apt-get install fdisk -y

    apt-get install libssl-dev -y

    apt-get install libpam-cracklib -y

    apt-get install logrotate -y

    • 执行apt-get install命令后,回显中出现的需要获取的包与取得的包大小一致,则下载成功,如图1所示。
      图1 完成下载
    • 执行apt-get install命令后,若出现“perl:warning:xxx”相关报错、“debconf:xxx”相关报错、“Failed to retrieve available kernel versions.”以及“Failed to check for processor microcode upgrades.”报错,不影响Linux组件下载。
  8. 执行以下命令退出根系统。

    exit

  9. 执行以下命令进入“squashfs-root”目录。

    cd squashfs-root

  10. 执行以下命令,重新生成Sample-root-filesystem-soc_ubuntu-22.04-aarch64.img。

    find . | cpio -o -H newc | gzip > ../Sample-root-filesystem-soc_ubuntu-22.04-aarch64.img

    Sample-root-filesystem-soc_ubuntu-22.04-aarch64.img在Ubuntu 22.04镜像所在目录下。