core: 放置 ci 文件时,准确寻找系统分区

This commit is contained in:
bin456789 2023-08-01 21:39:53 +08:00
parent 49a0994044
commit 84f9c30489
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B

View File

@ -414,15 +414,25 @@ mount_pseudo_fs() {
download_cloud_init_config() { download_cloud_init_config() {
if ! mount | grep -w 'on /os type'; then if ! mount | grep -w 'on /os type'; then
# 找到系统分区,也就是最大的分区
apk add lsblk apk add lsblk
mkdir -p /os mkdir -p /os
os_part=$(lsblk /dev/$xda --sort SIZE -o NAME | sed '$d' | tail -1) # 按分区容量大到小,依次寻找系统分区
mount /dev/$os_part /os for part in $(lsblk /dev/$xda --sort SIZE -no NAME | sed '$d' | tac); do
# btrfs挂载的是默认子卷如果没有默认子卷挂载的是根目录
# fedora 云镜像没有默认子卷且系统在root子卷中
if mount /dev/$part /os; then
if etc_dir=$({ ls -d /os/etc || ls -d /os/*/etc; } 2>/dev/null); then
break
fi
umount /os
fi
done
fi
if [ -z "$etc_dir" ]; then
error_and_exit "can't find os partition"
fi fi
# btrfs 系统可能不在根目录,例如 fedora 系统在 root 子卷中
etc_dir=$(ls -d /os/etc || ls -d /os/*/etc)
ci_file=$etc_dir/cloud/cloud.cfg.d/99_nocloud.cfg ci_file=$etc_dir/cloud/cloud.cfg.d/99_nocloud.cfg
# shellcheck disable=SC2154 # shellcheck disable=SC2154