From 67a2bee31cfef12939dda63336421b283c46c1de Mon Sep 17 00:00:00 2001 From: bin456789 Date: Sun, 8 Oct 2023 21:46:45 +0800 Subject: [PATCH] =?UTF-8?q?core:=20=E4=BF=AE=E6=94=B9=E4=B8=BB=E7=A1=AC?= =?UTF-8?q?=E7=9B=98=E6=9F=A5=E6=89=BE=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 排除只读盘,vda 放前面 --- redhat.cfg | 19 ++++++++++++++++++- trans.sh | 17 +++++++++++++++-- ubuntu-storage-early.sh | 18 +++++++++++++++--- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/redhat.cfg b/redhat.cfg index 7df818e..8aba238 100644 --- a/redhat.cfg +++ b/redhat.cfg @@ -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和vda,vda是主硬盘,另一个盘是只读 + 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 }' $include + # 设置 tty include=/tmp/include-bootloader console_cmdline=$(wget $confhome/ttys.sh -O- | sh -s console=) diff --git a/trans.sh b/trans.sh index 906dea1..1f13318 100644 --- a/trans.sh +++ b/trans.sh @@ -155,6 +155,19 @@ get_ttys() { wget $confhome/ttys.sh -O- | sh -s $prefix } +get_xda() { + # 排除只读盘,vda 放前面 + # 有的机器有sda和vda,vda是主硬盘,另一个盘是只读 + 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 </reinstall.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 diff --git a/ubuntu-storage-early.sh b/ubuntu-storage-early.sh index 6618a88..58fd714 100644 --- a/ubuntu-storage-early.sh +++ b/ubuntu-storage-early.sh @@ -1,4 +1,18 @@ #!/bin/bash + +get_xda() { + # 排除只读盘,vda 放前面 + # 有的机器有sda和vda,vda是主硬盘,另一个盘是只读 + 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 <>/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)