在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
分区#
sudo fdisk -l /dev/sdX
sudo fdisk /dev/sdX
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
sudo mkfs.fat -F32 /dev/sdX1
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网络启动#
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,就干这么点事,提取几个文件。
参考资料#
作者:上官飞鸿
出处:https://www.cnblogs.com/jackadam/p/18121055
版权:本作品采用「知识共享-署名-非商业性-禁止演绎(CC-BY-NC-ND)」许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!