搭建嵌入式Linux虚拟机开发环境

1 全文总结

  1. 总结
    • 虚拟机环境搭建: 下载ubuntu虚拟机服务器镜像
    • 搭建交叉编译环境
      • apt install -y build-essential libncurses-dev bison flex libssl-dev libelf-dev git dwarves
        • build-essential: 包含 GCC、Make 等基础编译工具。
        • libncurses-dev: 用于生成内核配置菜单。
        • bison 和 flex: 语法分析器生成工具。
        • libssl-dev 和 libelf-dev: 内核编译所需的库
        • dwarves: 包含pahole工具, 现代内核编译必须
      • apt-get install curl python2.7 python-pyelftools git ssh make gcc libssl-dev liblz4-tool expect g++ patchelf chrpath gawk texinfo chrpath diffstat binfmt-support qemu-user-static live-build bison flex fakeroot cmake gcc-multilib g+±multilib unzip device-tree-compiler python3-pip libncurses-dev python3-pyelftools vim mtd-utils
    • 安装调试工具
      • open-vm-tools
      • tftp: 服务端, 客户端
      • ssh
      • 烧录驱动

2 虚拟机环境搭建

复制代码
- VMWare虚拟机
- ubuntu服务器镜像下载
- 网络配置
- 安装工具

2.1 VMWare下载安装

  1. 磁盘分区
    • 准备一块格式化好的磁盘分区, 用来作为虚拟机的虚拟磁盘
  2. 注册账号
  3. 下载
    • 登录网站: https://www.vmware.com/
      • 搜索"Desktop Hypervisor"
      • 选中"Funsion and Workstation"
      • 点击"DownLoad Now"
    • 进入"My Downloads"
      • 选择"Free Software Downloads available HERE"
      • 找到Workstation并下载
  4. 安装
    • 双击安装包进行安装
  5. 创建虚拟机
    • 内存和磁盘根据电脑实际情况选择
    • 网络可以选择NAT, 这样可以理解使用网络
    • USB协议选择3.0

2.2 ubuntu服务端镜像

  1. 官网下载 : 会慢一点
  2. 镜像网站下载
  3. 虚拟机配置镜像文件启动
    • 虚拟机设置, 编辑启动盘

2.3 安装和启动

  1. 安装desktop : 按照指引安装即可
  2. 安装server
    • 语言: English
    • Installer update availabe
      • 使用下载的镜像, 不要使用更新的
      • 选择: Continue without updating

2.4 配置apt下载镜像

  1. 找到/etc/apt/sources.list

    清华大学镜像源

    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse

    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse

    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse

    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse

    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse

    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse

    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse

    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse

    阿里云镜像源

    deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse

    deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse

    deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse

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

    deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse

    deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse

    deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse

    deb-src https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse

    deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse

    deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse

2.5 网络配置

  1. 访问github.com

  2. 域名解析

    • 修改/etc/systemd/resolved.conf
      • DNS=1.1.1.1 8.8.8.8
  3. 没有网卡

    • ip link show: 检查网卡是否存在, ens33
    • ip link set ens33 up: 启动网卡
    • dhclient ens33: 分配IP
      • 重新启动: dhclient -r
      • 获取IP: dhclient
    • systemctl restart NetworkManager: 重启网络管理服务
  4. 挂载

    • 虚拟机内部安装: open-vm-tools, open-vm-tools-desktop
    • VM虚拟机配置选项: 启用共享文件夹服务
    • 安装
      • apt install -y open-vm-tools open-vm-tools-desktop
      • systemctl status vmtoolsd
      • vmware-hgfsclient
      • vmhgfs-fuse .host:/ /mnt/hgfs -o allow_other
    • sudo vmhgfs-fuse .host:/ /mnt/hgfs -o allow_other

3 安装交叉编译工具

复制代码
apt-get install curl python2.7 python-pyelftools git ssh make gcc libssl-dev liblz4-tool expect g++ patchelf chrpath gawk texinfo chrpath diffstat binfmt-support qemu-user-static live-build bison flex fakeroot cmake gcc-multilib g++-multilib unzip device-tree-compiler python3-pip libncurses-dev python3-pyelftools vim mtd-utils

