hhh333 发表于 2021-4-14 00:21:26

菜鸟WSL环境iPXE编译及网启二三事

本帖最后由 hhh333 于 2021-4-16 06:29 编辑

   iPXE网启确实够快,而且在不停更新,不得不每次按自己的意愿编译定制,时间一长又忘记,干脆记下来以免重新捡起时又走弯路。前面都在UOS中编译,刚好caocaofff提点在WSL环境中可能更方便,摸索了一下,不对之处请大佬们指正。
一、这是iPXE网站上有关编译的信息https://ipxe.org/download
You will need to have at least the following packages installed in order to build iPXE:
gcc
binutils
make
perl
liblzma or xz header files
mtools
mkisofs or genisoimage or xorrisofs (needed only for building .iso images)
syslinux (for isolinux, needed only for building .iso images)

二、WSL中搭建iPXE编译环境
WSL是win10的可选安装组件,因此要先安装WSL,如果不清楚,可以上网搜索安装方法,也是超简单的。可以参考这篇https://www.daehub.com/archives/9561.html
安装好后就可以启动进入Ubuntu,设定用户和密码,根据提示进行必要的升级就可进入编译环境搭建,在Ubuntu命令窗口中发下述命令安装组件:
sudo apt install git
sudo apt install git-core   #不装这个编译时会出现文件找不到
sudo apt install liblzma-dev #不装会出现lzma.h错误
sudo apt install gcc
sudo apt install make
sudo apt install mtools#DOS命令模拟器
sudo apt install mkisofs #不生成ISO不需要
sudo apt install syslinux #不生成ISO不需要

binutils和perl提示系统中已经存在不需要安装
可见与网站上的提示有所出入。

三、编译
1、使用git下载iPXE源代码
git clone git://git.ipxe.org/ipxe.git
这个不要用sudo,否则会没操作权限
2、进入ipxe/src先做些准备工作
先要了解究竟需要编译哪些文件,这个分两种情况,一种是适用于BIOS启动环境,另一种是EFI环境,以下是编译命令,可以存成BASH的批处理文件
#!/bin/bash
#编译前清空文件
make clean
#====BIOS编译命令,ipxe.lkrn不预置脚本调用时指定,undionly.kpxe可以内置脚本,也可以不内置脚本由网络启动器指定
make bin/ipxe.lkrn
make bin/undionly.kpxe EMBED=biosrom.txt
#====EFI编译命令,ipxe.efi包含网卡驱动较大,snponly只含通用驱动小=====
#64位
make bin-x86_64-efi/ipxe.efi EMBED=efirom.txt
make bin-x86_64-efi/snponly.efi EMBED=efirom.txt
#32位
make bin-i386-efi/ipxe.efi EMBED=efirom32.txt
make bin-i386-efi/snponly.efi EMBED=efirom32.txt
#====收集编译的文件=====
mkdir -p myipxe/32
mkdir -p myipxe/64
cp bin/ipxe.lkrn myipxe
cp bin/undionly.kpxe myipxe
cp bin-x86_64-efi/ipxe.efi myipxe/64
cp bin-x86_64-efi/snponly.efi myipxe/64
cp bin-i386-efi/ipxe.efi myipxe/32
cp bin-i386-efi/snponly.efi myipxe/32
以上生成的文件的用途:
A、bin/ipxe.lkrn用于其他PXE启动程序调用进入iPXE环境的启动程序,可以不用内置脚本而由PXE程序灵活配置,如下为PXELINUX调用这个程序的菜单
LABEL bootiPXE
      MENU LABEL [^X] --转iPXE网启
      kernel /BOOT/IPXE.KRN
      append initrd=/BOOT/H3_iPXEM.LST
下面是G4D调用
title 转iPXE网启                   Goto iPXE Menu\n可有更快的网启速度
      kernel /BOOT/IPXE.KRN
      initrd /BOOT/H3_iPXEM.LST
这个IPXE.KRN是由ipxe.lkrn改名而来

B、bin/undionly.kpxe这个是iPXE作网络第一启动时使用,最好在内嵌脚本中指定查找启动脚本的位置,当然也可以在网启服务工具中指定。我一般是将这个文件改名为ipxe.0放网启服务器网启目录的根下。


(注:如果在启动文件中内嵌了脚本指定外置菜单,这个启动器指定就无效了)

C、ipxe.efi、snponly.efi用于EFI环境iPXE做第一启动时的启动文件,前者包含网卡驱动较大,后者只含通用驱动小。由于用于EFI环境所以分64位和32位版本,不可混用,编译后分别位于bin-x86_64-efi和bin-i386-efi目录。由于是EFI一启,必须在内嵌脚本中指定菜单文件。

以上文件的文件名在编译时是不能改名的,因为编译工具是用文件名来判断用于何种类型的启动的。编译后名称可以任意改,如上图中EFI网启文件H3_iPXE64.efi就是由64位的ipxe.efi或snponly.efi改名而来。

在以上编译命令中用到了内嵌脚本,这个脚本不是菜单,只是用来指定菜单的位置和名称,即到服务器的什么地方取什么文件作菜单。语法与外置的菜单是一样的,当然也可以直接将外置菜单内嵌。目前的逻辑是用一个小的内嵌脚本调用外置脚本,一般情况下修改外置菜单就可以了,不必重新编译。以下脚本用于BIOS编译时的biosrom.txt的内容:
#!ipxe
dhcp
chain BOOT/H3_iPXEM.LST
以下是EFI64的efirom.txt
#!ipxe
dhcp
chain EFI/ipxe/H3_iPXEM.LST
以下是EFI32的efirom32.txt
#!ipxe
dhcp
set x32 32                #32位增加一个参数以方便后面菜单脚本编写
chain EFI/ipxe/H3_iPXEM.LST
这个很容易看懂,就不作过多解释了。
内嵌脚本编译时通过EMBED=xxx来指定,要提前编辑好,并放当前编译目录下,即ipxe/src下。准备好文件后就可进行编译了。

