Pxe引导时DHCP配置

发布时间:2026/7/30 23:39:09
Pxe引导时DHCP配置 模版allow booting; #响应使用者查询,允许客户端通过网络引导; deny booting; 拒绝使用者查询 allow bootp; #响应bootp协议bootp是dhcp的扩展协议部分老旧设备使用bootp协议; deny bootp; 拒绝激活查询 ddns-update-style none; #禁用DNS动态更新;可以在dhcp分配ip的同时分配hostname然后向dns服务器更新记录 ping-check true; ping-timeout 3; default-lease-time {{.DHCP.LeaseTime}}; #默认租期 max-lease-time {{.DHCP.MaxLeaseTime}}; #最长租期 authoritative; #拒绝不正确的IP地址的要求 option arch code 93 unsigned integer 16; option arp-cache-timeout 240; option domain-name-servers {{.DHCP.DNSServer}}; #域名服务器 option netbios-name-servers {{.DHCP.NetBIOSServer}}; group { {{range .Banneds}} host {{.Name}} { hardware ethernet {{.Mac}}; deny booting; } {{end}} } {{range .Subnets}} ########################## {{.Subnet}} ############################# subnet {{.Subnet}} netmask {{.Netmask}} { pool { option routers {{.Routers}}; #默认网关 range {{.RangeStart}} {{.RangeEnd}}; #地址池 #deny unknown-clients; #是否动态分配IP给未知的使用者, allow unknown-clients; group { {{range .Banneds}} host {{.Name}} { hardware ethernet {{.Mac}}; deny booting; } {{end}} } group { {{ $pEFIFile : .EFIFile }} {{ $pARMFile : .ARMFile }} {{ $pBIOSFile : .BIOSFile }} {{ $pNextServer : .NextServer}} {{range .Hosts}} host {{.Name}} { hardware ethernet {{.Mac}}; Fixed-address {{.IP}}; {{if .Gateway}} option routers {{.Gateway}}; {{end}} {{if .Netmask}} option subnet-mask {{.Netmask}}; {{end}} {{if eq .DenyBootp 0}} {{if .NextServer}} next-server {{.NextServer}}; #tftp服务器地址 {{else}} next-server {{$pNextServer}}; #tftp服务器地址 {{end}} if option arch 00:07 or option arch 00:09 { {{if .EFIFile}} filename {{.EFIFile}}; #efi引导文件 {{else}} filename {{$pEFIFile}}; #efi引导文件 {{end}} } else if option arch 00:0b or option arch 00:27 { {{if .ARMFile}} filename {{.ARMFile}}; #arm引导文件 {{else}} filename {{$pARMFile}}; #arm引导文件 {{end}} } else { {{if .BIOSFile}} filename {{.BIOSFile}}; #legacy引导文件 {{else}} filename {{$pBIOSFile}}; #legacy引导文件 {{end}} } {{end}} } {{range .DenyMacs}} host {{. | MacConvert}} { hardware ethernet {{.}}; deny booting; } {{end}} {{end}} } #end group } #end pool } #end subnet {{end}}参考值########################## 10.131.192.0 ############################# subnet 10.131.192.0 netmask 255.255.240.0 { pool { option routers 10.131.192.1; #默认网关 range 10.131.204.0 10.131.207.250; #地址池 allow unknown-clients; group { host 0050568ee78d { hardware ethernet 00:50:56:8e:e7:8d; deny booting; } host 005056b232c9 { hardware ethernet 00:50:56:b2:32:c9; Fixed-address 10.131.202.62; next-server 10.131.128.216; #tftp服务器地址 if option arch 00:07 or option arch 00:09 { filename grub/grubx64.efi; #efi引导文件 } else if option arch 00:0b or option arch 00:27 { filename ; #arm引导文件 } else { filename pxelinux.bios; #legacy引导文件 } } } } }再生龙pxe配置默认密码user/iloveclonezilla# Created by generate-pxe-menu! Do NOT edit unless you know what you are doing! # Keep those comment MENU DEFAULT and MENU HIDE! Do NOT remove them. # Note!!! If serial directive exists, it must be the first directive timeout 300 prompt 0 noescape 1 MENU MARGIN 5 # MENU MASTER PASSWD say ********************************************************************** say Clonezilla, the OpenSource Clone System. say THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK! say ********************************************************************** # Allow client to edit the parameters ALLOWOPTIONS 1 # simple menu title MENU TITLE clonezilla.org default Clonezilla # Since no network setting in the squashfs image, therefore if ip, the network # is disabled. Thats what we want. {{ $pInitrd : grub/initrd_amd64.img }} {{if eq .Proto http}} {{ $pInitrd printf http://%s/grub/initrd_amd64.img .NFS }} {{end}} label Clonezilla # MENU HIDE # MENU PASSWD # ip{{.MgtNic}}:{{.IP}}:{{.Netmask}}:{{.Gateway}} kernel {{.Kernel}} initrd {{$pInitrd}} append bootlive unionoverlay config components quiet noswap eddon nomodeset enforcing0 locales keyboard-layoutsNone ocs_live_runocs-live-general ocs_live_extra_param net.ifnames0 nosplash vmwgfx.enable_fbdev1 ocs_daemononssh fetch{{.Stage2}}/live/filesystem.squashfs usernameuser usercryptedKb/VNchPYhuf6 debug BOOTIF{{.Mac}} nicif{{.Mac}} ocs_netlink_timeout50 ip:{{.IP}}:{{.Netmask}}:{{.Gateway}}再生龙UEFI配置set default0 set timeout5 {{ $pKernel : .Kernel }} {{ $pInitrd : grub/initrd_amd64.img }} {{if eq .Proto http}} {{ $pKernel printf (http,%s)/%s/%s .NFS .PkgPath .OriginKernel }} {{ $pInitrd printf (http,%s)/grub/initrd_amd64.img .NFS }} insmod http {{end}} menuentry Clonezilla{ linux {{$pKernel}} bootlive unionoverlay config components quiet noswap eddon nomodeset enforcing0 locales keyboard-layoutsNone ocs_live_runocs-live-general ocs_live_extra_param net.ifnames0 nosplash vmwgfx.enable_fbdev1 ocs_daemononssh fetch{{.Stage2}}/live/filesystem.squashfs debug inst.sshd1 BOOTIF{{.Mac}} nicif{{.Mac}} ocs_netlink_timeout50 usernameuser usercryptedKb/VNchPYhuf6 ip:{{.IP}}:{{.Netmask}}:{{.Gateway}} initrd {{$pInitrd}} }再生龙ARM引导配置# set pref(tftp){{.PkgPath}}/boot/grub set default0 set timeout5 if loadfont $pref/unicode.pf2; then set gfxmodeauto insmod gfxterm # Set the language for boot menu prompt, e.g., en_US, zh_TW... set langen_US terminal_output gfxterm fi set hidden_timeout_quietfalse insmod png if background_image $pref/ocswp-grub2.png; then set color_normalblack/black set color_highlightmagenta/black else set color_normalcyan/blue set color_highlightwhite/blue fi set linux_cmdlinux set initrd_cmdinitrd export linux_cmd initrd_cmd if [ ${grub_platform} efi -a -e /amd64-release.txt ]; then # Only amd64 release we switch to linuxefi/initrdefi since it works better with security boot (shim) set linux_cmdlinuxefi set initrd_cmdinitrdefi fi insmod play play 960 440 1 0 4 440 1 {{ $pKernel : .Kernel }} {{ $pInitrd : grub/initrd_arm64.img }} {{if eq .Proto http}} {{ $pKernel printf (http,%s)/%s/%s .NFS .PkgPath .OriginKernel }} {{ $pInitrd printf (http,%s)/grub/initrd_arm64.img .NFS }} insmod http {{end}} # Since no network setting in the squashfs image, therefore if ip, the network is disabled. menuentry Clonezilla { $linux_cmd {{$pKernel}} bootlive unionoverlay config components quiet noswap eddon nomodeset enforcing0 localesen_US.UTF-8 keyboard-layoutsen ocs_live_runocs-live-general ocs_live_extra_param net.ifnames0 nosplash i915.blacklistyes radeonhd.blacklistyes nouveau.blacklistyes vmwgfx.enable_fbdev1 ocs_daemononssh fetch{{.Stage2}}/live/filesystem.squashfs debug inst.sshd1 BOOTIF{{.Mac}} nicif{{.Mac}} usernameuser usercryptedKb/VNchPYhuf6 ip:{{.IP}}:{{.Netmask}}:{{.Gateway}} $initrd_cmd {{$pInitrd}} }再生龙grub相关参数说明grub.cfg 参数Clonezilla Live的grub.cfg配置文件中的这一长串参数是在启动时传递给内核的引导参数用于控制Clonezilla Live的启动行为和系统配置。下面是每个参数的含义bootlive指示系统以Live模式启动这是Clonezilla特有的参数用于启动一个完整的操作系统而不是仅仅启动到安装或恢复模式。unionoverlay使用overlay文件系统这允许系统在内存中进行写操作而不会影响到启动媒体上的文件。config这个参数通常用于Debian Live系统它会使得启动过程中尝试从可移动媒体加载配置文件。components这个参数也是Debian Live系统特有的它会启用所有的live组件。quiet减少启动时的消息输出使得启动过程更加干净不显示详细的启动信息。noswap禁用交换分区这在Live系统中是常见的因为通常不希望Live系统使用硬盘上的交换分区。eddon启用增强型磁盘驱动Enhanced Disk Drive支持这有助于某些旧的BIOS系统更好地识别硬盘。nomodeset禁用内核模式设置KMS这可以解决某些显卡在启动时的兼容性问题。enforcing0这个参数通常与SELinux安全模块有关设置为0表示SELinux将以宽容模式运行而不是强制模式。ocs_live_batchno这是Clonezilla特有的参数设置为no表示在克隆过程中不使用批处理模式即会有交互式提示。vga788设置VGA模式为特定的分辨率788对应于640x480的分辨率。ip这个参数后面通常跟着网络配置信息如果为空表示不进行特定的网络配置。net.ifnames0禁用网络接口的预测性名称规则使得网络接口名称使用传统的eth0, eth1等。nosplash不显示启动画面。i915.blacklistyes禁用Intel i915显卡驱动。radeonhd.blacklistyes禁用radeonhd显卡驱动。nouveau.blacklistyes禁用nouveauNVIDIA开源驱动显卡驱动。vmwgfx.enable_fbdev1启用vmwgfx的fbdev后端这对于在某些虚拟机环境中使用VMware的显卡驱动是有用的。再生龙使用sudo sshfs root10.131.137.30:/root/images /home/partimag #需要输入密码sshfs -o ssh_commandsshpass -p Admin!23 ssh root10.131.137.30:/root/images /root/test或sudo mount -t nfs 10.131.137.30:/root/images /home/partimag #nfs未设置密码此处也无需密码备份磁盘sudo /usr/sbin/ocs-sr -q2 -c -j2 -z1p -i 4096 -fsck-y -senc -p choose -batch savedisk image_dir_01 sda #会自动检测原文件系统是否损坏自动执行fscksudo /usr/sbin/ocs-sr -q2 -c -j2 -z1p -i 4096 -sfsck -senc -p choose -batch savedisk image_dir_01 sda #不自动修复源文件系统sudo /usr/sbin/ocs-sr -q2 -j2 -z1p -i 4096 -sfsck -senc -p choose savedisk image_dir_01 sda #去掉了-c不需要确认不需要交互sudo /usr/sbin/ocs-sr -q2 -j2 -z1p -i 4096 -fsck-y -senc -nogui -p command savedisk image_dir_01 sda #不显示界面只在终端输出过程和日志恢复磁盘sudo /usr/sbin/ocs-sr -g auto -e1 auto -e2 -r -j2 -nogui -p command restoredisk image_dir_02 sda命令参数参考:https://gist.github.com/gotbletu/630478ddf5b4e6ad6abd1a8b23918830再生龙ISO启动时的调用链路init -- /scripts/live -- /lib/live/boot/9990-main.sh其中. /scripts/local. /scripts/nfs. /scripts/${BOOT}BOOT是内核参数bootlive/scripts/live里面的函数会覆盖掉前面的:mount_topmount_premountmountrootmount_bottom关键在于mountroot -- LiveLive存在于/lib/live/boot/9990-main.sh中其中下载FETCH(filesystem.squashfs)的代码调用路径9990-main.sh:main -- 9990-netboots.sh:do_netmount解压再生龙initrd.img:mkdir initrdcd initrdxzcat ../initrd.img | cpio -idmv #gzip格式的用gzip -dc ../initrd.img | cpio -idmv打包再生龙initrd.imgfind . | cpio -o -H newc | xz -C crc32 ../initrd.imgfind . | cpio -o -H newc initrd.img # 生成未压缩镜像find . | cpio -o -H newc | gzip -9 initrd.img # Gzip 高压缩比# 或find . | cpio -o -H newc | lz4 -l -9 initrd.img # LZ4 高速解压​​压缩格式​​ 内核配置项​​ 典型场景​​未压缩 无需特殊配置 调试或极小体积镜像Gzip CONFIG_RD_GZIP 兼容性最佳广泛使用LZ4 CONFIG_RD_LZ4 高速解压嵌入式设备优化Zstd CONFIG_RD_ZSTD 高压缩率与解压速度平衡XZ/LZMA CONFIG_RD_XZ 高压缩比场景较少用​​压缩算法选择优先级​​根据硬件特性选择算法参考 Ubuntu 测试数据​​x86/ARM 通用设备​​ → LZ4解压速度最快​​存储空间受限场景​​ → Zstd高压缩率与速度平衡​​传统兼容性要求​​ → Gzip最广泛支持再生龙备份系统盘命令mkdir -p /home/partimag/${tmpdir} /usr/sbin/ocs-sr -q2 -j2 -z1p -i 4096 -fsck-y -senc -nogui -p true -b savedisk ${tmpdir}/image_dir ${destdev} ${LOGFILE} 21再生龙恢复系统盘命令/usr/sbin/ocs-sr -e1 auto -e2 -r -j2 -nogui -p true -b restoredisk ${tmpdir}/image_dir ${destdev} ${LOGFILE} 21 #或者 /usr/sbin/ocs-sr -g auto -e1 auto -e2 -r -j2 -nogui -p true -b restoredisk ${tmpdir}/image_dir ${destdev} ${LOGFILE} 21

相关新闻