Compare commits

...

2 Commits

Author SHA1 Message Date
bin456789
8b60b7d2df
fnos: 修复了设置系统盘使用全部空间时安装失败 2025-03-04 00:34:50 +08:00
bin456789
70fcc01988
core: 统一处理允许 file 将 iso 识别成 raw 2025-03-04 00:34:49 +08:00
2 changed files with 48 additions and 13 deletions

View File

@ -339,7 +339,8 @@ test_url_real() {
real_type=$(file_enhanced $tmp_file) real_type=$(file_enhanced $tmp_file)
echo "File type: $real_type" echo "File type: $real_type"
for type in $expect_types; do # debian 9 ubuntu 16.04 可能会将 iso 识别成 raw
for type in $expect_types $([ "$expect_types" = iso ] && echo raw); do
if [[ ."$real_type" = *."$type" ]]; then if [[ ."$real_type" = *."$type" ]]; then
# 如果要设置变量 # 如果要设置变量
if [ -n "$var_to_eval" ]; then if [ -n "$var_to_eval" ]; then
@ -1258,7 +1259,7 @@ Continue?
sort -uV | tail -1 | grep .) sort -uV | tail -1 | grep .)
iso=$mirror/$filename iso=$mirror/$filename
# 在 ubuntu 20.04 上file 命令检测 ubuntu 22.04 iso 结果是 DOS/MBR boot sector # 在 ubuntu 20.04 上file 命令检测 ubuntu 22.04 iso 结果是 DOS/MBR boot sector
test_url $iso 'iso raw' test_url "$iso" iso
eval ${step}_iso=$iso eval ${step}_iso=$iso
# ks # ks
@ -1389,13 +1390,12 @@ Continue?
if [[ "$iso" = magnet:* ]]; then if [[ "$iso" = magnet:* ]]; then
: # 不测试磁力链接 : # 不测试磁力链接
else else
iso_filetype='iso raw'
iso_tested=false iso_tested=false
# 获取 massgrave.dev 直链 # 获取 massgrave.dev 直链
if grep -Eiq '\.massgrave\.dev/.*\.(iso|img)' <<<"$iso"; then if grep -Eiq '\.massgrave\.dev/.*\.(iso|img)' <<<"$iso"; then
# 如果已经是 iso 直链则跳过下面的 iso 测试 # 如果已经是 iso 直链则跳过下面的 iso 测试
if test_url_grace "$iso" "$iso_filetype"; then if test_url_grace "$iso" iso; then
iso_tested=true iso_tested=true
else else
msg="Could not find direct link for $iso" msg="Could not find direct link for $iso"
@ -1407,7 +1407,7 @@ Continue?
# 测试是否是 iso # 测试是否是 iso
if ! $iso_tested; then if ! $iso_tested; then
test_url "$iso" "$iso_filetype" test_url "$iso" iso
fi fi
# 判断 iso 架构是否兼容 # 判断 iso 架构是否兼容
@ -1502,8 +1502,7 @@ Continue with DD?
done done
iso=$(curl -L https://fnnas.com/ | grep -o 'https://[^"]*\.iso' | head -1) iso=$(curl -L https://fnnas.com/ | grep -o 'https://[^"]*\.iso' | head -1)
# debian 9 下 iso 会被识别为 raw test_url "$iso" iso
test_url "$iso" 'iso raw'
eval "${step}_iso='$iso'" eval "${step}_iso='$iso'"
} }

View File

