mirror of
https://github.com/bin456789/reinstall.git
synced 2025-01-18 20:39:14 +08:00
38 lines
908 B
Bash
38 lines
908 B
Bash
#!/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
|