core: 修复某些机器上分区不刷新

This commit is contained in:
bin456789 2024-08-23 00:15:15 +08:00
parent cc7d3a6b45
commit 8e1e06b26a
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B

View File

@ -156,28 +156,26 @@ download() {
update_part() {
sleep 1
sync
# 玄学
for i in $(seq 3); do
sync
# partprobe
if is_have_cmd partprobe; then
partprobe /dev/$xda 2>/dev/null
fi
# partx
# https://access.redhat.com/solutions/199573
if is_have_cmd partx; then
partx -u $1
fi
# partx
# https://access.redhat.com/solutions/199573
if is_have_cmd partx; then
partx -u /dev/$xda
fi
if rc-service --exists udev && rc-service -q udev status; then
# udev
udevadm trigger
udevadm settle
else
# busybox mdev
# -f 好像没用
mdev -sf 2>/dev/null
fi
done
# mdev
if rc-service --exists mdev && rc-service -q mdev status; then
# mdev 不会删除 /dev/disk/ 的旧分区,因此手动删除
rm -rf /dev/disk/*
mdev -sf 2>/dev/null
rc-service mdev restart
fi
}
is_efi() {
@ -235,14 +233,6 @@ setup_lighttpd() {
rc-service lighttpd start
}
setup_udev_util_linux() {
# mdev 不会删除 /sys/block/by-label 的旧分区名,所以用 udev
# util-linux 包含 lsblk
# util-linux 可自动探测 mount 格式
apk add udev util-linux
rc-service udev start
}
get_ttys() {
prefix=$1
# shellcheck disable=SC2154
@ -1719,7 +1709,7 @@ create_part() {
set 1 boot on \
set 2 msftres on \
set 3 msftdata on
update_part /dev/$xda
update_part
mkfs.fat -n efi /dev/$xda*1 #1 efi
echo #2 msr
@ -1733,7 +1723,7 @@ create_part() {
mkpart primary ntfs 1MiB -${part_size} \
mkpart primary ntfs -${part_size} ${max_usable_size} \
set 1 boot on
update_part /dev/$xda
update_part
mkfs.ext4 -E nodiscard -F -L os /dev/$xda*1 #1 os
mkfs.ntfs -f -F -L installer /dev/$xda*2 #2 installer
@ -1753,7 +1743,7 @@ create_part() {
mkpart '" "' $fs 101MiB -$installer_part_size \
mkpart '" "' ext4 -$installer_part_size 100% \
set 1 esp on
update_part /dev/$xda
update_part
mkfs.fat -n efi /dev/$xda*1 #1 efi
echo #2 os 用目标系统的格式化工具
@ -1765,7 +1755,7 @@ create_part() {
mkpart '" "' $fs 2MiB -$installer_part_size \
mkpart '" "' ext4 -$installer_part_size 100% \
set 1 bios_grub on
update_part /dev/$xda
update_part
echo #1 bios_boot
echo #2 os 用目标系统的格式化工具
@ -1778,7 +1768,7 @@ create_part() {
mklabel gpt \
mkpart '" "' ext4 1MiB -$installer_part_size \
mkpart '" "' ext4 -$installer_part_size 100%
update_part /dev/$xda
update_part
mkfs.ext4 -E nodiscard -F -L os /dev/$xda*1 #1 os
mkfs.ext4 -E nodiscard -F -L installer /dev/$xda*2 #2 installer
@ -1791,7 +1781,7 @@ create_part() {
mkpart '" "' fat32 1MiB 101MiB \
mkpart '" "' ext4 101MiB 100% \
set 1 boot on
update_part /dev/$xda
update_part
mkfs.fat /dev/$xda*1 #1 efi
mkfs.ext4 -E nodiscard -F /dev/$xda*2 #2 os
@ -1802,7 +1792,7 @@ create_part() {
mkpart '" "' ext4 1MiB 2MiB \
mkpart '" "' ext4 2MiB 100% \
set 1 bios_grub on
update_part /dev/$xda
update_part
echo #1 bios_boot
mkfs.ext4 -E nodiscard -F /dev/$xda*2 #2 os
@ -1812,7 +1802,7 @@ create_part() {
mklabel msdos \
mkpart primary ext4 1MiB 100% \
set 1 boot on
update_part /dev/$xda
update_part
mkfs.ext4 -E nodiscard -F /dev/$xda*1 #1 os
fi
@ -1830,7 +1820,7 @@ create_part() {
mkpart '" "' ext4 1025MiB -2GiB \
mkpart '" "' ext4 -2GiB 100% \
set 1 boot on
update_part /dev/$xda
update_part
mkfs.fat -n efi /dev/$xda*1 #1 efi
mkfs.ext4 -E nodiscard -F -L os /dev/$xda*2 #2 os
@ -1843,7 +1833,7 @@ create_part() {
mkpart '" "' ext4 2MiB -2GiB \
mkpart '" "' ext4 -2GiB 100% \
set 1 bios_grub on
update_part /dev/$xda
update_part
echo #1 bios_boot
mkfs.ext4 -E nodiscard -F -L os /dev/$xda*2 #2 os
@ -1855,12 +1845,12 @@ create_part() {
mkpart primary ext4 1MiB -2GiB \
mkpart primary ext4 -2GiB 100% \
set 1 boot on
update_part /dev/$xda
update_part
mkfs.ext4 -E nodiscard -F -L os /dev/$xda*1 #1 os
mkfs.fat -n installer /dev/$xda*2 #2 installer
fi
update_part /dev/$xda
update_part
# centos 7 无法加载alpine格式化的ext4
# 要关闭这个属性
@ -1871,7 +1861,7 @@ create_part() {
fi
fi
update_part /dev/$xda
update_part
# alpine 删除分区工具,防止 256M 小机爆内存
# setup-disk /dev/sda 会保留格式化工具,我们也保留
@ -2357,7 +2347,7 @@ EOF
modify_os_on_disk() {
only_process=$1
update_part /dev/$xda
update_part
# dd linux 的时候不用修改硬盘内容
if [ "$distro" = "dd" ] && ! lsblk -f /dev/$xda | grep ntfs; then
@ -2401,9 +2391,13 @@ modify_os_on_disk() {
get_need_swap_size() {
need_ram=$1
phy_ram=$(get_approximate_ram_size)
echo $((need_ram - phy_ram))
if [ $need_ram -gt $phy_ram ]; then
echo $((need_ram - phy_ram))
else
echo 0
fi
}
create_swap_if_ram_less_than() {
@ -2745,7 +2739,7 @@ install_qcow_by_copy() {
umount /os/boot/efi/
apk add mtools
mlabel -N "$(echo $efi_part_uuid | sed 's/-//')" -i /dev/$xda*1 ::$efi_part_label
update_part /dev/$xda
update_part
mount -o $efi_mount_opts /dev/$xda*1 /os/boot/efi/
fi
@ -3135,7 +3129,7 @@ dd_qcow() {
# 将前1M从内存 dd 到硬盘
umount /installer/
dd if=/first-1M of=/dev/$xda
update_part /dev/$xda
update_part
}
@ -3152,14 +3146,14 @@ resize_after_install_cloud_image() {
if fix_partition_table_by_parted 2>&1 | grep -q 'Fixing'; then
system_part_num=$(parted /dev/$xda -m print | tail -1 | cut -d: -f1)
printf "yes" | parted /dev/$xda resizepart $system_part_num 100% ---pretend-input-tty
update_part /dev/$xda
update_part
if [ "$distro" = gentoo ]; then
apk add e2fsprogs-extra
e2fsck -p -f /dev/$xda*$system_part_num
resize2fs /dev/$xda*$system_part_num
fi
update_part /dev/$xda
update_part
fi
fi
}
@ -4023,7 +4017,9 @@ trans() {
if [ "$distro" != "alpine" ]; then
setup_nginx_if_enough_ram
setup_udev_util_linux
# util-linux 包含 lsblk
# util-linux 可自动探测 mount 格式
apk add util-linux
fi
# dd qemu 切换成云镜像模式,暂时没用到