From 31f829d8d62de33c1b97563d3f5f855ea88cc84f Mon Sep 17 00:00:00 2001 From: bin456789 Date: Fri, 18 Oct 2024 23:58:03 +0800 Subject: [PATCH] =?UTF-8?q?core:=20=E5=AE=8C=E5=96=84=E6=89=A9=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reinstall.sh | 2 +- trans.sh | 185 +++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 151 insertions(+), 36 deletions(-) diff --git a/reinstall.sh b/reinstall.sh index c7f2263..433a827 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -2813,7 +2813,7 @@ EOF # hack 3 # 修改 trans.sh # 1. 直接调用 create_ifupdown_config - insert_into_file $initrd_dir/trans.sh after ': main' <&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 + # 打印分区表,并自动修复备份分区表 + fix_gpt_backup_partition_table_by_parted - 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 - fi + disk_size=$(get_disk_size /dev/$xda) + disk_end=$((disk_size - 1)) + + # 不能漏掉最后的 _ ,否则第6部分都划到给 last_part_fs + IFS=: read -r last_part_num _ last_part_end _ last_part_fs _ \ + < <(parted -msf /dev/$xda 'unit b print' | tail -1) + last_part_end=$(echo $last_part_end | sed 's/B//') + + # 大于 100M 才扩容 + if [ $((disk_end - last_part_end)) -ge $((100 * 1024 * 1024)) ]; then + printf "yes" | parted /dev/$xda resizepart $last_part_num 100% ---pretend-input-tty + update_part + + mkdir -p /os + + # lvm ? + # 用 cloud-utils-growpart? + case "$last_part_fs" in + ext4) + # debian ci + apk add e2fsprogs-extra + e2fsck -p -f /dev/$xda*$last_part_num + resize2fs /dev/$xda*$last_part_num + apk del e2fsprogs-extra + ;; + xfs) + # opensuse ci + apk add xfsprogs-extra + mount /dev/$xda*$last_part_num /os + xfs_growfs /dev/$xda*$last_part_num + umount /os + apk del xfsprogs-extra + ;; + btrfs) + # fedora ci + apk add btrfs-progs + mount /dev/$xda*$last_part_num /os + btrfs filesystem resize max /os + umount /os + apk del btrfs-progs + ;; + ntfs) + # windows dd + apk add ntfs-3g-progs + echo y | ntfsresize /dev/$xda*$last_part_num + ntfsfix -d /dev/$xda*$last_part_num + apk del ntfs-3g-progs + ;; + esac + update_part + parted /dev/$xda -s print fi } @@ -4624,6 +4734,11 @@ trans() { case "$img_type" in raw) dd_gzip_xz_raw + if false; then + # linux 扩容后无法轻易缩小,例如 xfs + # windows 扩容在 windows 下完成 + resize_after_install_cloud_image + fi modify_os_on_disk windows ;; qemu) # dd qemu 不可能到这里,因为上面已处理