core: 修改主硬盘查找逻辑

排除只读盘,vda 放前面
This commit is contained in:
bin456789 2023-10-08 21:46:45 +08:00
parent 455c3b33f9
commit 67a2bee31c
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B
3 changed files with 48 additions and 6 deletions

View File

@ -9,7 +9,7 @@ reboot
%include /tmp/include-url-command
# 分区
ignoredisk --only-use="sda|hda|xda|vda|xvda|nvme0n1"
%include /tmp/include-disk-only-use
%include /tmp/include-bootloader
clearpart --all --initlabel
reqpart # 如果需要,自动创建 efi 或 biosboot 分区
@ -34,6 +34,19 @@ selinux --disabled
##############################################
%pre
get_xda() {
# 排除只读盘vda 放前面
# 有的机器有sda和vdavda是主硬盘另一个盘是只读
for _xda in vda xda sda hda xvda nvme0n1; do
if [ -e "/sys/class/block/$_xda/ro" ] &&
[ "$(cat /sys/class/block/$_xda/ro)" = 0 ]; then
echo $_xda
return
fi
done
return 1
}
distro=$(awk -F: '{ print $3 }' </etc/system-release-cpe)
releasever=$(awk -F: '{ print $5 }' </etc/system-release-cpe)
@ -44,6 +57,10 @@ for var in $(grep -o "\b$prefix\.[^ ]*" /proc/cmdline | xargs); do
eval "$(echo $var | sed -E "s/$prefix\.([^=]*)=(.*)/\1='\2'/")"
done
# 只使用主硬盘
include=/tmp/include-disk-only-use
echo "ignoredisk --only-use=$(get_xda)" >$include
# 设置 tty
include=/tmp/include-bootloader
console_cmdline=$(wget $confhome/ttys.sh -O- | sh -s console=)

View File

@ -155,6 +155,19 @@ get_ttys() {
wget $confhome/ttys.sh -O- | sh -s $prefix
}
get_xda() {
# 排除只读盘vda 放前面
# 有的机器有sda和vdavda是主硬盘另一个盘是只读
for _xda in vda xda sda hda xvda nvme0n1; do
if [ -e "/sys/class/block/$_xda/ro" ] &&
[ "$(cat /sys/class/block/$_xda/ro)" = 0 ]; then
echo $_xda
return
fi
done
return 1
}
setup_tty_and_log() {
cat <<EOF >/reinstall.html
<!DOCTYPE html>
@ -1619,8 +1632,8 @@ clear_previous
add_community_repo
# 找到主硬盘
# shellcheck disable=SC2010
xda=$(ls /dev/ | grep -Ex 'sda|hda|xda|vda|xvda|nvme0n1')
xda=$(get_xda)
if [ "$distro" != "alpine" ]; then
setup_nginx_if_enough_ram
fi

View File

@ -1,4 +1,18 @@
#!/bin/bash
get_xda() {
# 排除只读盘vda 放前面
# 有的机器有sda和vdavda是主硬盘另一个盘是只读
for _xda in vda xda sda hda xvda nvme0n1; do
if [ -e "/sys/class/block/$_xda/ro" ] &&
[ "$(cat /sys/class/block/$_xda/ro)" = 0 ]; then
echo $_xda
return
fi
done
return 1
}
sed -i -E '/^\.{3}$/d' /autoinstall.yaml
echo 'storage:' >>/autoinstall.yaml
@ -8,9 +22,7 @@ cat <<EOF >>/autoinstall.yaml
size: 0
EOF
# xda=$(lsblk -dn -o NAME | grep -E 'nvme0n1|.da')
# shellcheck disable=SC2010
xda=$(ls /dev/ | grep -Ex 'sda|hda|xda|vda|xvda|nvme0n1')
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)