3、进行编译
准备好内嵌文件后就可以发命令进行编译了,最好一条一条来,以方便查看编译结果。


四、网启菜单的编写
这是我编写的BIOS-ipxe菜单

#!ipxe
set menu-timeout 10000
set menu-default w8pe
isset ${ip} || dhcp
isset ${next-server} || set next-server 192.168.7.100
set base-url http://www.slitaz.cn:8083/dl/slitaz/iso/rolling
console --picture /BOOT/IPXEBK.PNG
:start
      menu iPXE Boot Menu(ServerIP:${next-server})
      item --gap --                                                 -------------------------------- H3 PE TOOL ---------------------------
      item w7pe                                                   Win7 PE
      item w8pe                                                   Win8 PE
      item w8pe64                                                 Win8 PE 64
      item w81pe                                                   Win81 PE
      item w81pe64                                             Win81 PE 64
      item w10pe                                                   Win10 PE
      item w10pe64                                                Win10 PE 64
      item w03pein                                                 Win03 PE
      item maxdos                                                Maxdos Tool
      item plpbt                                                      PLPBT USB2.0 Driver
      item memtest                                                 Memtest 86
      item localhd0                                                 Local HD0
      item h3cdall                                                 ${next-server}/H3CDALL.ISO
      item slitaz5                                                 Slitaz5.0 from ${next-server}
      item slitaz5n                                                 Slitaz5.0 from ${base-url}
      item --gap --                                                 -------------------------------- TFTP Menu ----------------------------
      item --key l pxelinux                                        Load PXELinux Menu
      item --key g grub4dos                                     Load Grub4DOS Menu
#      item --key b grub2                                     Load Grub2 Menu
      item --key d dostools                                  Load DOSTOOLS Menu
      item --gap --                                                 -------------------------------- Advanced -----------------------------
      item --key c config                         Configure settings
      item --key s shell                         Drop to iPXE shell
      item --key r reboot                         Reboot computer
      item --key x exit                                  Exit iPXE and continue BIOS boot
      choose --timeout ${menu-timeout} --default ${menu-default} selected
      goto ${selected}

:localhd0
      sanboot --no-describe --drive 0x80

:shell
      echo Type 'exit' to get the back to the menu
      shell
      goto start

:failed
      echo Booting failed, dropping to shell
      goto shell

:reboot
      reboot

:exit
      exit

:config
      config
      goto start

:pxelinux
      chain http://${next-server}/pxelinux.0 || goto failed
      goto start

:grub4dos
      chain http://${next-server}/grldr || goto failed
      goto start

:grub2
      chain http://${next-server}/g2ldr || goto failed
      goto start

:dostools
      chain http://${next-server}/BOOT/H3_GRDOS.BIN || goto failed
      goto start

:memtest
      chain http://${next-server}/BOOT/memtest.bin || goto failed      #http://boot.ipxe.org/memtest.bin
      goto start

:plpbt
      chain http://${next-server}/BOOT/PLPBT.BIN
      goto start

:maxdos
      initrd http://${next-server}/BOOT/IMGS/MAXDOS.IMG
      chain http://${next-server}/BOOT/ISOLINUX/MEMDISK || goto failed

:0pe
      initrd http://${next-server}/ISO/0PE.ISO
      chain      http://${next-server}/memdisk iso raw
#chain http://${next-server}/ISO/grub.exe --config-file="map (rd)+1 (0xff);map --hook;chainloader (0xff)"

:w03pein
      chain http://${next-server}/BOOT/H3_PXELD.0 || goto failed
      goto start

:w7pe
      set bootfile H3_MGRW7.BIN && set sbcdfile BW7 && set pefile H3_7PE.WIM
      goto wimbootpe

:w8pe
      set bootfile H3_MGRW8.BIN && set sbcdfile BW8 && set pefile H3_8PE.WIM
      goto wimbootpe

:w8pe64
      set bootfile H3_MGR64.BIN && set sbcdfile B64 && set pefile H3_864.WIM
      goto wimbootpe

:w81pe
      set bootfile H3_MGR81.BIN && set sbcdfile B81 && set pefile H3_81PE.WIM
      goto wimbootpe

:w81pe64
      set bootfile H3_MGR16.BIN && set sbcdfile B16 && set pefile H3_8164.WIM
      goto wimbootpe

:w10pe
      set bootfile H3_MGR10.BIN && set sbcdfile B10 && set pefile H3_10PE.WIM
      goto wimbootpe

:w10pe64
      set bootfile H3_MGR06.BIN && set sbcdfile B06 && set pefile H3_1064.WIM
      goto wimbootpe

:slitaz5
      imgfree
      kernel http://${next-server}/BOOT/bzImage || goto failed
      initrd http://${next-server}/BOOT/rootfs.gz || goto failed
      imgargs bzImage initrd=rootfs.gz rw root=/dev/null lang=zh_CN kmap=us autologin
      boot || goto retry
      goto start

:slitaz5n
      imgfree
      kernel ${base-url}/boot64/bzImage64 || goto failed
      initrd ${base-url}/boot64/rootfs.gz || goto failed
      imgargs bzImage64 initrd=rootfs.gz rw root=/dev/null lang=zh_CN kmap=us autologin
      boot || goto retry
      goto start
      
