如何通过 pxe boot 执行 bash 脚本

如何通过 pxe boot 执行 bash 脚本

有人能告诉我如何通过 pxe 启动执行 bash 脚本吗?我想做的是,当 Raw Server 启动时,我想通过 PXE 启动将克隆的映像部署到硬盘上。我知道有一些工具(如 Fog)可以做类似的事情。但我正尝试通过 dd 作为大学项目的一部分来做到这一点。任何帮助都值得感激。

编辑:

I followed following procedure.
1. Copied vmlinuz and initrd to tftp directory
2. Unpacked initrd (Using https://www.novell.com/documentation/zenworks7/dm7admin/data/b2cdjzb.html)

3. Added following lines in init script

echo "Deploying image of an ESXi Hypervisor"
echo "Downloading image"
wget http://192.168.1.250/backup/esxi -O /bin/esxi
echo "Deploying image"
sudo dd if=~/bin/esxi of=/dev/rdisk2 bs=1m
echo "Process Complete"

4. Repacked initrd

5. Added both files initrd and vmlinuz under boot folder /tftpboot/boot

6. Added following lines in pxe default file

label VMware ESXi (Last Backup 1)
        KERNEL boot/vmlinuz
        APPEND initrd=boot/initrd 
But it still gives error "mountinng /sys on /root/sys failed"

我在这里遗漏了什么?

答案1

从任何支持 PXE 的发行版(例如 Ubuntu)获取内核和 initrd.gz。每个 initrd 都有一个init脚本,通常用于加载网络驱动程序、映射磁盘等。您可以创建一个补充的 initrd 并重新定义init添加您的代码。当您使用 pxeboot 客户端(例如 pxelinux)时,您可以连续加载两个 initrd,并用逗号分隔。第二个 initrd 的内容将覆盖原始 initrd 中的内容。此方法有几个优点:您不需要接触原始 initrd。组装辅助 initrd 很容易/很快,因为它是一个非常小的文件,等等。

编辑:

init 通常是一个调用多个模块的复杂脚本。正如我之前所说,它会加载网络驱动程序、映射磁盘等等。为了通过 PXE 启动您的内核/initrd 集,您肯定需要在行中传递其他参数append;请参阅如何塞瓦PXE 启动/安装多个 Linux 发行版(您可以从那里获取必要的参数)。请考虑 initrd 最终可能会显示特定的安装菜单或类似的东西;您必须遵循 init 的代码并在发生这种情况之前插入“您的”代码。此任务需要对 Bash 和 Linux 有很好的了解。请不要指望 5 分钟就能完成。

答案2

这是制作自定义可启动 Live CD 的演练,理论上您可以构建它来执行任何您想做的事情。

这将允许您创建一个可启动并执行您需要的操作的环境。

http://ubuntuforums.org/showthread.php?t=688872

然后您只需从 pxe 服务器启动该 iso。

https://help.ubuntu.com/community/PXEInstallServer

我只列出 ubuntu 作为操作系统,因为它有详尽的文档记录。

祝你好运!

相关内容