Function Overview
Operating system adaptation tool, used to automate the adaptation process for a new OS, including:
- Update OS information to the code repository
- Create OS-related configuration files
- Generate dependency and source information
- Update the build configuration
Use Cases
- When you need to create an adaptation for a new operating system version
- When you need to update OS-related configuration information
- When you need to configure hardware support for a new OS
- When you need to initialize the OS dependency and source information
Adaptation Steps
Step 1: Update Basic OS Information
- Obtain the OS information through
/etc/os-release. - Refer to the
BCLINUX_21_10_AARCH64 = "BCLinux_21.10_aarch64"format - In
module_utils/common_info, in theOSName, add the corresponding data - If it already exists, ignore it
Step 2: Update common_info Data
Data to update:
OSName: OS name constantdl_os_list: Download OS list- Note: Duplicate data should be ignored
Step 3: Update Hardware Compatibility Configuration
Update the data in module_utils/compatibility_config :
HardwareOSTagsInOS_TO_CARD_TAG_MAP- The user needs to provide the hardware types supported by this OS (I2, A2, A3, etc.)
Reference:compatibility_config.py lines 167-177
Step 4: Create OS Configuration Files
In the downloader_config directory:
- Create a folder with the same name
- Create the following files:
installed.txt: Installed library informationpkg_info.json: Package version information (JSON array format)source.repoorsource.list: System source configuration (depending on the OS type)
Step 5: Read Installed Library Information
Read the libraries installed on the system and write the related information to installed.txt
Step 6: Configure System Sources
Generate different source configuration files according to the OS type:
- RPM series (CentOS/RHEL/openEuler, etc.): Generate
source.repo- including sources such as base, docker-ce, everything, update, EPOL, etc.
- DEB series (Debian/Ubuntu, etc.): Generate
source.list- including sources such as debian main, updates, security, docker-ce, etc.
Step 7: Sort Out Dependencies and Generate Package Information
Use the dependency analysis script to sort out all dependencies (CANN and NPU), and generate the pkg_info.json file.
RPM series dependency analysis (using analyze_dep_tree.py)
Dependency list:
- cann group:gcc, gcc-c++, make, cmake, unzip, zlib-devel, libffi-devel, openssl-devel, pciutils, net-tools, sqlite-devel, lapack-devel, gcc-gfortran
- npu group:make, dkms, gcc, kernel-headers, kernel-devel
Analysis command:
python3 scripts/analyze_dep_tree.py --show_version --show_pkg_name \
--group cann --pkgs gcc gcc-c++ make cmake unzip zlib-devel libffi-devel openssl-devel pciutils net-tools sqlite-devel lapack-devel gcc-gfortran \
--group npu --pkgs make dkms gcc kernel-headers-$(uname -r) kernel-devel-$(uname -r)
DEB series dependency analysis (using apt_analyzer.py)
Dependency list:
- cann group:gcc, g++, make, cmake, libsqlite3-dev, zlib1g-dev, libssl-dev, libffi-dev, net-tools
- npu group:dkms, gcc, linux-headers
Analysis command:
python3 scripts/apt_analyzer.py --show_version --show_pkg_name \
--group cann --pkgs gcc g++ make cmake libsqlite3-dev zlib1g-dev libssl-dev libffi-dev net-tools \
--group npu --pkgs dkms gcc linux-headers-$(uname -r)
Parameter Description
| Parameter | Description |
|---|---|
| --show_version | Display the package version number in the output |
| --show_pkg_name | Display the full package name in the output |
| --group | Specify the dependency group name (such as cann, npu) |
| --pkgs | Specify the package list included in the group |
Output Format
The script outputs the dependency tree and package list in JSON format, generating the pkg_info.json format:
[
{ "name": "gcc", "version": "9.3.0-1.el7" },
{ "name": "make", "version": "3.82-24.el7" },
...
]
Step 8: Update build configuration
Update scripts/nexus_config.json:
- Classify according to OS type (rpm_os or deb_os)
- Add the OS information to the corresponding category
- Note deduplication
Directory structure
skills/os_adapter/
├── SKILL.md # 技能定义文件
├── scripts/ # 脚本目录
│ ├── os_adapter.py # 主适配脚本
│ ├── analyze_dep_tree.py # RPM 系列依赖分析脚本
│ ├── apt_analyzer.py # DEB 系列依赖分析脚本
│ └── utils.py # 工具函数
└── templates/ # 模板目录
├── installed.txt.tpl # installed.txt 模板
├── pkg_info.json.tpl # pkg_info.json 模板
├── source.repo.tpl # RPM 系列源配置模板
└── source.list.tpl # DEB 系列源配置模板
Usage
Connect to remote OS via SSH (recommended)
# 通过 SSH 连接远程 OS,自动获取 OS 信息、repo 信息和依赖信息
python scripts/os_adapter.py --ssh-host 192.168.1.100 --ssh-user root --ssh-key ~/.ssh/id_rsa --hardware "I2,A2,A3"
# 指定 SSH 端口
python scripts/os_adapter.py --ssh-host 192.168.1.100 --ssh-port 2222 --ssh-user root --hardware "I2,A2"
# 如果 SSH 无法获取 repo 信息,会提示用户手动配置
Local execution
# 执行完整适配流程(本地系统)
python scripts/os_adapter.py --os-name "NewOS_22.04_x86_64"
# 仅更新 OS 基本信息
python scripts/os_adapter.py --step basic-info --os-name "NewOS_22.04_x86_64"
# 仅创建配置文件
python scripts/os_adapter.py --step create-config --os-name "NewOS_22.04_x86_64"
# 指定硬件支持
python scripts/os_adapter.py --os-name "NewOS_22.04_x86_64" --hardware "I2,A2,A3"
Interactive use
# 交互式录入信息(支持 SSH 连接)
python scripts/os_adapter.py --interactive
SSH parameter description
| Parameter | Description | Default value |
|---|---|---|
| --ssh-host | SSH host address | None |
| --ssh-port | SSH port | 22 |
| --ssh-user | SSH username | root |
| --ssh-key | SSH private key file path | None |
Related file paths
| File | Path | Description |
|---|---|---|
| OSName | module_utils/common_info | OS name constant definitions |
| dl_os_list | module_utils/common_info | Download OS list |
| HardwareOSTags | module_utils/compatibility_config | Hardware compatibility configuration |
| OS configuration directory | downloader_config/{os_name}/ | OS configuration file directory |
| installed.txt | downloader_config/{os_name}/installed.txt | Installed library information |
| pkg_info.json | downloader_config/{os_name}/pkg_info.json | Package version information (JSON array) |
| source.repo | downloader_config/{os_name}/source.repo | RPM series system source configuration |
| source.list | downloader_config/{os_name}/source.list | DEB series system source configuration |
| nexus_config.json | scripts/nexus_config.json | Build configuration |
Notes
- SSH connection: It is recommended to connect to the remote OS via SSH, which can automatically obtain OS information and repo information
- Project detection: Before the script runs, it automatically detects whether it is an ascend-deployer project; it only runs if the detection passes
- Deduplication: All add operations need to check whether the item already exists to avoid duplicates
- Repo information retrieval: Prefer retrieval via SSH; if retrieval fails, the user will be prompted to configure manually
- Hardware support: The user needs to explicitly specify the hardware type supported by the OS
- OS type determination: Determine whether it is rpm_os or deb_os based on the package manager
- Version number retrieval: Obtain the exact package version number by calling the source API
Project detection
Before the script runs, it detects the following marker files/directories to confirm whether it is an ascend-deployer project:
module_utils/downloader_config/scripts/nexus_config.json
If detection fails, the script outputs an error message and exits.
Example
Adapt a remote OS via SSH
Suppose you want to adapt openEuler 24.03 aarch64:
- Run the adaptation script:
python scripts/os_adapter.py --ssh-host 192.168.1.100 --ssh-user root --ssh-key ~/.ssh/id_rsa --hardware "I2,A2"
- The script will automatically:
- Connect to the remote server via SSH
- Obtain OS information (/etc/os-release)
- Obtain the list of installed packages
- Obtain repo information (/etc/yum.repos.d/*.repo or /etc/apt/sources.list)
- In
OSNameadd a constant - In
dl_os_listadd an entry - In
OS_TO_CARD_TAG_MAPadd a hardware mapping - Create the configuration file directory and files
- Update
nexus_config.json
Example of adapting an RPM series OS
Suppose you want to adapt BCLinux 21.10 aarch64:
- Run the adaptation script:
python scripts/os_adapter.py --os-name "BCLinux_21.10_aarch64" --hardware "I2,A2"
- The script will automatically:
- In
OSNameaddBCLINUX_21_10_AARCH64 = "BCLinux_21.10_aarch64" - In
dl_os_listadd the corresponding entry - In
OS_TO_CARD_TAG_MAPadd hardware mapping - Create
downloader_config/BCLinux_21.10_aarch64/directory - Generate
installed.txt、pkg_info.json、source.repo - Update
nexus_config.jsoninrpm_oslist
- In
Example of adapting to DEB series OS
Assume you want to adapt Debian 10 x86_64:
- Execute the adaptation script:
python scripts/os_adapter.py --os-name "Debian_10_x86_64" --hardware "I2,A2"
- The script will automatically:
- In
OSNameaddDEBIAN_10_X86_64 = "Debian_10_x86_64" - In
dl_os_listadd the corresponding entry - In
OS_TO_CARD_TAG_MAPadd hardware mapping - Create
downloader_config/Debian_10_x86_64/directory - Generate
installed.txt、pkg_info.json、source.list - Update
nexus_config.jsonindeb_oslist
- In
Technical points
- Cross-platform compatibility: supports rpm and deb series operating systems
- Automated processing: automatically obtains system information as much as possible
- Interactive support: provides interactive input for information that cannot be obtained automatically
- Idempotency: repeated execution will not produce duplicate data
- Extensibility: easy to add new OS types and hardware support