:h3cdall
      sanboot --no-describe --keep ${next-server}/H3CDALL.ISO || goto failed
      goto start
      
:wimbootpe
      kernel http://${next-server}/BOOT/wimboot
      initrd http://${next-server}/BOOT/${bootfile} bootmgr
      initrd http://${next-server}/BOOT/${sbcdfile} ${sbcdfile}
      initrd http://${next-server}/BOOT/boot.sdi boot.sdi
      initrd http://${next-server}/BOOT/${pefile}      ${pefile}
      boot || goto failed
      goto start
#https://github.com/ipxe/wimboot/releases/latest/download/wimboot      
这是用于EFI的:
#!ipxe
set menu-timeout 10000
set menu-default w8pe
isset ${ip} || dhcp
isset ${next-server} || set next-server 192.168.7.100
set base-url http://www.slitaz.cn:8083/dl/slitaz/iso/rolling
#cpuid --ext 29 && set x64 64 || set x32 32
console --picture /EFI/ipxe/ipxebk.png
:start
menu iPXE EFI${x32} Boot Menu(ServerIP:${next-server})
item --gap --             -------------------------------- H3 PE TOOL ---------------------------
item w8pe                   1-- Win8 PE
item w81pe                  2-- Win81 PE
item w10pe                  3-- Win10 PE
item slitaz5                4-- Slitaz5.0 from ${next-server}
item slitaz5n               5-- Slitaz5.0 from ${base-url}
item --gap --             -------------------------------- Other Tool ---------------------------
item --key k KonBoot       KonBoot 2.5
#item --key t memtest       Load MemTest 7.4
#item --key g g2          Load Grub2
#item --key f g2fm          Load Grub2 FileManager
item --key d g2run       Load Grub2 RUN
item --gap --             -------------------------------- Advanced -----------------------------
item --key c config       Configure settings
item --key s shell       Drop to iPXE shell
item --key r reboot       Reboot computer
item --key x exit          Exit iPXE and continue efi boot
choose --timeout ${menu-timeout} --default ${menu-default} selected
goto ${selected}

:shell
echo Type 'exit' to get the back to the menu
shell
goto start

:failed
echo Booting failed, dropping to shell
goto shell

:reboot
reboot

:exit
exit

:config
config
goto start

:g2run
chain http://${next-server}/EFI/grub/run.efi || goto failed
goto start

:g2fm
      isset ${x32} && set bootfile grubfmia32.efi || set bootfile grubfmx64.efi
chain http://${next-server}/EFI/grub/${bootfile} || goto failed
goto start

:g2
      isset ${x32} && set bootfile g2bootia32.efi || set bootfile g2bootx64.efi
chain http://${next-server}/EFI/boot/${bootfile} || goto failed
goto start

:memtest
      isset ${x32} && set bootfile membootia32.efi || set bootfile membootx64.efi
chain http://${next-server}/EFI/boot/${bootfile} || goto failed
goto start

:KonBoot
      isset ${x32} && set bootfile KonBootia32.EFI || set bootfile KonBootx64.EFI
chain http://${next-server}/EFI/boot/${bootfile} || goto failed
goto start

:w8pe
      set bootfile bootx64.efi && set wimboot wimboot && set tbcdfile BCD && set sbcdfile b64 && set pefile H3_864.WIM
      isset ${x32} && set bootfile bootia32.efi && set wimboot wimboot.i386 && set tbcdfile B32 && set sbcdfile b832 && set pefile H3_8PE.WIM ||
goto wimbootpe

:w81pe
      set bootfile bootx64.efi && set wimboot wimboot && set bootfile bootx64.efi && set tbcdfile BCD && set sbcdfile b16 && set pefile H3_8164.WIM
      isset ${x32} && set bootfile bootia32.efi && set wimboot wimboot.i386 && set tbcdfile B32 && set sbcdfile b8132 && set pefile H3_81PE.WIM ||
goto wimbootpe

:w10pe
      set bootfile bootx64.efi && set wimboot wimboot && set bootfile bootx64.efi && set tbcdfile BCD && set sbcdfile b06 && set pefile H3_1064.WIM
      isset ${x32} && set bootfile bootia32.efi && set wimboot wimboot.i386 && set tbcdfile B32 && set sbcdfile b1032 && set pefile H3_10PE.WIM ||
goto wimbootpe

:slitaz5
      isset ${x32} && set bootfile bzbootia32.efi || set bootfile bzbootx64.efi
      imgfree
      kernel http://${next-server}/EFI/boot/${bootfile} || goto failed
      initrd http://${next-server}/BOOT/rootfs.gz || goto failed
      imgargs ${bootfile} initrd=rootfs.gz rw root=/dev/null lang=zh_CN kmap=us autologin
      boot || goto retry
      goto start

:slitaz5n
      isset ${x32} && set bzd boot32 && set bootfile bzImage || set bzd boot64 && set bootfile bzImage64
      imgfree
      kernel ${base-url}/${bzd}/${bootfile} || goto failed
      initrd ${base-url}/${bzd}/rootfs.gz || goto failed
      imgargs ${bootfile} initrd=rootfs.gz rw root=/dev/null lang=zh_CN kmap=us autologin
      boot || goto retry
      goto start

