From 12f17d6da2b72322a3c01d7875357610f770d272 Mon Sep 17 00:00:00 2001 From: Anonymous <> Date: Wed, 18 Mar 2026 15:39:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20azure=20=E7=BC=BA=E5=B0=91=E7=A3=81?= =?UTF-8?q?=E7=9B=98=E9=A9=B1=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.ja-JP.md | 7 +++ README.md | 6 +++ README.zh-CN.md | 8 +++- debi.sh | 119 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+), 1 deletion(-) diff --git a/README.ja-JP.md b/README.ja-JP.md index 6c5ad1e..d51dd6d 100644 --- a/README.ja-JP.md +++ b/README.ja-JP.md @@ -171,6 +171,7 @@ sudo reboot | `--cloud-kernel` | *標準* | クラウド最適化カーネルを使用 | | `--bpo-kernel` | *stable* | backportsから新しいカーネルを使用 | | `--firmware` | *自動検出* | ハードウェア用のnon-freeファームウェアを含める | +| `--hyperv-pci-hotfix` | *無効* | インストーラー内核に一致する Debian kernel パッケージをダウンロードして initrd に組み込み、インストーラー起動初期に `pci-hyperv.ko` を読み込む(Azure NVMe / Hyper-V vPCI のディスク検出向け) | ### 詳細オプション @@ -321,6 +322,12 @@ sudo ./debi.sh --ip YOUR_IP/CIDR --gateway YOUR_GATEWAY sudo ./debi.sh --firmware ``` +**インストーラーで Azure NVMe ディスクを検出できない場合(Hyper-V vPCI):** + +```bash +sudo ./debi.sh --hyperv-pci-hotfix +``` + **インストールのデバッグ:** ```bash diff --git a/README.md b/README.md index 129dcfd..fb647f5 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,7 @@ sudo reboot | `--cloud-kernel` | *standard* | Use cloud-optimized kernel | | `--bpo-kernel` | *stable* | Use newer kernel from backports | | `--firmware` | *auto-detect* | Include non-free firmware for hardware | +| `--hyperv-pci-hotfix` | *disabled* | Download the matching Debian kernel package, embed it in the installer initrd, and load `pci-hyperv.ko` during installer startup (useful for Azure NVMe/Hyper-V vPCI disk detection) | ### Advanced Options | Option | Default | Description | @@ -294,6 +295,11 @@ sudo ./debi.sh --ip YOUR_IP/CIDR --gateway YOUR_GATEWAY sudo ./debi.sh --firmware ``` +**Azure NVMe disk not detected in installer (Hyper-V vPCI):** +```bash +sudo ./debi.sh --hyperv-pci-hotfix +``` + **Installation debugging:** ```bash # Generate preseed file only diff --git a/README.zh-CN.md b/README.zh-CN.md index f9c9709..658e6c5 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -173,6 +173,7 @@ sudo reboot | `--cloud-kernel` | *标准内核* | 使用为云环境优化的内核 | | `--bpo-kernel` | *稳定版内核* | 使用来自 backports 的较新内核 | | `--firmware` | *自动检测* | 为硬件安装 non-free 固件 | +| `--hyperv-pci-hotfix` | *禁用* | 下载与安装器内核匹配的 Debian kernel 包,将其写入安装器 initrd,并在安装器启动早期加载 `pci-hyperv.ko`(适用于 Azure NVMe / Hyper-V vPCI 磁盘识别) | ### 高级选项 @@ -323,6 +324,12 @@ sudo ./debi.sh --ip YOUR_IP/CIDR --gateway YOUR_GATEWAY sudo ./debi.sh --firmware ``` +**Azure NVMe 磁盘在安装器中无法识别(Hyper-V vPCI):** + +```bash +sudo ./debi.sh --hyperv-pci-hotfix +``` + **安装过程调试:** ```bash @@ -354,4 +361,3 @@ sudo ./debi.sh --network-console --authorized-keys-url YOUR_KEYS_URL *作者 [@bohanyang](https://github.com/bohanyang) • [问题反馈](https://github.com/bohanyang/debi/issues) • [GitHub 仓库](https://github.com/bohanyang/debi)* - diff --git a/debi.sh b/debi.sh index 10ebcd2..85af32a 100755 --- a/debi.sh +++ b/debi.sh @@ -89,6 +89,120 @@ download() { fi } +find_kernel_package() { + local package_name filename + + package_name="linux-image-$1" + filename=$( + gzip -dc "$2" | awk -v pkg="$package_name" ' + BEGIN { RS = ""; FS = "\n" } + $1 == "Package: " pkg { + for (i = 1; i <= NF; i++) { + if ($i ~ /^Filename: /) { + sub(/^Filename: /, "", $i) + print $i + exit + } + } + } + ' + ) + [ -n "$filename" ] && { + printf '%s\n' "$filename" + return 0 + } + + package_name="linux-image-$1-unsigned" + filename=$( + gzip -dc "$2" | awk -v pkg="$package_name" ' + BEGIN { RS = ""; FS = "\n" } + $1 == "Package: " pkg { + for (i = 1; i <= NF; i++) { + if ($i ~ /^Filename: /) { + sub(/^Filename: /, "", $i) + print $i + exit + } + } + } + ' + ) + [ -n "$filename" ] && printf '%s\n' "$filename" +} + +find_installer_kernel_version() { + cpio -it -F "$1" 2> /dev/null | + sed -n 's#^lib/modules/\([^/]*\)/.*#\1#p' | + sort -u | + head -n 1 +} + +inject_hyperv_pci_hotfix() { + local initrd_file installer_kernel_version packages_url package_path tmpdir + + initrd_file=$1 + installer_kernel_version=$(find_installer_kernel_version "$initrd_file") + [ -n "$installer_kernel_version" ] || + err "Could not determine the installer kernel version from $initrd_file" + + tmpdir=$(mktemp -d) + packages_url="$mirror_protocol://$mirror_host$mirror_directory/dists/$suite/main/binary-$architecture/Packages.gz" + download "$packages_url" "$tmpdir/Packages.gz" + + package_path=$(find_kernel_package "$installer_kernel_version" "$tmpdir/Packages.gz" || true) + [ -n "$package_path" ] || { + rm -rf "$tmpdir" + err "Could not find a Debian kernel package for installer kernel $installer_kernel_version" + } + + mkdir -p \ + "$tmpdir/hotfix/debi-hyperv-pci" \ + "$tmpdir/hotfix/lib/debian-installer-startup.d" + download "$mirror_protocol://$mirror_host$mirror_directory/$package_path" "$tmpdir/hotfix/debi-hyperv-pci/kernel.deb" + chmod 0644 "$tmpdir/hotfix/debi-hyperv-pci/kernel.deb" + + cat > "$tmpdir/hotfix/lib/debian-installer-startup.d/S25pci-hyperv-hotfix" << EOF +#!/bin/sh +set -eu + +kernel_version=$installer_kernel_version +module_path="/lib/modules/\$kernel_version/kernel/drivers/pci/controller/pci-hyperv.ko" +package_path=/debi-hyperv-pci/kernel.deb +tmpdir= + +cleanup() { + [ -n "\$tmpdir" ] && rm -rf "\$tmpdir" +} + +trap cleanup EXIT INT TERM + +modprobe pci_hyperv_intf 2> /dev/null || true + +if [ ! -f "\$module_path" ]; then + tmpdir=\$(mktemp -d /tmp/debi-hv-pci.XXXXXX) || exit 0 + data_member=\$(ar t "\$package_path" 2> /dev/null | awk '/^data\\.tar\\./ { print; exit }') + ar p "\$package_path" "\$data_member" > "\$tmpdir/\$data_member" 2> /dev/null || exit 0 + mkdir -p "\$tmpdir/extract" "\$(dirname "\$module_path")" + xzcat "\$tmpdir/\$data_member" | tar -xf - -C "\$tmpdir/extract" "./lib/modules/\$kernel_version/kernel/drivers/pci/controller/pci-hyperv.ko" 2> /dev/null || exit 0 + cp -f "\$tmpdir/extract/lib/modules/\$kernel_version/kernel/drivers/pci/controller/pci-hyperv.ko" "\$module_path" || exit 0 + chmod 0644 "\$module_path" || exit 0 +fi + +modprobe pci_hyperv 2> /dev/null || insmod "\$module_path" 2> /dev/null || true +EOF + chmod 0755 "$tmpdir/hotfix/lib/debian-installer-startup.d/S25pci-hyperv-hotfix" + + ( + cd "$tmpdir/hotfix" + find debi-hyperv-pci lib | cpio -o -H newc -A -F "$initrd_file" > /dev/null 2>&1 + ) || { + rm -rf "$tmpdir" + err 'Could not append the Hyper-V PCI hotfix to the installer initrd' + } + + rm -rf "$tmpdir" +} + # Set "$mirror_proxy" with "$http/https/ftp_proxy" # only when it is empty and one of those is not empty set_mirror_proxy() { @@ -268,6 +382,7 @@ hold=false power_off=false architecture= firmware=false +hyperv_pci_hotfix=false force_efi_extra_removable=true grub_timeout=5 dry_run=false @@ -524,6 +639,9 @@ while [ $# -gt 0 ]; do --firmware) firmware=true ;; + --hyperv-pci-hotfix) + hyperv_pci_hotfix=true + ;; --no-force-efi-extra-removable) force_efi_extra_removable=false ;; @@ -948,6 +1066,7 @@ save_grub_cfg='cat' [ "$firmware" = true ] && download "$firmware_url" firmware.cpio.gz gzip -d initrd.gz + [ "$hyperv_pci_hotfix" = true ] && inject_hyperv_pci_hotfix "$PWD/initrd" # cpio reads a list of file names from the standard input echo preseed.cfg | cpio -o -H newc -A -F initrd From c02a41a968f6f2994e7df59b64cf55b2a8746e1a Mon Sep 17 00:00:00 2001 From: Bohan Yang <8384161+bohanwood@users.noreply.github.com> Date: Wed, 25 Mar 2026 20:14:33 +0900 Subject: [PATCH 2/2] Update README.ja-JP.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- README.ja-JP.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.ja-JP.md b/README.ja-JP.md index d51dd6d..73d1349 100644 --- a/README.ja-JP.md +++ b/README.ja-JP.md @@ -171,7 +171,7 @@ sudo reboot | `--cloud-kernel` | *標準* | クラウド最適化カーネルを使用 | | `--bpo-kernel` | *stable* | backportsから新しいカーネルを使用 | | `--firmware` | *自動検出* | ハードウェア用のnon-freeファームウェアを含める | -| `--hyperv-pci-hotfix` | *無効* | インストーラー内核に一致する Debian kernel パッケージをダウンロードして initrd に組み込み、インストーラー起動初期に `pci-hyperv.ko` を読み込む(Azure NVMe / Hyper-V vPCI のディスク検出向け) | +| `--hyperv-pci-hotfix` | *無効* | インストーラーのカーネルに一致する Debian kernel パッケージをダウンロードして initrd に組み込み、インストーラー起動初期に `pci-hyperv.ko` を読み込む(Azure NVMe / Hyper-V vPCI のディスク検出向け) | ### 詳細オプション