发表于2025-05-14 10:28:14
0 查看
PC 制卡流程 (临时版本)
一、方案说明
- 方案一: 个人 PC + VMware + Ubuntu 20.04 x86_64 虚拟机 (没有 Linux x86_64 物理服务器的情况)
- 方案二: 物理机安装 Ubuntu 20.04 x86_64 Linux 系统 (有 Linux x86_64 物理服务器的情况)
二、VMware17 Pro 安装(方案一,方案二请跳过)
三、创建 Ubuntu 20.04 虚拟机 (方案一,方案二请跳过)
四、Ubuntu 20 PXE 服务器配置 (方案一 && 方案二)
4.1 ubuntu 20.04 配置外网源,以清华源为例 (如果源不通,不可用,请先排查!)
4.2 上传制卡工具包到 /home/ascend/mksd
- 注意:以下文件缺一不可!

4.3 修改 /home/ascend/mksd/lib/common.sh,加上如下代码

4.4 安装 pxe 服务
- 这一步需要联网安装服务,请确保虚拟机可通外网,并且配置的 apt 源可用
- 安装 pxe 服务,需要安装和配置 httpd/dhcpd/tftp 服务,比较麻烦
- 为简化流程,可以将下面代码复制,放到 /opt/config_pxe.sh 里面 (发送的包里面也有该脚本,可以直接使用)
- 执行
bash -x /opt/config_pxe.sh eth0 (注意:eth0 是网卡名称,请根据虚拟机实际使用的网卡名称填写) - 最后打印
Config Success! 表示配置成功
4.5 配置 pxe 制卡
- 为简化流程,请将下面脚本复制放到 /opt/config_mksd.sh (发送的包里面也有该脚本,可以直接使用)
- 执行
bash -x /opt/config_mksd.sh buildDisk /dev/DISK_NAME - DISK_NAME 是磁盘名,可选 mmcblk0 / nvme0n1 / sda 三种,根据制卡需求填写
- 最后打印
Config Success! 表示配置成功
五、制卡
- 方案二: Ubuntu 20.04 物理服务器制卡
六、说明
- 文件中附加了一份正常的 PC 制卡日志,制卡过程中可对比该日志
- 如果虚拟机启动很慢,可以在虚拟机正常启动后,执行以下命令,禁用掉 cloud-init 服务:
本帖最后由 匿名用户 于 2025/06/12 16:22:30 编辑
PC 制卡流程 (临时版本)
一、方案说明
二、VMware17 Pro 安装(方案一,方案二请跳过)
三、创建 Ubuntu 20.04 虚拟机 (方案一,方案二请跳过)
四、Ubuntu 20 PXE 服务器配置 (方案一 && 方案二)
4.1 ubuntu 20.04 配置外网源,以清华源为例 (如果源不通,不可用,请先排查!)
root@ubuntu:~# cat /etc/apt/sources.list # 手动配置的源文件 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse root@ubuntu:~# root@ubuntu:~# root@ubuntu:~# apt-get update # 更新,检查源是否可用,虚拟机是否可访问外网 Hit:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal InRelease Hit:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates InRelease Hit:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security InRelease Hit:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports InRelease Reading package lists... Done root@ubuntu:~# root@ubuntu:~# apt-get install -y net-tools # 尝试通过外网源安装一个包 Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: net-tools 0 upgraded, 1 newly installed, 0 to remove and 206 not upgraded. Need to get 196 kB of archives. After this operation, 864 kB of additional disk space will be used. Get:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/main amd64 net-tools amd64 1.60+git20180626.aebd88e-1ubuntu1 [196 kB] Fetched 196 kB in 0s (437 kB/s) Selecting previously unselected package net-tools. (Reading database ... 72282 files and directories currently installed.) Preparing to unpack .../net-tools_1.60+git20180626.aebd88e-1ubuntu1_amd64.deb ... Unpacking net-tools (1.60+git20180626.aebd88e-1ubuntu1) ... Setting up net-tools (1.60+git20180626.aebd88e-1ubuntu1) ... Processing triggers for man-db (2.9.1-1) ... root@ubuntu:~# root@ubuntu:~# ifconfig # 有这个命令,表示安装成功 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 7.250.88.142 netmask 255.255.255.0 broadcast 7.250.88.255 inet6 fe80::20c:29ff:fe01:e88e prefixlen 64 scopeid 0x20<link> ether 00:0c:29:01:e8:8e txqueuelen 1000 (Ethernet) RX packets 56900 bytes 78404085 (78.4 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 27425 bytes 2131922 (2.1 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 144 bytes 12966 (12.9 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 144 bytes 12966 (12.9 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 04.2 上传制卡工具包到 /home/ascend/mksd
4.3 修改 /home/ascend/mksd/lib/common.sh,加上如下代码
4.4 安装 pxe 服务
bash -x /opt/config_pxe.sh eth0(注意:eth0是网卡名称,请根据虚拟机实际使用的网卡名称填写)Config Success!表示配置成功#!/bin/bash NET_ITF=$1 NET_IP=$(ifconfig $NET_ITF | awk '/broadcast/{print $2}') NET_IP_HEAD=$(echo $NET_IP | cut -d . -f 1-3) ISO_FILE=/opt/openEuler-22.03-LTS-SP3-aarch64-dvd.iso ISO_MOUNT_DIR=/opt/config_service #---------------------------- utils ----------------------------# function log_err() { echo -e "\e[31mError: $1\e[0m" echo } function log_info() { echo -e "\e[32m$1\e[0m" echo } function check_ret() { ret=$1 msg=$2 if [[ $ret -ne 0 ]]; then log_err "$msg failed or error, please check!" return 1 fi } #---------------------------- pxe ----------------------------# function extend_lv() { lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv resize2fs /dev/ubuntu-vg/ubuntu-lv } function fix_emmc_head() { cp /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 /lib64/ cp /usr/aarch64-linux-gnu/lib/libc.so.6 /lib/ /home/ascend/mksd/emmc-head --help >/dev/null 2>&1 check_ret $? "emmc-head" || return 1 } function install_package() { if dpkg -l | grep -q qemu-utils; then return 0 fi apt-get update apt-get install -y vim qemu-utils python3 make gcc unzip pigz bison flex libncurses-dev squashfs-tools bc device-tree-compiler libssl-dev cmake rpm2cpio qemu-user-static binfmt-support gcc-aarch64-linux-gnu g++-aarch64-linux-gnu dosfstools parted kpartx } function install_dhcp() { if systemctl cat isc-dhcp-server >/dev/null; then return 0 fi apt-get install isc-dhcp-server sed -i "s/^INTERFACESv4=.*/INTERFACESv4=\"$NET_ITF\"/" /etc/default/isc-dhcp-server cat >/etc/dhcp/dhcpd.conf <<EOF option domain-name "example.org"; default-lease-time 600; max-lease-time 7200; ddns-update-style none; next-server $NET_IP; option routers ${NET_IP_HEAD}.1; option client-architecture code 93 = unsigned integer 16; subnet ${NET_IP_HEAD}.0 netmask 255.255.255.0 { range ${NET_IP_HEAD}.100 ${NET_IP_HEAD}.200; filename "grubaa64.efi"; } EOF systemctl enable isc-dhcp-server systemctl restart isc-dhcp-server systemctl is-active --quiet isc-dhcp-server check_ret $? "install_dhcp" || return 1 } function install_tftp() { if systemctl cat tftpd-hpa >/dev/null; then return 0 fi apt-get install -y tftpd-hpa cat >/etc/default/tftpd-hpa <<EOF TFTP_USERNAME="tftp" TFTP_DIRECTORY="/var/www/html" TFTP_ADDRESS="0.0.0.0:69" TFTP_OPTIONS="-l -c -s" EOF systemctl enable tftpd-hpa.service systemctl restart tftpd-hpa.service systemctl is-active --quiet tftpd-hpa check_ret $? "install_tftp" || return 1 } function install_apche() { if systemctl cat apache2 >/dev/null; then return 0 fi apt-get install -y apache2 systemctl enable apache2.service systemctl restart apache2.service systemctl is-active --quiet apache2.service check_ret $? "install_apche" || return 1 } function config_files() { mv /var/www/html/index.html /tmp/ rm -rf /var/www/html/* mv /tmp/index.html /var/www/html/ if [ ! -f $ISO_FILE ]; then cp /home/ascend/mksd/openEuler-22.03-LTS-SP3-aarch64-dvd.iso /opt/ check_ret $? "cp /home/ascend/mksd/openEuler-22.03-LTS-SP3-aarch64-dvd.iso" || return 1 fi # 1. copy iso files rm -rf $ISO_MOUNT_DIR mkdir -p /var/www/html/openEuler/mnt $ISO_MOUNT_DIR mount $ISO_FILE $ISO_MOUNT_DIR cp -a $ISO_MOUNT_DIR/* /var/www/html/openEuler/mnt/ umount $ISO_MOUNT_DIR rm -rfv $ISO_MOUNT_DIR # 2. copy file to /var/www/html cp /var/www/html/openEuler/mnt/EFI/BOOT/grubaa64.efi /var/www/html/ cat >/var/www/html/grub.cfg <<EOF set default="1" function load_video { if [ x\$feature_all_video_module = xy ]; then insmod all_video else insmod efi_gop insmod efi_uga insmod ieee1275_fb insmod vbe insmod vga insmod video_bochs insmod video_cirrus fi } load_video set gfxpayload=keep insmod gzio insmod part_gpt insmod ext2 #insmod emmc set timeout=5 ### END /etc/grub.d/00_header ### ### BEGIN /etc/grub.d/10_linux ### menuentry 'Install openEuler-22.03-LTS-SP3-aarch64' --class red --class gnu-linux --class gnu --class os { linux /openEuler/vmlinuz rdinit=/sbin/init console=tty0 console=ttyAMA0,115200 earlycon=pl011,mmio32,0x840c0000 no_console_suspend inst.kdump_addon=on inst.ks=http://${NET_IP}/openEuler/openEuler-ks.cfg acpi=off initrd /openEuler/initrd.img devicetree /openEuler/hi1910p-asic-214-1p.dtb } EOF # 3. copy file to /var/www/html/openEuler cp /home/ascend/mksd/hi1910p-asic-214-1p.dtb /var/www/html/openEuler/ check_ret $? "cp /home/ascend/mksd/hi1910p-asic-214-1p.dtb" || return 1 cp /var/www/html/openEuler/mnt/images/pxeboot/initrd.img /var/www/html/openEuler/ cp /var/www/html/openEuler/mnt/images/pxeboot/vmlinuz /var/www/html/openEuler/ cat >/var/www/html/openEuler/openEuler-ks.cfg <<EOF #version=DEVEL # Use CDROM installation media url --url=http://${NET_IP}/openEuler/mnt # Use graphical install text # Run the Setup Agent on first boot firstboot --enable ignoredisk --only-use=none # Keyboard layouts keyboard --vckeymap=us --xlayouts='us' # System language lang en_US.UTF-8 # Network information network --bootproto=dhcp --device=eth0 --onboot=off --ipv6=auto network --hostname=localhost.localdomain # Root password rootpw --iscrypted \$6\$yOB1GmWUH/0lv7DI\$CrHEHmfupzFvuJzOubdlL2MpCnnN.bPuHV.K8FqNVOljpU4HU9xNTb7xJEHPoMS.OddKhkAApCcFSuxRpqhnx. %addon com_huawei_grub_safe --iscrypted --password='grub.pbkdf2.sha512.10000.02FA27E6AE2F62BE690363C4FDAF316E4941B5A82B85BE0A4CEE74BC29F3EA24D4376583D4A882C8A3321AB30B00960DCF4C15C07E440163C8539E3B7E0F8154.25EC7A98021DBF5AF0F48D1990E9DE842CC14033144BDAF757D08131DE4E210BD88BD88DF618C1F99B98475BEEBE0B4CE566D1496494673E568160306B6AA529' %end # System timezone timezone Asia/Beijing --isUtc # Reboot after install #reboot # System bootloader configuration bootloader --append="cma=256M coredump_filter=0x31 pmu_nmi_enable enable_charge_mighp enable_corelockup_detector enable_ascend_share_pool enable_sp_multi_group_mode default_hugepagesz=2M log_redirect=0x1fc000@0xb101000 iommu.passthrough=1 net.ifnames=0 biosdevname=0 crash_kexec_post_notifiers crashkernel=512M cdm-nodes=0x06" --location=mbr --boot-drive=none autopart --type=lvm # Partition clearing information clearpart --all --initlabel --drives=none %packages #@^product %end %pre %end %post --nochroot %end EOF # 4. move install.img mv /var/www/html/openEuler/mnt/images/install.img /var/www/html/openEuler/mnt/images/install.img_bak chmod 755 -R /var/www/html/ } function main() { if [[ X"$NET_ITF" == X ]] || [[ X"$NET_IP" == X ]]; then log_err "Network Name or IP not exist!" return 1 fi extend_lv || return 1 fix_emmc_head || return 1 install_package || return 1 install_dhcp || return 1 install_tftp || return 1 install_apche || return 1 config_files || return 1 } main main_ret=$? if [[ $main_ret -eq 0 ]]; then log_info "Config Success!" else log_err "Config Failed!" fi4.5 配置 pxe 制卡
bash -x /opt/config_mksd.sh buildDisk /dev/DISK_NAMEConfig Success!表示配置成功#!/bin/bash ISO_FILE=/home/ascend/mksd/openEuler-22.03-LTS-SP3-aarch64-dvd.iso INSTALL_IMG=/var/www/html/openEuler/mnt/images/install.img INSTALL_IMG_BAK=/var/www/html/openEuler/mnt/images/install.img_bak ROOT_FS_IMG=/var/www/html/openEuler/mnt/images/squashfs-root/LiveOS/rootfs.img ROOT_FS_DIR=/var/www/html/openEuler/mnt/images/squashfs-root LOCAL_MPOINT=/opt/iso ROOT_FS_MPOINT=/opt/mnt ROOT_FS_REPO_MPOINT=/opt/mnt/repo BUILD_TYPE=$1 BUILD_DISK=$2 #---------------------------- utils ----------------------------# function log_err() { echo -e "\e[31mError: $1\e[0m" echo } function log_info() { echo -e "\e[32m$1\e[0m" echo } function check_file_exist() { file_name=$1 if [[ -e $file_name ]]; then return 0 else log_err "$file_name not exist, please check!" return 1 fi } function check_ret() { ret=$1 msg=$2 if [[ $ret -ne 0 ]]; then log_err "$msg" return 1 fi } function umount_dir_check() { for dirmnt in "$@"; do if mount | grep -q $dirmnt; then umount ${dirmnt} 2>/dev/null check_ret $? "Umount ${dirmnt} failed!" || return 1 fi done } #---------------------------- functions ----------------------------# check_env() { check_file_exist $ISO_FILE || return 1 check_file_exist $INSTALL_IMG_BAK || return 1 umount_dir_check $ROOT_FS_REPO_MPOINT $ROOT_FS_MPOINT $LOCAL_MPOINT || return 1 rm -rfv $LOCAL_MPOINT $ROOT_FS_MPOINT $INSTALL_IMG $ROOT_FS_DIR mkdir -p $LOCAL_MPOINT $ROOT_FS_MPOINT mount -o loop $ISO_FILE $LOCAL_MPOINT return 0 } function check_package() { if ! which qemu-img; then apt-get update apt-get install -y qemu-utils if ! which qemu-img; then log_err "Install qemu-img falied!" return 1 fi fi } function exptend_rootfs() { cd /var/www/html/openEuler/mnt/images/ unsquashfs install.img_bak check_ret $? "unsquashfs install.img failed" || return 1 qemu-img info $ROOT_FS_IMG qemu-img resize -f raw $ROOT_FS_IMG 10G loop_d=$(losetup -f --show $ROOT_FS_IMG) e2fsck -f $loop_d resize2fs $loop_d losetup -d $loop_d mount $ROOT_FS_IMG $ROOT_FS_MPOINT total=$(df -h | grep /opt/mnt | awk '{print $2}') if ! echo $total | grep '^9'; then log_err "exptend_rootfs failed" return 1 fi } function config_service() { local target_file=/opt/mnt/lib/systemd/system/anaconda.target cat >/opt/mnt/lib/systemd/system/install_sh.service <<EOF service tftp [Unit] Description=install_sh [Service] Type=simple ExecStart=/bin/bash /home/ascend/mksd/make_os_sd.sh ${BUILD_TYPE} ${BUILD_DISK} StandardOutput=journal+console StandardError=journal+console EOF sed -i '/anaconda/d' $target_file sed -i '$i\Wants=install_sh.service\nWants=sshd.service\n' $target_file && sed -i 'N;$D' $target_file sed -i '/^$/d' $target_file cp /opt/mnt/etc/ssh/sshd_config.anaconda /opt/mnt/etc/ssh/sshd_config } function install_package() { mkdir -p $ROOT_FS_REPO_MPOINT mount --bind $LOCAL_MPOINT $ROOT_FS_REPO_MPOINT cat >${ROOT_FS_MPOINT}/chroot_install.sh <<EOF #!/bin/sh mkdir -p etc/yum.repos.d cat >/etc/yum.repos.d/openEuler.repo <<EOE [base] name=OpenEuler-Local baseurl=file:///repo gpgcheck=0 enabled=1 EOE dnf-3 install -y yum net-tools vim exit $? EOF chmod +x ${ROOT_FS_MPOINT}/chroot_install.sh chroot $ROOT_FS_MPOINT /bin/bash -c "./chroot_install.sh" check_ret $? "chroot_install.sh run failed!" || return 1 } function cp_mksd() { mkdir -p ${ROOT_FS_MPOINT}/home/ascend cp -a /home/ascend/mksd ${ROOT_FS_MPOINT}/home/ascend check_ret $? "cp /home/ascend/mksd failed!" || return 1 umount_dir_check $ROOT_FS_REPO_MPOINT $ROOT_FS_MPOINT rm -rfv $ROOT_FS_REPO_MPOINT $INSTALL_IMG cd /var/www/html/openEuler/mnt/images/ mksquashfs squashfs-root ./install.img -comp xz umount $LOCAL_MPOINT } #---------------------------- entrance ----------------------------# function main() { if [[ $# -ne 2 ]]; then log_err "Please input para: buildDisk /dev/mmcblk0 or genEmmcBin /dev/mmcblk0" return 1 fi bash -x /home/ascend/mksd/make_os_sd.sh buildBurnImg ${BUILD_DISK} check_ret $? "chroot_install.sh run failed!" || return 1 cp /home/ascend/mksd/sd_card_making_log/burn_os.img /home/ascend/mksd/ check_ret $? "cp /home/ascend/mksd/sd_card_making_log/burn_os.img failed!" || return 1 check_env || return 1 check_package || return 1 exptend_rootfs || return 1 config_service || return 1 install_package || return 1 cp_mksd || return 1 } main $* if [[ $? -eq 0 ]]; then log_info "Config Success!" else log_err "Config Failed!" fi五、制卡
六、说明
方案一: 1. 确保安装 pxe 服务阶段,就是执行 config_pxe.sh 脚本的时候,虚拟机可以访问外网,并且源是可用的,可以装包! 此时虚拟机与PC属于相同网段,可以互相ping通。PC 网线是插到交换机的,PC 是可以访问外网的。 2. 五、制卡 阶段, PC 网线是插到板子上的,请确保此阶段 PC 的 IP 还是原来的 IP,与虚拟机处于相同网段,PC 与 虚拟机互相可ping通。 3. 制卡时如遇到无法制卡,可以找一张制好的卡,配置与 PC 和 虚拟机 相同网段的静态IP,在板子上 ping PC 或者虚拟机,能 ping 通表示制卡链路是通的。 方案二: 1. 确保安装 pxe 服务阶段,就是执行 config_pxe.sh 脚本的时候,物理服务器可以访问外网,并且源是可用的,可以装包。 2. 制卡时,请确保物理服务器的 IP 没有改变! 因为 dhcp/httpd/tftp 服务绑定了该网卡的IP,变了可能服务起不来或者不起作用! 3. 制卡时如遇到无法制卡,可以找一张制好的卡,配置与物理服务器相同的网段的静态 IP,能互相 ping 通表示制卡链路就是通的。