:wimbootpe
kernel http://${next-server}/BOOT/${wimboot}
initrd -n ${bootfile} http://${next-server}/EFI/boot/ms${bootfile}
initrd -n ${tbcdfile} http://${next-server}/EFI/microsoft/boot/${sbcdfile}
initrd http://${next-server}/BOOT/BOOT.SDI
initrd http://${next-server}/BOOT/${pefile}
boot || goto failed
goto start
可见语法是较简单的:支持“:标号”和“goto",变量由"set"设置,用"${变量}"进行引用,”&&"表示“则”,“||”表示“否则”因此可以控制流程方向,“isset、iseq”用来判断......其他关键词可以看说明https://ipxe.org/docs。

五、注意事项
1、脚本的格式:内嵌菜单、外置菜单都可用ansi格式,但sh脚本最好在linux环境进行编辑,如果直接在windows下编辑再直接在WSL环境中用,是没有权限的要通过“chmod 744 文件名”赋权才能使用。
2、外置脚本中使用了背景菜单,以上直接编译的文件启动时会出错失败。因此还得改两个文件:src/config/general.h console.h把其中的两个参数去除注释才行#define CONSOLE_CMD #define CONSOLE_FRAMEBUFFER这两行前面的“//"要去掉。
3、实际上还有一个WSL与Win10之间互相存取文件的问题。我比较暴力,直接到用户目录下找到WSL安装位置,直接拷入拷出,但由win->WSL的文件要记得赋权限,不然WSL看得到拿不到,要特别注意格式,否则会出现不可见的乱字符。哦,对了,WSL在Win10的位置看下这个路径就知道了:C:\Users\hwg\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\hwg\ipxe\src。而Win10在WSL中的位置可以看下图



2010sya 发表于 2021-4-14 07:30:12

谢谢分享

dkzzlf 发表于 2021-4-14 07:40:07

感谢分享

2011slkj 发表于 2021-4-14 08:23:08

谢谢分享,认真学习

邪恶海盗 发表于 2021-4-14 09:04:08

set base-url

暴露了,撸主这个菜单是抄别人的...{:1_186:}

其实我觉得可以用虚拟机,装个Slitaz这样的轻量级Linux做编译环境...

hhh333 发表于 2021-4-14 09:29:52

邪恶海盗 发表于 2021-4-14 09:04
set base-url

暴露了,撸主这个菜单是抄别人的...


哟厉害了我的国。其实你应该说imgargs这个用法更是抄的,本来是用来启动神雕的Slitaz啊,觉得这么写起来代码少一些,方便变更网址时修改,这写法又不是技术含量蛮高的东西。

江南一根葱 发表于 2021-4-14 09:31:54

本帖最后由 江南一根葱 于 2021-4-14 09:32 编辑

赶嚼你们对wimboot误解太深了,你这菜单,可以精简掉大半,tinypxe官方包里的菜单有很好的示例。。

hhh333 发表于 2021-4-14 09:46:34

本帖最后由 hhh333 于 2021-4-14 09:49 编辑

江南一根葱 发表于 2021-4-14 09:31
赶嚼你们对wimboot误解太深了,你这菜单,可以精简掉大半,tinypxe官方包里的菜单有很好的示例。。
有啥高级的用法?wimboot下过来要改名的,不好弄吧。我正自我感觉良好呢{:1_186:}

江南一根葱 发表于 2021-4-14 09:48:21

hhh333 发表于 2021-4-14 09:46
有啥高级的用法?wimboot下过来要改名的,不好弄吧

从来都不需要改名,
你可以参考我折腾的ipxefm,如果一定要执意你这样改很多文件名,你可以这样弄

:wimbootmenu
menu iPXE Boot Menu(ServerIP:${next-server})
item --gap --             -------------------------------- H3 PE TOOL ---------------------------
item H3_7PE.WIM               Win7 PE
item H3_11pe.WIM                Win11 PE
choose --timeout ${menu-timeout} --default ${menu-default} selected
iseq ${selected} H3_7PE.WIM && set wim ${selected} && set bootmgr H3_MGRW7.BIN && set bcd BW7&& goto wimboot
iseq ${selected} H3_11PE.WIM && set wim ${selected} && set bootmgr H3_MGRW11.BIN && set bcd BW11&& goto wimboot
goto ${selected}

:wimboot
kernel http://${next-server}/BOOT/wimboot                              #http://git.ipxe.org/releases/wimboot/wimboot-latest.zip
initrd http://${next-server}/BOOT/${bootmgr} bootmgr
initrd http://${next-server}/BOOT/${bcd}   ${bcd}
initrd http://${next-server}/BOOT/boot.sdi boot.sdi
initrd http://${next-server}/BOOT/${wim} ${wim}
boot || goto failed
goto wimbootmenu

江南一根葱 发表于 2021-4-14 09:51:25

hhh333 发表于 2021-4-14 09:46
有啥高级的用法?wimboot下过来要改名的,不好弄吧。我正自我感觉良好呢

我们是这样写的
:wimbootmenu
menu iPXE Boot Menu(ServerIP:${next-server})
item --gap --             -------------------------------- H3 PE TOOL ---------------------------
item H3_7PE.WIM               Win7 PE
choose --timeout ${menu-timeout} --default ${menu-default} selected
set wim ${selected} && goto wimboot

:wimboot
kernel http://${next-server}/BOOT/wimboot                              #http://git.ipxe.org/releases/wimboot/wimboot-latest.zip
initrd http://${next-server}/BOOT/bootmgr bootmgr
initrd http://${next-server}/BOOT/bcd   bcd
initrd http://${next-server}/BOOT/boot.sdi boot.sdi
initrd http://${next-server}/BOOT/${wim} boot.wim
boot || goto failed
goto wimbootmenu
只要加一两句判断,就可以bios/uefi双环境