@ -2224,7 +2224,7 @@ dd_raw_with_extract() {
fi fi
} }
get_dick_sector_count() { get_disk_sector_count() {
# cat /proc/partitions # cat /proc/partitions
blockdev --getsz "$1" blockdev --getsz "$1"
} }
@ -2233,6 +2233,10 @@ get_disk_size() {
blockdev --getsize64 "$1" blockdev --getsize64 "$1"
} }
get_disk_logic_sector_size() {
blockdev --getss "$1"
}
is_xda_gt_2t() { is_xda_gt_2t() {
disk_size=$(get_disk_size /dev/$xda) disk_size=$(get_disk_size /dev/$xda)
disk_2t=$((2 * 1024 * 1024 * 1024 * 1024)) disk_2t=$((2 * 1024 * 1024 * 1024 * 1024))
@ -2314,15 +2318,46 @@ create_part() {
# 因此直接用用户输入的分区大小 # 因此直接用用户输入的分区大小
# 1. 官方安装器对系统盘大小的定义包含引导分区大小 # 1. 官方安装器对系统盘大小的定义包含引导分区大小
# 2. 官方用的是 100M 而不是 100MiB # 2. 官方 efi 用的是 1MiB-100M但我们用 1MiB-101MiB
# 预期的系统分区大小,包括引导的 1M + 100M 的引导分区
expect_m=$((${fnos_part_size%[Gg]} * 1024))
sector_size=$(get_disk_logic_sector_size /dev/$xda)
total_sector_count=$(get_disk_sector_count /dev/$xda)
# 截止最后一个分区的总扇区数(也就是总硬盘扇区数 - 备份分区表扇区数)
if is_efi; then
total_sector_count_except_backup_gpt=$((total_sector_count - 33))
else
total_sector_count_except_backup_gpt=$total_sector_count
fi
# 向下取整 MiB
# gpt 最后 33 个扇区是备份分区表,不可用
# parted 会忽略最后不足 1MiB 的部分
max_can_use_m=$((total_sector_count_except_backup_gpt * sector_size / 1024 / 1024))
echo "expect_m: $expect_m"
echo "max_can_use_m: $max_can_use_m"
# 20G 的硬盘,即使用 msdos 分区表parted 也不接受 part end 为 20480MiB因此要用 100%
# The location 20480MiB is outside of the device /dev/vda.
# 但是 100% 分区后 end 就是 20480MiB
os_part_end=${expect_m}MiB
if [ "$expect_m" -ge "$max_can_use_m" ]; then
echo "Expect size is equal/greater than max size. Setting to 100%"
os_part_end=100%
fi
# 需关闭这几个特性,否则 grub 无法识别 # 需关闭这几个特性,否则 grub 无法识别
ext4_opts="-O ^metadata_csum_seed,^orphan_file" ext4_opts="-O ^metadata_csum_seed,^orphan_file"
if is_efi; then if is_efi; then
parted /dev/$xda -s -- \ parted /dev/$xda -s -- \
mklabel gpt \ mklabel gpt \
mkpart BOOT fat32 1MiB 100M \ mkpart BOOT fat32 1MiB 101MiB \
mkpart SYSTEM ext4 100M ${fnos_part_size}iB \ mkpart SYSTEM ext4 101MiB $os_part_end \
set 1 esp on set 1 esp on
update_part update_part
@ -2333,8 +2368,8 @@ create_part() {
# 官方安装器不支持 bios + >2t # 官方安装器不支持 bios + >2t
parted /dev/$xda -s -- \ parted /dev/$xda -s -- \
mklabel msdos \ mklabel msdos \
mkpart primary 1MiB 100M \ mkpart primary 1MiB 101MiB \
mkpart primary 100M ${fnos_part_size}iB \ mkpart primary 101MiB $os_part_end \
set 2 boot on set 2 boot on
update_part update_part
@ -3892,6 +3927,7 @@ install_fnos() {
rm -rf $initrd_dir rm -rf $initrd_dir
# 复制 trimfs.tgz 并删除 ISO 以获得更多空间 # 复制 trimfs.tgz 并删除 ISO 以获得更多空间
echo "moving trimfs.tgz..."
cp /iso/trimfs.tgz /os/installer cp /iso/trimfs.tgz /os/installer
umount /iso umount /iso
rm /os/installer/fnos.iso rm /os/installer/fnos.iso