3.1 编译与构建工具

  1. make
  2. gcc/g++
  3. gcc-multilib/g+±multilib
  4. cmake
  5. bison/flex
    • 语法分析器和词法分析器生成器,用于编译需要解析器的组件
  6. device-tree-compiler
    • 设备树编译器,用于将 .dts 编译成 .dtb,或将 .dtb 反编译,是嵌入式 Linux 内核开发的核心工具

3.2 库与头文件

  1. libssl-dev: openssl开发库
  2. liblz4-tool: LZ4压缩工具
  3. libncurses-dev: 终端图形库开发文件,用于编译 menuconfig 等终端交互式配置界面
  4. python3-pip
    • Python 包管理器,用于安装额外的 Python 工具

3.3 python相关

  1. python2.7
  2. python-pyelftools: Python 2 的 ELF 文件解析库,用于分析 ELF 文件
  3. python3-pyelftools: Python 3 版本的 ELF 解析库

3.4 二进制与库操作工具

  1. patchelf: 修改 ELF 文件头的工具,可更改动态链接器(interpreter)和 RPATH,用于移植或调试
  2. chrpath: 修改 ELF 文件中的 RPATH / RUNPATH,用于调整共享库搜索路径(类似 patchelf,更轻量)
  3. fakeroot: 在非 root 环境下模拟 root 权限,用于创建文件系统镜像

3.5 文件与归档工具

  1. unzip
  2. gawk: GNU AWK,文本处理工具,常用于解析日志、处理配置脚本
  3. textinfo: GNU 文档系统,某些软件(如 binutils)的文档编译需要
  4. diffstat: 统计 diff 文件的变化行数,常用于补丁审查
  5. mtd-utils
    • MTD(Memory Technology Device)工具集,用于操作 NAND Flash、SPI Flash 等,包括 flash_erase、nanddump
    • 对 Rockchip 平台(常用 SPI‑NAND 或 eMMC)很重要

3.6 网络与版本控制

  1. curl
  2. git
  3. ssh

3.7 终端与系统工具

  1. vim
  2. expect:
  3. binfmt-support / qemu-user-static
    • 支持在 x86 主机上运行 ARM/ARM64 等架构的用户态程序(通过 QEMU 模拟),常用于交叉编译后测试或创建 chroot 环境
  4. live-build
    • Debian Live 构建工具,用于定制和构建 Debian 根文件系统镜像

4 工具安装

4.1 虚拟机工具安装

  1. 安装ssh

    • sudo -i, 进入root环境
    • apt update:
    • apt install openssh-server: 安装ssh服务
    • systemctl enable ssh: 启动ssh服务
  2. 安装nfs

    • sudo -i, 进入root环境
    • apt update:
    • apt install nfs-common
  3. open-vm-tools

    • apt-get install open-vm-tools open-vm-tools-desktop

4.2 宿主机工具安装

  1. VSCode
  2. MobaXterm
    • 串口, 远程中断连接工具
    • 下载, 用于连接虚拟机
    • 使用ssh
      • 输入虚拟机的IP(ip a查看), 输入用户名
    • mount挂载
      • mount -t nfs -o nolock PC的IP:/C/...共享文件夹 /mnt/windows_linux上的挂载点
相关推荐
H_oRIZoN_3 小时前
Linux入门DAY41(51 单片机 串口与通信协议)
linux·运维·单片机
GeW4 小时前
RHCE备考别瞎学!按这个计划走,30天提高通过率,快速拿证
linux
Escalating_xu5 小时前
【System V 信号量】从 P/V 原语到 Builder 封装:写出可控、可清理的进程互斥组件
java·linux·开发语言·jvm
傲世仙尊5 小时前
System V 进程间通信详解:共享内存、消息队列与信号量(CSDN博客)
linux·开发语言·c++
码农小韩5 小时前
Linux应用开发(六)——进程间通信
linux·linux驱动·嵌入式软件开发·嵌入式操作系统·linux应用
笨笨饿6 小时前
#138_解决Codex要五次回复的问题
linux·stm32·单片机·嵌入式硬件·mcu·物联网·嵌入式实时数据库
m0_459872926 小时前
Linux 系统基础
linux·运维·服务器
吴声子夜歌6 小时前
Shell编程——数组
linux·运维·shell
blueSatchel7 小时前
ros-humble仿真-建图-导航
linux·ros2
Lucis__7 小时前
基于责任链模式的消息队列—异步处理流水线的最佳实践
linux·c++·消息队列·责任链模式·ipc