hhh333 发表于 2021-4-14 09:57:41

江南一根葱 发表于 2021-4-14 09:48
从来都不需要改名,
你可以参考我折腾的ipxefm,如果一定要执意你这样改很多文件名,你可以这样弄


哦,你是指BIOS菜单,EFI菜单是这么写的,大同小异。BIOS菜单写得较早一点

hhh333 发表于 2021-4-14 10:01:57

江南一根葱 发表于 2021-4-14 09:51
我们是这样写的
:wimbootmenu
menu iPXE Boot Menu(ServerIP:${next-server})


bios和efi菜单分开好些,没必要合成一个,本来启动文件就不一样。

hhh333 发表于 2021-4-14 10:04:29

我把BIOS那个再精练一下。与EFI风格一样。不喜欢牺牲可读性。不然过两个月自己也看不懂了。{:1_186:}

caocaofff 发表于 2021-4-14 10:14:30

想要高级的方法?用PHP吧,动态菜单,直接在服务器端控制客户端的启动菜单,爽歪歪https://cdn.jsdelivr.net/gh/hishis/forum-master/public/images/patch.gif

江南一根葱 发表于 2021-4-14 10:21:42

本帖最后由 江南一根葱 于 2021-4-14 10:57 编辑

hhh333 发表于 2021-4-14 09:57
哦,你是指BIOS菜单,EFI菜单是这么写的,大同小异。BIOS菜单写得较早一点
efi也一样,只不过改成
initrd -n boot.wim
这样可能是bios uefi通吃的,
而且启动文件就差一个bootmgrfw.efi,
nitrd -n boot.wim http://${next-server}/BOOT/${wim} boot.wim
bios/uefi双启可以这样写:wimboot
#假如取文件失败就换个地址
kernel http://${booturl}/app/wimboot/wimboot quiet || goto retryip
#在bios和efi不同环境取相应的文件

iseq ${platform} pcbios&& initrd http://${booturl}/app/wimboot/bootmgrbootmgr ||
iseq ${platform} efi&& initrd -n bootx64.efi http://${booturl}/app/wimboot/bootmgfw.efi ||


initrd http://${booturl}/app/wimboot/BCDBCD ||
initrd http://${booturl}/app/wimboot/boot.sdi   boot.sdi ||

iseq ${platform} pcbios&& initrd http://${booturl}${bootfile} boot.wim ||
iseq ${platform} efi && initrd -n boot.wim http://${booturl}${bootfile} ||
boot ||



hhh333 发表于 2021-4-14 10:31:25

caocaofff 发表于 2021-4-14 10:14
想要高级的方法?用PHP吧,动态菜单,直接在服务器端控制客户端的启动菜单,爽歪歪

哈哈,这个没玩过,简单讲下玩法{:1_186:}

hhh333 发表于 2021-4-14 10:37:18

江南一根葱 发表于 2021-4-14 09:48
从来都不需要改名,
你可以参考我折腾的ipxefm,如果一定要执意你这样改很多文件名,你可以这样弄



改了下BIOS菜单,与EFI差不多,不提前判断再goto直接统一goto ${selected},规范些
#!ipxe
set menu-timeout 10000
set menu-default w8pe
isset ${ip} || dhcp
isset ${next-server} || set next-server 192.168.7.100
set base-url http://www.slitaz.cn:8083/dl/slitaz/iso/rolling
console --picture /BOOT/IPXEBK.PNG
:start
menu iPXE Boot Menu(ServerIP:${next-server})
item --gap --             -------------------------------- H3 PE TOOL ---------------------------
item w7pe               Win7 PE
item w8pe               Win8 PE
item w8pe64               Win8 PE 64
item w81pe                Win81 PE
item w81pe64            Win81 PE 64
item w10pe                Win10 PE
item w10pe64            Win10 PE 64
item w03pein            Win03 PE
item maxdos               Maxdos Tool
item plpbt                PLPBT USB2.0 Driver
item memtest            Memtest 86
item localhd0             Local HD0
item h3cdall            ${next-server}/H3CDALL.ISO
item slitaz5            Slitaz5.0 from ${next-server}
item slitaz5n             Slitaz5.0 from ${base-url}
item --gap --             -------------------------------- TFTP Menu ----------------------------
item --key l pxelinux    Load PXELinux Menu
item --key g grub4dos    Load Grub4DOS Menu
#item --key b grub2       Load Grub2 Menu
item --key d dostools    Load DOSTOOLS Menu
item --gap --             -------------------------------- Advanced -----------------------------
item --key c config       Configure settings
item --key s shell       Drop to iPXE shell
item --key r reboot       Reboot computer
item --key x exit          Exit iPXE and continue BIOS boot
choose --timeout ${menu-timeout} --default ${menu-default} selected
goto ${selected}

:localhd0
        sanboot --no-describe --drive 0x80

:shell
echo Type 'exit' to get the back to the menu
shell
goto start

:failed
echo Booting failed, dropping to shell
goto shell

:reboot
reboot

:exit
exit

:config
config
goto start

:pxelinux
chain http://${next-server}/pxelinux.0 || goto failed
goto start

:grub4dos
chain http://${next-server}/grldr || goto failed
goto start

:grub2
chain http://${next-server}/g2ldr || goto failed
goto start

:dostools
chain http://${next-server}/BOOT/H3_GRDOS.BIN || goto failed
goto start

:memtest
chain http://${next-server}/BOOT/memtest.bin || goto failed#http://boot.ipxe.org/memtest.bin
goto start

