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