X86下构建 ARM 文件系统并运行

简介: X86下构建 ARM 文件系统并运行

文章目录

X86下构建 ARM 文件系统并运行

构建流程

安装 qemu-user-static

安装 debootstrap

构建 ARM 平台的 Ubuntu 根文件系统

查看 Ubuntu 根文件系统

关于 debootstrap 的用法

验证arm64 ubuntu rootfs

附录


X86下构建 ARM 文件系统并运行

资料参考


在 X86 机器下可以构建一个原生的arm 文件系统,基于qemu-user-static debootstrap chroot命令就可以实现


  1. 通过qemu-debootstrap可以构建原生的arm 文件系统。

  2. 通过qemu-aarch64-static 及chroot, 可以在X86主机上对arm 文件系统进行挂载。

  3. 通过apt命令工具可以对arm 文件系统安装相应的软件包,可以添加帐号,定制主机名等。


下面就通过具体的一系列操作来实现在通用 X86-PC 机上搭建可以运行在 ARM 下的文件系统。


构建流程

基于资料参考接下来的会把整个构建的log都贴出来:


安装 qemu-user-static

$ sudo apt-get install qemu-user-static
[sudo] password for vmuser:
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following additional packages will be installed:
  binfmt-support
The following NEW packages will be installed:
  binfmt-support qemu-user-static
0 upgraded, 2 newly installed, 0 to remove and 325 not upgraded.
Need to get 7,753 kB of archives.
After this operation, 86.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.aliyun.com/ubuntu xenial/main amd64 binfmt-support amd64 2.1.6-1 [50.7 kB]
Get:2 http://mirrors.aliyun.com/ubuntu xenial-updates/universe amd64 qemu-user-static amd64 1:2.5+dfsg-5ubuntu10.34 [7,702 kB]
Fetched 7,753 kB in 8s (910 kB/s)                                                                                                                                                                         
Selecting previously unselected package binfmt-support.
(Reading database ... 276761 files and directories currently installed.)
Preparing to unpack .../binfmt-support_2.1.6-1_amd64.deb ...
Unpacking binfmt-support (2.1.6-1) ...
Selecting previously unselected package qemu-user-static.
Preparing to unpack .../qemu-user-static_1%3a2.5+dfsg-5ubuntu10.34_amd64.deb ...
Unpacking qemu-user-static (1:2.5+dfsg-5ubuntu10.34) ...
Processing triggers for systemd (229-4ubuntu21.15) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up binfmt-support (2.1.6-1) ...
Setting up qemu-user-static (1:2.5+dfsg-5ubuntu10.34) ...
Processing triggers for systemd (229-4ubuntu21.15) ...
Processing triggers for ureadahead (0.100.0-19) ...


安装 debootstrap

$ sudo apt install debootstrap
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following NEW packages will be installed:
  debootstrap
0 upgraded, 1 newly installed, 0 to remove and 325 not upgraded.
Need to get 37.2 kB of archives.
After this operation, 262 kB of additional disk space will be used.
Get:1 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 debootstrap all 1.0.78+nmu1ubuntu1.6 [37.2 kB]
Fetched 37.2 kB in 0s (357 kB/s)
Selecting previously unselected package debootstrap.
(Reading database ... 276841 files and directories currently installed.)
Preparing to unpack .../debootstrap_1.0.78+nmu1ubuntu1.6_all.deb ...
Unpacking debootstrap (1.0.78+nmu1ubuntu1.6) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up debootstrap (1.0.78+nmu1ubuntu1.6) ...


构建 ARM 平台的 Ubuntu 根文件系统

接下来使用 qemu-debootstrap 构建 ARM 平台的 Ubuntu 根文件系统


$ sudo qemu-debootstrap --verbose --arch=arm64 --variant=buildd xenial  ubuntu_arm64_xenial  http://mirrors.ustc.edu.cn/ubuntu-ports
[sudo] password for vmuser:
Ok , we get it.
I: Configuring gcc-5...
I: Configuring libstdc++-5-dev:arm64...
I: Configuring gcc...
I: Configuring g++-5...
I: Configuring g++...
I: Configuring build-essential...
I: Configuring libc-bin...
I: Base system installed successfully.


查看 Ubuntu 根文件系统

现在就能够通过命令看到获取到的 Ubuntu 根文件系统:


$ du -h ubuntu_arm64_xenial/


1.2M         ubuntu_arm64_xenial/var/cache/debconf
12K  ubuntu_arm64_xenial/var/cache/ldconfig
4.0K ubuntu_arm64_xenial/var/cache/apt/archives/partial
54M ubuntu_arm64_xenial/var/cache/apt/archives
54M ubuntu_arm64_xenial/var/cache/apt
55M ubuntu_arm64_xenial/var/cache
4.0K ubuntu_arm64_xenial/var/tmp
68M ubuntu_arm64_xenial/var
318M        ubuntu_arm64_xenial/


