在linux 创建单分区 BIOS & UEFI双启动的USB启动盘 pxe TFTP目录

简介:#

还在折腾PXE启动,UEFI的在WDS,一直无法正常启动,也不知道哪里的问题。反正以后还要在WDS上面加多一层引导,前面用的grub4dos grub4dos uefi。

可能是不支持吧,所以折腾一下GRUB2吧。

安装linux#

我习惯使用fedora,现在用的是39的版本。

安装包#

dnf install   grub2-common grub2-pc  grub2-efi-x64-cdboot  grub2-efi-x64-modules 

分区#

Make sure it's the right drive! (check the capacity and the partitions) :

sudo fdisk -l /dev/sdX

Open fdisk :

sudo fdisk /dev/sdX

Press the following keys (THIS WILL ERASE ALL DATA FROM THE SELECTED DRIVE!) :

o <enter> # Create a new empty DOS partition table

n <enter> # Create a new partition

p <enter> # Select primary partition type

1 <enter> # Set partition number to 1

<enter> # Start partition at the first possible sector (default)

<enter> # Set partition end to the last possible sector (default)

Note: if fdisk (newer versions only) asks whether the partition signature should be deleted, then answer yes.

t <enter> # Change partition type

e f <enter> # Set partition type to EFI (FAT-12/16/32)

a <enter> # Enable the bootable flag on partition 1

w <enter> # Write the partition table

Create a fresh filesystem in the newly created partition :

sudo mkfs.fat -F32 /dev/sdX1

Mount the filesystem :

sudo mount -o umask=000 /dev/sdX1 /mnt

 

写入bios引导#

sudo grub2-install --no-floppy --boot-directory=/mnt/boot --target=i386-pc /dev/sdX

 

写入UEFI引导#

sudo grub2-install --removable --boot-directory=/mnt/boot --efi-directory=/mnt --target=x86_64-efi /dev/sdX

 

引导菜单#

/mnt/boot/grub/grub.cfg

menuentry 'Xubuntu 22.04 amd64'{
    #rmmod tpm #uncomment if grub version is >=2.04 in UEFI mode (see https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1851311)
    set isofile="/isos/xubuntu-22.04.3-desktop-amd64.iso"
    #search --set=root --file $isofile #uncomment if the bootloader and OS files are on different partitions
    loopback isoloop $isofile
    linux (isoloop)/casper/vmlinuz locale=fr_FR console-setup/layoutcode=fr boot=casper iso-scan/filename=$isofile quiet --
    initrd (isoloop)/casper/initrd
}

随便写一个,能看见就好了。

后面继续学习如何写grub2的引导菜单配置。

PXE网络启动#

GNU GRUB 手册 2.12

复制代码
grub-mknetdir --net-directory=/srv/tftp --subdir=/boot/grub -d /usr/lib/grub/<platform>

#bios
grub2-mknetdir --net-directory=/srv/tftp --subdir=/boot/grub -d /usr/lib/grub/i386-pc

#uefi
grub2-mknetdir --net-directory=/srv/tftp --subdir=/boot/grub -d /usr/lib/grub/x86_64-efi


#UEFI只配置了x64,几乎见不到32bit计算机了。
#grub.cfg 文件与路径输出位于同一目录中。
复制代码

执行命令时会提示你引导文件及路径是什么。

[root@localhost ~]# grub2-mknetdir --net-directory=/srv/tftp --subdir=/boot/grub -d /usr/lib/grub/x86_64-efi
Netboot directory for x86_64-efi created. Configure your DHCP server to point to /srv/tftp/boot/grub/x86_64-efi/core.efi
[root@localhost ~]# grub2-mknetdir --net-directory=/srv/tftp --subdir=/boot/grub -d /usr/lib/grub/i386-pc
Netboot directory for i386-pc created. Configure your DHCP server to point to /srv/tftp/boot/grub/i386-pc/core.0

我也不准备继续用linxu做PXE TFTP服务器,复制文件出来待用吧。

随便编辑一下grub.cfg,两个都要随便加个菜单。

测试#

又找了个测试工具 Qemu启动测试器 终结版,还单文件。

磁盘,光驱,镜像,pxe,linux内核,全支持。

我测试磁盘是可以正常出引导菜单的,pxe就不出引导菜单,以后搞菜单再说吧。

 bios#

 uefi#

 

总结#

和参考资料介绍的略不一样,主命令变为了grub2-install

安装的包名字也变了。

暂时先不管grub.cfg。

装个linux,就干这么点事,提取几个文件。

参考资料#

ndeineko/grub2-bios-uefi-usb: Create a usb boot drive with support for legacy BIOS and 32/64bit UEFI in a single partition on Linux (github.com)

作者:上官飞鸿

出处:https://www.cnblogs.com/jackadam/p/18121055

版权:本作品采用「知识共享-署名-非商业性-禁止演绎(CC-BY-NC-ND)」许可协议进行许可。

posted @   上官飞鸿  阅读(184)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
more_horiz
keyboard_arrow_up light_mode palette
选择主题
menu
点击右上角即可分享
微信分享提示