mirror of
https://github.com/bin456789/reinstall.git
synced 2025-01-18 20:39:14 +08:00
chore: lint
This commit is contained in:
parent
4663800196
commit
4fd0011bd7
24
resize.sh
24
resize.sh
@ -26,36 +26,36 @@ xda=$(lsblk -r --inverse "$root_drive" | grep -w disk | awk '{print $1}')
|
||||
# 删除 installer 分区
|
||||
installer_num=$(readlink -f /dev/disk/by-label/installer | grep -o '[0-9]*$')
|
||||
if [ -n "$installer_num" ]; then
|
||||
# 要添加 LC_NUMERIC 或者将%转义成\%才能在cron里正确运行
|
||||
# locale -a 不一定有"en_US.UTF-8",但肯定有"C.UTF-8"
|
||||
LC_NUMERIC="C.UTF-8"
|
||||
printf "d\n%s\nw" "$installer_num" | fdisk /dev/$xda
|
||||
update_part /dev/$xda
|
||||
# 要添加 LC_NUMERIC 或者将%转义成\%才能在cron里正确运行
|
||||
# locale -a 不一定有"en_US.UTF-8",但肯定有"C.UTF-8"
|
||||
LC_NUMERIC="C.UTF-8"
|
||||
printf "d\n%s\nw" "$installer_num" | fdisk "/dev/$xda"
|
||||
update_part "/dev/$xda"
|
||||
fi
|
||||
|
||||
# 找出现在的最后一个分区,也就是系统分区
|
||||
# el7 的 lsblk 没有 --sort,所以用其他方法
|
||||
# shellcheck disable=2012
|
||||
part_num=$(ls -1v /dev/$xda* | tail -1 | grep -o '[0-9]*$')
|
||||
part_fstype=$(lsblk -no FSTYPE /dev/$xda*$part_num)
|
||||
part_num=$(ls -1v "/dev/$xda"* | tail -1 | grep -o '[0-9]*$')
|
||||
part_fstype=$(lsblk -no FSTYPE "/dev/$xda"*"$part_num")
|
||||
|
||||
# 扩容分区
|
||||
# ubuntu 和 el7 用 growpart,其他用 parted
|
||||
# el7 不能用parted在线扩容,而fdisk扩容会改变 PARTUUID,所以用 growpart
|
||||
if grep -E -i 'centos:7|ubuntu' /etc/os-release; then
|
||||
growpart /dev/$xda $part_num
|
||||
growpart "/dev/$xda" "$part_num"
|
||||
else
|
||||
printf 'yes\n100%%' | parted /dev/$xda resizepart $part_num ---pretend-input-tty
|
||||
printf 'yes\n100%%' | parted "/dev/$xda" resizepart "$part_num" ---pretend-input-tty
|
||||
fi
|
||||
update_part /dev/$xda
|
||||
update_part "/dev/$xda"
|
||||
|
||||
# 扩容最后一个分区的文件系统
|
||||
case $part_fstype in
|
||||
xfs) xfs_growfs / ;;
|
||||
ext*) resize2fs /dev/$xda*$part_num ;;
|
||||
ext*) resize2fs "/dev/$xda"*"$part_num" ;;
|
||||
btrfs) btrfs filesystem resize max / ;;
|
||||
esac
|
||||
update_part /dev/$xda
|
||||
update_part "/dev/$xda"
|
||||
|
||||
# 删除脚本自身
|
||||
rm -f /resize.sh /etc/cron.d/resize
|
||||
|
@ -1,16 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
get_xda() {
|
||||
# 排除只读盘,vda 放前面
|
||||
# 有的机器有sda和vda,vda是主硬盘,另一个盘是只读
|
||||
for _xda in vda xda sda hda xvda nvme0n1; do
|
||||
if [ -e "/sys/class/block/$_xda/ro" ] &&
|
||||
[ "$(cat /sys/class/block/$_xda/ro)" = 0 ]; then
|
||||
echo $_xda
|
||||
return
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
# 排除只读盘,vda 放前面
|
||||
# 有的机器有sda和vda,vda是主硬盘,另一个盘是只读
|
||||
for _xda in vda xda sda hda xvda nvme0n1; do
|
||||
if [ -e "/sys/class/block/$_xda/ro" ] &&
|
||||
[ "$(cat /sys/class/block/$_xda/ro)" = 0 ]; then
|
||||
echo $_xda
|
||||
return
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
sed -i -E '/^\.{3}$/d' /autoinstall.yaml
|
||||
@ -27,11 +27,11 @@ xda=$(get_xda)
|
||||
# https://curtin.readthedocs.io/en/latest/topics/storage.html
|
||||
size_os=$(lsblk -bn -o SIZE /dev/disk/by-label/os)
|
||||
|
||||
if parted /dev/$xda print | grep '^Partition Table' | grep gpt; then
|
||||
# efi
|
||||
if [ -e /dev/disk/by-label/efi ]; then
|
||||
size_efi=$(lsblk -bn -o SIZE /dev/disk/by-label/efi)
|
||||
cat <<EOF >>/autoinstall.yaml
|
||||
if parted "/dev/$xda" print | grep '^Partition Table' | grep gpt; then
|
||||
# efi
|
||||
if [ -e /dev/disk/by-label/efi ]; then
|
||||
size_efi=$(lsblk -bn -o SIZE /dev/disk/by-label/efi)
|
||||
cat <<EOF >>/autoinstall.yaml
|
||||
config:
|
||||
# disk
|
||||
- ptable: gpt
|
||||
@ -72,10 +72,10 @@ if parted /dev/$xda print | grep '^Partition Table' | grep gpt; then
|
||||
type: mount
|
||||
id: mount-efi
|
||||
EOF
|
||||
else
|
||||
# bios > 2t
|
||||
size_biosboot=$(parted /dev/$xda unit b print | grep bios_grub | awk '{print $4}' | sed 's/B$//')
|
||||
cat <<EOF >>/autoinstall.yaml
|
||||
else
|
||||
# bios > 2t
|
||||
size_biosboot=$(parted "/dev/$xda" unit b print | grep bios_grub | awk '{print $4}' | sed 's/B$//')
|
||||
cat <<EOF >>/autoinstall.yaml
|
||||
config:
|
||||
# disk
|
||||
- ptable: gpt
|
||||
@ -108,10 +108,10 @@ EOF
|
||||
type: mount
|
||||
id: mount-os
|
||||
EOF
|
||||
fi
|
||||
fi
|
||||
else
|
||||
# bios
|
||||
cat <<EOF >>/autoinstall.yaml
|
||||
# bios
|
||||
cat <<EOF >>/autoinstall.yaml
|
||||
config:
|
||||
# disk
|
||||
- ptable: msdos
|
||||
|
Loading…
x
Reference in New Issue
Block a user