关于 debootstrap 的用法

如果要自定义rootfs,则可以添加build args,qemu-debootstrap会将args传输到debootstrap,


因此,了解debootstrap的用法可以帮助构建自定义的 ubuntu rootfs。


$ debootstrap --help
Usage: debootstrap [OPTION]... <suite> <target> [<mirror> [<script>]]
Bootstrap a Debian base system into a target directory.
      --help                 display this help and exit
      --version              display version information and exit
      --verbose              don't turn off the output of wget
      --download-only        download packages, but don't perform installation
      --print-debs           print the packages to be installed, and exit
      --arch=A               set the architecture to install (use if no dpkg)
                               [ --arch=powerpc ]
      --include=A,B,C        adds specified names to the list of base packages
      --exclude=A,B,C        removes specified packages from the list
      --components=A,B,C     use packages from the listed components of the
                             archive
      --variant=X            use variant X of the bootstrap scripts
                             (currently supported variants: buildd, fakechroot,
                              scratchbox, minbase)
minbase: 只包含必要的包和apt; 
buildd: 包含编译工具包 
fakechroot: 包含不用root权限的包 
scratchbox: 包含scratchbox(交叉编译工具链)相关包
      --keyring=K            check Release files against keyring K
      --no-check-gpg         avoid checking Release file signatures
      --force-check-gpg      force checking Release file signatures
                             (also disables automatic fallback to HTTPS in case
                             of a missing keyring), aborting otherwise
      --no-resolve-deps      don't try to resolve dependencies automatically
      --unpack-tarball=T     acquire .debs from a tarball instead of http
      --make-tarball=T       download .debs and create a tarball (tgz format)
      --second-stage-target=DIR
                             Run second stage in a subdirectory instead of root
                               (can be used to create a foreign chroot)
                               (requires --second-stage)
      --extractor=TYPE       override automatic .deb extractor selection
                               (supported: dpkg-deb ar)
      --debian-installer     used for internal purposes by debian-installer
      --private-key=file     read the private key from file
      --certificate=file     use the client certificate stored in file (PEM)
      --no-check-certificate do not check certificate against certificate authorities


验证arm64 ubuntu rootfs

# cp /usr/bin/qemu-aarch64-static ubuntu_arm64_xenial/usr/bin/
# mount  proc ubuntu_arm64_xenial/proc -t proc
# mount  sysfs ubuntu_arm64_xenial/sys -t sysfs
# cp /etc/hosts ubuntu_arm64_xenial/etc/hosts
# cp /etc/resolv.conf ubuntu_arm64_xenial/etc/resolv.conf
# chroot ubuntu_arm64_xenial/
root@vmuser-virtual-machine:/# ls   ---- 》we got it, running arm rootfs in X86 host
bin  boot  dev  etc  home  lib  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@vmuser-virtual-machine:/# ifconfig
bash: ifconfig: command not found
root@vmuser-virtual-machine:/# apt install net-tools   
Reading package lists... Done
Building dependency tree... Done
The following NEW packages will be installed:
  net-tools
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 165 kB of archives.
After this operation, 688 kB of additional disk space will be used.
Get:1 http://ports.ubuntu.com/ubuntu-ports xenial/main arm64 net-tools arm64 1.60-26ubuntu1 [165 kB]
Fetched 165 kB in 2s (79.9 kB/s)   
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
         LANGUAGE = "en_US",
         LC_ALL = (unset),
         LC_PAPER = "zh_CN.UTF-8",
         LC_NUMERIC = "zh_CN.UTF-8",
         LC_IDENTIFICATION = "zh_CN.UTF-8",
         LC_MEASUREMENT = "zh_CN.UTF-8",
         LC_NAME = "zh_CN.UTF-8",
         LC_TELEPHONE = "zh_CN.UTF-8",
         LC_ADDRESS = "zh_CN.UTF-8",
         LC_MONETARY = "zh_CN.UTF-8",
         LC_TIME = "zh_CN.UTF-8",
         LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
debconf: delaying package configuration, since apt-utils is not installed
E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)
Selecting previously unselected package net-tools.
(Reading database ... 11949 files and directories currently installed.)
Preparing to unpack .../net-tools_1.60-26ubuntu1_arm64.deb ...
Unpacking net-tools (1.60-26ubuntu1) ...
Setting up net-tools (1.60-26ubuntu1) ...


附录

下面是构建桌面系统对应的源:


deb http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted
deb http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricted
deb http://ports.ubuntu.com/ubuntu-ports/ xenial universe
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial universe
deb http://ports.ubuntu.com/ubuntu-ports/ xenial-updates universe
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-updates universe
deb http://ports.ubuntu.com/ubuntu-ports/ xenial-backports main restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-backports main restricted
deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricted
deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security universe
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-security universe
deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security multiverse
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-security multiverse