:plpbt
chain http://${next-server}/BOOT/PLPBT.BIN
goto start

:maxdos
initrd http://${next-server}/BOOT/IMGS/MAXDOS.IMG
chain http://${next-server}/BOOT/ISOLINUX/MEMDISK || goto failed

:0pe
initrd http://${next-server}/ISO/0PE.ISO
chainhttp://${next-server}/memdisk iso raw
#chain http://${next-server}/ISO/grub.exe --config-file="map (rd)+1 (0xff);map --hook;chainloader (0xff)"

:w03pein
chain http://${next-server}/BOOT/H3_PXELD.0 || goto failed
goto start

:w7pe
        set bootfile H3_MGRW7.BIN && set sbcdfile BW7 && set pefile H3_7PE.WIM
goto wimbootpe
#http://git.ipxe.org/releases/wimboot/wimboot-latest.zip

:w8pe
        set bootfile H3_MGRW8.BIN && set sbcdfile BW8 && set pefile H3_8PE.WIM
goto wimbootpe

:w8pe64
        set bootfile H3_MGR64.BIN && set sbcdfile B64 && set pefile H3_864.WIM
goto wimbootpe

:w81pe
        set bootfile H3_MGR81.BIN && set sbcdfile B81 && set pefile H3_81PE.WIM
goto wimbootpe

:w81pe64
        set bootfile H3_MGR16.BIN && set sbcdfile B16 && set pefile H3_8164.WIM
goto wimbootpe

:w10pe
        set bootfile H3_MGR10.BIN && set sbcdfile B10 && set pefile H3_10PE.WIM
goto wimbootpe

:w10pe64
        set bootfile H3_MGR06.BIN && set sbcdfile B06 && set pefile H3_1064.WIM
goto wimbootpe

:slitaz5
        imgfree
        kernel http://${next-server}/BOOT/bzImage || goto failed
        initrd http://${next-server}/BOOT/rootfs.gz || goto failed
        imgargs bzImage initrd=rootfs.gz rw root=/dev/null lang=zh_CN kmap=us autologin
        boot || goto retry
        goto start

:slitaz5n
        imgfree
        kernel ${base-url}/boot64/bzImage64 || goto failed
        initrd ${base-url}/boot64/rootfs.gz || goto failed
        imgargs bzImage64 initrd=rootfs.gz rw root=/dev/null lang=zh_CN kmap=us autologin
        boot || goto retry
        goto start
       
:h3cdall
        sanboot --no-describe --keep ${next-server}/H3CDALL.ISO || goto failed
        goto start
       
:wimbootpe
kernel http://${next-server}/BOOT/wimboot
initrd http://${next-server}/BOOT/${bootfile} bootmgr
initrd http://${next-server}/BOOT/${sbcdfile}        ${sbcdfile}
initrd http://${next-server}/BOOT/boot.sdi boot.sdi
initrd http://${next-server}/BOOT/${pefile}        ${pefile}
boot || goto failed
goto start


江南一根葱 发表于 2021-4-14 10:48:45

本帖最后由 江南一根葱 于 2021-4-14 11:01 编辑

hhh333 发表于 2021-4-14 10:37
改了下BIOS菜单,与EFI差不多,不提前判断再goto直接统一goto ${selected},规范些
所有的bootmgr和bcd是可以共用一个的,
tinypxe官方包里有提供。。
所以其实只需要单独写个wimboot菜单出来,然后在主菜单引用,
set wim ${selected} && goto wimboot一句就可以了。。
可以用这些文件,

另外就是最新版的wimboot下载地址变了,现在是
https://github.com/ipxe/wimboot/releases/latest/download/wimboot
我附件中的wimboot是最新的,修复了很多bios下启动的问题,还添加了静默参数 quiet,用法
kernel http://${booturl}/app/wimboot/wimboot quiet
这样可以不显示那些字符,,兼容bios/uefi可以这样写
:wimboot
#假如取文件失败就换个地址
kernel http://${booturl}/app/wimboot/wimboot quiet || goto retryip
#在bios和efi不同环境取相应的文件
iseq ${platform} pcbios&& initrd http://${booturl}/app/wimboot/bootmgrbootmgr ||
iseq ${platform} efi&& initrd -n bootx64.efi http://${booturl}/app/wimboot/bootmgfw.efi ||
initrd http://${booturl}/app/wimboot/BCDBCD ||
initrd http://${booturl}/app/wimboot/boot.sdi   boot.sdi ||
iseq ${platform} pcbios&& initrd http://${booturl}${bootfile} boot.wim ||
iseq ${platform} efi && initrd -n boot.wim http://${booturl}${bootfile} ||
boot ||



hhh333 发表于 2021-4-14 10:58:18

江南一根葱 发表于 2021-4-14 10:48
所有的bootmgr和bcd是可以共用一个的,
tinypxe官方包里有提供。。
所以其实只需要单独写个wimboot菜单 ...

哦,好像新版可以用大内存是吧

江南一根葱 发表于 2021-4-14 11:06:27

item 后面的这些,最好替换成有价值的,引用方便,把w7pe什么的,写成H3_7PE.WIM不是更香吗,也更容易看得懂
可以pefile就是${selected}。

hhh333 发表于 2021-4-14 11:11:51

江南一根葱 发表于 2021-4-14 11:06
item 后面的这些,最好替换成有价值的,引用方便,把w7pe什么的,写成H3_7PE.WIM不是更香吗,也更容易看得 ...

哈哈,也是,小技巧多啊

邪恶海盗 发表于 2021-4-14 16:10:30

