From f232a9316a0ebb281af1f9d8e0d261fcca658c24 Mon Sep 17 00:00:00 2001 From: kelvin Date: Thu, 21 Dec 2023 02:04:31 +0800 Subject: add pxe files --- .../commands/pxelinux/build/cdpxe/__init__.py | 230 +++++++-------------- 1 file changed, 77 insertions(+), 153 deletions(-) (limited to 'lib') diff --git a/lib/sunhpc/commands/pxelinux/build/cdpxe/__init__.py b/lib/sunhpc/commands/pxelinux/build/cdpxe/__init__.py index e409e0a..7ba45e0 100644 --- a/lib/sunhpc/commands/pxelinux/build/cdpxe/__init__.py +++ b/lib/sunhpc/commands/pxelinux/build/cdpxe/__init__.py @@ -10,6 +10,14 @@ class Command(sunhpc.commands.pxelinux.build.command): """ Build the iso pxe (dhcpd, tftpd, httpd service for the sunhpc cluster. + 1) config interface(e,g.. eth0/eth1) ip address + 2) source /opt/sunhpc/etc/env.sunhpc + 3) git clone https://gitee.com/qcsun/sunhpc.git + 4) git clone https://gitee.com/qcsun/tools.git + 5) rpm -ivh tools/sunhpc-python-3.12.0-1.el8.x86_64.rpm + 6) sunhpc pxelinux build Rocky-8.7-x86_64-dvd1.iso + 7) sunhpc pxelinux build cdpxe dev=eth1 repo=/export/sunhpc/install/repos/Rocky/8/x86_64 + Whether to output detailed information, default: no @@ -27,14 +35,14 @@ class Command(sunhpc.commands.pxelinux.build.command): - supply an boot mode, mbr or uefi. Default: UEFI + supply an boot mode, mbr or uefi. Default: MBR In local build the iso pxe dhcpd, tftpd, httpd services. - + Build the iso pxe dhcpd, tftpd, httpd service. """ @@ -71,70 +79,6 @@ class Command(sunhpc.commands.pxelinux.build.command): if owner: os.system('chown %s %s' % (owner, dst)) - def writeKSRepos(self, ksdirs, httpd_repos, rpath, addr): - if not os.path.exists(ksdirs): - os.makedirs(ksdirs) - - if not os.path.islink(httpd_repos): - os.symlink(rpath, httpd_repos) - - rootpw = '$6$eT.sWNwV69wyvhaR$N5tY4rJn6Y2slOrwuejfUBq3MhC5SNe1gUfTSYmOACObwW4ckUK9fjkKwC9TgSPhwwlaGdbtn0EFg11TJmAbC1' - usernm = 'admin' - userpw = '$6$0WN9CulSREVORA0S$FVWh6tkvdncbmSrsNPEb13GwxnGnEOKZliZLdL2IdY5E/fzLB8QmZAmgxyHh6ElSjObUCTbDEJ0l9.wRCRrsU.' - - bpacks, baddon, banaconda, bender = '%packages', '%addon', '%anaconda', '%end' - ksfile = os.path.join(ksdirs, 'kickstart.conf') - with open(ksfile, 'w') as f: - f.write(textwrap.dedent("""\ - #version=RHEL8 - # Use graphical install - graphical - - %s - @^graphical-server-environment - @container-management - @development - @graphical-admin-tools - @headless-management - @infiniband - @legacy-unix - @network-file-system-client - @performance - @remote-desktop-clients - @remote-system-management - @rpm-development-tools - @system-tools - @web-server - %s - - keyboard --xlayouts='us' - lang en_US.UTF-8 - firstboot --enable - timezone Asia/Shanghai --isUtc --nontp - - network --bootproto=dhcp --onboot=on --ipv6=auto - network --hostname=compute.local - clearpart --all --initlabel - autopart --type=lvm - - repo --name="AppStream" --baseurl=http://%s/redhat/AppStream - repo --name="BaseOS" --baseurl=http://%s/redhat/BaseOS - - rootpw --iscrypted %s - user --name=%s --password=%s --iscrypted --gecos="%s" - - %s com_redhat_kdump --disable --reserve-mb='auto' - %s - - %s - pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty - pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok - pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty - %s - """ % (bpacks, bender, addr, addr, rootpw, usernm, userpw, usernm, baddon, bender, banaconda, bender))) - - os.system('chmod 777 %s' % ksfile) - def run(self, params, args): (quiet, pxedir, dev, rpath, boot) = self.fillParams([ @@ -142,9 +86,8 @@ class Command(sunhpc.commands.pxelinux.build.command): ('pxedir', '/tftpboot/pxelinux'), ('dev', None), ('repo', ''), - ('boot', 'uefi') + ('boot', 'mbr') ]) - q = self.str2bool(quiet) if dev is None: @@ -168,15 +111,40 @@ class Command(sunhpc.commands.pxelinux.build.command): self.installHttpd(dev, rpath, address, q) # off selinux - os.system('sed -i "s/SELINUX=enforcing/SELINUX=disabled/ /etc/selinux/config"') + os.system('sed -i "s/^SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config') def installHttpd(self, devices, rpath, address, q): self.msg('Starting build the httpd service...', q=q) - rootdir = '/var/www/html' - ksdirs = os.path.join(rootdir, 'ks') - httpd_repos = os.path.join(rootdir, 'redhat') - self.writeKSRepos(ksdirs, httpd_repos, rpath, address) + webdir = '/var/www/html' + ksdirs = os.path.join(webdir, 'ksfile') + redhat = os.path.join(webdir, 'redhat') + repos = os.path.join(redhat, 'r8') + + if not os.path.exists(ksdirs): + os.makedirs(ksdirs) + + if not os.path.exists(redhat): + os.makedirs(redhat) + + if not os.path.islink(repos): + os.symlink(rpath, repos) + + shared = '/opt/sunhpc/share/pxeboot/kickstart' + ksfile = os.listdir(shared) + for i in ksfile: + if i.startswith('r8_min.conf'): + self.msg('Copying to %s - %s' % (ksdirs, i), q=q) + self.copyit(os.path.join(shared, i), os.path.join(ksdirs, i), 0o755, '0.0') + if i.startswith('r8_gui.conf'): + self.msg('Copying to %s - %s' % (ksdirs, i), q=q) + self.copyit(os.path.join(shared, i), os.path.join(ksdirs, i), 0o755, '0.0') + + if not os.path.exists(os.path.join(ksdirs, i)): + continue + + # replace ip address for kickstart config file. + os.system('sed -i "s/ipaddress/%s/g" %s' % (address, os.path.join(ksdirs, i))) sunhpc_httpd_config = '/etc/httpd/conf.d/ks-sunhpc.conf' if not os.path.exists(sunhpc_httpd_config): @@ -205,7 +173,7 @@ class Command(sunhpc.commands.pxelinux.build.command): Require all granted - """ % (address, rootdir, ksdirs, httpd_repos))) + """ % (address, webdir, ksdirs, repos))) self.fw.addports(['80', '443'], ['tcp']) self.fw.addservice('http') @@ -226,8 +194,16 @@ class Command(sunhpc.commands.pxelinux.build.command): cmds += '--disablerepo=* --enablerepo=sunhpc-appstream,sunhpc-baseos' self.shcmd(cmds) + # pxedir: /tftpboot/pxelinux + c7 = os.path.join(pxedir, 'c7') + r8 = os.path.join(pxedir, 'r8') + r9 = os.path.join(pxedir, 'r9') + pd = os.path.join(pxedir, 'pxelinux.cfg') if not os.path.exists(pxedir): - os.makedirs(pxedir) + os.makedirs(c7) + os.makedirs(r8) + os.makedirs(r9) + os.makedirs(pd) self.fw.addports(['69'], ['udp']) self.fw.addservice('tftp') @@ -272,13 +248,14 @@ class Command(sunhpc.commands.pxelinux.build.command): os.system('systemctl daemon-reload') os.system('systemctl restart tftp.service') - # # copy uefi boot file # BaseOS/Packages/s/shim-x64-15.6-1.el8.x86_64.rpm # BaseOS/Packages/g/grub2-efi-x64-2.02-142.el8.rocky.0.2.x86_64.rpm + # /usr/share/syslinux/{pxelinux.0, menu.c32} + # isolinux/{ldlinux.c32, libcom32.c32, libutil.c32} # decompress: rpm2cpio xxx-xxx-xxx.rpm |cpio -dim - # boot/efi/EFI/BOOT/BOOTX64.EFI + # boot/efi/EFI/BOOT/shimx64.efi # boot/efi/EFI/rocky/grubx64.efi # share = '/opt/sunhpc/share/pxeboot' @@ -287,85 +264,44 @@ class Command(sunhpc.commands.pxelinux.build.command): pxefile = os.listdir(share) + os.listdir(repos) for i in pxefile: if i.startswith('initrd.img'): - self.msg('Copying to %s - %s' % (pxedir, i), q=q) - self.copyit(os.path.join(repos, i), os.path.join(pxedir, i), 0o755, '0.0') - + self.msg('Copying to %s - %s' % (r8, i), q=q) + self.copyit(os.path.join(repos, i), os.path.join(r8, i), 0o755, '0.0') if i.startswith('vmlinuz'): - self.msg('Copying to %s - %s' % (pxedir, i), q=q) - self.copyit(os.path.join(repos, i), os.path.join(pxedir, i), 0o755, '0.0') + self.msg('Copying to %s - %s' % (r8, i), q=q) + self.copyit(os.path.join(repos, i), os.path.join(r8, i), 0o755, '0.0') - if i.startswith('memtest'): + if i.startswith('grubx64.efi'): self.msg('Copying to %s - %s' % (pxedir, i), q=q) - self.copyit(os.path.join(repos, i), os.path.join(pxedir, i), 0o755, '0.0') - - if i.startswith('BOOTX64.EFI'): + self.copyit(os.path.join(share, i), os.path.join(pxedir, i), 0o644, '0.0') + if i.startswith('ldlinux.c32'): self.msg('Copying to %s - %s' % (pxedir, i), q=q) self.copyit(os.path.join(share, i), os.path.join(pxedir, i), 0o644, '0.0') - - if i.startswith('grubx64.efi'): + if i.startswith('libcom32.c32'): self.msg('Copying to %s - %s' % (pxedir, i), q=q) self.copyit(os.path.join(share, i), os.path.join(pxedir, i), 0o644, '0.0') - - if i.startswith('pxelinux.0'): + if i.startswith('libutil.c32'): self.msg('Copying to %s - %s' % (pxedir, i), q=q) self.copyit(os.path.join(share, i), os.path.join(pxedir, i), 0o644, '0.0') - - if i.startswith('ldlinux.c32'): + if i.startswith('menu.c32'): self.msg('Copying to %s - %s' % (pxedir, i), q=q) self.copyit(os.path.join(share, i), os.path.join(pxedir, i), 0o644, '0.0') - - if i.startswith('lpxelinux.0'): + if i.startswith('pxelinux.0'): self.msg('Copying to %s - %s' % (pxedir, i), q=q) self.copyit(os.path.join(share, i), os.path.join(pxedir, i), 0o644, '0.0') - - if i.startswith('gpxelinux.0'): + if i.startswith('shimx64.efi'): + self.msg('Copying to %s - %s' % (pxedir, i), q=q) + self.copyit(os.path.join(share, i), os.path.join(pxedir, i), 0o644, '0.0') + if i.startswith('vesamenu.c32'): self.msg('Copying to %s - %s' % (pxedir, i), q=q) self.copyit(os.path.join(share, i), os.path.join(pxedir, i), 0o644, '0.0') - self.writeBootCFG(pxedir, boot, address, q) + if i.startswith('default'): + self.msg('Copying to %s - %s' % (pd, i), q=q) + self.copyit(os.path.join(share, i), os.path.join(pd, i), 0o644, '0.0') - def writeBootCFG(self, pxedirs, boot, address, q): - - # pxedirs : /tftpboot/pxelinux - # boot : mbr + # replace ip address for pxelinux.cfg/default + os.system('sed -i "s/ipaddress/%s/g" %s' % (address, os.path.join(pd, 'default'))) - ksfile = 'http://%s/ks/kickstart.conf' % address - images = 'http://%s/redhat/image/' % address - pxedir = os.path.join(pxedirs, 'pxelinux.cfg') - if not os.path.exists(pxedir): - os.makedirs(pxedir) - - if boot.lower() in ['mbr']: - - default = os.path.join(pxedir, 'default') - self.msg('Configure pxelinux pxe boot file to %s ' % (default), q=q) - with open(default, 'w') as f: - f.write(textwrap.dedent("""\ - # - # Generated by sunhpc pxelinux build tftpd - # - default sunhpc - prompt 0 - label sunhpc - kernel vmlinuz - append initrd=initrd.img inst.ks=%s inst.stage2=%s quiet net.ifnames=0 - """ % (ksfile, images))) - os.chmod(default, 0o0664) - os.system('chown root.apache %s' % default) - else: - - default = os.path.join(pxedirs, 'grub.cfg') - with open(default, 'w') as f: - f.write(textwrap.dedent("""\ - # - # the file generate by sunhpc - # - set timeout = 30 - menuentry 'Install Rocky 8' { - initrdefi pxelinux/initrd.img - linuxefi pxelinux/vmlinuz inst.ks=%s inst.stage2=%s quiet net.ifnames=0 - } - """ % (ksfile, images))) def installDhcpd(self, devices, boot, address, q): self.msg('Starting build the dhcpd service...', q=q) @@ -409,22 +345,10 @@ class Command(sunhpc.commands.pxelinux.build.command): class "pxeclients" { match if substring (option vendor-class-identifier, 0, 9) = "PXEClient"; next-server %s; - - if exists user-class and option user-class = "iPXE" { - filename "ipxe_after/index.ipxe"; + if option arch-type = 00:07 { + filename "shimx64.efi"; } else { - if option arch-type = 00:00 { - # 0x00 0x00 x86 BIOS - filename "pxelinux.0"; - } else if option arch-type = 00:06 { - # 0x00 0x06 x86 UEFI - filename "BOOTX86.EFI"; - } else if option arch-type = 00:07 { - # 0x00 0x07 x64 UEFI - filename "BOOTX64.EFI"; - } else { - filename "pxelinux.0"; - } + filename "pxelinux.0"; } } } -- cgit v1.2.3