From 3cb359e71141fb58a8dde011d50e4e9026d96326 Mon Sep 17 00:00:00 2001 From: Daniel Hilst Selli <392820+dhilst@users.noreply.github.com> Date: Wed, 26 Nov 2025 16:07:19 -0300 Subject: [PATCH] feat: Add support for RHEL 10 Signed-off-by: Daniel Hilst Selli <392820+dhilst@users.noreply.github.com> --- makerpm | 2 +- xCAT-server/lib/xcat/plugins/ddns.pm | 15 +- .../xcat/install/rh/compute.rhels10.pkglist | 13 + .../xcat/install/rh/compute.rhels10.tmpl | 53 ++ .../install/rocky/compute.rocky10.pkglist | 1 + .../xcat/install/rocky/compute.rocky10.tmpl | 1 + .../install/rocky/service.rocky10.pkglist | 1 + .../xcat/install/rocky/service.rocky10.tmpl | 1 + .../service.rocky10.x86_64.otherpkgs.pkglist | 1 + .../xcat/install/scripts/compute.rhels10.tmpl | 53 ++ .../xcat/install/scripts/getinstdisk.rhels10 | 251 ++++++++++ .../share/xcat/install/scripts/post.rhels10 | 23 + .../xcat/install/scripts/post.xcat.rhels10 | 453 ++++++++++++++++++ .../share/xcat/install/scripts/pre.rhels10 | 327 +++++++++++++ .../netboot/rh/compute.rhels10.x86_64.pkglist | 31 ++ .../dracut_105/patch/syslog/module-setup.sh | 41 ++ .../dracut_105/patch/syslog/rsyslogd-start.sh | 56 +++ .../patch/syslog/syslog-genrules.sh | 97 ++++ .../rh/dracut_105/stateless/installkernel | 2 + .../rh/dracut_105/stateless/module-setup.sh | 37 ++ .../rh/dracut_105/stateless/xcat-cmdline.sh | 5 + .../rh/dracut_105/stateless/xcat-updateflag | 40 ++ .../netboot/rh/dracut_105/stateless/xcatroot | 385 +++++++++++++++ .../rh/dracut_105/statelite/installkernel | 2 + .../rh/dracut_105/statelite/module-setup.sh | 38 ++ .../rh/dracut_105/statelite/xcat-cmdline.sh | 4 + .../rh/dracut_105/statelite/xcat-premount.sh | 24 + .../rh/dracut_105/statelite/xcat-prepivot.sh | 202 ++++++++ .../rh/dracut_105/statelite/xcat-updateflag | 40 ++ .../netboot/rh/dracut_105/statelite/xcatroot | 385 +++++++++++++++ xCAT-server/share/xcat/netboot/rh/genimage | 237 ++++++--- .../rocky/compute.rocky10.x86_64.exlist | 1 + .../rocky/compute.rocky10.x86_64.pkglist | 1 + .../rocky/compute.rocky10.x86_64.postinstall | 1 + .../share/xcat/netboot/rocky/dracut_105 | 1 + .../rocky/service.rocky10.x86_64.exlist | 1 + .../service.rocky10.x86_64.otherpkgs.pkglist | 1 + .../rocky/service.rocky10.x86_64.pkglist | 1 + .../rocky/service.rocky10.x86_64.postinstall | 1 + 39 files changed, 2748 insertions(+), 81 deletions(-) create mode 100644 xCAT-server/share/xcat/install/rh/compute.rhels10.pkglist create mode 100644 xCAT-server/share/xcat/install/rh/compute.rhels10.tmpl create mode 120000 xCAT-server/share/xcat/install/rocky/compute.rocky10.pkglist create mode 120000 xCAT-server/share/xcat/install/rocky/compute.rocky10.tmpl create mode 120000 xCAT-server/share/xcat/install/rocky/service.rocky10.pkglist create mode 120000 xCAT-server/share/xcat/install/rocky/service.rocky10.tmpl create mode 120000 xCAT-server/share/xcat/install/rocky/service.rocky10.x86_64.otherpkgs.pkglist create mode 100644 xCAT-server/share/xcat/install/scripts/compute.rhels10.tmpl create mode 100644 xCAT-server/share/xcat/install/scripts/getinstdisk.rhels10 create mode 100644 xCAT-server/share/xcat/install/scripts/post.rhels10 create mode 100644 xCAT-server/share/xcat/install/scripts/post.xcat.rhels10 create mode 100644 xCAT-server/share/xcat/install/scripts/pre.rhels10 create mode 100644 xCAT-server/share/xcat/netboot/rh/compute.rhels10.x86_64.pkglist create mode 100755 xCAT-server/share/xcat/netboot/rh/dracut_105/patch/syslog/module-setup.sh create mode 100755 xCAT-server/share/xcat/netboot/rh/dracut_105/patch/syslog/rsyslogd-start.sh create mode 100755 xCAT-server/share/xcat/netboot/rh/dracut_105/patch/syslog/syslog-genrules.sh create mode 100755 xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/installkernel create mode 100644 xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/module-setup.sh create mode 100644 xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcat-cmdline.sh create mode 100755 xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcat-updateflag create mode 100755 xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcatroot create mode 100755 xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/installkernel create mode 100644 xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/module-setup.sh create mode 100644 xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-cmdline.sh create mode 100644 xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-premount.sh create mode 100755 xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-prepivot.sh create mode 100755 xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-updateflag create mode 100755 xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcatroot create mode 120000 xCAT-server/share/xcat/netboot/rocky/compute.rocky10.x86_64.exlist create mode 120000 xCAT-server/share/xcat/netboot/rocky/compute.rocky10.x86_64.pkglist create mode 120000 xCAT-server/share/xcat/netboot/rocky/compute.rocky10.x86_64.postinstall create mode 120000 xCAT-server/share/xcat/netboot/rocky/dracut_105 create mode 120000 xCAT-server/share/xcat/netboot/rocky/service.rocky10.x86_64.exlist create mode 120000 xCAT-server/share/xcat/netboot/rocky/service.rocky10.x86_64.otherpkgs.pkglist create mode 120000 xCAT-server/share/xcat/netboot/rocky/service.rocky10.x86_64.pkglist create mode 120000 xCAT-server/share/xcat/netboot/rocky/service.rocky10.x86_64.postinstall diff --git a/makerpm b/makerpm index c65a02da3..0e0fe5d85 100755 --- a/makerpm +++ b/makerpm @@ -269,7 +269,7 @@ else # linux echo "Error: rpmbuild does not appear to be installed or working." exit 2 fi - RPMROOT=`rpmbuild --eval '%_topdir' xCATsn/xCATsn.spec` + RPMROOT="/root/rpmbuild" if [ $? -gt 0 ]; then echo "Error: Could not determine rpmbuild's root directory." exit 2 diff --git a/xCAT-server/lib/xcat/plugins/ddns.pm b/xCAT-server/lib/xcat/plugins/ddns.pm index ab0414d88..4439d1849 100644 --- a/xCAT-server/lib/xcat/plugins/ddns.pm +++ b/xCAT-server/lib/xcat/plugins/ddns.pm @@ -1286,7 +1286,7 @@ sub update_namedconf { my @bind_version =xCAT::Utils->runcmd($bind_version_cmd, 0); # Turn off DNSSEC if running with bind vers 9.16.6 or higher if ((scalar @bind_version > 0) && (xCAT::Utils::CheckVersion($bind_version[0], "9.16.6") >= 0)) { - push @newnamed, "\tdnssec-enable no;\n"; + # push @newnamed, "\t# dnssec-enable no;\n"; push @newnamed, "\tdnssec-validation no;\n"; } } @@ -1358,7 +1358,7 @@ sub update_namedconf { $ctx->{privkey} = encode_base64(genpassword(32)); chomp($ctx->{privkey}); } - push @newnamed, "key xcat_key {\n", "\talgorithm hmac-md5;\n", "\tsecret \"" . $ctx->{privkey} . "\";\n", "};\n\n"; + push @newnamed, "key xcat_key {\n", "\talgorithm hmac-sha256;\n", "\tsecret \"" . $ctx->{privkey} . "\";\n", "};\n\n"; $ctx->{restartneeded} = 1; } } @@ -1535,6 +1535,7 @@ sub add_or_delete_records { find_nameserver_for_dns($ctx, $tmpdm); } } + my $zone; foreach $zone (keys %{ $ctx->{updatesbyzone} }) { unless (defined($ctx->{nsmap}->{$zone}) && $ctx->{nsmap}->{$zone}) { @@ -1553,6 +1554,7 @@ sub add_or_delete_records { my $entry; my $numreqs = 300; # limit to 300 updates in a payload, something broke at 644 on a certain sample, choosing 300 for now my $update = Net::DNS::Update->new($zone); + foreach $entry (@{ $ctx->{updatesbyzone}->{$zone} }) { if ($ctx->{deletemode}) { $update->push(update => rr_del($entry)); @@ -1564,7 +1566,8 @@ sub add_or_delete_records { # sometimes even the xcat_key is correct, but named still replies NOTAUTH, so retry for (1 .. 3) { - $update->sign_tsig("xcat_key", $ctx->{privkey}); + #$update->sign_tsig("xcat_key", $ctx->{privkey}); + $update->sign_tsig("/etc/xcat/ddns.key"); $numreqs = 300; my $reply = $resolver->send($update); if ($reply) { @@ -1582,11 +1585,13 @@ sub add_or_delete_records { } $update = Net::DNS::Update->new($zone); #new empty request } + } if ($numreqs != 300) { #either no entries at all to begin with or a perfect multiple of 300 - # sometimes even the xcat_key is correct, but named still replies NOTAUTH, so retry + # sometimes even the xcat_key is correct, but named still replies NOTAUTH, so retry for (1 .. 3) { - $update->sign_tsig("xcat_key", $ctx->{privkey}); + $update->sign_tsig("/etc/xcat/ddns.key"); + # $update->sign_tsig("xcat_key", $ctx->{privkey}); my $reply = $resolver->send($update); if ($reply) { if ($reply->header->rcode eq 'NOTAUTH') { diff --git a/xCAT-server/share/xcat/install/rh/compute.rhels10.pkglist b/xCAT-server/share/xcat/install/rh/compute.rhels10.pkglist new file mode 100644 index 000000000..1123dcf8d --- /dev/null +++ b/xCAT-server/share/xcat/install/rh/compute.rhels10.pkglist @@ -0,0 +1,13 @@ +@^minimal-environment +chrony +net-tools +nfs-utils +openssh-server +openssl +rsync +util-linux +wget +python3 +tar +bzip2 +perl-interpreter diff --git a/xCAT-server/share/xcat/install/rh/compute.rhels10.tmpl b/xCAT-server/share/xcat/install/rh/compute.rhels10.tmpl new file mode 100644 index 000000000..90b60aea8 --- /dev/null +++ b/xCAT-server/share/xcat/install/rh/compute.rhels10.tmpl @@ -0,0 +1,53 @@ +# Use text install +text +# Use network installation +%include /tmp/repos +# Keyboard layouts +keyboard --vckeymap=us --xlayouts='us' +# System language +lang en_US.UTF-8 + +# Network information +#KICKSTARTNET# +# Root password +rootpw --iscrypted #CRYPT:passwd:key=system,username=root:password# +# Not run the Setup Agent on first boot +firstboot --disable +# Do not configure the X Window System +skipx +# System services +#services --enabled="chronyd" +# System timezone +timezone #TABLE:site:key=timezone:value# --utc +# Partition clearing information +zerombr +clearpart --all --initlabel +#XCAT_PARTITION_START# +%include /tmp/partitionfile +#XCAT_PARTITION_END# + +# Do not configure any iptables rules +firewall --disable +selinux --disable +reboot + +%packages +#INCLUDE_DEFAULT_PKGLIST# + +%end + +%pre +{ +echo "Running Kickstart Pre-installation script..." +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels10# +} &>>/tmp/pre-install.log +%end +%post --interpreter=/bin/bash +mkdir -p /var/log/xcat/ +cat /tmp/pre-install.log >>/var/log/xcat/xcat.log +{ +echo "Running Kickstart Post-installation script..." +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.rhels10# +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.rhels10# +} &>>/var/log/xcat/xcat.log +%end diff --git a/xCAT-server/share/xcat/install/rocky/compute.rocky10.pkglist b/xCAT-server/share/xcat/install/rocky/compute.rocky10.pkglist new file mode 120000 index 000000000..e2131ffe2 --- /dev/null +++ b/xCAT-server/share/xcat/install/rocky/compute.rocky10.pkglist @@ -0,0 +1 @@ +../rh/compute.rhels9.pkglist \ No newline at end of file diff --git a/xCAT-server/share/xcat/install/rocky/compute.rocky10.tmpl b/xCAT-server/share/xcat/install/rocky/compute.rocky10.tmpl new file mode 120000 index 000000000..6d2611284 --- /dev/null +++ b/xCAT-server/share/xcat/install/rocky/compute.rocky10.tmpl @@ -0,0 +1 @@ +../rh/compute.rhels9.tmpl \ No newline at end of file diff --git a/xCAT-server/share/xcat/install/rocky/service.rocky10.pkglist b/xCAT-server/share/xcat/install/rocky/service.rocky10.pkglist new file mode 120000 index 000000000..4c28bda11 --- /dev/null +++ b/xCAT-server/share/xcat/install/rocky/service.rocky10.pkglist @@ -0,0 +1 @@ +../rh/service.rhels9.pkglist \ No newline at end of file diff --git a/xCAT-server/share/xcat/install/rocky/service.rocky10.tmpl b/xCAT-server/share/xcat/install/rocky/service.rocky10.tmpl new file mode 120000 index 000000000..9b9bff784 --- /dev/null +++ b/xCAT-server/share/xcat/install/rocky/service.rocky10.tmpl @@ -0,0 +1 @@ +../rh/service.rhels9.tmpl \ No newline at end of file diff --git a/xCAT-server/share/xcat/install/rocky/service.rocky10.x86_64.otherpkgs.pkglist b/xCAT-server/share/xcat/install/rocky/service.rocky10.x86_64.otherpkgs.pkglist new file mode 120000 index 000000000..722b927e1 --- /dev/null +++ b/xCAT-server/share/xcat/install/rocky/service.rocky10.x86_64.otherpkgs.pkglist @@ -0,0 +1 @@ +../rh/service.rhels9.x86_64.otherpkgs.pkglist \ No newline at end of file diff --git a/xCAT-server/share/xcat/install/scripts/compute.rhels10.tmpl b/xCAT-server/share/xcat/install/scripts/compute.rhels10.tmpl new file mode 100644 index 000000000..90b60aea8 --- /dev/null +++ b/xCAT-server/share/xcat/install/scripts/compute.rhels10.tmpl @@ -0,0 +1,53 @@ +# Use text install +text +# Use network installation +%include /tmp/repos +# Keyboard layouts +keyboard --vckeymap=us --xlayouts='us' +# System language +lang en_US.UTF-8 + +# Network information +#KICKSTARTNET# +# Root password +rootpw --iscrypted #CRYPT:passwd:key=system,username=root:password# +# Not run the Setup Agent on first boot +firstboot --disable +# Do not configure the X Window System +skipx +# System services +#services --enabled="chronyd" +# System timezone +timezone #TABLE:site:key=timezone:value# --utc +# Partition clearing information +zerombr +clearpart --all --initlabel +#XCAT_PARTITION_START# +%include /tmp/partitionfile +#XCAT_PARTITION_END# + +# Do not configure any iptables rules +firewall --disable +selinux --disable +reboot + +%packages +#INCLUDE_DEFAULT_PKGLIST# + +%end + +%pre +{ +echo "Running Kickstart Pre-installation script..." +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels10# +} &>>/tmp/pre-install.log +%end +%post --interpreter=/bin/bash +mkdir -p /var/log/xcat/ +cat /tmp/pre-install.log >>/var/log/xcat/xcat.log +{ +echo "Running Kickstart Post-installation script..." +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.rhels10# +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.rhels10# +} &>>/var/log/xcat/xcat.log +%end diff --git a/xCAT-server/share/xcat/install/scripts/getinstdisk.rhels10 b/xCAT-server/share/xcat/install/scripts/getinstdisk.rhels10 new file mode 100644 index 000000000..57f05620a --- /dev/null +++ b/xCAT-server/share/xcat/install/scripts/getinstdisk.rhels10 @@ -0,0 +1,251 @@ +#!/bin/sh + +#----------------------------------------------------------- +# +# Get proper disk to install OS +# +# 1. Check all partitions listed in /proc/partitions, whether +# there is a disk that had OS installed. If there is, add it to +# the disk array. +# 2. If there is no disk that had OS installed found +# in Step 1, then check all disks in +# /proc/partitions file. Sort them by driver type, then by WWN/PATH +# select the first one. +# 3. If no disks selected in Steps 1 or 2, then +# select the default disk: /dev/sda. +# +# Output: Install disk name written to /tmp/xcat.install_disk +# +#----------------------------------------------------------- + +install_disk="" +install_disk_file="/tmp/xcat.install_disk" + +tmpdir="/tmp/xcat.getinstalldisk" +mkdir -p $tmpdir + +has_awk=$(find /usr/* -name "awk") + +utolcmd="sed -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" + +tmpfile="$tmpdir/getinstalldisk_" + +if [ -z "$install_disk" ]; then + + echo "[get_install_disk]Contents of /proc/partitions:" + cat /proc/partitions + echo "" + + # Get all partitions and disks from /proc/partitions file + if [ -z "$has_awk" ]; then + entries=$(cat /proc/partitions | sed 's/ */ /g' | cut -d " " -f5 | grep -v "name" | grep -E '^[s|h|v]d|nvme') + else + entries=$(awk -F ' ' '{print $4}' /proc/partitions | grep -v "name" | grep -E '^[s|h|v]d|nvme') + fi + + # Classify entries by DEVTYPE + for entry in $entries; do + DEVSIZE=$(udevadm info --attribute-walk --name=$entry|grep \{size\}| sed -e 's/[^"]*"//' -e 's/"//'|tail -n 1) + if [ -z "$DEVSIZE" -o $DEVSIZE -lt 262144 ]; then + # ignore small devices, that are likely remote media or similar + echo "[get_install_disk] Skipping partition $entry. Size too small: $DEVSIZE" + continue + fi + + if [ -z "$has_awk" ]; then + dev_type=$(udevadm info --query=property --name=/dev/$entry | grep -i "DEVTYPE" | cut -d "=" -f2 | $utolcmd) + else + dev_type=$(udevadm info --query=property --name=/dev/$entry | grep -i "DEVTYPE" | awk -F = '{print $2}' | $utolcmd) + fi + + if [ "$dev_type" = "disk" ]; then + disks=$disks"$entry " + elif [ "$dev_type" = "partition" ]; then + partitions=$partitions"$entry " + fi + done + + mount_dir=$tmpdir"/xcat.getinstalldisk.mount" + mkdir -p $mount_dir; + + disk_array="" + umount_rc=0 + + for partition in $partitions; do + echo "[get_install_disk]Check the partition $partition." + + if [ -e "$tmpfile${partition%%[0-9]*}" ]; then + echo "[get_install_disk] The disk ${partition%%[0-9]*} had OS installed, check next partition." + continue + fi + + # Get partition's fs_type + if [ -z "$has_awk" ]; then + fs_type=$(udevadm info --query=property --name=/dev/$partition | grep -i "FS_TYPE" | cut -d "=" -f2) + else + fs_type=$(udevadm info --query=property --name=/dev/$partition | grep -i "FS_TYPE" | awk -F = '{print $2}') + fi + + rc=255 + + # Mount partition based on fs type, if fs_type is "swap", do not mount it, jump to next partition. + if [ -z "$fs_type" ]; then + mount /dev/$partition $mount_dir + rc=$? + elif [ "$fs_type" != "swap" ]; then + mount -t $fs_type /dev/$partition $mount_dir + rc=$? + fi + + # Check whether mount successfully + if [ $rc -eq 0 ]; then + echo "[get_install_disk] Partition $partition mount success." + + ker_dir=$mount_dir + if [ -d "$mount_dir/boot" ]; then + ker_dir="$mount_dir/boot" + fi + + # If there is kernel file, add partition's disk into disk_array + # It seems the kernel file in ubuntu and sles are named like vmlinux, but in RH it is called vmlinuz + # To check both vmlinux and vmlinuz, use regular expression "vmlinu*" to match them + for i in $(find $ker_dir -maxdepth 1 -name "vmlinu*"); do + case $partition in + nvme*) + # Expected nvme partition format example: nvme0n1p1 + disk_part=${partition%%p*} + ;; + *) + # Expected sd partition format example: sda1 + disk_part=${partition%%[0-9]*} + ;; + esac + touch "$tmpfile$disk_part" + disk_array=$disk_array"$disk_part " + echo "[get_install_disk] The partition $partition has kernel file." + break + done + + umount -l $mount_dir || echo "[get_install_disk] $partition umount failed." + if [ $? -ne 0 ]; then + # Preserve a umount failure RC + umount_rc=$? + fi + else + echo "[get_install_disk] Partition $partition mount failed or the partition is swap." + fi + done + + # If disk_array is not empty, make disks equal disk_array for next step to sort + if [ "$disk_array" ]; then + disks=$disk_array + echo "[get_install_disk]The disks which have kernel:" + echo "[get_install_disk] $disks" + echo "" + fi + + if [ $umount_rc -eq 0 ]; then + rmdir $mount_dir; + else + # Do not remove $mount_dir if there was a umount failure, as it might wipe out + # the contents of a still mounted disk + echo "[get_install_disk]There was a umount failure earlier, not removing $mount_dir" + fi + + for file in $tmpfile*; do + rm $file; + done + + has_wwn=0 + has_path=0 + file_pre="" + disk_data="" + + # Check disks which had installed OS, or check all disks in /proc/partitions + for disk in $disks; do + # Get disk's information: WWN, PATH and DRIVER + disk_info=$(udevadm info --query=property --name=$disk) + output_for_wwn=$(IFS= ;echo $disk_info | grep '\' | cut -d "=" -f2) + disk_wwn=$(echo $output_for_wwn | $utolcmd) + output_for_path=$(IFS= ;echo $disk_info | grep DEVPATH | cut -d "=" -f2) + disk_path=$(echo $output_for_path | $utolcmd) + disk_driver=$(udevadm info --attribute-walk --name=$disk | grep DRIVERS| grep -v '""'| grep -v '"sd"'| + \head -n 1| sed -e 's/[^"]*"//' -e 's/"//' | $utolcmd) + + echo "[get_install_disk]The disk $disk information: " + echo "[get_install_disk] disk_wwn=$disk_wwn" + echo "[get_install_disk] disk_path=$disk_path" + echo "[get_install_disk] disk_driver=$disk_driver" + + # Check whether there is WWN, PATH information + if [ "$disk_wwn" ]; then + has_wwn=1 + file_pre="wwn" + disk_data=$disk_wwn + elif [ $has_wwn -eq 1 ]; then + echo "[get_install_disk] The disk $disk has no wwn info." + echo "[get_install_disk] There is another disk with wwn info, so don't record this disk." + continue; + elif [ "$disk_path" ]; then + has_path=1 + file_pre="path" + disk_data=$disk_path + elif [ $has_path -eq 1 ]; then + echo "[get_install_disk] The disk $disk has no wwn or path info." + echo "[get_install_disk] There is another disk with path info, so don't record this disk." + continue; + else + file_pre="other" + disk_data="" + fi + + # Sort disks by DRIVER type + case "$disk_driver" in + "ata_piix"*|"PMC MaxRAID"|"ahci"|"megaraid_sas") + echo "$disk $disk_data" >> "$tmpfile""$file_pre""firstchoicedisks" + echo "[get_install_disk] Add disk: $disk $disk_data into $file_pre firstchoicedisks" + ;; + "mptsas"|"mpt2sas"|"mpt3sas") + echo "$disk $disk_data" >> "$tmpfile""$file_pre""secondchoicedisks" + echo "[get_install_disk] Add disk: $disk $disk_data into $file_pre secondchoicedisks" + ;; + *) + echo "$disk $disk_data" >> "$tmpfile""$file_pre""thirdchoicedisks" + echo "[get_install_disk] Add disk: $disk $disk_data into $file_pre thirdchoicedisks" + ;; + esac + done + + for seq in first second third; do + if [ -s $tmpfile$file_pre${seq}choicedisks ]; then + install_file="$tmpfile$file_pre${seq}choicedisks" + break + fi + done + + if [ "$install_file" ] && [ -s $install_file ]; then + install_disk=/dev/$(cat $install_file | grep -v "^$" | sort -k 2 -b | cut -d " " -f1 | head -n 1) + echo "[get_install_disk]The install_disk is $install_disk by sorting $file_pre and DRIVER." + fi + + for file in $tmpfile*; do + rm $file; + done +fi +rm -rf $tmpdir; + +# Enable boot in Xen VM +if [ -z "$install_disk" ] && [ -b "/dev/xvda" ]; then + install_disk="/dev/xvda" + echo "[get_install_disk]Choosing default install_disk $install_disk." +fi + +# Cannot find proper disk for OS install, select the default one "/dev/sda" +if [ -z "$install_disk" ]; then + install_disk="/dev/sda" + echo "[get_install_disk]Choosing default install_disk $install_disk." + msgutil_r "$MASTER_IP" "warn" "Disk detection failed, defaulting to $install_disk" "/var/log/xcat/xcat.log" "$log_label" +fi + +# Output the result to $install_disk_file +echo $install_disk > $install_disk_file diff --git a/xCAT-server/share/xcat/install/scripts/post.rhels10 b/xCAT-server/share/xcat/install/scripts/post.rhels10 new file mode 100644 index 000000000..d7faa49c9 --- /dev/null +++ b/xCAT-server/share/xcat/install/scripts/post.rhels10 @@ -0,0 +1,23 @@ +#!/bin/bash +# The nic name might change between the installation and 1st boot +# Active all the nics with network link during system boot + +[ "$XCATDEBUGMODE" ] || export XCATDEBUGMODE="#TABLEBLANKOKAY:site:key=xcatdebugmode:value#" +[ "$MASTER_IP" ] || export MASTER_IP="#ENV:MASTER_IP#" +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/scriptlib# + +# Show connections : +nmcli -g NAME,STATE con show | \ + # print connection name for activated interfaces (ignores loopback iterface) + perl -F: -lane 'print $F[0] if $F[0] ne "lo" && $F[1] eq "activated"' | \ + # enable connection during the boot + xargs -t -I% nmcli con mod % connection.autoconnect yes + +internet_repo_file_list="oracle-linux-ol10.repo uek-ol10.repo Rocky-AppStream.repo Rocky-BaseOS.repo Rocky-Extras.repo CentOS-Base.repo almalinux-ha.repo almalinux-nfv.repo almalinux-powertools.repo almalinux.repo almalinux-resilientstorage.repo almalinux-rt.repo" + +for repo_file in $internet_repo_file_list +do + if [ -f /etc/yum.repos.d/$repo_file ]; then + sed -i -e 's/enabled=1/enabled=0/' /etc/yum.repos.d/$repo_file + fi +done diff --git a/xCAT-server/share/xcat/install/scripts/post.xcat.rhels10 b/xCAT-server/share/xcat/install/scripts/post.xcat.rhels10 new file mode 100644 index 000000000..bbabcd1fe --- /dev/null +++ b/xCAT-server/share/xcat/install/scripts/post.xcat.rhels10 @@ -0,0 +1,453 @@ +#!/bin/bash +# +# Run xCAT post install +# +export MASTER_IP="#ENV:MASTER_IP#" +export MASTER="#XCATVAR:XCATMASTER#" +export NODESTATUS="#XCATVAR:NODESTATUS#" +export XCATIPORT="#TABLE:site:key=xcatiport:value#" +export INSTALLDIR="#TABLE:site:key=installdir:value#" +export TFTPDIR="#TABLE:site:key=tftpdir:value#" +export XCATDEBUGMODE="#TABLEBLANKOKAY:site:key=xcatdebugmode:value#" +export HTTPPORT="#TABLEBLANKOKAY:site:key=httpport:value#" + +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/scriptlib# + +umask 0022 + +case "$XCATDEBUGMODE" in +"1"|"2") + set -x + ;; +esac + +if [ -z "$XCATIPORT" ]; then + XCATIPORT="3002" +fi +if [ -z "$INSTALLDIR" ]; then + INSTALLDIR="/install" +fi +if [ -z "$TFTPDIR" ]; then + TFTPDIR="/tftpboot" +fi +if [[ "${TFTPDIR:0:1}" != "/" ]]; then + TFTPDIR="/$TFTPDIR" +fi +if [ -z "$HTTPPORT" ]; then + HTTPPORT="80" +fi + +NODESTATUS="$(echo "$NODESTATUS"| tr -d \'\" | tr A-Z a-z)" + +( +cat <<'EOF' +#INCLUDE:#TABLE:site:key=installdir:value#/postscripts/updateflag.awk# +EOF +) >/tmp/updateflag + +chmod 0755 /tmp/updateflag + +cd /tmp +log_label="xcat.deployment" +msgutil_r "$MASTER_IP" "info" "Executing post.xcat to prepare for firstbooting ..." "/var/log/xcat/xcat.log" "$log_label" + +RAND="$(perl -e 'print int(rand(50)). "\n"')" +case "$XCATDEBUGMODE" in +"1"|"2") + msgutil_r "$MASTER_IP" "debug" "sleep $RAND" "/var/log/xcat/xcat.log" "$log_label" + ;; +esac +sleep "$RAND" + +# Stop if no openssl to help the next bit +if ! type openssl >/dev/null 2>&1 +then + msgutil_r "$MASTER_IP" "error" "/usr/bin/openssl does not exist, halt ..." "/var/log/xcat/xcat.log" "$log_label" + /tmp/updateflag "$MASTER" "$XCATIPORT" "installstatus failed" + sleep infinity +fi + +# Save to /opt/xcat/xcatinfo file +mkdir -p /opt/xcat +touch /opt/xcat/xcatinfo + +grep -q 'XCATSERVER=' /opt/xcat/xcatinfo >/dev/null 2>&1 +if [ "$?" -eq "0" ] +then + sed -i "s/XCATSERVER=.*/XCATSERVER=$MASTER_IP/" /opt/xcat/xcatinfo +else + echo "XCATSERVER=$MASTER_IP" >>/opt/xcat/xcatinfo +fi + +grep -q 'INSTALLDIR' /opt/xcat/xcatinfo >/dev/null 2>&1 +if [ "$?" -eq "0" ] +then + sed -i "s/INSTALLDIR=.*/INSTALLDIR=$INSTALLDIR/" /opt/xcat/xcatinfo +else + echo "INSTALLDIR=$INSTALLDIR" >>/opt/xcat/xcatinfo +fi + +grep 'HTTPPORT' /opt/xcat/xcatinfo > /dev/null 2>&1 +if [ $? -eq 0 ]; then + sed -i "s/HTTPPORT=.*/HTTPPORT=$HTTPPORT/" /opt/xcat/xcatinfo +else + echo "HTTPPORT=$HTTPPORT" >> /opt/xcat/xcatinfo +fi + +case "$XCATDEBUGMODE" in +"1"|"2") + msgutil_r "$MASTER_IP" "debug" "/opt/xcat/xcatinfo generated" "/var/log/xcat/xcat.log" "$log_label" + ;; +esac + +# Download the postscripts +msgutil_r "$MASTER_IP" "info" "trying to download postscripts from $MASTER_IP..." "/var/log/xcat/xcat.log" "$log_label" + +# Stop if no curl to help the next bit +if ! type curl >/dev/null 2>&1 +then + msgutil_r "$MASTER_IP" "error" "Command curl not found, halt ..." "/var/log/xcat/xcat.log" "$log_label" + /tmp/updateflag "$MASTER" "$XCATIPORT" "installstatus failed" + sleep infinity +fi + +# $1 URL +# $2 Destination directory +function download_recursive() +{ + local url="$1" + local dest_dir="$2" + local f + + [ "${url: -1}" = "/" ] && url="${url:0:-1}" + [ "${dest_dir: -1}" = "/" ] && dest_dir="${dest_dir:0:-1}" + mkdir -p "${dest_dir}" + + while read -r f + do + case "$f" in + *"/") + download_recursive "${url}/${f}" "${dest_dir}/${f:0:-1}" + [ "$?" -ne "0" ] && return 1 + ;; + *) + curl --fail --retry 20 --max-time 60 "${url}/${f}" -o "${dest_dir}/${f}" + [ "$?" -ne "0" ] && return 1 + ;; + esac + done < <(curl --fail --retry 20 --max-time 60 "${url}/" | grep -o '.*' | egrep -v "O=D|Directory" | cut -d '"' -f 2) + return 0 +} + +download_recursive "http://$MASTER_IP:${HTTPPORT}$INSTALLDIR/postscripts/" "/xcatpost" 2>/tmp/download.log +if [ "$?" -ne "0" ] +then + msgutil_r "$MASTER_IP" "error" "failed to download postscripts from http://$MASTER_IP$INSTALLDIR/postscripts/, check /tmp/download.log on the node, halt ..." "/var/log/xcat/xcat.log" "$log_label" + /tmp/updateflag "$MASTER" "$XCATIPORT" "installstatus failed" + sleep infinity +fi + +# Add execute permision to all files recursively under /xcatpost. +chmod -R +x `find /xcatpost/ -maxdepth 1 -print | grep -E -v '^(/xcatpost/|/xcatpost/_xcat|/xcatpost/_ssh|/xcatpost/ca|/xcatpost/hostkeys)$'` + +msgutil_r "$MASTER_IP" "info" "postscripts downloaded successfully" "/var/log/xcat/xcat.log" "$log_label" + +# Get the precreated mypostscript file +rm -rf /xcatpost/mypostscript +export NODE="#TABLE:nodelist:THISNODE:node#" + +msgutil_r "$MASTER_IP" "info" "trying to get mypostscript from $MASTER_IP..." "/var/log/xcat/xcat.log" "$log_label" + +curl --fail --retry 20 --max-time 60 "http://$MASTER_IP:${HTTPPORT}$TFTPDIR/mypostscripts/mypostscript.$NODE" -o "/xcatpost/mypostscript.$NODE" 2> /tmp/download.log +if [ "$?" = "0" ] +then + case "$XCATDEBUGMODE" in + "1"|"2") + msgutil_r "$MASTER_IP" "debug" "precreated mypostscript downloaded successfully" "/var/log/xcat/xcat.log" "$log_label" + ;; + esac + mv /xcatpost/mypostscript.$NODE /xcatpost/mypostscript + chmod 700 /xcatpost/mypostscript +fi + +# Though this is the only method going forward, flag to allow backward compatibility with 2.2 generated netboot images +USEOPENSSLFORXCAT=1 +export USEOPENSSLFORXCAT +XCATSERVER=$MASTER_IP:3001 +export XCATSERVER + +# If mypostscript doesn't exist, we will get it through getpostscript.awk +if [ ! -x /xcatpost/mypostscript ]; then + case "$XCATDEBUGMODE" in + "1"|"2") + msgutil_r "$MASTER_IP" "debug" "no pre-generated mypostscript., trying to get it with getpostscript.awk..." "/var/log/xcat/xcat.log" "$log_label" + ;; + esac + + # To support the postscripts in the subdirectories under /install/postscripts + # chmod +x /xcatpost/* + # Stop if no getpostscript.awk to help the next bit + if [ ! -x /xcatpost/getpostscript.awk ]; then + msgutil_r "$MASTER_IP" "error" "/xcatpost/getpostscript.awk does not exist, halt ..." "/var/log/xcat/xcat.log" "$log_label" + /tmp/updateflag "$MASTER" "$XCATIPORT" "installstatus failed" + sleep infinity + fi + /xcatpost/getpostscript.awk | egrep '' | sed -e 's/<[^>]*>//g' | egrep -v '^ *$' | sed -e 's/^ *//' | sed -e 's/<//g' -e 's/&/\&/g' -e 's/"/"/g' -e "s/'/'/g" >/xcatpost/mypostscript + + MYCONT="$(grep '^MASTER=' /xcatpost/mypostscript)" + RETRY=0 + while [ -z "$MYCONT" ]; do + RETRY=$(($RETRY + 1)) + if [ "$RETRY" -eq "10" ]; then + break + fi + + let SLI=$RANDOM%10+10 + sleep $SLI + /xcatpost/getpostscript.awk |egrep ''|sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' | sed -e 's/<//g' -e 's/&/\&/g' -e 's/"/"/g' -e "s/'/'/g" > /xcatpost/mypostscript + + MYCONT="$(grep '^MASTER=' /xcatpost/mypostscript)" + done +fi + +TMP="$(sed "/^#\s*postscripts-start-here/,/^#\s*postscripts-end-here/ s/\(.*\)/run_ps postscript \1/;s/run_ps postscript\s*#/#/;s/run_ps postscript\s*$//" /xcatpost/mypostscript)" +echo "$TMP" >/xcatpost/mypostscript +TMP="$(sed "/^#\s*postbootscripts-start-here/,/^#\s*postbootscripts-end-here/ s/\(.*\)/run_ps postbootscript \1/;s/run_ps postbootscript\s*#/#/;s/run_ps postbootscript\s*$//" /xcatpost/mypostscript)" + +cd /xcatpost +# gunzip xcatpost.tar.gz +# tar -xvf xcatpost.tar +# /xcatpost/#TABLE:nodelist:THISNODE:node# +export PATH="$PATH:/xcatpost" + +# use the run_ps subroutine to run the postscripts + +case "$XCATDEBUGMODE" in +"1"|"2") + echo "set -x" >/xcatpost/mypostscript + ;; +*) + >/xcatpost/mypostscript + ;; +esac + +echo " +. /xcatpost/xcatlib.sh + +# global value to store the running status of the postbootscripts,the value is non-zero if one postbootscript failed +return_value=0 + +# subroutine used to run postscripts +# \$1 argument is the script type +# rest argument is the script name and arguments +run_ps () { + local ret_local=0 + mkdir -p "\"/var/log/xcat\"" + # On some Linux distro, the rsyslogd daemon write log files with permision + # other than root:root. And in some case, the directory /var/log/xcat was + # created by xCAT, and had root:root ownership. In this way, rsyslogd + # did not have enough permission to write to log files under this directory. + # As a dirty hack, change the ownership of directory /var/log/xcat to the + # same ownership of directory /var/log. + chown `ls -ld /var/log | awk '{ print \$3\":\"\$4 }'` "\"/var/log/xcat\"" + local logfile=\"/var/log/xcat/xcat.log\" + local scriptype=\$1 + shift; + + if [ -z \"\$scriptype\" ]; then + scriptype=\"postscript\" + fi + log_label=\"xcat.deployment.\"\$scriptype + if [ -f \$1 ]; then + msgutil_r \"\$MASTER_IP\" \"info\" "\"Running \$scriptype: \$1\"" \"\$logfile\" \"\$log_label\" + if [ \"\$XCATDEBUGMODE\" = \"1\" ] || [ \"\$XCATDEBUGMODE\" = \"2\" ]; then + local compt=\$(file \$1) + local reg=\"shell script\" + if [[ \"\$compt\" =~ \$reg ]]; then + bash -x ./\$@ 2>&1 + ret_local=\$? + else + ./\$@ 2>&1 | logger -t xcat -p debug + ret_local=\${PIPESTATUS[0]} + fi + else + ./\$@ 2>&1 + ret_local=\${PIPESTATUS[0]} + fi + + if [ \"\$ret_local\" -ne \"0\" ]; then + return_value=\$ret_local + fi + msgutil_r \"\$MASTER_IP\" \"info\" "\"\$scriptype \$1 return with \$ret_local\"" \"\$logfile\" \"\$log_label\" + else + msgutil_r \"\$MASTER_IP\" \"error\" "\"\$scriptype \$1 does NOT exist.\"" \"\$logfile\" \"\$log_label\" + return_value=-1 + fi + + + return 0 +} +# subroutine end + +" >>/xcatpost/mypostscript +echo "$TMP" >>/xcatpost/mypostscript + +case "$XCATDEBUGMODE" in +"1"|"2") + echo "set +x" >>/xcatpost/mypostscript + ;; +esac + +chmod 0755 /xcatpost/mypostscript +if [ ! -x /xcatpost/mypostscript ]; then + msgutil_r "$MASTER_IP" "error" "failed to generate mypostscript file, halt ..." "/var/log/xcat/xcat.log" "$log_label" + /tmp/updateflag "$MASTER" "$XCATIPORT" "installstatus failed" + sleep infinity +else + case "$XCATDEBUGMODE" in + "1"|"2") + msgutil_r "$MASTER_IP" "debug" "generate mypostscript file successfully" "/var/log/xcat/xcat.log" "$log_label" + ;; + esac +fi + +# Save the postboot scripts to /xcatpost/mypostscript.post +TMP=`sed "/^#\s*postscripts-start-here/,/^#\s*postscripts-end-here/ d" /xcatpost/mypostscript` +echo "$TMP" >/xcatpost/mypostscript.post +chmod 0755 /xcatpost/mypostscript.post + +if [ ! -x /xcatpost/mypostscript.post ] +then + msgutil_r "$MASTER_IP" "error" "failed to generate /xcatpost/mypostscript.post" "/var/log/xcat/xcat.log" "$log_label" +else + case "$XCATDEBUGMODE" in + "1"|"2") + msgutil_r "$MASTER_IP" "debug" "generate mypostscript.post file successfully" "/var/log/xcat/xcat.log" "$log_label" + ;; + esac +fi + +export OSVER="#TABLE:nodetype:THISNODE:os#" +# Create the post init service as a hook to run PS and PBS, as well as status updating +cat >/etc/systemd/system/xcatpostinit1.service <<'EOF' +#INCLUDE:/install/postscripts/xcatpostinit1.service# +EOF + +case "$XCATDEBUGMODE" in +"1"|"2") + msgutil_r "$MASTER_IP" "debug" "/etc/systemd/system/xcatpostinit1.service generated" "/var/log/xcat/xcat.log" "$log_label" + ;; +esac + +ln -s /etc/systemd/system/xcatpostinit1.service /etc/systemd/system/multi-user.target.wants/xcatpostinit1.service + +case "$XCATDEBUGMODE" in +"1"|"2") + msgutil_r "$MASTER_IP" "debug" "xcatpostinit1.service enabled" "/var/log/xcat/xcat.log" "$log_label" + ;; +esac + +cat >/opt/xcat/xcatpostinit1 <<'EOF' +#INCLUDE:/install/postscripts/xcatpostinit1.install# +EOF +chmod 0755 /opt/xcat/xcatpostinit1 + +# Create the xcatinstallpost +mkdir -p /opt/xcat +cat >/opt/xcat/xcatinstallpost <<'EOF' +#INCLUDE:#TABLE:site:key=installdir:value#/postscripts/xcatinstallpost# + +if [ -f /xcatpost/mypostscript.post ] +then + RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /xcatpost/mypostscript.post | cut -d= -f2 | tr -d \'\" | tr A-Z a-z` +fi + +if [[ ! "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]] && [[ ! "$NODESTATUS" =~ ^(1|yes|y)$ ]]; then + systemctl disable xcatpostinit1.service + case "$XCATDEBUGMODE" in + "1"|"2") + msgutil_r "$MASTER_IP" "debug" "systemctl disable xcatpostinit1.service" "/var/log/xcat/xcat.log" "xcat.xcatinstallpost" + ;; + esac +fi + +EOF + +chmod 0755 /opt/xcat/xcatinstallpost + +if [ ! -x /opt/xcat/xcatinstallpost ] +then + msgutil_r "$MASTER_IP" "error" "failed to generate /opt/xcat/xcatinstallpost" "/var/log/xcat/xcat.log" "$log_label" +else + case "$XCATDEBUGMODE" in + "1"|"2") + msgutil_r "$MASTER_IP" "debug" "/opt/xcat/xcatinstallpost generated" "/var/log/xcat/xcat.log" "$log_label" + ;; + esac +fi + +# Create the dskls post +cat >/opt/xcat/xcatdsklspost <<'EOF' +#INCLUDE:#TABLE:site:key=installdir:value#/postscripts/xcatdsklspost# +EOF +chmod 755 /opt/xcat/xcatdsklspost + +if [ ! -x /opt/xcat/xcatdsklspost ]; then + msgutil_r "$MASTER_IP" "error" "failed to generate /opt/xcat/xcatdsklspost" "/var/log/xcat/xcat.log" "$log_label" +else + case "$XCATDEBUGMODE" in + "1"|"2") + msgutil_r "$MASTER_IP" "debug" "/opt/xcat/xcatdsklspost generated" "/var/log/xcat/xcat.log" "$log_label" + ;; + esac +fi + +#create the preboot script and run here +TMP="$(sed '/^#\s*postbootscripts-start-here/,/^#\s*postbootscripts-end-here/ d' /xcatpost/mypostscript)" +echo "$TMP" >/xcatpost/mypostscript + +echo " +# Save bad return code to /opt/xcat/xcatinfo +if [ \"\$return_value\" -ne \"0\" ]; then + grep 'POSTSCRIPTS_RC' /opt/xcat/xcatinfo > /dev/null 2>&1 + if [ \$? -eq 0 ]; then + sed -i \"s/POSTSCRIPTS_RC=.*/POSTSCRIPTS_RC=1/\" /opt/xcat/xcatinfo + else + echo \"POSTSCRIPTS_RC=1\" >>/opt/xcat/xcatinfo + fi +fi +" >>/xcatpost/mypostscript + +chmod 0700 /xcatpost/mypostscript + +export ARCH="#TABLE:nodetype:THISNODE:arch#" +export CONSOLEPORT="#TABLEBLANKOKAY:nodehm:THISNODE:serialport#" + +# For redhat: +# place-holder for the code to save the repo info on compute node,pointing to the "pkgdir" of the osimage +# so that the provisioned node has the repo pointed to the distro path on MN +#WRITEREPO# + +case "$XCATDEBUGMODE" in +"1"|"2") + msgutil_r "$MASTER_IP" "info" "running mypostscript" "/var/log/xcat/xcat.log" "$log_label" + ;; +esac +/xcatpost/mypostscript +case "$XCATDEBUGMODE" in +"1"|"2") + msgutil_r "$MASTER_IP" "info" "mypostscript returned" "/var/log/xcat/xcat.log" "$log_label" + ;; +esac + +msgutil_r "$MASTER_IP" "info" "finished firstboot preparation, sending request to $MASTER:3002 for changing status..." "/var/log/xcat/xcat.log" "$log_label" +# The following command should always be run to prevent infinite installation loops +updateflag.awk "$MASTER" 3002 + +cd / + +case "$XCATDEBUGMODE" in +"1"|"2") + set +x + ;; +esac diff --git a/xCAT-server/share/xcat/install/scripts/pre.rhels10 b/xCAT-server/share/xcat/install/scripts/pre.rhels10 new file mode 100644 index 000000000..dd9ba1b7f --- /dev/null +++ b/xCAT-server/share/xcat/install/scripts/pre.rhels10 @@ -0,0 +1,327 @@ +export XCATDEBUGMODE="#TABLEBLANKOKAY:site:key=xcatdebugmode:value#" + +case "$XCATDEBUGMODE" in +"1"|"2") + set -x + ;; +esac +export MASTER_IP="#ENV:MASTER_IP#" +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/scriptlib# +log_label="xcat.deployment" +msgutil_r "$MASTER_IP" "info" "============deployment starting============" "/var/log/xcat/xcat.log" "$log_label" +msgutil_r "$MASTER_IP" "info" "Running Anaconda Pre-Installation script..." "/var/log/xcat/xcat.log" "$log_label" +if grep -q n8r /proc/cmdline >/dev/null 2>&1 +then + stty crtscts +fi +for x in 0 1 2 3 4 5 6 7 8 +do + mknod /dev/vcs$x c 7 $x + mknod /dev/vcsa$x c 7 $[$x+128] +done +chmod 0644 /dev/vcs* +chown root.tty /dev/vcs* + +if [ -r /tmp/updates/etc/pki/tls/certs/ca-bundle.crt ] +then + cp -f /tmp/updates/etc/pki/tls/certs/ca-bundle.crt /etc/pki/tls/certs/ +fi + +cat >/tmp/baz.py <<'EOF' +#!/usr/libexec/platform-python +import socket +import sys + +sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +sock.connect(('#XCATVAR:XCATMASTER#',#TABLE:site:key=xcatiport:value#)) + +print(sys.argv[1]) +response = sock.recv(100) +if(response == b"ready\n"): + sock.send((sys.argv[1]+"\n").encode()) + response = sock.recv(100) + +sock.close() +EOF + +cat >/tmp/foo.py <<'EOF' +#!/usr/libexec/platform-python + +import socket +import os +import linecache +import re + +sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +sock.connect(('#XCATVAR:XCATMASTER#',#TABLE:site:key=xcatiport:value#)) + +response = sock.recv(100) +if(response == b"ready\n"): + sock.send("installmonitor\n".encode()) + response = sock.recv(100) + +sock.close() + +sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + +port = 3054 +sock.bind(('', port)) + +sock.listen(5) + +try: + while 1: + newSocket, address = sock.accept() + while 1: + received = newSocket.recv(200) + if not received: + break + command = re.split(b'\s+',received) + if(command[0] == b"stat"): + ilog = "" + line = "" + post = 0 + percent = 0 + count = 0 + numpack = 0 + pre = 0 + if(os.path.isfile('/tmp/xcatpre.log')): + ilog = '/tmp/xcatpre.log' + pre = 1 + if(os.path.isfile('/tmp/packaging.log')): + ilog = '/tmp/packaging.log' + if(os.path.isfile('/mnt/sysimage/tmp/post.log')): + ilog = '/mnt/sysimage/tmp/post.log' + post = True + if(ilog): + count = len(open(ilog).readlines()) + line = linecache.getline(ilog,count) + linecache.clearcache() + if(line and not post and not pre): + r2 = re.compile("Installing ([^ ]*) \((\d+)/(\d+)\)") + m2 = r2.search(line) + if m2: + newline = "%s (%.2f%%)" % (m2.group(1), 100 * float(m2.group(2)) / float(m2.group(3))) + else: + newline = "post" + line = "installing " + newline + if(line and post and not pre): + line = "installing " + line + if(not line): + line = "installing prep" + newSocket.send(line.encode()) + break +#UNCOMMENTOENABLEDEBUGPORT# if(command[0] == b"sh"): #DEBUG purposes only, wide open root priv command here. +#UNCOMMENTOENABLEDEBUGPORT# newcommand = b"" +#UNCOMMENTOENABLEDEBUGPORT# for i in command[1:]: +#UNCOMMENTOENABLEDEBUGPORT# newcommand = newcommand + i + b" " +#UNCOMMENTOENABLEDEBUGPORT# output = os.popen(newcommand.decode('utf-8')).read().encode() +#UNCOMMENTOENABLEDEBUGPORT# newSocket.send(output) +#UNCOMMENTOENABLEDEBUGPORT# break + if(command[0] == b"screendump"): + newcommand = "cat /dev/vcs" + for i in command[1:]: + newcommand = newcommand + i + output = os.popen(newcommand).read() + newSocket.send(output.encode()) + break + + newSocket.close() + +finally: + sock.close() +EOF + +chmod 0755 /tmp/foo.py +chmod 0755 /tmp/baz.py + +NODESTATUS="#TABLEBLANKOKAY:site:key=nodestatus:value#" + +case "$NODESTATUS" in +"0"|"N"|"n") + ;; +*) + /tmp/baz.py "installstatus installing" & + ;; +esac + +/tmp/foo.py >/foo.log 2>&1 & + +base64decode() +{ + h0="0"; h1="1"; h2="2"; h3="3"; h4="4"; h5="5"; h6="6"; h7="7"; + h8="8"; h9="9"; h10="A"; h11="B"; h12="C"; h13="D"; h14="E"; h15="F"; + + while : + do + i=0 + while [ "$i" -lt 4 ] + do + read -n 1 c || return + + case "${c}" in + "A") d=0 ;; "B") d=1 ;; "C") d=2 ;; "D") d=3 ;; + "E") d=4 ;; "F") d=5 ;; "G") d=6 ;; "H") d=7 ;; + "I") d=8 ;; "J") d=9 ;; "K") d=10 ;; "L") d=11 ;; + "M") d=12 ;; "N") d=13 ;; "O") d=14 ;; "P") d=15 ;; + "Q") d=16 ;; "R") d=17 ;; "S") d=18 ;; "T") d=19 ;; + "U") d=20 ;; "V") d=21 ;; "W") d=22 ;; "X") d=23 ;; + "Y") d=24 ;; "Z") d=25 ;; "a") d=26 ;; "b") d=27 ;; + "c") d=28 ;; "d") d=29 ;; "e") d=30 ;; "f") d=31 ;; + "g") d=32 ;; "h") d=33 ;; "i") d=34 ;; "j") d=35 ;; + "k") d=36 ;; "l") d=37 ;; "m") d=38 ;; "n") d=39 ;; + "o") d=40 ;; "p") d=41 ;; "q") d=42 ;; "r") d=43 ;; + "s") d=44 ;; "t") d=45 ;; "u") d=46 ;; "v") d=47 ;; + "w") d=48 ;; "x") d=49 ;; "y") d=50 ;; "z") d=51 ;; + "0") d=52 ;; "1") d=53 ;; "2") d=54 ;; "3") d=55 ;; + "4") d=56 ;; "5") d=57 ;; "6") d=58 ;; "7") d=59 ;; + "8") d=60 ;; "9") d=61 ;; "+") d=62 ;; "/") d=63 ;; + "=") d=0 ;; + *) continue ;; + esac + + eval "a${i}=${c}" + eval "b${i}=${d}" + + i=$(( i + 1 )) + done + + o0=$(( ((b0 << 2) | (b1 >> 4)) & 0xff )) + o1=$(( ((b1 << 4) | (b2 >> 2)) & 0xff )) + o2=$(( ((b2 << 6) | b3) & 0xff )) + + [ "${a2}" == "=" ] && + eval "printf \"\\x\${h$(( o0 / 16 ))}\${h$(( o0 % 16 + ))}\"" && + return + [ "${a3}" == "=" ] && + eval "printf \"\\x\${h$(( o0 / 16 ))}\${h$(( o0 % 16 + ))}\\x\${h$(( o1 / 16 ))}\${h$(( o1 % 16 + ))}\"" && + return + eval "printf \"\\x\${h$(( o0 / 16 ))}\${h$(( o0 % 16 + ))}\\x\${h$(( o1 / 16 ))}\${h$(( o1 % 16 + ))}\\x\${h$(( o2 / 16 ))}\${h$(( o2 % 16 ))}\"" + done +} + +# $1 - The device name, eg., sda +# Returns the device size, unit is KB. +getdisksize() +{ + local disk="$1" + + disk="${disk#/dev/}" + + [ -z "${disk}" ] && echo "0" && return + + local blah + local blocks + local name + + while read -r blah blah blocks name + do + if [ "${name}" = "${disk}" ] + then + echo "${blocks}" + return + fi + done /tmp/vgs 2>&1 +vgchange -a n xcatvg +vgremove -f xcatvg + +msgutil_r "$MASTER_IP" "info" "Found $instdisk, generate partition file..." "/var/log/xcat/xcat.log" "$log_label" +echo "ignoredisk --only-use=$instdisk" >>/tmp/partitionfile +case "$(uname -m)" in +"ppc64"|"ppc64le") + echo "part prepboot --fstype=prepboot --asprimary --ondisk=$instdisk --size=8" >>/tmp/partitionfile + ;; +esac +disklabeltype=$(fdisk -l /dev/xvda | awk -F': ' '/Disklabel type/ { print $2 }') +if [ `blockdev --getsz $instdisk` -gt 4294967295 ] || [ "$disklabeltype" == "gpt" ]; then + echo "part biosboot --ondisk=$instdisk --size=1" >> /tmp/partitionfile +fi +if [ -d /sys/firmware/efi ] +then + echo "part /boot/efi --fstype=$EFIFSTYPE --ondisk=$instdisk --size=256" >>/tmp/partitionfile +fi + +DISKSIZE="$(getdisksize "${instdisk}")" + +# TODO: Ondisk detection, /dev/disk/by-id/edd-int13_dev80 for legacy maybe, and no idea about efi. At least maybe blacklist SAN if mptsas/mpt2sas/megaraid_sas seen... +echo "part /boot --fstype=$BOOTFSTYPE --asprimary --ondisk=$instdisk --size=1024" >>/tmp/partitionfile +echo "part pv.000997 --grow --asprimary --ondisk=$instdisk --size=1024" >>/tmp/partitionfile +echo "volgroup xcatvg --pesize=4096 pv.000997" >>/tmp/partitionfile +echo "logvol swap --name=swap --vgname=xcatvg --recommended" >>/tmp/partitionfile + +echo "logvol / --fstype=$FSTYPE --name=root --vgname=xcatvg --size=1024 --grow " >>/tmp/partitionfile + +# Specify "bootloader" configuration in "/tmp/partitionfile" if there is no user customized partition file +BOOTLOADER="bootloader" + +# Specifies which drive the boot loader should be written to +# and therefore which drive the computer will boot from. +[ -n "$instdisk" ] && BOOTLOADER="$BOOTLOADER --boot-drive=$(basename $instdisk)" + +echo "$BOOTLOADER" >>/tmp/partitionfile + +#XCA_PARTITION_SCRIPT# + +#specify the kernel options which will be persistent after installation +if [ -n "#ENV:PERSKCMDLINE#" ];then + #append the persistent kernel options to the lines including "bootloader --append" + sed -i -e /bootloader/s#\'#\"#g -e '/bootloader/s/--append=\([^"]\S*[^"]\)/--append="\1"/g' -e '/bootloader/s/--append="\(.*\)"/--append="\1 #ENV:PERSKCMDLINE#"/g' /tmp/partitionfile + #append the persistent kernel options to the lines including "bootloader" without "--append" + sed -i -e '/bootloader/{/append=/!s/$/& --append="#ENV:PERSKCMDLINE#" /}' /tmp/partitionfile + #append the persistent kernel options to /tmp/partitionfile if it does not include "bootloader" + grep -q bootloader /tmp/partitionfile >/dev/null 2>&1 || echo -e "bootloader --append=\"#ENV:PERSKCMDLINE#\"" >>/tmp/partitionfile +fi + +# save the content of /tmp/partitionfile in /var/log/xcat/xcat.log +# so that we can inspect the partition scheme after installation +echo "================ The Partition Scheme ===============" +cat /tmp/partitionfile +echo "=====================================================" +msgutil_r "$MASTER_IP" "info" "Generate the repository for the installation" "/var/log/xcat/xcat.log" "$log_label" +# The following code is to generate the repository for the installation +cat /proc/cmdline + +NEXTSERVER="$(grep -m 1 http /proc/cmdline)" +NEXTSERVER="${NEXTSERVER#*http://}" +NEXTSERVER="${NEXTSERVER%%:*}" + +export nextserver="$NEXTSERVER" +#INSTALL_SOURCES_IN_PRE# + +case "$XCATDEBUGMODE" in +"1"|"2") + set +x + ;; +esac diff --git a/xCAT-server/share/xcat/netboot/rh/compute.rhels10.x86_64.pkglist b/xCAT-server/share/xcat/netboot/rh/compute.rhels10.x86_64.pkglist new file mode 100644 index 000000000..23895e5ff --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rh/compute.rhels10.x86_64.pkglist @@ -0,0 +1,31 @@ +@minimal-environment +initscripts +chrony +kernel +net-tools +nfs-utils +openssh-server +rsync +tar +util-linux +wget +python3 +tar +bzip2 +bc +dracut +dracut-network +rsyslog +hostname +e2fsprogs +ethtool +parted +openssl +dhclient +openssh-clients +bash +vim-minimal +rpm +iputils +perl-interpreter + diff --git a/xCAT-server/share/xcat/netboot/rh/dracut_105/patch/syslog/module-setup.sh b/xCAT-server/share/xcat/netboot/rh/dracut_105/patch/syslog/module-setup.sh new file mode 100755 index 000000000..ba8ed94cf --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rh/dracut_105/patch/syslog/module-setup.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh + +check() { + # do not add this module by default + return 255 +} + +depends() { + return 0 +} + +install() { + local _i + local _installs + if type -P rsyslogd >/dev/null; then + _installs="rsyslogd" + inst_libdir_file rsyslog/lmnet.so rsyslog/imklog.so rsyslog/imuxsock.so rsyslog/imjournal.so + elif type -P syslogd >/dev/null; then + _installs="syslogd" + elif type -P syslog-ng >/dev/null; then + _installs="syslog-ng" + else + derror "Could not find any syslog binary although the syslogmodule" \ + "is selected to be installed. Please check." + fi + if [ -n "$_installs" ]; then + inst_multiple cat $_installs + inst_hook cmdline 90 "$moddir/parse-syslog-opts.sh" + inst_hook pre-udev 61 "$moddir/syslog-genrules.sh" + inst_hook cleanup 99 "$moddir/syslog-cleanup.sh" + inst_simple "$moddir/rsyslogd-start.sh" /sbin/rsyslogd-start + inst_simple "$moddir/rsyslogd-stop.sh" /sbin/rsyslogd-stop + mkdir -m 0755 -p ${initdir}/etc/templates + inst_simple "${moddir}/rsyslog.conf" /etc/templates/rsyslog.conf + fi + dracut_install logger + dracut_need_initqueue +} + diff --git a/xCAT-server/share/xcat/netboot/rh/dracut_105/patch/syslog/rsyslogd-start.sh b/xCAT-server/share/xcat/netboot/rh/dracut_105/patch/syslog/rsyslogd-start.sh new file mode 100755 index 000000000..4545af2c2 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rh/dracut_105/patch/syslog/rsyslogd-start.sh @@ -0,0 +1,56 @@ +#!/bin/sh +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh + +# Triggered by udev and starts rsyslogd with bootparameters + +type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh + +rsyslog_config() { + local server=$1 + shift + local syslog_template=$1 + shift + local filters=$* + local filter= + local confline= + + cat $syslog_template + +# for filter in $filters; do +# echo "${filter} @${server}" +# done + + # In dracut 33, default rsyslogd configuration does not use journald. Then when + # rsyslog in debug mode, it causes `/dev/log` is not available after switch_root (#4929) + echo "\$ModLoad imjournal" + echo "\$OmitLocalLogging on" + echo "\$IMJournalStateFile imjournal.state" + + if [ -n "$filters" ];then + confline="${filters}"; + else + confline="*.*" + fi + + if [ -n "$server" ];then + confline="$confline @${server}" + else + confline="$confline /var/log/messages" + fi + + echo "$confline" +# echo "*.* /tmp/syslog" +} + +[ -f /tmp/syslog.server ] && read server < /tmp/syslog.server +[ -f /tmp/syslog.filters ] && read filters < /tmp/syslog.filters +[ -z "$filters" ] && filters="kern.*" +[ -f /tmp/syslog.conf ] && read conf < /tmp/syslog.conf +[ -z "$conf" ] && conf="/etc/rsyslog.conf" && echo "$conf" > /tmp/syslog.conf + +template=/etc/templates/rsyslog.conf +if [ -n "$server" ]; then + rsyslog_config "$server" "$template" "$filters" > $conf + rsyslogd -i /var/run/syslogd.pid +fi diff --git a/xCAT-server/share/xcat/netboot/rh/dracut_105/patch/syslog/syslog-genrules.sh b/xCAT-server/share/xcat/netboot/rh/dracut_105/patch/syslog/syslog-genrules.sh new file mode 100755 index 000000000..6f9d0d262 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rh/dracut_105/patch/syslog/syslog-genrules.sh @@ -0,0 +1,97 @@ +#!/bin/sh +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh + +# Creates the syslog udev rules to be triggered when interface becomes online. +type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh + +detect_syslog() { + syslogtype="" + if [ -e /sbin/rsyslogd ]; then + syslogtype="rsyslogd" + elif [ -e /sbin/syslogd ]; then + syslogtype="syslogd" + elif [ /sbin/syslog-ng ]; then + syslogtype="syslog-ng" + else + warn "Could not find any syslog binary although the syslogmodule is selected to be installed. Please check." + fi + echo "$syslogtype" + [ -n "$syslogtype" ] +} + +#the initqueue.sh shipped does not support --online option and +#there are some problem when processing --onetime option +#implement a patched initqueue function here, named initqueue_enhanced +initqueue_enhanced() { + local onetime= + local qname= + local unique= + local name= + local env= + while [ $# -gt 0 ]; do + case "$1" in + --onetime) + onetime="yes";; + --settled) + qname="/settled";; + --finished) + qname="/finished";; + --timeout) + qname="/timeout";; + --online) + qname="/online";; + --unique) + unique="yes";; + --name) + name="$2";shift;; + --env) + env="$2"; shift;; + *) + break;; + esac + shift + done + + local job= + if [ -z "$unique" ]; then + job="${name}$$" + else + job="${name:-$1}" + job=${job##*/} + fi + + local exe= + exe=$1 + shift + + [ -x "$exe" ] || exe=$(command -v $exe) + if [ -z "$exe" ] ; then + echo "Invalid command" + return 1 + fi + + { + [ -n "$env" ] && echo "$env" + echo "$exe $@" + [ -n "$onetime" ] && echo "[ -e $hookdir/initqueue${qname}/${job}.sh ] && rm -f -- $hookdir/initqueue${qname}/${job}.sh" + } > "/tmp/$$-${job}.sh" + + mv -f "/tmp/$$-${job}.sh" "$hookdir/initqueue${qname}/${job}.sh" + [ -z "$qname" ] && >> $hookdir/initqueue/work + + return 0 +} + +[ -f /tmp/syslog.type ] && read syslogtype < /tmp/syslog.type +if [ -z "$syslogtype" ]; then + syslogtype=$(detect_syslog) + echo $syslogtype > /tmp/syslog.type +fi +if [ -e "/sbin/${syslogtype}-start" ]; then + #printf 'ACTION=="online", SUBSYSTEM=="net", RUN+="/sbin/initqueue --onetime /sbin/'${syslogtype}'-start $env{INTERFACE}"\n' > /etc/udev/rules.d/70-syslog.rules + #printf 'ATTR{operstate}!="down", SUBSYSTEM=="net", RUN+="/sbin/initqueue --onetime /sbin/'${syslogtype}'-start $env{INTERFACE}"\n' > /etc/udev/rules.d/70-syslog.rules + initqueue_enhanced --online --onetime /sbin/${syslogtype}-start +else + warn "syslog-genrules: Could not find binary to start syslog of type \"$syslogtype\". Syslog will not be started." +fi diff --git a/xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/installkernel b/xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/installkernel new file mode 100755 index 000000000..7902ce5f7 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/installkernel @@ -0,0 +1,2 @@ +#!/bin/bash +instmods nfs sunrpc diff --git a/xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/module-setup.sh b/xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/module-setup.sh new file mode 100644 index 000000000..5c67754c3 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/module-setup.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# Dracut module for xCAT Stateless Boot +# /opt/xcat/.../dracut_105/stateless/module-setup.sh + +check() { + # Always allow this module to load + return 0 +} + +depends() { + echo "network nfs" + # EL10 may require network-manager explicitly if selected + return 0 +} + +install() { + # Install binaries + # Note: Copied from dracut_047/install.netboot + dracut_install curl tar cpio gzip modprobe touch echo cut wc xz \ + grep ifconfig hostname awk egrep dirname expr \ + mount.nfs parted mke2fs bc mkswap swapon chmod mkfs mkfs.ext4 mkfs.xfs xfs_db \ + ethtool + + # xCAT helper scripts + inst_script "$moddir/xcatroot" "/sbin/xcatroot" + inst_simple "$moddir/xcat-updateflag" "/tmp/updateflag" + + # cmdline hook + inst_hook cmdline 10 "$moddir/xcat-cmdline.sh" + + # udev rules with "xcat" + for file in /etc/udev/rules.d/*; do + if grep -qi xcat "$file"; then + inst_simple "$file" "$file" + fi + done +} diff --git a/xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcat-cmdline.sh b/xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcat-cmdline.sh new file mode 100644 index 000000000..0c12de011 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcat-cmdline.sh @@ -0,0 +1,5 @@ +root=1 +rootok=1 +netroot=xcat +echo '[ -e $NEWROOT/proc ]' > $hookdir/initqueue/finished/xcatroot.sh +chmod +x $hookdir/initqueue/finished/xcatroot.sh diff --git a/xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcat-updateflag b/xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcat-updateflag new file mode 100755 index 000000000..336d88ffd --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcat-updateflag @@ -0,0 +1,40 @@ +#!/usr/bin/awk -f +# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html + +BEGIN { + xcatdhost = ARGV[1] + xcatdport = ARGV[2] + flag = ARGV[3] + + if (!flag) flag = "next" + + ns = "/inet/tcp/0/" xcatdhost "/" xcatdport + + loop = 0 + while(1) { + if((ns |& getline) > 0) + print $0 | "logger -t xcat -p local4.info" + else { + print "Retrying flag update" | "logger -t xcat -p local4.info" + print "updateflag.awk: Retrying flag update" >> "/var/log/xcat/xcat.log" + close(ns) + system("sleep 10") + loop = loop + 1 + } + + if($0 == "ready") + print flag |& ns + if($0 == "done") + break + if(loop > 10) { + print "flag update failed" | "logger -t xcat -p local4.info" + print "updateflag.awk: flag update failed" >> "/var/log/xcat/xcat.log" + break + } + } + + close(ns) + + exit 0 +} + diff --git a/xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcatroot b/xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcatroot new file mode 100755 index 000000000..b851865b5 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcatroot @@ -0,0 +1,385 @@ +#!/bin/bash +log_label="xcat.deployment" + +NEWROOT=$3 +RWDIR=.statelite + +. /lib/dracut-lib.sh +XCAT="$(getarg XCAT=)" +XCATMASTER=$XCAT +STATEMNT="$(getarg STATEMNT=)" +rootlimit="$(getarg rootlimit=)" +xcatdebugmode="$(getarg xcatdebugmode=)" +rflags="$(getarg rootflags=)" +getarg nonodestatus +NODESTATUS=$? + +MASTER=`echo $XCATMASTER |awk -F: '{print $1}'` +XCATIPORT="$(getarg XCATIPORT=)" +if [ $? -ne 0 ]; then + XCATIPORT="3002" +fi + +[ "$xcatdebugmode" = "1" -o "$xcatdebugmode" = "2" ] && SYSLOGHOST="" || SYSLOGHOST="-n $MASTER" +logger $SYSLOGHOST -t $log_label -p local4.info "=============deployment starting====================" +logger $SYSLOGHOST -t $log_label -p local4.info "Executing xcatroot to prepare for netbooting (dracut_33)..." +[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "MASTER=$MASTER XCATIPORT=$XCATIPORT NODESTATUS=$NODESTATUS" + +if [ "$NODESTATUS" != "0" ]; then + logger $SYSLOGHOST -t $log_label -p local4.info "Sending request to $MASTER:$XCATIPORT for changing status to netbooting..." + /tmp/updateflag $MASTER $XCATIPORT "installstatus netbooting" +fi + + +imgurl="$(getarg imgurl=)"; +if [ ! -z "$imgurl" ]; then + if [ xhttp = x${imgurl%%:*} ]; then + logger $SYSLOGHOST -t $log_label -p local4.info "Downloading rootfs image from $imgurl..." + NFS=0 + FILENAME=${imgurl##*/} + while [ ! -r "$FILENAME" ]; do + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Downloading $imgurl..." + echo Getting $imgurl... + if ! curl --fail $imgurl -o $FILENAME; then + logger $SYSLOGHOST -t $log_label -p local4.error "Downloading $imgurl FAILED, retrying..." + rm -f $FILENAME + echo Failed to get the image, waiting for next retrying... + sleep 27 + fi + done + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Download complete." + elif [ xnfs = x${imgurl%%:*} ]; then + NFS=1 + SERVER=${imgurl#nfs:} + SERVER=${SERVER#/} + SERVER=${SERVER#/} + ROOTDIR=$SERVER + SERVER=${SERVER%%/*} + SERVER=${SERVER%:} + ROOTDIR=/${ROOTDIR#*/} + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "SERVER=$SERVER ROOTDIR=$ROOTDIR" + fi +fi +#echo 0 > /proc/sys/vm/zone_reclaim_mode #Avoid kernel bug + +if [ -r /rootimg.sfs ]; then + echo Setting up squashfs with ram overlay. + mknod /dev/loop0 b 7 0 + mkdir -p /ro + mkdir -p /rw + mount -t squashfs /rootimg.sfs /ro + mount -t tmpfs rw /rw + modprobe overlay + if [ $? -eq 0 ]; then + echo "Mounting $NEWROOT with type overlay" + mkdir -p /rw/upper + mkdir -p /rw/work + mount -t overlay -o lowerdir=/ro,upperdir=/rw/upper,workdir=/rw/work mergedroot $NEWROOT + else + echo "Mounting $NEWROOT with type aufs" + mount -t aufs -o dirs=/rw:/ro mergedroot $NEWROOT + mkdir -p $NEWROOT/ro + mkdir -p $NEWROOT/rw + mount --move /ro $NEWROOT/ro + mount --move /rw $NEWROOT/rw + fi +elif [ -r /rootimg.cpio.gz ] || [ -r /rootimg.cpio.xz ]; then + logger $SYSLOGHOST -t $log_label -p local4.info "Setting up RAM-root tmpfs on downloaded rootimg.cpio.[gz/xz]..." + echo Setting up RAM-root tmpfs. + rootopts="mode=755" + if [ -n "$rflags" ]; then + rootopts="$rootopts","$rflags" + fi + if [ -z "$rootlimit" ];then + mount -t tmpfs -o $rootopts rootfs $NEWROOT + else + mount -t tmpfs -o "$rootopts",size=$rootlimit rootfs $NEWROOT + fi + + cd $NEWROOT + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Extracting the root filesystem..." + echo "Extracting the root filesystem..." + if [ -r /rootimg.cpio.gz ]; then + if [ -x /bin/cpio ]; then + gzip -cd /rootimg.cpio.gz |/bin/cpio -idum + else + gzip -cd /rootimg.cpio.gz |cpio -idum + fi + elif [ -r /rootimg.cpio.xz ]; then + if [ -x /bin/cpio ]; then + xz -cd /rootimg.cpio.xz |/bin/cpio -idum + else + xz -cd /rootimg.cpio.xz |cpio -idum + fi + fi + $NEWROOT/etc/init.d/localdisk + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Done extracting the root filesystem..." + echo "Done extracting the root filesystem..." +elif [ -r /rootimg.tar.gz ] || [ -r /rootimg.tar.xz ]; then + logger $SYSLOGHOST -t $log_label -p local4.info "Setting up RAM-root tmpfs on downloaded rootimg.tar.[gz/xz]..." + echo Setting up RAM-root tmpfs. + if [ -z $rootlimit ];then + mount -t tmpfs -o mode=755 rootfs $NEWROOT + else + mount -t tmpfs -o mode=755,size=$rootlimit rootfs $NEWROOT + fi + + cd $NEWROOT + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Extracting the root filesystem..." + echo "Extracting the root filesystem..." + if [ -r /rootimg.tar.gz ]; then + tar --selinux --xattrs-include='*' -zxf /rootimg.tar.gz + if [ $? -ne 0 ]; then + tar --selinux -zxf /rootimg.tar.gz + fi + elif [ -r /rootimg.tar.xz ]; then + tar --selinux --xattrs-include='*' -Jxf /rootimg.tar.xz + if [ $? -ne 0 ]; then + tar --selinux -Jxf /rootimg.tar.xz + fi + fi + $NEWROOT/etc/init.d/localdisk + msg="Done extracting the root filesystem." + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "$msg" + echo "$msg" +elif [ -r /rootimg-statelite.gz ]; then + msg="Setting up RAM-root tmpfs for statelite mode." + logger $SYSLOGHOST -t $log_label -p local4.info "$msg" + echo "$msg" + + if [ -z $rootlimit];then + mount -t tmpfs -o mode=755 rootfs $NEWROOT + else + mount -t tmpfs -o mode=755,size=$rootlimit rootfs $NEWROOT + fi + + cd $NEWROOT + msg="Extracting root filesystem..." + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "$msg" + echo "$msg" + if [ -x /bin/cpio ]; then + gzip -cd /rootimg-statelite.gz |/bin/cpio -idum + else + gzip -cd /rootimg-statelite.gz |cpio -idum + fi + msg="Done extracting the root filesystem." + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "$msg" + echo "$msg" + # then, the statelite staffs will be processed + msg="Setting up Statelite..." + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "$msg" + echo "$msg" + + modprobe nfs + MAXTRIES=7 + ITER=0 + if [ ! -e "$NEWROOT/$RWDIR" ]; then + echo "" + echo "The /$RWDIR directory doesn't exist in the rootimg... " + echo "" + logger $SYSLOGHOST -t $log_label -p local4.err "The /$RWDIR directory doesn't exist in the rootimg..." + /bin/sh + fi + + if [ ! -e "$NEWROOT/etc/init.d/statelite" ]; then + echo "" + echo "$NEWROOT/etc/init.d/statelite doesn't exist... " + echo "" + logger $SYSLOGHOST -t $log_label -p local4.err "$NEWROOT/etc/init.d/statelite doesn't exist... " + /bin/sh + fi + + mount -t tmpfs rw $NEWROOT/$RWDIR + mkdir -p $NEWROOT/$RWDIR/tmpfs + ME=`hostname -s` + if [ ! -z $NODE ]; then + ME=$NODE + fi + + + # mount the SNAPSHOT directory here for persistent use. + if [ ! -z $STATEMNT ]; then + SNAPSHOTSERVER=${STATEMNT%:*} + SNAPSHOTROOT=${STATEMNT#*/} + if [ -z $SNAPSHOTROOT ]; then + SNAPSHOTROOT=$SNAPSHOTSERVER + SNAPSHOTSERVER= + fi + fi + + if [ ! -z $SNAPSHOTSERVER ]; then + mkdir -p $NEWROOT/$RWDIR/persistent + MAXTRIES=5 + ITER=0 + if [ -z $MNTOPTS ]; then + MNT_OPTIONS="nolock,rsize=32768,tcp,timeo=14" + else + MNT_OPTIONS=$MNTOPTS + fi + while ! mount $SNAPSHOTSERVER:/$SNAPSHOTROOT $NEWROOT/$RWDIR/persistent -o $MNT_OPTIONS; do + ITER=$(( ITER + 1 )) + if [ "$ITER" == "$MAXTRIES" ]; then + msg="You are dead, rpower $ME boot to play again. + Possible problems: + 1. $SNAPSHOTSERVER is not exporting $SNAPSHOTROOT ? + 2. Is DNS set up? Maybe that's why I can't mount $SNAPSHOTSERVER." + echo "$msg" + logger $SYSLOGHOST -t $log_label -p local4.err "$msg" + /bin/sh + exit + fi + RS=$(( $RANDOM % 20 )) + echo "Trying again in $RS seconds ..." + sleep $RS + done + + # create directory which is named after my node name + mkdir -p $NEWROOT/$RWDIR/persistent/$ME + ITER=0 + # umount current persistent mount + while ! umount -l $NEWROOT/$RWDIR/persistent; do + ITER=$(( ITER + 1 )) + if [ "$ITER" == "$MAXTRIES" ]; then + msg="Your are dead, rpower $ME boot to play again. + Cannot umount $NEWROOT/$RWDIR/persistent." + echo "$msg" + logger $SYSLOGHOST -t $log_label -p local4.err "$msg" + /bin/sh + exit + fi + RS=$(( $RANDOM % 20 )) + echo "Trying again in $RS seconds..." + sleep $RS + done + + # mount persistent to server:/rootpath/nodename + ITER=0 + while ! mount $SNAPSHOTSERVER:/$SNAPSHOTROOT/$ME $NEWROOT/$RWDIR/persistent -o $MNT_OPTIONS; do + ITER=$(( ITER + 1 )) + if [ "$ITER" == "$MAXTRIES" ]; then + msg="Your are dead, rpower $ME boot to play again. + Possible problems: cannot mount to $SNAPSHOTSERVER:/$SNAPSHOTROOT/$ME." + echo "$msg" + logger $SYSLOGHOST -t $log_label -p local4.err "$msg" + /bin/sh + exit + fi + RS=$(( $RANDOM % 20 )) + echo "Trying again in $RS seconds..." + sleep $RS + done + fi + + logger $SYSLOGHOST -t $log_label -p local4.info "Enabling localdisk ..." + $NEWROOT/etc/init.d/localdisk + logger $SYSLOGHOST -t $log_label -p local4.info "Preparing mount points ..." + $NEWROOT/etc/init.d/statelite + fastboot=yes + export fastboot + keep_old_ip=yes + export keep_old_ip + + mount -n --bind /dev $NEWROOT/dev + mount -n --bind /proc $NEWROOT/proc + mount -n --bind /sys $NEWROOT/sys + +else + msg="Failed to download image, panic in 5..." + logger $SYSLOGHOST -t $log_label -p local4.error "$msg" + echo -n "$msg" + for i in 4 3 2 1 0; do + /bin/sleep 1 + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "$i..." + echo -n $i... + done + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "You're dead. rpower nodename reset to play again." + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "* Did you packimage with -m cpio, -m squashfs, or -m nfs?" + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "* If using -m squashfs did you include aufs.ko with geninitrd? e.g.: -n tg3,squashfs,aufs,loop" + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "If using -m nfs did you export NFS and sync rootimg? And did you include the aufs and nfs modules in the proper order: e.g.: -n tg3,aufs,loop,sunrpc,lockd,nfs_acl,nfs" + + echo + echo "You're dead. rpower nodename reset to play again. + +* Did you packimage with -m cpio, -m squashfs, or -m nfs? +* If using -m squashfs did you include aufs.ko with geninitrd? + e.g.: -n tg3,squashfs,aufs,loop +* If using -m nfs did you export NFS and sync rootimg? And + did you include the aufs and nfs modules in the proper order: + e.g.: -n tg3,aufs,loop,sunrpc,lockd,nfs_acl,nfs + +" + /bin/sh + exit +fi +cd / + +function getdevfrommac() { + boothwaddr=$1 + ip link show | while read line + do + dev=`echo $line | egrep "^[0-9]+: [0-9A-Za-z]+" | cut -d ' ' -f 2 | cut -d ':' -f 1` + if [ "X$dev" != "X" ]; then + devname=$dev + fi + + if [ "X$devname" != "X" ]; then + hwaddr=`echo $line | egrep "^[ ]*link" | awk '{print $2}'` + if [ "X$hwaddr" = "X$boothwaddr" ]; then + echo $devname + fi + fi + done +} + + +if [ -z $STATEMNT ]; then + for lf in /tmp/dhclient.*.lease; do + netif=${lf#*.} + netif=${netif%.*} + cp $lf "$NEWROOT/var/lib/dhclient/dhclient-$netif.leases" + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Saving $NEWROOT/var/lib/dhclient/dhclient-$netif.leases" + done + + ifname="$(getarg ifname=)" + netdev="$(getarg netdev=)" + BOOTIF="$(getarg BOOTIF=)" + if [ ! -z "$ifname" ]; then + MACX=${ifname#*:} + ETHX=${ifname%:$MACX*} + elif [ ! -z "$netdev" ]; then + ETHX=$netdev + MACX=`ip link show $netdev | grep ether | awk '{print $2}'` + elif [ ! -z "$BOOTIF" ]; then + MACX=$BOOTIF + MACX=${MACX#01-} + MACX=${MACX//-/:} + ETHX=$(getdevfrommac $MACX) + fi + + + if [ ! -z "$MACX" ] && [ ! -z "$ETHX" ]; then + if [ ! -e $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX ]; then + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Creating $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX" + touch $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX + fi + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Writing $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX: DEVICE=$ETHX;BOOTPROTO=dhcp;HWADDR=$MACX;ONBOOT=yes" + echo "DEVICE=$ETHX" > $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX + echo "BOOTPROTO=dhcp" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX + echo "HWADDR=$MACX" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX + echo "ONBOOT=yes" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX + fi +fi + +[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Saving $NEWROOT/etc/resolv.conf" +cp /etc/resolv.conf "$NEWROOT/etc/" + +if [ -d "$NEWROOT/etc/sysconfig" -a ! -e "$NEWROOT/etc/sysconfig/selinux" ]; then + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "disable selinux ..." + echo "SELINUX=disabled" >> "$NEWROOT/etc/sysconfig/selinux" +fi + +logger $SYSLOGHOST -t $log_label -p local4.info "Exiting xcatroot..." +# inject new exit_if_exists +echo 'settle_exit_if_exists="--exit-if-exists=/dev/root"; rm "$job"' > $hookdir/initqueue/xcat.sh +# force udevsettle to break +> $hookdir/initqueue/work diff --git a/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/installkernel b/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/installkernel new file mode 100755 index 000000000..7902ce5f7 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/installkernel @@ -0,0 +1,2 @@ +#!/bin/bash +instmods nfs sunrpc diff --git a/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/module-setup.sh b/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/module-setup.sh new file mode 100644 index 000000000..40dc6a31d --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/module-setup.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# Dracut module for xCAT Stateless Boot +# /opt/xcat/.../dracut_105/stateless/module-setup.sh + +check() { + # Always allow this module to load + return 0 +} + +depends() { + echo "network nfs" + # EL10 may require network-manager explicitly if selected + return 0 +} + +install() { + # Install required binaries + dracut_install \ + curl cpio gzip modprobe wc touch echo cut \ + grep ifconfig hostname awk egrep dirname expr \ + parted mke2fs bc mkswap swapon chmod \ + mkfs mkfs.ext4 mkfs.xfs xfs_db \ + ethtool + + # Install updateflag helper + inst_simple "$moddir/xcat-updateflag" "/sbin/xcat-updateflag" + + # Hooks + inst_hook pre-mount 50 "$moddir/xcat-premount.sh" + inst_hook pre-pivot 50 "$moddir/xcat-prepivot.sh" + + # Install xCAT udev rules + for f in /etc/udev/rules.d/*; do + if grep -qi xcat "$f"; then + inst_rules "$f" + fi + done +} diff --git a/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-cmdline.sh b/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-cmdline.sh new file mode 100644 index 000000000..80d088557 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-cmdline.sh @@ -0,0 +1,4 @@ +root=1 +rootok=1 +netroot=xcat +echo '[ -e $NEWROOT/proc ]' > $hookdir/initqueue/finished/xcatroot.sh diff --git a/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-premount.sh b/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-premount.sh new file mode 100644 index 000000000..9f320bb66 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-premount.sh @@ -0,0 +1,24 @@ +#!/bin/sh +#script to update nodelist.nodestatus during provision + +XCAT="$(getarg XCAT=)" +STATEMNT="$(getarg STATEMNT=)" +MASTER=`echo $XCAT |awk -F: '{print $1}'` + +getarg nonodestatus +NODESTATUS=$? + +XCATIPORT="$(getarg XCATIPORT=)" +if [ $? -ne 0 ]; then +XCATIPORT="3002" +fi + +log_label="xcat.deployment" +[ "$xcatdebugmode" = "1" -o "$xcatdebugmode" = "2" ] && SYSLOGHOST="" || SYSLOGHOST="-n $MASTER" +logger $SYSLOGHOST -t $log_label -p local4.info "=============deployment starting====================" +logger $SYSLOGHOST -t $log_label -p local4.info "Starting xcat-premount..." +[ "$xcatdebugmode" > "0" ] && logger $SYSLOGHOST -t $log_label -p local4.debug "MASTER=$MASTER XCATIPORT=$XCATIPORT NODESTATUS=$NODESTATUS" +if [ $NODESTATUS -ne 0 ];then + logger $SYSLOGHOST -t $log_label -p local4.info "Sending request to $MASTER:$XCATIPORT for changing status to netbooting..." +/tmp/updateflag $MASTER $XCATIPORT "installstatus netbooting" +fi diff --git a/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-prepivot.sh b/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-prepivot.sh new file mode 100755 index 000000000..a3bcb8188 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-prepivot.sh @@ -0,0 +1,202 @@ +#!/bin/bash +log_label="xcat.deployment" +NEWROOT=/sysroot +SERVER=${SERVER%%/*} +SERVER=${SERVER%:} +RWDIR=.statelite +XCAT="$(getarg XCAT=)" +xcatdebugmode="$(getarg xcatdebugmode=)" +XCATMASTER=$XCAT +MASTER=`echo $XCATMASTER |awk -F: '{print $1}'` +STATEMNT="$(getarg STATEMNT=)" +if [ ! -z $STATEMNT ]; then #btw, uri style might have left future options other than nfs open, will u se // to detect uri in the future I guess + SNAPSHOTSERVER=${STATEMNT%:*} + SNAPSHOTROOT=${STATEMNT#*/} + #echo $SNAPSHOTROOT + #echo $SNAPSHOTSERVER + # may be that there is not server and just a directory. + if [ -z $SNAPSHOTROOT ]; then + SNAPSHOTROOT=$SNAPSHOTSERVER + SNAPSHOTSERVER= + fi +fi + + +[ "$xcatdebugmode" = "1" -o "$xcatdebugmode" = "2" ] && SYSLOGHOST="" || SYSLOGHOST="-n $MASTER" +logger $SYSLOGHOST -t $log_label -p local4.info "Executing xcat-prepivot to set up statelite..." +echo Setting up Statelite +mkdir -p $NEWROOT + +# now we need to mount the rest of the system. This is the read/write portions +# echo Mounting snapshot directories + +MAXTRIES=7 +ITER=0 +if [ ! -e "$NEWROOT/$RWDIR" ]; then + echo "" + msg="This NFS root directory doesn't have a /$RWDIR directory for me to mount a rw filesystem. You'd better create it... " + echo "$msg" + echo "" + logger $SYSLOGHOST -t $log_label -p local4.error "$msg" + /bin/sh +fi + +if [ ! -e "$NEWROOT/etc/init.d/statelite" ]; then + echo "" + msg="$NEWROOT/etc/init.d/statelite doesn't exist. Perhaps you didn't create this image with the -m statelite mode" + echo "$msg" + logger $SYSLOGHOST -t $log_label -p local4.error "$msg" + echo "" + /bin/sh +fi + +mount -t tmpfs rw $NEWROOT/$RWDIR +mkdir -p $NEWROOT/$RWDIR/tmpfs +ME=`hostname -s` +if [ ! -z $NODE ]; then + ME=$NODE +fi + +# mount the SNAPSHOT directory here for persistent use. +if [ ! -z $SNAPSHOTSERVER ]; then + mkdir -p $NEWROOT/$RWDIR/persistent + MAXTRIES=5 + ITER=0 + if [ -z $MNTOPTS ]; then + MNT_OPTIONS="nolock,rsize=32768,tcp,timeo=14" + else + MNT_OPTIONS=$MNTOPTS + fi + while ! mount $SNAPSHOTSERVER:/$SNAPSHOTROOT $NEWROOT/$RWDIR/persistent -o $MNT_OPTIONS; do + ITER=$(( ITER + 1 )) + if [ "$ITER" == "$MAXTRIES" ]; then + msg="Your are dead, rpower $ME boot to play again. + Possible problems: +1. $SNAPSHOTSERVER is not exporting $SNAPSHOTROOT ? +2. Is DNS set up? Maybe that's why I can't mount $SNAPSHOTSERVER." + echo "$msg" + logger $SYSLOGHOST -t $log_label -p local4.error "$msg" + /bin/sh + exit + fi + RS=$(( $RANDOM % 20 )) + msg="Trying again in $RS seconds..." + echo "$msg" + logger $SYSLOGHOST -t $log_label -p local4.info "$msg" + sleep $RS + done + + # create directory which is named after my node name + mkdir -p $NEWROOT/$RWDIR/persistent/$ME + ITER=0 + # umount current persistent mount + while ! umount -l $NEWROOT/$RWDIR/persistent; do + ITER=$(( ITER + 1 )) + if [ "$ITER" == "$MAXTRIES" ]; then + msg="Your are dead, rpower $ME boot to play again. + Cannot umount $NEWROOT/$RWDIR/persistent." + echo "$msg" + logger $SYSLOGHOST -t $log_label -p local4.error "$msg" + /bin/sh + exit + fi + RS=$(( $RANDOM % 20 )) + msg="Trying again in $RS seconds..." + echo "$msg" + logger $SYSLOGHOST -t $log_label -p local4.info "$msg" + sleep $RS + done + + # mount persistent to server:/rootpath/nodename + ITER=0 + while ! mount $SNAPSHOTSERVER:/$SNAPSHOTROOT/$ME $NEWROOT/$RWDIR/persistent -o $MNT_OPTIONS; do + ITER=$(( ITER + 1 )) + if [ "$ITER" == "$MAXTRIES" ]; then + msg="Your are dead, rpower $ME boot to play again. + Possible problems: cannot mount to $SNAPSHOTSERVER:/$SNAPSHOTROOT/$ME." + echo $msg + logger $SYSLOGHOST -t $log_label -p local4.info "$msg" + /bin/sh + exit + fi + RS=$(( $RANDOM % 20 )) + msg="Trying again in $RS seconds..." + echo "$msg" + logger $SYSLOGHOST -t $log_label -p local4.info "$msg" + sleep $RS + done +fi + +# TODO: handle the dhclient/resolv.conf/ntp, etc +logger $SYSLOGHOST -t $log_label -p local4.info "Enabling localdisk ..." +echo "Enable localdisk ..." +$NEWROOT/etc/init.d/localdisk +logger $SYSLOGHOST -t $log_label -p local4.info "Preparing mount points ..." +$NEWROOT/etc/init.d/statelite +READONLY=yes +export READONLY +fastboot=yes +export fastboot +keep_old_ip=yes +export keep_old_ip +mount -n --bind /dev $NEWROOT/dev +mount -n --bind /proc $NEWROOT/proc +mount -n --bind /sys $NEWROOT/sys + +function getdevfrommac() { + boothwaddr=$1 + ip link show | while read line + do + dev=`echo $line | egrep "^[0-9]+: [0-9A-Za-z]+" | cut -d ' ' -f 2 | cut -d ':' -f 1` + if [ "X$dev" != "X" ]; then + devname=$dev + fi + + if [ "X$devname" != "X" ]; then + hwaddr=`echo $line | egrep "^[ ]*link" | awk '{print $2}'` + if [ "X$hwaddr" = "X$boothwaddr" ]; then + echo $devname + fi + fi + done +} + + +for lf in /tmp/dhclient.*.lease; do + netif=${lf#*.} + netif=${netif%.*} + cp $lf "$NEWROOT/var/lib/dhclient/dhclient-$netif.leases" +done + +if [ ! -z "$ifname" ]; then + MACX=${ifname#*:} + ETHX=${ifname%:$MACX*} +elif [ ! -z "$netdev" ]; then + ETHX=$netdev + MACX=`ip link show $netdev | grep ether | awk '{print $2}'` +elif [ ! -z "$BOOTIF" ]; then + MACX=$BOOTIF + ETHX=$(getdevfrommac $BOOTIF) +fi + +if [ ! -z "$MACX" ] && [ ! -z "$ETHX" ]; then + if [ ! -e $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX ]; then + touch $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX + fi + echo "DEVICE=$ETHX" > $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX + echo "BOOTPROTO=dhcp" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX + echo "HWADDR=$MACX" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX + echo "ONBOOT=yes" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX +fi + +cp /etc/resolv.conf "$NEWROOT/etc/" + +if [ -d "$NEWROOT/etc/sysconfig" -a ! -e "$NEWROOT/etc/sysconfig/selinux" ]; then + echo "SELINUX=disabled" >> "$NEWROOT/etc/sysconfig/selinux" +fi + +# inject new exit_if_exists +echo 'settle_exit_if_exists="--exit-if-exists=/dev/root"; rm "$job"' > $hookdir/initqueue/xcat.sh +# force udevsettle to break +> $hookdir/initqueue/work +logger $SYSLOGHOST -t $log_label -p local4.info "Exit xcat-prepivot" diff --git a/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-updateflag b/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-updateflag new file mode 100755 index 000000000..336d88ffd --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-updateflag @@ -0,0 +1,40 @@ +#!/usr/bin/awk -f +# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html + +BEGIN { + xcatdhost = ARGV[1] + xcatdport = ARGV[2] + flag = ARGV[3] + + if (!flag) flag = "next" + + ns = "/inet/tcp/0/" xcatdhost "/" xcatdport + + loop = 0 + while(1) { + if((ns |& getline) > 0) + print $0 | "logger -t xcat -p local4.info" + else { + print "Retrying flag update" | "logger -t xcat -p local4.info" + print "updateflag.awk: Retrying flag update" >> "/var/log/xcat/xcat.log" + close(ns) + system("sleep 10") + loop = loop + 1 + } + + if($0 == "ready") + print flag |& ns + if($0 == "done") + break + if(loop > 10) { + print "flag update failed" | "logger -t xcat -p local4.info" + print "updateflag.awk: flag update failed" >> "/var/log/xcat/xcat.log" + break + } + } + + close(ns) + + exit 0 +} + diff --git a/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcatroot b/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcatroot new file mode 100755 index 000000000..b851865b5 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcatroot @@ -0,0 +1,385 @@ +#!/bin/bash +log_label="xcat.deployment" + +NEWROOT=$3 +RWDIR=.statelite + +. /lib/dracut-lib.sh +XCAT="$(getarg XCAT=)" +XCATMASTER=$XCAT +STATEMNT="$(getarg STATEMNT=)" +rootlimit="$(getarg rootlimit=)" +xcatdebugmode="$(getarg xcatdebugmode=)" +rflags="$(getarg rootflags=)" +getarg nonodestatus +NODESTATUS=$? + +MASTER=`echo $XCATMASTER |awk -F: '{print $1}'` +XCATIPORT="$(getarg XCATIPORT=)" +if [ $? -ne 0 ]; then + XCATIPORT="3002" +fi + +[ "$xcatdebugmode" = "1" -o "$xcatdebugmode" = "2" ] && SYSLOGHOST="" || SYSLOGHOST="-n $MASTER" +logger $SYSLOGHOST -t $log_label -p local4.info "=============deployment starting====================" +logger $SYSLOGHOST -t $log_label -p local4.info "Executing xcatroot to prepare for netbooting (dracut_33)..." +[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "MASTER=$MASTER XCATIPORT=$XCATIPORT NODESTATUS=$NODESTATUS" + +if [ "$NODESTATUS" != "0" ]; then + logger $SYSLOGHOST -t $log_label -p local4.info "Sending request to $MASTER:$XCATIPORT for changing status to netbooting..." + /tmp/updateflag $MASTER $XCATIPORT "installstatus netbooting" +fi + + +imgurl="$(getarg imgurl=)"; +if [ ! -z "$imgurl" ]; then + if [ xhttp = x${imgurl%%:*} ]; then + logger $SYSLOGHOST -t $log_label -p local4.info "Downloading rootfs image from $imgurl..." + NFS=0 + FILENAME=${imgurl##*/} + while [ ! -r "$FILENAME" ]; do + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Downloading $imgurl..." + echo Getting $imgurl... + if ! curl --fail $imgurl -o $FILENAME; then + logger $SYSLOGHOST -t $log_label -p local4.error "Downloading $imgurl FAILED, retrying..." + rm -f $FILENAME + echo Failed to get the image, waiting for next retrying... + sleep 27 + fi + done + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Download complete." + elif [ xnfs = x${imgurl%%:*} ]; then + NFS=1 + SERVER=${imgurl#nfs:} + SERVER=${SERVER#/} + SERVER=${SERVER#/} + ROOTDIR=$SERVER + SERVER=${SERVER%%/*} + SERVER=${SERVER%:} + ROOTDIR=/${ROOTDIR#*/} + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "SERVER=$SERVER ROOTDIR=$ROOTDIR" + fi +fi +#echo 0 > /proc/sys/vm/zone_reclaim_mode #Avoid kernel bug + +if [ -r /rootimg.sfs ]; then + echo Setting up squashfs with ram overlay. + mknod /dev/loop0 b 7 0 + mkdir -p /ro + mkdir -p /rw + mount -t squashfs /rootimg.sfs /ro + mount -t tmpfs rw /rw + modprobe overlay + if [ $? -eq 0 ]; then + echo "Mounting $NEWROOT with type overlay" + mkdir -p /rw/upper + mkdir -p /rw/work + mount -t overlay -o lowerdir=/ro,upperdir=/rw/upper,workdir=/rw/work mergedroot $NEWROOT + else + echo "Mounting $NEWROOT with type aufs" + mount -t aufs -o dirs=/rw:/ro mergedroot $NEWROOT + mkdir -p $NEWROOT/ro + mkdir -p $NEWROOT/rw + mount --move /ro $NEWROOT/ro + mount --move /rw $NEWROOT/rw + fi +elif [ -r /rootimg.cpio.gz ] || [ -r /rootimg.cpio.xz ]; then + logger $SYSLOGHOST -t $log_label -p local4.info "Setting up RAM-root tmpfs on downloaded rootimg.cpio.[gz/xz]..." + echo Setting up RAM-root tmpfs. + rootopts="mode=755" + if [ -n "$rflags" ]; then + rootopts="$rootopts","$rflags" + fi + if [ -z "$rootlimit" ];then + mount -t tmpfs -o $rootopts rootfs $NEWROOT + else + mount -t tmpfs -o "$rootopts",size=$rootlimit rootfs $NEWROOT + fi + + cd $NEWROOT + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Extracting the root filesystem..." + echo "Extracting the root filesystem..." + if [ -r /rootimg.cpio.gz ]; then + if [ -x /bin/cpio ]; then + gzip -cd /rootimg.cpio.gz |/bin/cpio -idum + else + gzip -cd /rootimg.cpio.gz |cpio -idum + fi + elif [ -r /rootimg.cpio.xz ]; then + if [ -x /bin/cpio ]; then + xz -cd /rootimg.cpio.xz |/bin/cpio -idum + else + xz -cd /rootimg.cpio.xz |cpio -idum + fi + fi + $NEWROOT/etc/init.d/localdisk + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Done extracting the root filesystem..." + echo "Done extracting the root filesystem..." +elif [ -r /rootimg.tar.gz ] || [ -r /rootimg.tar.xz ]; then + logger $SYSLOGHOST -t $log_label -p local4.info "Setting up RAM-root tmpfs on downloaded rootimg.tar.[gz/xz]..." + echo Setting up RAM-root tmpfs. + if [ -z $rootlimit ];then + mount -t tmpfs -o mode=755 rootfs $NEWROOT + else + mount -t tmpfs -o mode=755,size=$rootlimit rootfs $NEWROOT + fi + + cd $NEWROOT + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Extracting the root filesystem..." + echo "Extracting the root filesystem..." + if [ -r /rootimg.tar.gz ]; then + tar --selinux --xattrs-include='*' -zxf /rootimg.tar.gz + if [ $? -ne 0 ]; then + tar --selinux -zxf /rootimg.tar.gz + fi + elif [ -r /rootimg.tar.xz ]; then + tar --selinux --xattrs-include='*' -Jxf /rootimg.tar.xz + if [ $? -ne 0 ]; then + tar --selinux -Jxf /rootimg.tar.xz + fi + fi + $NEWROOT/etc/init.d/localdisk + msg="Done extracting the root filesystem." + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "$msg" + echo "$msg" +elif [ -r /rootimg-statelite.gz ]; then + msg="Setting up RAM-root tmpfs for statelite mode." + logger $SYSLOGHOST -t $log_label -p local4.info "$msg" + echo "$msg" + + if [ -z $rootlimit];then + mount -t tmpfs -o mode=755 rootfs $NEWROOT + else + mount -t tmpfs -o mode=755,size=$rootlimit rootfs $NEWROOT + fi + + cd $NEWROOT + msg="Extracting root filesystem..." + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "$msg" + echo "$msg" + if [ -x /bin/cpio ]; then + gzip -cd /rootimg-statelite.gz |/bin/cpio -idum + else + gzip -cd /rootimg-statelite.gz |cpio -idum + fi + msg="Done extracting the root filesystem." + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "$msg" + echo "$msg" + # then, the statelite staffs will be processed + msg="Setting up Statelite..." + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "$msg" + echo "$msg" + + modprobe nfs + MAXTRIES=7 + ITER=0 + if [ ! -e "$NEWROOT/$RWDIR" ]; then + echo "" + echo "The /$RWDIR directory doesn't exist in the rootimg... " + echo "" + logger $SYSLOGHOST -t $log_label -p local4.err "The /$RWDIR directory doesn't exist in the rootimg..." + /bin/sh + fi + + if [ ! -e "$NEWROOT/etc/init.d/statelite" ]; then + echo "" + echo "$NEWROOT/etc/init.d/statelite doesn't exist... " + echo "" + logger $SYSLOGHOST -t $log_label -p local4.err "$NEWROOT/etc/init.d/statelite doesn't exist... " + /bin/sh + fi + + mount -t tmpfs rw $NEWROOT/$RWDIR + mkdir -p $NEWROOT/$RWDIR/tmpfs + ME=`hostname -s` + if [ ! -z $NODE ]; then + ME=$NODE + fi + + + # mount the SNAPSHOT directory here for persistent use. + if [ ! -z $STATEMNT ]; then + SNAPSHOTSERVER=${STATEMNT%:*} + SNAPSHOTROOT=${STATEMNT#*/} + if [ -z $SNAPSHOTROOT ]; then + SNAPSHOTROOT=$SNAPSHOTSERVER + SNAPSHOTSERVER= + fi + fi + + if [ ! -z $SNAPSHOTSERVER ]; then + mkdir -p $NEWROOT/$RWDIR/persistent + MAXTRIES=5 + ITER=0 + if [ -z $MNTOPTS ]; then + MNT_OPTIONS="nolock,rsize=32768,tcp,timeo=14" + else + MNT_OPTIONS=$MNTOPTS + fi + while ! mount $SNAPSHOTSERVER:/$SNAPSHOTROOT $NEWROOT/$RWDIR/persistent -o $MNT_OPTIONS; do + ITER=$(( ITER + 1 )) + if [ "$ITER" == "$MAXTRIES" ]; then + msg="You are dead, rpower $ME boot to play again. + Possible problems: + 1. $SNAPSHOTSERVER is not exporting $SNAPSHOTROOT ? + 2. Is DNS set up? Maybe that's why I can't mount $SNAPSHOTSERVER." + echo "$msg" + logger $SYSLOGHOST -t $log_label -p local4.err "$msg" + /bin/sh + exit + fi + RS=$(( $RANDOM % 20 )) + echo "Trying again in $RS seconds ..." + sleep $RS + done + + # create directory which is named after my node name + mkdir -p $NEWROOT/$RWDIR/persistent/$ME + ITER=0 + # umount current persistent mount + while ! umount -l $NEWROOT/$RWDIR/persistent; do + ITER=$(( ITER + 1 )) + if [ "$ITER" == "$MAXTRIES" ]; then + msg="Your are dead, rpower $ME boot to play again. + Cannot umount $NEWROOT/$RWDIR/persistent." + echo "$msg" + logger $SYSLOGHOST -t $log_label -p local4.err "$msg" + /bin/sh + exit + fi + RS=$(( $RANDOM % 20 )) + echo "Trying again in $RS seconds..." + sleep $RS + done + + # mount persistent to server:/rootpath/nodename + ITER=0 + while ! mount $SNAPSHOTSERVER:/$SNAPSHOTROOT/$ME $NEWROOT/$RWDIR/persistent -o $MNT_OPTIONS; do + ITER=$(( ITER + 1 )) + if [ "$ITER" == "$MAXTRIES" ]; then + msg="Your are dead, rpower $ME boot to play again. + Possible problems: cannot mount to $SNAPSHOTSERVER:/$SNAPSHOTROOT/$ME." + echo "$msg" + logger $SYSLOGHOST -t $log_label -p local4.err "$msg" + /bin/sh + exit + fi + RS=$(( $RANDOM % 20 )) + echo "Trying again in $RS seconds..." + sleep $RS + done + fi + + logger $SYSLOGHOST -t $log_label -p local4.info "Enabling localdisk ..." + $NEWROOT/etc/init.d/localdisk + logger $SYSLOGHOST -t $log_label -p local4.info "Preparing mount points ..." + $NEWROOT/etc/init.d/statelite + fastboot=yes + export fastboot + keep_old_ip=yes + export keep_old_ip + + mount -n --bind /dev $NEWROOT/dev + mount -n --bind /proc $NEWROOT/proc + mount -n --bind /sys $NEWROOT/sys + +else + msg="Failed to download image, panic in 5..." + logger $SYSLOGHOST -t $log_label -p local4.error "$msg" + echo -n "$msg" + for i in 4 3 2 1 0; do + /bin/sleep 1 + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "$i..." + echo -n $i... + done + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "You're dead. rpower nodename reset to play again." + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "* Did you packimage with -m cpio, -m squashfs, or -m nfs?" + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "* If using -m squashfs did you include aufs.ko with geninitrd? e.g.: -n tg3,squashfs,aufs,loop" + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "If using -m nfs did you export NFS and sync rootimg? And did you include the aufs and nfs modules in the proper order: e.g.: -n tg3,aufs,loop,sunrpc,lockd,nfs_acl,nfs" + + echo + echo "You're dead. rpower nodename reset to play again. + +* Did you packimage with -m cpio, -m squashfs, or -m nfs? +* If using -m squashfs did you include aufs.ko with geninitrd? + e.g.: -n tg3,squashfs,aufs,loop +* If using -m nfs did you export NFS and sync rootimg? And + did you include the aufs and nfs modules in the proper order: + e.g.: -n tg3,aufs,loop,sunrpc,lockd,nfs_acl,nfs + +" + /bin/sh + exit +fi +cd / + +function getdevfrommac() { + boothwaddr=$1 + ip link show | while read line + do + dev=`echo $line | egrep "^[0-9]+: [0-9A-Za-z]+" | cut -d ' ' -f 2 | cut -d ':' -f 1` + if [ "X$dev" != "X" ]; then + devname=$dev + fi + + if [ "X$devname" != "X" ]; then + hwaddr=`echo $line | egrep "^[ ]*link" | awk '{print $2}'` + if [ "X$hwaddr" = "X$boothwaddr" ]; then + echo $devname + fi + fi + done +} + + +if [ -z $STATEMNT ]; then + for lf in /tmp/dhclient.*.lease; do + netif=${lf#*.} + netif=${netif%.*} + cp $lf "$NEWROOT/var/lib/dhclient/dhclient-$netif.leases" + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Saving $NEWROOT/var/lib/dhclient/dhclient-$netif.leases" + done + + ifname="$(getarg ifname=)" + netdev="$(getarg netdev=)" + BOOTIF="$(getarg BOOTIF=)" + if [ ! -z "$ifname" ]; then + MACX=${ifname#*:} + ETHX=${ifname%:$MACX*} + elif [ ! -z "$netdev" ]; then + ETHX=$netdev + MACX=`ip link show $netdev | grep ether | awk '{print $2}'` + elif [ ! -z "$BOOTIF" ]; then + MACX=$BOOTIF + MACX=${MACX#01-} + MACX=${MACX//-/:} + ETHX=$(getdevfrommac $MACX) + fi + + + if [ ! -z "$MACX" ] && [ ! -z "$ETHX" ]; then + if [ ! -e $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX ]; then + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Creating $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX" + touch $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX + fi + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Writing $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX: DEVICE=$ETHX;BOOTPROTO=dhcp;HWADDR=$MACX;ONBOOT=yes" + echo "DEVICE=$ETHX" > $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX + echo "BOOTPROTO=dhcp" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX + echo "HWADDR=$MACX" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX + echo "ONBOOT=yes" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX + fi +fi + +[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Saving $NEWROOT/etc/resolv.conf" +cp /etc/resolv.conf "$NEWROOT/etc/" + +if [ -d "$NEWROOT/etc/sysconfig" -a ! -e "$NEWROOT/etc/sysconfig/selinux" ]; then + [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "disable selinux ..." + echo "SELINUX=disabled" >> "$NEWROOT/etc/sysconfig/selinux" +fi + +logger $SYSLOGHOST -t $log_label -p local4.info "Exiting xcatroot..." +# inject new exit_if_exists +echo 'settle_exit_if_exists="--exit-if-exists=/dev/root"; rm "$job"' > $hookdir/initqueue/xcat.sh +# force udevsettle to break +> $hookdir/initqueue/work diff --git a/xCAT-server/share/xcat/netboot/rh/genimage b/xCAT-server/share/xcat/netboot/rh/genimage index 102411566..f34f1c985 100755 --- a/xCAT-server/share/xcat/netboot/rh/genimage +++ b/xCAT-server/share/xcat/netboot/rh/genimage @@ -110,6 +110,10 @@ sub mount_chroot { system("cd /dev;find .|cpio -H newc -o >$rootimage_dir/dev/dev.archive;cd -"); system("cd $rootimage_dir/dev;cpio -idum<./dev.archive;rm -f ./dev.archive;cd -"); } + + if (-d "/run") { + system("mount --bind /run $rootimg_dir/run"); + } } @@ -323,7 +327,7 @@ if($onlyinitrd){ } unless (scalar(@yumdirs) || scalar(@pkgdir_internet)) { print "Need $installroot/$osver/$arch/ available from a system that has ran copycds on $osver $arch or correct web repo\n"; - exit 1; + exit 1; } @@ -779,7 +783,9 @@ if ((-d "$rootimg_dir/usr/share/dracut") or (-d "$rootimg_dir/usr/lib/dracut")) $dracutver = `rpm --root $rootimg_dir -qi dracut | grep Version | awk -F' ' '{print \$3}'`; chomp($dracutver); if ($dracutver =~ /^\d\d\d$/) { - if ($dracutver >= "047") { + if ($dracutver >= "105") { + $dracutdir = "dracut_105"; + } elsif ($dracutver >= "047") { $dracutdir = "dracut_047"; } elsif ($dracutver >= "033") { $dracutdir = "dracut_033"; @@ -1027,7 +1033,9 @@ sub mkinitrd_dracut { $dracutmoduledir = "$rootimg_dir/usr/lib/dracut/modules.d/"; } + if ($dracutver >= "033") { + # Patches syslog module my $perm = (stat("$fullpath/$dracutdir/patch/syslog/module-setup.sh"))[2]; cp("$fullpath/$dracutdir/patch/syslog/module-setup.sh", $dracutmoduledir . "98syslog/"); chmod($perm & 07777, $dracutmoduledir . "98syslog/" . "module-setup.sh"); @@ -1056,9 +1064,40 @@ sub mkinitrd_dracut { my $dracutmpath = $dracutmoduledir . "98xcat/"; mkpath($dracutmpath); - my $perm = (stat("$fullpath/$dracutdir/check"))[2]; - cp("$fullpath/$dracutdir/check", $dracutmpath); - chmod($perm & 07777, "$dracutmpath/check"); + if ($dracutver >= "105") { + # Copy xcat module to the image depending on the mode + my %files = ( + stateless => [ + 'installkernel', + 'module-setup.sh', + 'xcat-cmdline.sh', + 'xcatroot', + 'xcat-updateflag', + ], + statelite => [ + 'installkernel', + 'module-setup.sh', + 'xcat-cmdline.sh', + 'xcat-premount.sh', + 'xcat-prepivot.sh', + 'xcatroot', + 'xcat-updateflag', + ], + ); + + + foreach (@{$files{$mode}}) { + my $src = "$fullpath/$dracutdir/$mode/$_"; + my $perm = (stat($src))[2]; + print "Copying $src -> $dracutmpath/$_\n"; + cp("$src", $dracutmpath) || xdie "Copy $src failed"; + chmod($perm & 07777, "$dracutmpath/$_") || xdie "chmod $dracutmpath/$_ failed"; + } + } else { + my $perm = (stat("$fullpath/$dracutdir/check"))[2]; + cp("$fullpath/$dracutdir/check", $dracutmpath); + chmod($perm & 07777, "$dracutmpath/check"); + } foreach (@ndrivers) { s/\.ko$//; } @@ -1079,84 +1118,131 @@ sub mkinitrd_dracut { print "Try to load drivers: $add_drivers to initrd.\n"; my $DRACUTCONF; - if ($mode eq "statelite") { + if ($dracutver >= "105") { + # post-EL10 code + # Update etc/dracut.conf + if ($mode eq "statelite") { + my $dracutmodulelist = "xcat nfs base network network-manager kernel-modules syslog dbus dbus-broker"; - # for statelite - cp("$fullpath/$dracutdir/install.statelite", "$dracutmpath/install"); - $perm = (stat("$fullpath/$dracutdir/install.statelite"))[2]; - chmod($perm & 07777, "$dracutmpath/install"); - cp("$installroot/postscripts/updateflag.awk", "$dracutmpath/xcat-updateflag"); - $perm = (stat("$installroot/postscripts/updateflag.awk"))[2]; - chmod($perm & 07777, "$dracutmpath/xcat-updateflag"); - - cp("$fullpath/$dracutdir/xcat-prepivot.sh", $dracutmpath); - $perm = (stat("$fullpath/$dracutdir/xcat-prepivot.sh"))[2]; - chmod($perm & 07777, "$dracutmpath/xcat-prepivot.sh"); - - cp("$fullpath/$dracutdir/xcat-premount.sh", $dracutmpath); - $perm = (stat("$fullpath/$dracutdir/xcat-premount.sh"))[2]; - chmod($perm & 07777, "$dracutmpath/xcat-premount.sh"); - - #update etc/dracut.conf - open($DRACUTCONF, '>', "$rootimg_dir/etc/dracut.conf"); - my $dracutmodulelist = "xcat nfs base network kernel-modules syslog"; - - foreach (qw/systemd systemd-initrd dracut-systemd fadump kernel-modules-extra/) { - my ($dir) = glob($dracutmoduledir . "[0-9]*" . $_); - if (-d $dir) { - $dracutmodulelist .= " $_"; + foreach (qw/systemd systemd-initrd dracut-systemd fadump kernel-modules-extra/) { + my ($dir) = glob($dracutmoduledir . "[0-9]*" . $_); + if (-d $dir) { + $dracutmodulelist .= " $_"; + } } - } - print $DRACUTCONF qq{dracutmodules+=" $dracutmodulelist "\n}; - print $DRACUTCONF qq{add_drivers+=" $add_drivers "\n}; - print $DRACUTCONF qq{filesystems+=" nfs "\n}; - close $DRACUTCONF; - } elsif ($mode eq "stateless") { - cp("$fullpath/$dracutdir/install.netboot", "$dracutmpath/install"); - $perm = (stat("$fullpath/$dracutdir/install.netboot"))[2]; - chmod($perm & 07777, "$dracutmpath/install"); + open($DRACUTCONF, '>', "$rootimg_dir/etc/dracut.conf"); + print $DRACUTCONF qq{dracutmodules+=" $dracutmodulelist "\n}; + print $DRACUTCONF qq{add_drivers+=" $add_drivers "\n}; + print $DRACUTCONF qq{filesystems+=" nfs "\n}; + } elsif ($mode eq "stateless") { + my $dracutmodulelist = "xcat nfs base network network-manager kernel-modules syslog dbus dbus-broker"; - cp("$fullpath/$dracutdir/xcat-cmdline.sh", "$dracutmpath/"); - $perm = (stat("$fullpath/$dracutdir/xcat-cmdline.sh"))[2]; - chmod($perm & 07777, "$dracutmpath/xcat-cmdline.sh"); - - cp("$installroot/postscripts/updateflag.awk", "$dracutmpath/xcat-updateflag"); - $perm = (stat("$installroot/postscripts/updateflag.awk"))[2]; - chmod($perm & 07777, "$dracutmpath/xcat-updateflag"); - - if ($prinic) { - my $optspec; - open($optspec, '>>', "$dracutmpath/xcat-cmdline.sh"); - print $optspec "PRINIC=$prinic\n"; - close $optspec; - } - - cp("$fullpath/$dracutdir/xcatroot", "$dracutmpath/"); - $perm = (stat("$fullpath/$dracutdir/xcatroot"))[2]; - chmod($perm & 07777, "$dracutmpath/xcatroot"); - - cp("$fullpath/$dracutdir/installkernel", "$dracutmpath/"); - $perm = (stat("$fullpath/$dracutdir/installkernel"))[2]; - chmod($perm & 07777, "$dracutmpath/installkernel"); - - my $dracutmodulelist = "xcat nfs base network kernel-modules syslog"; - - foreach (qw/systemd systemd-initrd dracut-systemd fadump kernel-modules-extra/) { - my ($dir) = glob($dracutmoduledir . "[0-9]*" . $_); - if (-d $dir) { - $dracutmodulelist .= " $_"; + foreach (qw/systemd systemd-initrd dracut-systemd fadump kernel-modules-extra/) { + my ($dir) = glob($dracutmoduledir . "[0-9]*" . $_); + if (-d $dir) { + $dracutmodulelist .= " $_"; + } } - } - # update etc/dracut.conf - open($DRACUTCONF, '>', "$rootimg_dir/etc/dracut.conf"); - print $DRACUTCONF qq{dracutmodules+=" $dracutmodulelist "\n}; - print $DRACUTCONF qq{add_drivers+=" $add_drivers "\n}; - close $DRACUTCONF; + # update etc/dracut.conf + open($DRACUTCONF, '>', "$rootimg_dir/etc/dracut.conf"); + print $DRACUTCONF qq{dracutmodules+=" $dracutmodulelist "\n}; + print $DRACUTCONF qq{add_drivers+=" $add_drivers "\n}; + close $DRACUTCONF; + } else { + xdie "the mode: $mode is not supported by genimage"; + } } else { - xdie "the mode: $mode is not supported by genimage"; + # Legacy xCAT pre-EL10 code + if ($mode eq "statelite") { + + # for statelite + cp("$fullpath/$dracutdir/install.statelite", "$dracutmpath/install"); + $perm = (stat("$fullpath/$dracutdir/install.statelite"))[2]; + chmod($perm & 07777, "$dracutmpath/install"); + + cp("$installroot/postscripts/updateflag.awk", "$dracutmpath/xcat-updateflag"); + $perm = (stat("$installroot/postscripts/updateflag.awk"))[2]; + chmod($perm & 07777, "$dracutmpath/xcat-updateflag"); + + cp("$fullpath/$dracutdir/xcat-prepivot.sh", $dracutmpath); + $perm = (stat("$fullpath/$dracutdir/xcat-prepivot.sh"))[2]; + chmod($perm & 07777, "$dracutmpath/xcat-prepivot.sh"); + + cp("$fullpath/$dracutdir/xcat-premount.sh", $dracutmpath); + $perm = (stat("$fullpath/$dracutdir/xcat-premount.sh"))[2]; + chmod($perm & 07777, "$dracutmpath/xcat-premount.sh"); + + #update etc/dracut.conf + open($DRACUTCONF, '>', "$rootimg_dir/etc/dracut.conf"); + my $dracutmodulelist = "xcat nfs base network kernel-modules syslog"; + if (majversion($osver) >= 10) { + $dracutmodulelist .= " network-manager"; + } + + + foreach (qw/systemd systemd-initrd dracut-systemd fadump kernel-modules-extra/) { + my ($dir) = glob($dracutmoduledir . "[0-9]*" . $_); + if (-d $dir) { + $dracutmodulelist .= " $_"; + } + } + + print $DRACUTCONF qq{dracutmodules+=" $dracutmodulelist "\n}; + print $DRACUTCONF qq{add_drivers+=" $add_drivers "\n}; + print $DRACUTCONF qq{filesystems+=" nfs "\n}; + close $DRACUTCONF; + } elsif ($mode eq "stateless") { + cp("$fullpath/$dracutdir/install.netboot", "$dracutmpath/install"); + $perm = (stat("$fullpath/$dracutdir/install.netboot"))[2]; + chmod($perm & 07777, "$dracutmpath/install"); + + cp("$fullpath/$dracutdir/xcat-cmdline.sh", "$dracutmpath/"); + $perm = (stat("$fullpath/$dracutdir/xcat-cmdline.sh"))[2]; + chmod($perm & 07777, "$dracutmpath/xcat-cmdline.sh"); + + cp("$installroot/postscripts/updateflag.awk", "$dracutmpath/xcat-updateflag"); + $perm = (stat("$installroot/postscripts/updateflag.awk"))[2]; + chmod($perm & 07777, "$dracutmpath/xcat-updateflag"); + + if ($prinic) { + my $optspec; + open($optspec, '>>', "$dracutmpath/xcat-cmdline.sh"); + print $optspec "PRINIC=$prinic\n"; + close $optspec; + } + + cp("$fullpath/$dracutdir/xcatroot", "$dracutmpath/"); + $perm = (stat("$fullpath/$dracutdir/xcatroot"))[2]; + chmod($perm & 07777, "$dracutmpath/xcatroot"); + + cp("$fullpath/$dracutdir/installkernel", "$dracutmpath/"); + $perm = (stat("$fullpath/$dracutdir/installkernel"))[2]; + chmod($perm & 07777, "$dracutmpath/installkernel"); + + my $dracutmodulelist = "xcat nfs base network kernel-modules syslog"; + if (majversion($osver) >= 10) { + $dracutmodulelist .= " network-manager"; + } + + foreach (qw/systemd systemd-initrd dracut-systemd fadump kernel-modules-extra/) { + my ($dir) = glob($dracutmoduledir . "[0-9]*" . $_); + if (-d $dir) { + $dracutmodulelist .= " $_"; + } + } + + # update etc/dracut.conf + open($DRACUTCONF, '>', "$rootimg_dir/etc/dracut.conf"); + print $DRACUTCONF qq{dracutmodules+=" $dracutmodulelist "\n}; + print $DRACUTCONF qq{add_drivers+=" $add_drivers "\n}; + close $DRACUTCONF; + } else { + xdie "the mode: $mode is not supported by genimage"; + + } } my $additional_options = undef; @@ -1189,6 +1275,7 @@ sub mkinitrd_dracut { or xdie("Error: failed to generate the initial ramdisk for $mode.\n"); umount_chroot($rootimg_dir); print "the initial ramdisk for $mode is generated successfully.\n"; + print("Move $rootimg_dir/tmp/initrd.$$.gz -> $destdir/initrd-$mode.gz"); move("$rootimg_dir/tmp/initrd.$$.gz", "$destdir/initrd-$mode.gz"); } diff --git a/xCAT-server/share/xcat/netboot/rocky/compute.rocky10.x86_64.exlist b/xCAT-server/share/xcat/netboot/rocky/compute.rocky10.x86_64.exlist new file mode 120000 index 000000000..350fe0ca1 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rocky/compute.rocky10.x86_64.exlist @@ -0,0 +1 @@ +../rh/compute.rhels9.x86_64.exlist \ No newline at end of file diff --git a/xCAT-server/share/xcat/netboot/rocky/compute.rocky10.x86_64.pkglist b/xCAT-server/share/xcat/netboot/rocky/compute.rocky10.x86_64.pkglist new file mode 120000 index 000000000..757a60563 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rocky/compute.rocky10.x86_64.pkglist @@ -0,0 +1 @@ +../rh/compute.rhels9.x86_64.pkglist \ No newline at end of file diff --git a/xCAT-server/share/xcat/netboot/rocky/compute.rocky10.x86_64.postinstall b/xCAT-server/share/xcat/netboot/rocky/compute.rocky10.x86_64.postinstall new file mode 120000 index 000000000..b8c4b83f9 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rocky/compute.rocky10.x86_64.postinstall @@ -0,0 +1 @@ +../rh/compute.rhels9.x86_64.postinstall \ No newline at end of file diff --git a/xCAT-server/share/xcat/netboot/rocky/dracut_105 b/xCAT-server/share/xcat/netboot/rocky/dracut_105 new file mode 120000 index 000000000..1ab1cebfc --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rocky/dracut_105 @@ -0,0 +1 @@ +../rh/dracut_105/ \ No newline at end of file diff --git a/xCAT-server/share/xcat/netboot/rocky/service.rocky10.x86_64.exlist b/xCAT-server/share/xcat/netboot/rocky/service.rocky10.x86_64.exlist new file mode 120000 index 000000000..d4d45eec7 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rocky/service.rocky10.x86_64.exlist @@ -0,0 +1 @@ +../rh/service.rhels9.x86_64.exlist \ No newline at end of file diff --git a/xCAT-server/share/xcat/netboot/rocky/service.rocky10.x86_64.otherpkgs.pkglist b/xCAT-server/share/xcat/netboot/rocky/service.rocky10.x86_64.otherpkgs.pkglist new file mode 120000 index 000000000..722b927e1 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rocky/service.rocky10.x86_64.otherpkgs.pkglist @@ -0,0 +1 @@ +../rh/service.rhels9.x86_64.otherpkgs.pkglist \ No newline at end of file diff --git a/xCAT-server/share/xcat/netboot/rocky/service.rocky10.x86_64.pkglist b/xCAT-server/share/xcat/netboot/rocky/service.rocky10.x86_64.pkglist new file mode 120000 index 000000000..8b2b675cb --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rocky/service.rocky10.x86_64.pkglist @@ -0,0 +1 @@ +../rh/service.rhels9.x86_64.pkglist \ No newline at end of file diff --git a/xCAT-server/share/xcat/netboot/rocky/service.rocky10.x86_64.postinstall b/xCAT-server/share/xcat/netboot/rocky/service.rocky10.x86_64.postinstall new file mode 120000 index 000000000..40882ade9 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rocky/service.rocky10.x86_64.postinstall @@ -0,0 +1 @@ +../rh/service.rhels9.x86_64.postinstall \ No newline at end of file