我的菜单,貌似是用的TinyPXE的改的:
#!ipxe

#set boot-url http://hidao.org/pxe
set boot-url http://${next-server}
#set iqn iqn.2008-08.com.starwindsoftware:test
#set nfs-server nfs://${next-server}
#set cifs-server //${next-server}
#set mytarget iscsi:${next-server}::::iqn.2008-08.com.starwindsoftware:target1
#set gateway 0.0.0.0
#set keep-san 1
#set initiator-iqn iqn.client

# Setup some basic convenience variables
set menu-timeout 8000
set submenu-timeout ${menu-timeout}
#check platform (pcbios or efi), buildarch (i386 or X86_64)
echo Platform: ${platform}
echo Buildarch: ${buildarch}
# Ensure we have menu-default set to something
isset ${menu-default} || set menu-default WinPE_x64
#console --picture ${boot-url}/bg.png

######## MAIN MENU ###################
:start
iseq ${platform} efi && menu iPXE Boot Menu (UEFI) - Mod By hidao.org || menu iPXE Boot Menu (BIOS) - Mod By hidao.org
item --gap -- IP:${ip} , DHCP:${dhcp-server} , boot-url = ${boot-url}
item
item --gap --                  ----------------------- Win PE -----------------------
item --key 1 isoboot          Boot boot.iso ------------------------ (BIOS/UEFI) Unavailable
item --key 2 WinPE_x86          Boot boot32.wim ---------------------- (BIOS/UEFI) Unavailable
item --key 3 WinPE_x64          Boot boot64.wim ---------------------- (BIOS/UEFI) Unavailable
item --gap --
item --gap --                  ----------------------- Linux ------------------------
item --key l Slitaz             Boot Slitaz -------------------------- (BIOS Only) Available
item --key t TinyCore          Boot TinyCore ------------------------ (BIOS Only) Available
item --key k kolibri          Boot Kolibri ------------------------- (BIOS Only) Available
item --key e menuetos          Boot MenuetOS ------------------------ (BIOS Only) Available
item --key w gocloud          Install openwrt X86 ------------------ (BIOS Only) Available
item --gap --
item --gap --                  ----------------------- Other Tools ------------------
item --key m memtest          Boot Memtest x86 --------------------- (BIOS/UEFI) Available
item --key g GhostDos          Boot GhostDos ------------------------ (BIOS Only) Available
item --key d MaxDos             Boot MaxDos -------------------------- (BIOS Only) Available
item --gap --
#item --gap --                  ---------------------- Exit Boot -----------
item --key x exit             Exit iPXE and continue boot ----------------------
item --gap --
item --gap --
item --gap --                  ----------------------- Advanced options -------------
item --key c config             Configure settings -------------------------------
item --key i shell             Enter iPXE shell ---------------------------------
item --key r reboot             Reboot -------------------------------------------
item --key s power             Shutdown -----------------------------------------
choose --timeout ${menu-timeout} --default ${menu-default} selected
goto ${selected}
#choose --default exit --timeout ${menu-timeout} target && goto ${target}

########## UTILITY ITEMS ####################
:local80
sanboot --no-describe --drive 0x80

:local81
sanboot --no-describe --drive 0x81

:isoboot
initrd ${boot-url}/sources/boot.iso || goto Failed
chain ${boot-url}/memdisk iso raw || goto Failed
boot || goto Failed

:WinPE_x86
iseq ${platform} efi && set bootfile bootia32.efi && set bcdfile efi-BCD && set wimbootfile wimboot.efi || set bootfile bootmgr && set bcdfile bios-BCD && set wimbootfile wimboot
kernel ${boot-url}/${wimbootfile}      || goto Failed
initrd ${boot-url}/boot/${bootfile}    || goto Failed      
initrd ${boot-url}/boot/${bcdfile} BCD || goto Failed         
initrd ${boot-url}/boot/boot.sdi       || goto Failed            
initrd ${boot-url}/sources/boot32.wim|| goto Failed         
boot || goto Failed
goto start

:WinPE_x64
iseq ${platform} efi && set bootfile bootix64.efi && set bcdfile efi-bcd && set wimbootfile wimboot.efi || set bootfile bootmgr && set bcdfile bios-bcd && set wimbootfile wimboot
kernel ${boot-url}/${wimbootfile} ${wimbootfile} || goto Failed
initrd ${boot-url}/boot/${bootfile}${bootfile} || goto Failed
initrd ${boot-url}/boot/${bcdfile}         BCD || goto Failed
initrd ${boot-url}/boot/boot.sdi      BOOT.SDI || goto Failed
initrd${boot-url}/sources/boot64.wimboot.wim || goto Failed
boot || goto Failed
goto start
   
:TinyCore
kernel ${boot-url}/sources/vmlinuz root=/dev/null vga=788 autologin   || goto Failed
initrd ${boot-url}/sources/core.gz    || goto Failed
boot || goto Failed
   
:Slitaz
kernel ${boot-url}/sources/bzImage root=/dev/null vga=788 autologin   || goto Failed
initrd ${boot-url}/sources/rootfs.gz    || goto Failed
boot || goto Failed

:kolibri
initrd ${boot-url}/images/kolibri.img   || goto Failed
chain ${boot-url}/memdisk img raw       || goto Failed
boot || goto Failed

:menuetos
initrd ${boot-url}/images/menuetos.img   || goto Failed
chain ${boot-url}/memdisk img raw       || goto Failed
boot || goto Failed

:gocloud
chain ${boot-url}/oppxeins       || goto Failed
boot || goto Failed

