grub2引导iso安装Fedora-i3-37-Live

GRUB2是一种加载Linux内核的引导程序,可以通过它添加Live CD启动项用于系统出问题后进行rescue,也可以通过它引导iso文件进行操作系统安装。

下载iso

下载所需的iso文件,并将其copy到/boot下。为方便管理新建/boot/iso目录用于存放live cd iso:

mkdir /boot/iso
rsync -avP ./Fedora-i3-Live-x86_64-37-1.7.iso /boot/iso/

live iso文件大小约1.4GB, 需要/boot分区足够大。

增加grub2启动项⚓

update-grub2或grub2-mkconfig在生成配置文件的时候,默认会读取/etc/grub.d/目录下的配置

sudo ls -l /etc/grub.d 
-rwxr-xr-x 1 root root 10627  4月 16  2022 00_header
-rwxr-xr-x 1 root root  6260  4月 16  2022 05_debian_theme
-rwxr-xr-x 1 root root 18683  4月 16  2022 10_linux
-rwxr-xr-x 1 root root 43031  4月 16  2022 10_linux_zfs
-rwxr-xr-x 1 root root 14180  4月 16  2022 20_linux_xen
-rwxr-xr-x 1 root root 13369  4月 16  2022 30_os-prober
-rwxr-xr-x 1 root root  1372  4月 16  2022 30_uefi-firmware
-rwxr-xr-x 1 root root   700  2月 19  2022 35_fwupd
-rwxr-xr-x 1 root root   773  3月 15 16:18 40_custom
-rwxr-xr-x 1 root root   215  4月 16  2022 41_custom
-rw-r--r-- 1 root root   483  4月 16  2022 README

可以在40_custom添加自定义的iso启动项,这个文件默认内容如下:

#!/usr/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.

千万注意不要删除exec tail -n +3 $0这一行及以上的内容。
tail -n +3 $0 的意思是取本文件第3行(包括)及之后的内容, 也就读取我们后续添加的内容。

在/etc/grub.d/40_custom文件添加如下内容:

sudo vim /etc/grub.d/40_custom
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.

menuentry "Fedora i3 37 Live" {
        # remove tpm mod to avoid out of memory err
        rmmod tpm
        insmod loopback
        set isofile="/boot/iso/Fedora-i3-Live-x86_64-37-1.7.iso"

        echo "Setting up loopback"
        loopback loop "${isofile}"

        isolabel="Fedora-i3-Live-37-1-7"
        # fedora grub2 no probe command
        #probe -l loop --set=isolabel
        echo "ISO Label is ${isolabel}"

        echo "Booting...."
        linux (loop)/images/pxeboot/vmlinuz iso-scan/filename="${isofile}" root=live:CDLABEL=$isolabel rootfstype=auto ro rd.live.image noquiet rd.luks=0 rd.md=0 rd.dm=0
        initrd (loop)/images/pxeboot/initrd.img
}

注1:如果碰到grub2没有modprobe命令的情况,需要手动指定isolabel,可以用iso-info(由libcdio包提供)来读取iso文件的isolabel;
注2:在GRUB2中,linux16和linux是两种不同的命令。linux16指的是启动16位内核。而linux则指的是启动32位或64位内核。在大多数情况下,您应该使用linux而非linux16。因为现代的Linux内核基本上都是64位的。

生效grub2配置

sudo update-grub2

然后重启系统选择新增的grub引导项即可进入操作系统安装界面;

参考文章

如何从 grub2 启动 Fedora32 Live CD iso
grub2 设置启动引导 Fedora 21 Workstation Live iso
grub2各种手动命令引导教程
Grub2引导LinuxISO进行系统安装及救援
无法访问此网站
grub2引导安装linux mint,在Ubuntu 18.04中配置GRUB2引导加载程序环境
Linux 系统设置 : insmod 命令详解

posted @ 2023-03-15 22:07  露宝的大先生  阅读(299)  评论(0编辑  收藏  举报