ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Tiny pxe网络启动--远程安装、维护系统

2021-05-20 17:01:04  阅读:1342  来源: 互联网

标签:goto failed -- boot Tiny server item pxe


Tiny pxe网络启动–远程安装、维护系统

参考文档:

  1. http://labalec.fr/erwan/?page_id=958

  2. https://ipxe.org/docs

Tiny PXE Server是一款小巧而功能强大的网络系统启动软件,支持DHCP/TFTP/HTTP/BINL/DNS等多个协议,支持grub4dos,pxelinux,ipxe等多个引导器,支持从PXE/gPXE/IPXE启动,支持http协议启动或传输文件。

Tiny PXE Server下载地址:http://erwan.labalec.fr/tinypxeserver/pxesrv.zip

启动PXE服务端

下载解压后直接运行pxesrv.exe,点击”Online“即可运行服务端,终止运行点击”Offline“。

配置说明

在这里插入图片描述

说明:

  1. ProxyDhcp:是Dhcp代理服务

    勾选:在局域网已有Dhcp服务的情况下,建议勾选,不会与现有Dhcp服务冲突,但它能传递Next-Server等选项,传统Dhcp服务不一定能传递参数和选项;

    不勾选:如果局域网没有Dhcp服务,可使用此软件的Dhcp服务,就不勾选,客户端会得到该软件分配的IP。

  2. HTTPd:开启本机的httpd服务,即web服务,可通过httpd服务来启动系统,浏览器可访问。

  3. SMB:文件共享协议,勾选并启动后主机会把当前目录下的files目录共享出去,共享名为PXE,可通过命令:net share查看主机共享出去的目录,如:

    C:\Users\wzy>net share
    
    共享名       资源                            注解
    
    -------------------------------------------------------------------------------
    C$           C:\                             默认共享
    D$           D:\                             默认共享
    E$           E:\                             默认共享
    IPC$                                         远程 IPC
    ADMIN$       C:\Windows                      远程管理
    PXE          E:\pxe网络启动\pxesrv\files
    命令成功完成。
    
  4. Option:有多个Option项,在不启动ProxyDhcp时,它会让主机充当DHCP服务器,分配IP地址及这些选项都能生效,启动ProxyDhcp时,这里设定的ip地址/子网/DNS等选项被忽略,由主Dhcp来分配,其它选项(比如Next-server)可以被分配。

  5. Boot File:启动文件,可选择files目录下的各种启动文件,默认ipxe.pxe适合BIOS/UEFI等多种启动,在有些情况下也有选择pxelinux.0等的,一般保持默认。

  6. Filename if user-class=gPXE or iPXE:选择ipxe或gpxe启动菜单文件,默认menu.ipxe,在files目录下,可以根据这个模板生成自己的菜单文件。

  7. More:更多选项(略)

  8. TFTP服务:面板上没有体现的服务,其实Tftp服务是pxe启动的根本,运行这个软件时,Tftp服务自动启动。没有tftp服务,就没有pxe在启动之初下载文件的能力,Httpd或Smb服务虽然能下载文件,但客户端pxe没有启动前是不能使用的;

    Tftp服务适合传输小文件,大文件传输太慢,旧的pxe仅基于tftp来传输,不适合安装大系统;

    检测服务启动是否成功,在命令行下运行,可以看到UDP:69端口在侦听:

    C:\Users\wzy>netstat -an | find "69"
      UDP    172.16.6.36:69         *:*
    
  9. Tftpboot目录:即Tftp服务启动的根目录,它存放pxe启动文件和菜单文件,在软件里这个目录是files目录,我们可以在files下创建各系统的子目录,但目录结构要与menu.ipxe启动菜单内核和安装包文件对应一致。

  10. 日志:在软件面板中上部,有一块区域显示日志,客户端启动时获取IP,下载文件,执行启动等都会有日志显示在上面,这里可以在出错时给我们分析排除错误很大的帮助。

iPxe启动菜单配置文件

这个菜单文件才是重点,系统提供了多个菜单文件,扩展名为.ipxe的都是,但它并非只能叫这个扩展名,.txt或者别的扩展名也是可以的,只要它是纯文件文件,符合ipxe的语法规则就可以。