相关文章
|
5月前
|
存储 机器学习/深度学习 数据库
阿里云服务器X86/ARM/GPU/裸金属/超算五大架构技术特点、场景适配参考
在云计算技术飞速发展的当下,云计算已经渗透到各个行业,成为企业数字化转型的关键驱动力。选择合适的云服务器架构对于提升业务效率、降低成本至关重要。阿里云提供了多样化的云服务器架构选择,包括X86计算、ARM计算、GPU/FPGA/ASIC、弹性裸金属服务器以及高性能计算等。本文将深入解析这些架构的特点、优势及适用场景,以供大家了解和选择参考。
965 61
|
6月前
|
存储 机器学习/深度学习 算法
阿里云X86/ARM/GPU/裸金属/超算等五大服务器架构技术特点、场景适配与选型策略
在我们选购阿里云服务器的时候,云服务器架构有X86计算、ARM计算、GPU/FPGA/ASIC、弹性裸金属服务器、高性能计算可选,有的用户并不清楚他们之间有何区别。本文将深入解析这些架构的特点、优势及适用场景,帮助用户更好地根据实际需求做出选择。
|
9月前
|
机器学习/深度学习 弹性计算 人工智能
阿里云服务器ECS架构区别及选择参考:X86计算、ARM计算等架构介绍
在我们选购阿里云服务器的时候,云服务器架构有X86计算、ARM计算、GPU/FPGA/ASIC、弹性裸金属服务器、高性能计算可选,有的用户并不清楚他们之间有何区别,本文主要简单介绍下这些架构各自的主要性能及适用场景,以便大家了解不同类型的架构有何不同,主要特点及适用场景有哪些。
1301 10
|
11月前
|
机器学习/深度学习 弹性计算 人工智能
阿里云服务器架构有啥区别?X86计算、Arm、GPU异构、裸金属和高性能计算对比
阿里云ECS涵盖x86、ARM、GPU/FPGA/ASIC、弹性裸金属及高性能计算等多种架构。x86架构采用Intel/AMD处理器,适用于广泛企业级应用;ARM架构低功耗,适合容器与微服务;GPU/FPGA/ASIC专为AI、图形处理设计;弹性裸金属提供物理机性能;高性能计算则针对大规模并行计算优化。
702 7
|
12月前
|
Docker 容器
docker:记录如何在x86架构上构造和使用arm架构的镜像
为了实现国产化适配,需将原x86平台上的Docker镜像转换为适用于ARM平台的镜像。本文介绍了如何配置Docker buildx环境,包括检查Docker版本、安装buildx插件、启用实验性功能及构建多平台镜像的具体步骤。通过这些操作,可以在x86平台上成功构建并运行ARM64镜像,实现跨平台的应用部署。
7747 2
|
机器学习/深度学习 弹性计算 编解码
阿里云服务器计算架构X86/ARM/GPU/FPGA/ASIC/裸金属/超级计算集群有啥区别?
阿里云服务器ECS提供了多种计算架构,包括X86、ARM、GPU/FPGA/ASIC、弹性裸金属服务器及超级计算集群。X86架构常见且通用,适合大多数应用场景;ARM架构具备低功耗优势,适用于长期运行环境;GPU/FPGA/ASIC则针对深度学习、科学计算、视频处理等高性能需求;弹性裸金属服务器与超级计算集群则分别提供物理机级别的性能和高速RDMA互联,满足高性能计算和大规模训练需求。
469 6
|
Go 开发工具 git
在Qemu+ARM上运行Minix3内核
在Qemu+ARM上运行Minix3内核
|
5月前
|
消息中间件 数据可视化 Kafka
docker arm架构部署kafka要点
本内容介绍了基于 Docker 的容器化解决方案,包含以下部分: 1. **Docker 容器管理**:通过 Portainer 可视化管理工具实现对主节点和代理节点的统一管理。 2. **Kafka 可视化工具**:部署 Kafka-UI 以图形化方式监控和管理 Kafka 集群,支持动态配置功能, 3. **Kafka 安装与配置**:基于 Bitnami Kafka 镜像,提供完整的 Kafka 集群配置示例,涵盖 KRaft 模式、性能调优参数及数据持久化设置,适用于高可用生产环境。 以上方案适合 ARM64 架构,为用户提供了一站式的容器化管理和消息队列解决方案。
407 10
|
8月前
|
弹性计算 编解码 运维
飞天技术沙龙回顾:业务创新新选择,倚天 Arm 架构深入探讨
飞天技术沙龙回顾:业务创新新选择,倚天 Arm 架构深入探讨
133 1
|
10月前
|
人工智能 芯片 Windows
ARM架构PC退货率与CEO策略透视
ARM架构PC退货率与CEO策略透视

热门文章

最新文章