diff --git a/debian.cfg b/debian.cfg index 998b581..94c8933 100644 --- a/debian.cfg +++ b/debian.cfg @@ -102,15 +102,20 @@ d-i preseed/early_command string \ hostname="$(grep -o 'extra\.deb_hostname=[^ ]*' /proc/cmdline | cut -d= -f2)"; \ debconf-set mirror/http/hostname "$hostname" +# debian 11 initrd 没有 xargs awk +# debian 12 initrd 没有 xargs d-i partman/early_command string \ confhome="$(grep -o 'extra\.confhome=[^ ]*' /proc/cmdline | cut -d= -f2)"; \ swapfile=/target/swapfile; \ postinst=/var/lib/dpkg/info/bootstrap-base.postinst; \ cp $postinst $postinst.orig; \ - echo "fallocate -l 384M $swapfile; mkswap $swapfile; swapon $swapfile; $postinst.orig" >$postinst; \ - echo "swapoff $swapfile; rm $swapfile" >/usr/lib/finish-install.d/95swapoff; \ + mem=$(grep ^MemTotal: /proc/meminfo | { read x y z; echo $y; }); \ + mem=$((mem / 1024)); \ + swap_size=$((512 - mem)); \ + [ $swap_size -gt 0 ] && echo "fallocate -l ${swap_size}M $swapfile; mkswap $swapfile; swapon $swapfile; $postinst.orig" >$postinst; \ + echo "swapoff -a; rm -f $swapfile" >/usr/lib/finish-install.d/95swapoff; \ chmod a+x /usr/lib/finish-install.d/95swapoff; \ xda=$(wget --tries=5 $confhome/get-xda.sh -O- | sh -s); \ @@ -122,6 +127,7 @@ d-i partman/early_command string \ debconf-set debian-installer/add-kernel-opts "$ttys"; \ kernel="$(grep -o 'extra\.kernel=[^ ]*' /proc/cmdline | cut -d= -f2)"; \ + . /can_use_cloud_kernel.sh || kernel=$(echo "$kernel" | sed 's/-cloud//'); \ debconf-set base-installer/kernel/image "$kernel"; \ [ -d /sys/firmware/efi ] && debconf-set partman-auto/expert_recipe "$(debconf-get partman-auto/expert_recipe_efi)"; \ diff --git a/reinstall.sh b/reinstall.sh index 62221ed..b1a08b6 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -1875,7 +1875,8 @@ mod_initrd_debian() { db_progress START 0 5 debian-installer/netcfg/title # 找到主网卡 - # debian 11 initrd 没有 awk + # debian 11 initrd 没有 xargs awk + # debian 12 initrd 没有 xargs if false; then iface=$(ip -o link | grep "@mac_addr" | awk '{print $2}' | cut -d: -f1) else @@ -1994,14 +1995,16 @@ expand_packages() { } EOF + # https://github.com/linuxhw/LsPCI?tab=readme-ov-file#storageata-pci # https://debian.pkgs.org/12/debian-main-amd64/linux-image-6.1.0-18-cloud-amd64_6.1.76-1_amd64.deb.html - # scsi-core-modules 是 ata-modules 的依赖,包含 sd_mod.ko scsi_mod.ko - # ata-modules 是下方模块的依赖,Priority 是 optional。只有 ata_generic.ko 和 libata.ko 两个驱动 + # 以下是 debian-installer 有的驱动,这些驱动云内核不一定都有,(+)表示有 + # scsi-core-modules 是 ata-modules 的依赖,包含 sd_mod.ko(+) scsi_mod.ko(+) + # ata-modules 是下方模块的依赖,Priority 是 optional。只有 ata_generic.ko(+) 和 libata.ko(+) 两个驱动 # pata-modules 里面的驱动都是 pata_ 开头 - # 但只有 pata_legacy.ko 在云内核中 - # sata-modules 里面的驱动大部分是 sata_ 开头的,其他重要的还有 ahci.ko ata_piix.ko libahci.ko + # 但只有 pata_legacy.ko(+) 在云内核中 + # sata-modules 里面的驱动大部分是 sata_ 开头的,其他重要的还有 ahci.ko libahci.ko ata_piix.ko(+) # 云内核没有 sata 模块,也没有内嵌,有一个 CONFIG_SATA_HOST=y,libata-$(CONFIG_SATA_HOST) += libata-sata.o - # scsi-modules 包含 virtio_scsi.ko virtio_blk.ko + # scsi-modules 包含 virtio_scsi.ko(+) virtio_blk.ko(+) download_and_extract_udeb() { package=$1 @@ -2045,6 +2048,27 @@ EOF ) } + can_use_cloud_kernel() { + # xen 是 vbd + # 有些虚拟机用了 ahci,但云内核没有 ahci 驱动 + # shellcheck disable=SC2317 + get_disk_controller | grep -Ewq \ + 'ata_generic|ata_piix|pata_legacy|nvme|virtio_blk|virtio_scsi|vbd|hv_storvsc|vmw_pvscsi' + } + + # 在 debian installer 中判断能否用云内核 + cat <can_use_cloud_kernel.sh + get_disk_controller(){ + $(get_function_content get_disk_controller) + } + + can_use_cloud_kernel(){ + $(get_function_content can_use_cloud_kernel) + } + + can_use_cloud_kernel +EOF + # 提前下载 fdisk # 因为 fdisk-udeb 包含 fdisk 和 sfdisk,提前下载可减少占用 mkdir_clear $tmp/fdisk @@ -2062,9 +2086,10 @@ EOF for driver in $(get_disk_controller); do echo "using driver: $driver" case $driver in - nvme | virtio_blk | virtio_scsi | hv_storvsc) extra_drivers+=" $driver" ;; + # xen 是 vbd + nvme | virtio_blk | virtio_scsi | vbd | hv_storvsc | vmw_pvscsi) extra_drivers+=" $driver" ;; pata_legacy) sed -i '/^pata-modules/d' $net_retriever ;; - pata_* | sata_* | ahci) error_and_exit "Debain cloud kernel does not support this driver: $driver" ;; + pata_* | sata_* | ahci) error_and_exit "Debian cloud kernel does not support this driver: $driver" ;; esac done diff --git a/trans.sh b/trans.sh index 9dd9356..85cc132 100644 --- a/trans.sh +++ b/trans.sh @@ -493,7 +493,8 @@ is_need_manual_set_dnsv6() { } get_current_dns_v4() { - # debian 11 initrd 没有 awk + # debian 11 initrd 没有 xargs awk + # debian 12 initrd 没有 xargs if false; then grep '^nameserver' /etc/resolv.conf | awk '{print $2}' | grep '\.' else @@ -502,7 +503,8 @@ get_current_dns_v4() { } get_current_dns_v6() { - # debian 11 initrd 没有 awk + # debian 11 initrd 没有 xargs awk + # debian 12 initrd 没有 xargs if false; then grep '^nameserver' /etc/resolv.conf | awk '{print $2}' | grep ':' else @@ -3002,6 +3004,7 @@ refind_main_disk() { main_disk=$(sfdisk --disk-id /dev/$xda | sed 's/0x//') else apk add lsblk + # main_disk=$(blkid --match-tag PTUUID -o value /dev/$xda) main_disk=$(lsblk --nodeps -rno PTUUID /dev/$xda) fi } @@ -3015,6 +3018,9 @@ get_ubuntu_kernel_flavor() { # https://github.com/canonical/cloud-init/blob/main/tools/ds-identify # http://git.annexia.org/?p=virt-what.git;a=blob;f=virt-what.in;hb=HEAD { + # busybox blkid 不显示 sr0 的 UUID + apk add lsblk + if is_dmi_contains "amazon" || is_dmi_contains "ec2"; then flavor=aws elif is_dmi_contains "Google Compute Engine" || is_dmi_contains "GoogleCloud"; then @@ -3023,6 +3029,8 @@ get_ubuntu_kernel_flavor() { flavor=oracle elif is_dmi_contains "7783-7084-3265-9085-8269-3286-77"; then flavor=azure + elif lsblk -o UUID,LABEL | grep -i 9796-932E | grep -i config-2; then + flavor=ibm elif is_virt; then flavor=virtual-hwe-$releasever else