core: 使用 get-xda.sh 寻找主硬盘

This commit is contained in:
bin456789 2024-02-02 00:31:21 +08:00
parent 5150feddc6
commit 5d3227fe64
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B
5 changed files with 50 additions and 46 deletions

View File

@ -71,9 +71,12 @@ d-i preseed/early_command string \
debconf-set mirror/http/hostname "$hostname"
d-i partman/early_command string \
debconf-set partman-auto/disk "$(list-devices disk | head -n1)"; \
confhome="$(grep -o 'extra\.confhome=[^ ]*' /proc/cmdline | cut -d= -f2)"; \
anna-install fdisk-udeb; \
xda=$(wget $confhome/get-xda.sh -O- | sh -s); \
debconf-set partman-auto/disk "/dev/$xda"; \
ttys=$(wget $confhome/ttys.sh -O- | sh -s console=); \
debconf-set debian-installer/add-kernel-opts "$ttys"; \

37
get-xda.sh Normal file
View File

@ -0,0 +1,37 @@
#!/bin/sh
# debian ubuntu redhat 安装模式共用此脚本
# alpine 未用到此脚本
get_all_disks() {
# busybox blkid 不接受任何参数
disks=$(blkid | cut -d: -f1 | cut -d/ -f3 | sed -E 's/p?[0-9]+$//' | sort -u)
# blkid 会显示 sr0经过上面的命令输出为 sr
# 因此要检测是否有效
for disk in $disks; do
if [ -b "/dev/$disk" ]; then
echo "$disk"
fi
done
}
get_xda() {
main_disk="$(grep -o 'extra\.main_disk=[^ ]*' /proc/cmdline | cut -d= -f2)"
# 防止 $main_disk 为空
if [ -z "$main_disk" ]; then
return 1
fi
for disk in $(get_all_disks); do
if fdisk -l "/dev/$disk" | grep -iq "$main_disk"; then
echo "$disk"
return
fi
done
# 如果没找到,返回假的值,防止意外地格式化全部盘
echo 'FAKE_DISK'
return 1
}
get_xda

View File

@ -44,33 +44,17 @@ for var in $(grep -o "\b$prefix\.[^ ]*" /proc/cmdline | xargs); do
eval "$(echo "$var" | sed -E "s/$prefix\.([^=]*)=(.*)/\1='\2'/")"
done
get_all_disks() {
lsblk -rn --nodeps -o NAME,TYPE | grep 'disk$' | awk '{print $1}'
}
get_xda() {
# 防止 $main_disk 为空
if [ -z "$main_disk" ]; then
return
fi
for disk in $(get_all_disks); do
# shellcheck disable=SC2154
if fdisk -l "/dev/$disk" | grep -iq "$main_disk"; then
echo "$disk"
break
fi
done
}
# centos7 证书链未更新,需要 --no-check-certificate
# 只使用主硬盘
include=/tmp/include-disk-only-use
echo "ignoredisk --only-use=$(get_xda)" >$include
xda=$(wget --no-check-certificate "$confhome/get-xda.sh" -O- | sh -s)
echo "ignoredisk --only-use=$xda" >$include
# 设置 tty
include=/tmp/include-bootloader
# shellcheck disable=SC2154
console_cmdline=$(wget "$confhome/ttys.sh" -O- | sh -s console=)
console_cmdline=$(wget --no-check-certificate "$confhome/ttys.sh" -O- | sh -s console=)
echo "bootloader --append=\"$console_cmdline\"" >$include
# 有 installer 分区,表示用了两步安装

View File

@ -1,24 +1,4 @@
#!/bin/bash
get_all_disks() {
lsblk -rn --nodeps -o NAME,TYPE | grep 'disk$' | awk '{print $1}'
}
get_xda() {
# 防止 $main_disk 为空
if [ -z "$main_disk" ]; then
return
fi
for disk in $(get_all_disks); do
# shellcheck disable=SC2154
if fdisk -l "/dev/$disk" | grep -iq "$main_disk"; then
echo "$disk"
break
fi
done
}
sed -i -E '/^\.{3}$/d' /autoinstall.yaml
echo 'storage:' >>/autoinstall.yaml
@ -28,12 +8,11 @@ cat <<EOF >>/autoinstall.yaml
size: 0
EOF
xda="$(get_xda)"
# 是用 size 寻找分区number 没什么用
# https://curtin.readthedocs.io/en/latest/topics/storage.html
size_os=$(lsblk -bn -o SIZE /dev/disk/by-label/os)
# shellcheck disable=SC2154
if parted "/dev/$xda" print | grep '^Partition Table' | grep gpt; then
# efi
if [ -e /dev/disk/by-label/efi ]; then

View File

@ -27,8 +27,9 @@ autoinstall:
done
# 生成分区信息
export main_disk
curl -L $confhome/ubuntu-storage-early.sh | bash -s
xda=$(curl -L "$confhome/get-xda.sh" | sh -s)
export xda
curl -L "$confhome/ubuntu-storage-early.sh" | sh -s
# 内核风味
# https://bugs.launchpad.net/subiquity/+bug/1989353