具体的ipxe语法和案例可参考:https://ipxe.org/官方的文档。

我们打开一个menu.ipxe的文档来看看:

#!ipxe

#set boot-url http://${proxydhcp}/next-server
set boot-url http://${next-server}
set iscsi-server ${next-server}
set iqn iqn.2008-08.com.starwindsoftware:target1
set iscsi-target iscsi:${iscsi-server}::::${iqn}
set nfs-server ${next-server}
set cifs-server //${next-server}

# Setup some basic convenience variables
set menu-timeout 5000
set submenu-timeout ${menu-timeout}

# Ensure we have menu-default set to something
isset ${menu-default} || set menu-default exit

######## MAIN MENU ###################
:start
menu Welcome to iPXE's Boot Menu
item
item --gap -- ------------------------- Utilities ------------------------------
#item bootsan    Boot On San (${iscsi-target})
item bootaoe    Boot On AOE (e0.0)
#item iscsi	setup, sanhook or sanboot iscsi
item iscsi	Boot On San
item pxelinux    pxelinux
item grub4dos    grub4dos
item grub2    grub2
#item grub_cd		boot to dvd (via grub4dos)
#item grub_startrom		boot to startrom.0 (via grub4dos)
item grub_floppy		boot floppy (via grub4dos)
item grub_hd0		boot to hd0 (via grub4dos)
item hdt    hdt
#item netbootme	Netboot.Me
#item undi_dos    undi_dos
item disk_util Disk Utilities
item winpe Live Systemes
item linux Install Linux Distros
item --gap -- ------------------------------ Advanced ---------------------------------
item config       Configure settings
item shell      Enter iPXE shell
item reboot     Reboot
item exit       Exit (boot local disk)
choose --default exit --timeout 30000 target && goto ${target}

########## UTILITY ITEMS ####################
:shell
echo Type exit to get the back to the menu
shell
set menu-timeout 0
goto start

:failed
echo Booting failed, dropping to shell
goto shell

:reboot
reboot

:exit
exit

:cancel
echo You cancelled the menu, dropping you to a shell
 
:config
config
goto start
 
:back
set submenu-timeout 0
clear submenu-default
goto start
......

整个菜单文件篇幅太大,我们后面省略,它有一级、二级、三级等多级菜单,很多小系统工具我们平时用不上,我们能根据模板编写一级菜单就基本够用了。

ipxe语法规则:

首行:

#!ipxe

这行是必须的,就像Linux的脚本文件前面的 #!/bin/bash 一样,类似于指定命令解释程序。

除了首行#号有特殊意义,后面的#都表示注释

变量设置:

set boot-url http://${next-server}
set iscsi-server ${next-server}
set iqn iqn.2008-08.com.starwindsoftware:target1
set iscsi-target iscsi:${iscsi-server}::::${iqn}
set nfs-server ${next-server}
set cifs-server //${next-server}

# Setup some basic convenience variables
set menu-timeout 5000
set submenu-timeout ${menu-timeout}

# Ensure we have menu-default set to something
isset ${menu-default} || set menu-default exit

设置变量:一般把全局变量定义在前面,作用于下面所有启动项。

语法:set <变量名> <变量值>

$<变量名>:调用前面已经定义过的变量

${next-server}:是指调用在Tiny pxe server面板上指定的next-server值,通常我们把它指定为pxesrv本机

isset ${menu-default} || set menu-default exit:**||**表示执行前面的命令,如果前面执行结果为假,则执行后面的命令,

启动菜单设置:

案例:

1.安装windows7
2.安装windows10
3.启动再生龙系统
4.启动Debian10的系统安装

实现:

######## MAIN MENU ###################
:start
menu Welcome to iPXE's Boot Menu
item
item --gap -- ------------------------- Utilities ------------------------------
item win7        Install Windows 7
item win10       Install Windows 10
item winpe       Winpe
item clonezilla  Boot clonezilla
item debian      Install Debian 10
item --gap -- ------------------------------ Advanced ---------------------------------
item --key r reboot	[R] Reboot the Computer
item --key x exit	[X] Exit (boot local disk)
choose --default exit --timeout 60000 target && goto ${target}

