From b9288dae33b259fdd4cb1d328f7b4459932c381d Mon Sep 17 00:00:00 2001 From: bin456789 Date: Fri, 1 Mar 2024 22:06:33 +0800 Subject: [PATCH] =?UTF-8?q?core:=20=E4=B8=8D=E5=A4=8D=E5=88=B6=20vmlinuz?= =?UTF-8?q?=20/=20initramfs=20=E5=88=B0=E6=A0=B9=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reinstall.sh | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/reinstall.sh b/reinstall.sh index 5a4d86d..d0ba228 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -99,7 +99,7 @@ is_use_dd() { } is_os_in_btrfs() { - mount | grep -w 'on / type btrfs' + mount | grep -qw 'on / type btrfs' } is_os_in_subvol() { @@ -873,6 +873,10 @@ del_cr() { sed 's/\r//g' } +del_blank_lines() { + sed '/^[[:space:]]*$/d' +} + # 记录主硬盘 find_main_disk() { if is_in_windows; then @@ -1674,7 +1678,7 @@ if [ "$nextos_distro" = alpine ]; then fi # 将内核/netboot.xyz.lkrn 放到正确的位置 -if is_use_grub; then +if false && is_use_grub; then if is_in_windows; then cp -f /reinstall-vmlinuz /cygdrive/$c/ is_have_initrd && cp -f /reinstall-initrd /cygdrive/$c/ @@ -1771,25 +1775,47 @@ if is_use_grub; then target_cfg=$grub_cfg fi + # 找到 /reinstall-vmlinuz /reinstall-initrd 的绝对路径 + if is_in_windows; then + # dir=/cygwin/ + dir=$(cygpath -m / | cut -d: -f2-)/ + else + # 获取当前系统根目录在 btrfs 中的绝对路径 + if is_os_in_btrfs; then + # btrfs subvolume show / + # 输出可能是 / 或 root 或 @/.snapshots/1/snapshot + dir=$(btrfs subvolume show / | head -1) + if ! [ "$dir" = / ]; then + dir="/$dir/" + fi + else + dir=/ + fi + fi + + vmlinuz=${dir}reinstall-vmlinuz + initrd=${dir}reinstall-initrd + # 生成 linux initrd 命令 if is_netboot_xyz; then - linux_cmd="linux16 /reinstall-vmlinuz" + linux_cmd="linux16 $vmlinuz" else find_main_disk build_cmdline - linux_cmd="linux$efi /reinstall-vmlinuz $cmdline" - initrd_cmd="initrd$efi /reinstall-initrd" + linux_cmd="linux$efi $vmlinuz $cmdline" + initrd_cmd="initrd$efi $initrd" fi # 生成 grub 配置 # 实测 centos 7 lvm 要手动加载 lvm 模块 echo $target_cfg - cat <