mirror of
https://github.com/bin456789/reinstall.git
synced 2025-01-18 20:39:14 +08:00
core: 使用 get-xda.sh 寻找主硬盘
This commit is contained in:
parent
5150feddc6
commit
5d3227fe64
@ -71,9 +71,12 @@ d-i preseed/early_command string \
|
|||||||
debconf-set mirror/http/hostname "$hostname"
|
debconf-set mirror/http/hostname "$hostname"
|
||||||
|
|
||||||
d-i partman/early_command string \
|
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)"; \
|
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=); \
|
ttys=$(wget $confhome/ttys.sh -O- | sh -s console=); \
|
||||||
debconf-set debian-installer/add-kernel-opts "$ttys"; \
|
debconf-set debian-installer/add-kernel-opts "$ttys"; \
|
||||||
|
|
||||||
|
37
get-xda.sh
Normal file
37
get-xda.sh
Normal 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
|
24
redhat.cfg
24
redhat.cfg
@ -44,33 +44,17 @@ for var in $(grep -o "\b$prefix\.[^ ]*" /proc/cmdline | xargs); do
|
|||||||
eval "$(echo "$var" | sed -E "s/$prefix\.([^=]*)=(.*)/\1='\2'/")"
|
eval "$(echo "$var" | sed -E "s/$prefix\.([^=]*)=(.*)/\1='\2'/")"
|
||||||
done
|
done
|
||||||
|
|
||||||
get_all_disks() {
|
# centos7 证书链未更新,需要 --no-check-certificate
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
# 只使用主硬盘
|
# 只使用主硬盘
|
||||||
include=/tmp/include-disk-only-use
|
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
|
# 设置 tty
|
||||||
include=/tmp/include-bootloader
|
include=/tmp/include-bootloader
|
||||||
# shellcheck disable=SC2154
|
# 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
|
echo "bootloader --append=\"$console_cmdline\"" >$include
|
||||||
|
|
||||||
# 有 installer 分区,表示用了两步安装
|
# 有 installer 分区,表示用了两步安装
|
||||||
|
@ -1,24 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/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
|
sed -i -E '/^\.{3}$/d' /autoinstall.yaml
|
||||||
echo 'storage:' >>/autoinstall.yaml
|
echo 'storage:' >>/autoinstall.yaml
|
||||||
|
|
||||||
@ -28,12 +8,11 @@ cat <<EOF >>/autoinstall.yaml
|
|||||||
size: 0
|
size: 0
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
xda="$(get_xda)"
|
|
||||||
|
|
||||||
# 是用 size 寻找分区,number 没什么用
|
# 是用 size 寻找分区,number 没什么用
|
||||||
# https://curtin.readthedocs.io/en/latest/topics/storage.html
|
# https://curtin.readthedocs.io/en/latest/topics/storage.html
|
||||||
size_os=$(lsblk -bn -o SIZE /dev/disk/by-label/os)
|
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
|
if parted "/dev/$xda" print | grep '^Partition Table' | grep gpt; then
|
||||||
# efi
|
# efi
|
||||||
if [ -e /dev/disk/by-label/efi ]; then
|
if [ -e /dev/disk/by-label/efi ]; then
|
||||||
|
@ -27,8 +27,9 @@ autoinstall:
|
|||||||
done
|
done
|
||||||
|
|
||||||
# 生成分区信息
|
# 生成分区信息
|
||||||
export main_disk
|
xda=$(curl -L "$confhome/get-xda.sh" | sh -s)
|
||||||
curl -L $confhome/ubuntu-storage-early.sh | bash -s
|
export xda
|
||||||
|
curl -L "$confhome/ubuntu-storage-early.sh" | sh -s
|
||||||
|
|
||||||
# 内核风味
|
# 内核风味
|
||||||
# https://bugs.launchpad.net/subiquity/+bug/1989353
|
# https://bugs.launchpad.net/subiquity/+bug/1989353
|
||||||
|
Loading…
x
Reference in New Issue
Block a user