:(冒号):这个冒号表示一段代码,到下一个冒号前,这段代码都是一个整体,会按照顺序执行,除非遇到goto跳转到其它冒号的代码段。

item:item [执行代码段名称] [代码段执行功能描述]

表示一个标题项,比如一个启动菜单项,一行一个标题,item和它后面的一个单词不显示,item后面第二个单词之后的会显示在屏幕上,比如item win7 Install windows 7,这行仅显示”Install windows 7“,后面要有:win7代码段,否则选择它也执行不了。

item --gap:此行用于分割一行,后面的内容显示在屏幕上,但它不能作为菜单项可选择,即调整光标时,它将跳过此行不能被选择。

item --key:item --key <快捷键字符> <执行代码段名称> [代码段执行功能描述]

item --key这行菜单可定义快捷键,即不将光标移动到此行,直接按一个快捷键就会立即执行。

choose --default: choose --default <执行代码段名称> --timeout <时间毫秒> target && goto ${target}

choose --default exit --timeout 60000 target && goto ${target},设置exit为默认选择项,可以修改成默认从硬盘启动或者重启皆可,&&表示执行前面的时间到期,就执行后面的语句。

程序代码段:

这里才是真正要执行的命令,代码段以:(冒号)开头,至下一个:(冒号)前截止,或者遇到goto跳转到其它代码段。

########## UTILITY ITEMS ####################
#执行错误返回到开始菜单项
:failed
echo Booting failed, dropping to shell
goto start

:reboot
reboot

:exit
exit

:win7
kernel ${next-server}/wimboot || goto failed
initrd ${next-server}/windows7/boot/bcd bcd || goto failed
initrd ${next-server}/windows7/boot/boot.sdi boot.sdi  || goto failed
#windows的boot.wim最好是用微软工具生成的winpe启动文件,win10的也一样,在此不赘述
initrd ${next-server}/windows7/sources/boot.wim boot.wim || goto failed
boot || goto failed
goto start

:win10
kernel ${next-server}/wimboot || goto failed
initrd ${next-server}/windows10/boot/bcd bcd || goto failed
initrd ${next-server}/windows10/boot/boot.sdi boot.sdi  || goto failed
initrd ${next-server}/windows10/sources/boot.wim boot.wim || goto failed
boot || goto failed
goto start

:winpe
sanboot --no-describe ${boot-url}/images/winpe.iso || goto failed
goto start 

:clonezilla
initrd ${boot-url}/_ISO/clonezilla/live/initrd.img || goto failed
kernel ${boot-url}/_ISO/clonezilla/live/vmlinuz boot=live config noswap nolocales edd=on nomodeset vga=788 nosplash noprompt fetch=${boot-url}/_ISO/clonezilla/live/filesystem.squashfs || goto failed
boot || goto failed
goto start

:debian
cpuid --ext 29 && set arch amd64 || set arch i386
#sanboot http://ftp.fr.debian.org/debian/dists/Debian9.1/main/installer-amd64/current/images/netboot/mini.iso
sanboot ${boot-url}/images/debian-10.7.0-amd64-netinst.iso || goto failed
boot || goto failed
goto start

上面的代码,每一个启动菜单项对应一段执行代码,每行命令执行都带了 || goto failed代码,可省略,但有它出错了它可以返回主菜单;

kernel:调用内核

initrd:调用img

sanboot:调用iso文件

以上启动过程中调用的文件,也可以调用httpd服务或者smb服务上的文件来启动,大文件不适合tftp服务来调用,速度非常慢,httpd和smb传输文件非常快,所以代码段执行的文件调用本例中我们都采用httpd路径来调取。

创建windows7/10等系统安装包存储的目录和文件

在files目录下创建,首先进入这个目录,在此用命令来创建,win的命令与linux有点类似

创建目录:

cd pxesrv\files
#创建windows7/10及其下的boot和sources子目录
#创建_ISO及其下的clonezilla子目录
mkdir windows7\boot,windows7\sources,windows10\boot,windows10\sources,_ISO\clonezilla

拷贝或解压win的启动内核文件和安装包,x为光盘驱动符号:

