

如何从 grub2 启动 Ubuntu Live CD iso
source link: https://ttys3.dev/post/how-to-boot-ubuntu-live-cd-iso-from-grub2/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

December 27, 2020
上次写了
《如何从 grub2 启动 Fedora32 Live CD iso》 , 这次顺便把 Ubuntu
的也补一下吧。
公司开发环境为了大家统一,全部采用的 Ubuntu.
这年头也很少随身带U盘了,因此,只靠硬盘, 自己能求自己,还是能在关键时候有用的。
下载live cd iso并校验⚓
curl -LZO https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/groovy/ubuntu-20.10-desktop-amd64.iso
curl -LO https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/groovy/SHA256SUMS
curl -LO https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/groovy/SHA256SUMS.gpg
校验 可 参考官方文档 https://ubuntu.com/tutorials/how-to-verify-ubuntu#4-retrieve-the-correct-signature-key
gpg --keyid-format long --verify SHA256SUMS.gpg SHA256SUMS
sha256sum -c SHA256SUMS
增加grub2启动项⚓
先准备下文件,由于Ubuntu默认划分的 /boot
分区较小,因此不能放下live cd iso.
直接放到 /
吧。 准备下目录: sudo mkdir /opt/iso
, 然后把 iso 文件 copy 到这个目录。
注意,这里的/
分区我使用的是LVM, 因此,我们要使用 sudo blkid
找出 /
所在的 LV 的 UUID.
❯ sudo blkid
/dev/mapper/vgubuntu-swap_1: UUID="f63131c3-9d02-4813-9db9-d85571f09084" TYPE="swap"
/dev/mapper/vgubuntu-root: UUID="cb94816d-569d-4658-963c-eb675052fc98" BLOCK_SIZE="4096" TYPE="ext4"
/dev/sda1: UUID="ba87f398-f52b-420f-9d19-af30a320c8f5" BLOCK_SIZE="4096" TYPE="xfs" PARTLABEL="Linux filesystem" PARTUUID="e21fd454-dc9a-41cb-8c72-c9fb05cb5d41"
/dev/nvme0n1p1: UUID="97CB-9857" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="ca61970c-01"
/dev/nvme0n1p5: UUID="C7sb3l-laqt-gLDw-ji2s-yC3r-x5bw-Axa9yu" TYPE="LVM2_member" PARTUUID="ca61970c-05"
注意这里 /dev/mapper/vgubuntu-root: UUID="cb94816d-569d-4658-963c-eb675052fc98" BLOCK_SIZE="4096" TYPE="ext4"
就是 /
所在的LV了。
在grub2里,我们只需要取这里的cb94816d-569d-4658-963c-eb675052fc98
即可。
#!/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 "Ubuntu 20.10 ISO" {
set isofile="/opt/iso/ubuntu-20.10-desktop-amd64.iso"
# or set isofile="/<username>/Downloads/ubuntu-20.04-desktop-amd64.iso"
# if you use a single partition for your $HOME
rmmod tpm
search --no-floppy --fs-uuid --set=root cb94816d-569d-4658-963c-eb675052fc98
loopback loop ($root)$isofile
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile noprompt noeject
initrd (loop)/casper/initrd
}
grub2 配置调整⚓
Fedora 和 Ubuntu 现在都默认不显示grub menu了 (要开机时按esc才显示), 可以通过修改配置调整成总是显示:
修改 /etc/default/grub
:
#GRUB_TIMEOUT_STYLE=hidden
#GRUB_TIMEOUT_STYLE=countdown
GRUB_TIMEOUT_STYLE=menu
文档解释: GRUB_TIMEOUT_STYLE
If this option is unset or set to ‘menu’, then GRUB will display the menu and then wait for the timeout set by ‘GRUB_TIMEOUT’ to expire before booting the default entry. Pressing a key interrupts the timeout.
If this option is set to ‘countdown’ or ‘hidden’, then, before displaying the menu, GRUB will wait for the timeout set by ‘GRUB_TIMEOUT’ to expire. If ESC is pressed during that time, it will display the menu and wait for input. If a hotkey associated with a menu entry is pressed, it will boot the associated menu entry immediately. If the timeout expires before either of these happens, it will boot the default entry. In the ‘countdown’ case, it will show a one-line indication of the remaining time.
更新 grub2 配置文件⚓
Ubuntu 下面有一个比较方便的 update-grub2
用来更新grub2配置, 该命令实际上是对 grub2-mkconfig
的便捷封装,
你不用指定配置文件路径,直接跑就行了。
❯ sudo update-grub2
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.8.0-29-generic
Found initrd image: /boot/initrd.img-5.8.0-29-generic
Found linux image: /boot/vmlinuz-5.8.0-28-generic
Found initrd image: /boot/initrd.img-5.8.0-28-generic
Found linux image: /boot/vmlinuz-5.8.0-26-generic
Found initrd image: /boot/initrd.img-5.8.0-26-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
done
参考文档⚓
https://www.gnu.org/software/grub/manual/grub/html_node/Simple-configuration.html
https://unix.stackexchange.com/questions/516429/boot-iso-file-located-on-lvm-from-grub2
https://superuser.com/a/1289853/1162309
https://help.ubuntu.com/community/Grub2/ISOBoot#ISO_File_Location
Recommend
-
114
Ubuntu 将停止提供 32 位 ISO 镜像
-
9
GRUB2 has always rubbed me the wrong way. It works — most of the time — but its complexity and structural distance from GRUB Legacy make debugging and customization nearl...
-
11
如何把一个Linux ISO 文件烧录到 17 个 USB 启动盘?-51CTO.COM 如何把一个Linux ISO 文件烧录到 17 个 USB 启动盘? 作者:runningwater 译 2015-03-13 11:13:19 精通代码的人会写一个 bash 脚本...
-
6
Ubuntu 20.04 下安装配置 Grub2 图形化界面工具-51CTO.COM Ubuntu 20.04 下安装配置 Grub2 图形化界面工具 作者:聆听世界的鱼 2022-02-15 09:19:55 在本文中,我们将解释如何在您的 Ubuntu 20.04.3 LTS 系...
-
16
June 27, 2020 添加 Live CD 启动项,主要用于系统挂了之后,我们还可以通过它来rescue下载live cd⚓
-
6
官方的 Ubuntu 精简 ISO 真的“精简”吗? 作者:Arindam 2023-04-28 10:34:28 系统 Ubuntu 23.04 “Lunar Lobster” 新推出的精简安装程序到底有...
-
6
V2EX › 问与答 如何从可启动的 U 盘提取一个 ISO 文件来?
-
10
ISO启动原理及启动盘制作 2023-11-01
-
12
Netboot Ubuntu with EFI This method is not netinst. The ISO is downloaded from a URL into RAM, and mounted. After that, installation proceeds exactly as if it was a pen drive / CDROM, and the network cable can be disconnected if...
-
4
主页PostsIPXE万能工具hiren.iso的启动方式 IPXE万能工具hi...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK