欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

PyPXE 快速安装操作系统(超薄型)

最编程 2024-03-31 07:56:37
...
【直播预告】国产数据库,一半都是花架子?”

写在前面

遥想10年前,第一次接触pxe,当时用过2种方式:
第1种是通过wds安装;第2种是通过网络ghost
以上两种方式,只能用来安装windows。
后来公司要部署5000台fedora替换windows,于是又发现了 再升龙 ,打包fedora后,网络部署,解决了大问题。
时间来到了2021年,github闲逛时,发现了两款python pxe模块 PyPXEnetboot.xyz ,于是又开始了折腾。

操作环境

  1. 一台安装了 python 3.9 的电脑(本机 192.168.1.5),操作系统不限
  2. 一台需要安装操作系统的电脑
  3. 没了

网络架构

  1. 由于 netboot.xyz 需要下载操作系统镜像iso,因此需要外网访问权限
  2. 将“待安装操作系统的电脑” 接入现有dhcp网络,不用担心 PyPXE 的dhcp冲突,可以通过 --dhcp-proxy 功能避免

注意事项

笔者写这篇文章的时候,该模块还有一个 bug,需要在安装后手动修复:
python/lib/python3.7/site-packages/pypxe/tftp.py 131行

response += str(self.blksize) + b'\x00'

修改为

response += str(self.blksize).encode('ascii') + b'\x00'

下载组件

  1. 安装 PyPXE
pip install PyPXE
  1. 下载PyPXE源码,主要用到netboot 目录
git clone https://github.com/pypxe/PyPXE.git
cd PyPXE
  1. 下载 netboot.xyz
    3.1 在 netboot.xyz github页面,下载Bootloader,我们需要用到的是 netboot.xyz.kpxe
cd PyPXE
wget https://boot.netboot.xyz/ipxe/netboot.xyz.kpxe
cp netboot.xyz.kpxe netboot

一条命令部署操作系统

python -m pypxe.server --dhcp-proxy --netboot-file="netboot.xyz.kpxe"  --ipxe --dhcp-server-ip="192.168.1.5" --tftp-server-ip="192.168.1.5" --dhcp-fileserver="192.168.1.5" --debug all

待安装系统电脑

通过pxe启动,选择需要安装的操作系统。