1. Check to see if imsm is enabled if there is an imsm RAID array
Kyle Sheumaker [Mon, 24 Sep 2018 15:07:55 +0000 (10:07 -0500)]
2. Add efi-boot-order-fix.pl to change network order as first boot option

etc/cloner3/efi-boot-order-fix.pl [new file with mode: 0755]
etc/cloner3/installer.sh
etc/cloner3/prep_disks.sh
manifest

diff --git a/etc/cloner3/efi-boot-order-fix.pl b/etc/cloner3/efi-boot-order-fix.pl
new file mode 100755 (executable)
index 0000000..126f85e
--- /dev/null
@@ -0,0 +1,191 @@
+#!/usr/bin/perl
+use strict;
+my $EFIBOOTMGR = "/usr/sbin/efibootmgr -v";
+
+my %entries = get_efi_entries();
+
+my @net = efi_ipv4_pxe_entries(%entries);
+my @os = efi_os_entries(%entries);
+my @leftover;
+foreach my $i (keys %entries) {
+    my $found = 0;
+    foreach my $o (@net, @os) {
+        if ($i eq $o) {
+            print "FOUND $i $o\n";
+            $found = 1;
+            last;
+        }
+    }
+    if (! $found) {
+        push @leftover, $i;
+    }
+}
+my $order = join(",", @net, @os);
+my $cmd = "/usr/sbin/efibootmgr --bootorder=$order";
+exec($cmd);
+sub efi_os_entries {
+    my (%entries) = @_;
+    my %os;
+    foreach my $i (keys %entries) {
+        my $e = $entries{$i};
+        if ($$e{'type'} ne "os") {
+            next;
+        }
+        if ($os{$$e{'label'}}) {
+            $os{$$e{'label'} . "_" . $i} = $e;
+        }
+        else {
+            $os{$$e{'label'}} = $e;
+        }
+    }
+    my @order;
+    foreach my $i (sort keys %os) {
+        push @order, $os{$i}{'id'};
+    }
+    return @order;
+}
+sub efi_network_entries {
+    my (%entries) = @_;
+    my @order;
+    foreach my $i (keys %entries) {
+        my $e = $entries{$i};
+        if ($$e{'type'} ne "network") {
+            next;
+        }
+        #my $mac = $$e{'network'}{'mac'};
+        #my $type = $$e{'network'}{'type'};
+        #my $proto = $$e{'network'}{'protocol'};
+#
+        #if ($type eq "ipv4" && $proto eq "pxe") {
+            #$net{$mac} = $e;
+        #}
+        push @order, $$e{'id'};
+    }
+    @order = sort { $a cmp $b } @order;
+    return @order;
+}
+sub efi_ipv4_pxe_entries {
+    my (%entries) = @_;
+    my %net;
+    foreach my $i (keys %entries) {
+        my $e = $entries{$i};
+        if ($$e{'type'} ne "network") {
+            next;
+        }
+        my $mac = $$e{'network'}{'mac'};
+        my $type = $$e{'network'}{'type'};
+        my $proto = $$e{'network'}{'protocol'};
+        if ($type eq "ipv4" && $proto eq "pxe") {
+            $net{$mac} = $e;
+        }
+    }
+    my @order;
+    foreach my $i (sort keys %net) {
+        push @order, $net{$i}{'id'};
+    }
+    return @order;
+}
+sub get_efi_entries {
+    my @bootorder;
+    my %boot;
+    open (CMD, "$EFIBOOTMGR |") || die "Error opening $EFIBOOTMGR";
+    while (!eof(CMD)) {
+        my $line = <CMD>;
+        chomp $line;
+        if ($line =~ /^BootOrder/) {
+            $line =~ s/^BootOrder\:\s+//g;
+            @bootorder = split(/,/, $line);
+        }
+        elsif ($line =~ /^Boot[0-9]+/) {
+            $line =~ s/^Boot//g;
+            if ($line !~ /\*/) {
+                next;
+            }
+            $line =~ s/\*//g;
+            my @pieces = split(/\t/, $line);
+            my ($id, $label) = split(/ /, $pieces[0], 2);
+            my $device  = $pieces[1];
+            my $entry_type = "";
+            my %entry = (
+                "id"    => $id,
+                "label"    => $label,
+            );
+            my %network;
+            # it's a network device...
+            if ($device =~ /MAC\(([0-9A-F]+),[0-9]+\)/i) {
+                my $mac = ${1};
+                my $net_type = "ipv6";
+                if ($device =~ /ipv4/i) {
+                    $net_type = "ipv4";
+                }
+                my $protocol = "pxe";
+                if ($label =~ /http/i) {
+                    $protocol = "http";
+                }
+                %network = (
+                    "mac" => $mac,
+                    "type" => $net_type,
+                    "protocol" => $protocol
+                );
+                $entry_type = "network";
+            }
+            elsif ($device =~ /^Fv/) {
+                $entry_type = "firmware";
+            }
+            elsif ($device =~ /File/) {
+                $entry_type = "os";
+            }
+            else {
+                $entry_type = "unknown";
+            }
+            $entry{'network'} = \%network;
+            $entry{'type'} = $entry_type;
+            $boot{$id} = \%entry;
+        }
+    }
+    return %boot;
+}
index c89eaa1..6a6b63a 100755 (executable)
@@ -360,6 +360,18 @@ then
                clone_fatal_error "Failed to run ${EFIBOOTMGR} ${EFIARGS}"
        fi
 
+
+       msg -n "Changing boot order to NET then OS"
+       server_log "Changing boot order to NET then OS"
+       cp /etc/cloner3/efi-boot-order-fix.pl /cloner/mnt/tmp
+       chroot /cloner/mnt /tmp/efi-boot-order-fix.pl >> /tmp/stdout.log 2>> /tmp/stderr.log
+       if [ "$?" = "0" ]
+       then
+               ok_msg
+       else
+               fail_msg
+       fi
+
        umount /cloner/mnt/sys/firmware/efi/efivars
 
        GRUB_MKCONFIG=""
index 5733ea0..bd321ac 100755 (executable)
@@ -28,6 +28,12 @@ then
 
         for i in `ls -1 /cloner/setup/*.raid-imsm 2> /dev/null`
         do
+               RESULT=`mdadm --detail-platform | grep "Platform : Intel" 2>/dev/null`
+               if [ "$?" != 0 ]
+               then
+                       clone_fatal_error "Unable to detect imsm RAID support.  Make sure Intel RSTe enabled in the BIOS/Firmware."
+               fi
+
                ARRAY=`basename ${i} .raid-msm`
                msg "Creating arrays for ${ANSI_BLUE}${ARRAY}${ANSI_DONE} "
 
index d6e7217..8547176 100644 (file)
--- a/manifest
+++ b/manifest
@@ -19,6 +19,7 @@
 755:./etc/cloner3/startup.sh
 755:./etc/cloner3/switch_cd.sh
 755:./etc/cloner3/uuid_fix.sh
+755:./etc/cloner3/efi-boot-order-fix.pl
 755:./etc/logdev.sh
 644:./etc/mke2fs.conf
 644:./etc/dropbear/dropbear_rsa_host_key