:memtest
chain ${boot-url}/images/memtest || goto Failed
boot || goto Faild
goto start


:GhostDos
initrd ${boot-url}/images/ghost.img   || goto Failed
chain ${boot-url}/memdisk img raw   || goto Failed
boot || goto Failed

:MaxDos
initrd ${boot-url}/images/MAXDOS.img      || goto Failed
chain ${boot-url}/memdisk ima raw         || goto Failed
boot || goto Failed

:Failed
echo Booting Failed, dropping to shell
goto shell
   
:shell
echo Type exit to get the back to the menu
shell
set menu-timeout 0
goto start


:reboot
reboot

:Power
poweroff

:exit
exit

:config
config
goto start

hhh333 发表于 2021-4-14 16:53:52

邪恶海盗 发表于 2021-4-14 16:10
我的菜单,貌似是用的TinyPXE的改的:

我不知道仔细读了TinyPXE的菜单没有,记不起了。不过我还是坚持把bios和efi分开的观点。毕竟差异比较大,efi中的工具也少,不然要不断地进行判断,人为增加菜单难度,牺牲可读性没必要。何况efi中还有32位与64位要判断。

邪恶海盗 发表于 2021-4-14 17:22:18

hhh333 发表于 2021-4-14 16:53
我不知道仔细读了TinyPXE的菜单没有,记不起了。不过我还是坚持把bios和efi分开的观点。毕竟差异比较大, ...

我觉得我的菜单可读性还是不错的,当然每个人的习惯不一样,适合自己的才是最好的

江南一根葱 发表于 2021-4-14 18:02:50

本帖最后由 江南一根葱 于 2021-4-14 18:58 编辑

hhh333 发表于 2021-4-14 16:53
我不知道仔细读了TinyPXE的菜单没有,记不起了。不过我还是坚持把bios和efi分开的观点。毕竟差异比较大, ...
不需要分开,更不需要判断,脑洞够大的话,据说还可以这样写
[*]:wimmenu
[*]menu wimfile
[*]   item --gap Choose Resolution ratio
[*]   item --key 1 win8.wim         1. win8pe
[*]   item --key 2 win9.wim         2. win9pe
[*]   item --key 3 win10.wim          3. win10pe
[*]   item --key m menu             M. Back to menu
[*]choose --timeout ${bootfile-timeout} --default 800x600 selected ||
[*]iseq ${selected} menu && goto menu ||
[*]set wim ${selected} && goto wimboot ||
[*]
[*]:wimboot
[*]kernel ${booturl}/app/wimboot/wimboot ||
[*]initrd ${booturl}/app/wimboot/bootmgr.exe bootmgr.exe ||
[*]initrd ${booturl}/app/wimboot/bootx64.efi bootx64.efi ||
[*]initrd ${booturl}/app/wimboot/bootia32.efi bootia32.efi ||
[*]initrd ${booturl}/app/wimboot/bcd bcd ||
[*]initrd ${booturl}/app/wimboot/boot.sdi boot.sdi ||
[*]initrd -n boot.wim ${booturl}/${wim}boot.wim ||
[*]boot || goto wimmenu

通吃bios/uefi64/uefi32

2013mqqdg 发表于 2021-4-15 00:32:39

神贴,看来我的菜单还是小儿科了{:1_201:}

hhh333 发表于 2021-4-15 10:07:24

江南一根葱 发表于 2021-4-14 18:02
不需要分开,更不需要判断,脑洞够大的话,据说还可以这样写
[*]:wimmenu
[*]menu wimfile


呵,三个启动都down下来,确实也是个思路,不过不经济吧,浪费两个文件

江南一根葱 发表于 2021-4-15 10:47:57

本帖最后由 江南一根葱 于 2021-4-15 10:49 编辑

hhh333 发表于 2021-4-15 10:07
呵,三个启动都down下来,确实也是个思路,不过不经济吧,浪费两个文件
哈哈,你更浪费啊,,每个wim都配一份bcd和bootmgfw.efi,{:1_186:}
用你的文件的话,连wimboot都不需要的,而且,这样让电脑自己去判断,还不会出错,“代码”也有高强的可读性

hhh333 发表于 2021-4-15 11:45:18

江南一根葱 发表于 2021-4-15 10:47
哈哈,你更浪费啊,,每个wim都配一份bcd和bootmgfw.efi,
用你的文件的话,连wimboot都不需要 ...

我浪费几个字,你浪费流量,就这区别{:1_189:}

江南一根葱 发表于 2021-4-15 13:43:44

hhh333 发表于 2021-4-15 11:45
我浪费几个字,你浪费流量,就这区别


[*]喜欢改文件名且又想节省几m流量的话,再加个判断,这样写姿势更丰富,更容易看懂(个人觉得)。
   #判断

[*]issq ${platform} pcbios && set msboot bootmgr.exe ||
[*]issq ${platform} efi && set msboot bootx64.efi ||
   #启动

[*]:wimboot
[*]kernel ${booturl}/app/wimboot/wimboot ||
[*]initrd ${booturl}/app/wimboot/${msboot} ${msboot} ||
[*]initrd ${booturl}/app/wimboot/bcd bcd ||
[*]initrd ${booturl}/app/wimboot/boot.sdi boot.sdi ||
[*]initrd -n boot.wim ${booturl}/${wim}boot.wim ||
[*]boot || goto wimmenu
至于其它提高代码可读性的方法,我觉得稍对齐些(完全遵守缩进规则太难),用notepad艹打开编辑,完全没问题。

页: [1] 2
查看完整版本: 菜鸟WSL环境iPXE编译及网启二三事