# windows7内核及wim安装包,加载win7的iso到x盘
copy x:\boot\bcd  pxesrv\files\windows7\boot\
copy x:\boot\boot.sdi  pxesrv\files\windows7\boot\
copy x:\sources\boot.wim  pxesrv\files\windows7\sources\

# windows10内核及wim安装包,加载win10的iso到x盘
copy x:\boot\bcd  pxesrv\files\windows10\boot\
copy x:\boot\boot.sdi  pxesrv\files\windows10\boot\
copy x:\sources\boot.wim  pxesrv\files\windows10\sources\

复制iso光盘镜像文件到指定路径,images存放iso文件:

copy e:\iso\winpe.iso pxesrv\files\images
copy e:\iso\debian-10.7.0-amd64-netinst.iso pxesrv\files\images

查下结果:

E:\pxe网络启动>tree /f pxesrv\files\windows7
├─boot
│      bcd
│      boot.sdi
│
└─sources
        boot.wim

E:\pxe网络启动>tree /f pxesrv\files\windows10
├─boot
│      bcd
│      boot.sdi
│
└─sources
        boot.wim
        
E:\pxe网络启动>tree /f pxesrv\files\images
E:\PXE网络启动\PXESRV\FILES\IMAGES
    debian-10.7.0-amd64-netinst.iso
    winpe.iso
没有子文件夹

结果目标文件与menu.ipxe的路径一致。

最终测试

  1. 启动服务端:
    在这里插入图片描述

  2. 启动客户端:
    在这里插入图片描述

  3. 客户端启动过程:

在这里插入图片描述

最后附上完整的menu.ipxe内容

#!ipxe

set boot-url http://${next-server}

# Setup some basic convenience variables
set menu-timeout 5000

# Ensure we have menu-default set to something
isset ${menu-default} || set menu-default exit

######## MAIN MENU ###################
:start
menu Welcome to iPXE's Boot Menu
item
item --gap -- ------------------------- Utilities ------------------------------
item win7        Install Windows 7
item win10       Install Windows 10
item winpe       Winpe
item clonezilla  Boot clonezilla
item debian      Install Debian 10
item --gap -- ------------------------------ Advanced ---------------------------------
item --key r reboot	[R] Reboot the Computer
item --key x exit	[X] Exit (boot local disk)
choose --default exit --timeout 60000 target && goto ${target}

########## UTILITY ITEMS ####################
:failed
echo Booting failed, dropping to shell
goto start

:reboot
reboot

:exit
exit

:win7
kernel ${next-server}/wimboot || goto failed
initrd ${next-server}/windows7/boot/bcd bcd || goto failed
initrd ${next-server}/windows7/boot/boot.sdi boot.sdi  || goto failed
#windows的boot.wim最好是用微软工具生成的winpe启动文件,win10的也一样,在此不赘述
initrd ${next-server}/windows7/sources/boot.wim boot.wim || goto failed
boot || goto failed
goto start

:win10
kernel ${next-server}/wimboot || goto failed
initrd ${next-server}/windows10/boot/bcd bcd || goto failed
initrd ${next-server}/windows10/boot/boot.sdi boot.sdi  || goto failed
initrd ${next-server}/windows10/sources/boot.wim boot.wim || goto failed
boot || goto failed
goto start

:winpe
sanboot --no-describe ${boot-url}/images/winpe.iso || goto failed
goto start 

:clonezilla
initrd ${boot-url}/_ISO/clonezilla/live/initrd.img || goto failed
kernel ${boot-url}/_ISO/clonezilla/live/vmlinuz boot=live config noswap nolocales edd=on nomodeset vga=788 nosplash noprompt fetch=${boot-url}/_ISO/clonezilla/live/filesystem.squashfs || goto failed
boot || goto failed
goto start

:debian
cpuid --ext 29 && set arch amd64 || set arch i386
#sanboot http://ftp.fr.debian.org/debian/dists/Debian9.1/main/installer-amd64/current/images/netboot/mini.iso
sanboot ${boot-url}/images/debian-10.7.0-amd64-netinst.iso || goto failed
boot || goto failed
goto start

标签:goto,failed,--,boot,Tiny,server,item,pxe
来源: https://blog.csdn.net/qq_24841037/article/details/117082305

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有