{"id":483,"date":"2023-04-21T13:29:52","date_gmt":"2023-04-21T13:29:52","guid":{"rendered":"https:\/\/www.aixperts.co.uk\/?p=483"},"modified":"2023-04-30T17:52:39","modified_gmt":"2023-04-30T17:52:39","slug":"checking-suse-bootability","status":"publish","type":"post","link":"https:\/\/www.aixperts.co.uk\/?p=483","title":{"rendered":"Checking SUSE bootability on POWER"},"content":{"rendered":"\n<p>This little script checks the GRUB boot image for the VG\/LV\/file string pointing to the correct place, e.g. \/boot\/grub\/grub.cfg.<\/p>\n\n\n\n<p>This works on SUSE \/ SLES on POWER. <br><br># SLES bootability monitor<br>#<br># Henrik Morsing        1.0     24-FEB-2023     Initial<br><br>ver=1.0<br><br>[[ &#8220;${1}&#8221; == &#8220;DEBUG&#8221; ]] &amp;&amp; DEBUG=1<br><br>unset ERR<br><br>   # Find rootvg disks<br><br>   rootlv=&#8221;$(mount | grep &#8216; \/ &#8216; | awk &#8216;{ print $1 }&#8217;)&#8221;<br>   rootvg=$(mount | grep &#8216; \/ &#8216; | awk &#8216;{ print $1 }&#8217; | awk -F- &#8216;{ print $1 }&#8217; | awk -F\/ &#8216;{ print $NF }&#8217;)<br>   disk=&#8221;$(\/usr\/sbin\/pvs | grep ${rootvg} | awk -F- &#8216;{ print $1 }&#8217; | awk -F\/ &#8216;{ print $NF }&#8217;)&#8221;<br><br>   PV=&#8221;$(\/usr\/sbin\/pvs | grep ${rootvg} | awk &#8216;{ print $1 }&#8217;)&#8221;<br>   boot_LV=&#8221;$(\/usr\/sbin\/fdisk -l | grep PReP | grep mapper | awk &#8216;{ print $1 }&#8217;)&#8221;<br><br><br>   # This checks the PVid and LVid in the boot LV<br>   # points to the disk in the rootvg.<br>   # It also checks the grub image pointed to exists.<br><br>   \/usr\/local\/bin\/dd_wrapper ${boot_LV} 2&gt;\/dev\/null | strings | grep lvmid | grep grub2 | awk -F \/ &#8216;{ print $2,$3 }&#8217; | tr -d &#8216;)&#8217; | while read vgid lvid<br>   do<br><br>      checkVG=&#8221;$(\/sbin\/vgdisplay -c | grep ${vgid} | awk -F: &#8216;{ print $1 }&#8217; | tr -d &#8216; &#8216;)&#8221;<br><br>      if [[ &#8220;${checkVG}&#8221; == &#8220;${rootvg}&#8221; ]]<br>      then<br>         [[ ${DEBUG} ]] &amp;&amp; printf &#8220;Boot image points to correct volume group\\t\\t\\033[1;32m[OK]\\033[0m\\n&#8221;<br>      else<br>         [[ ${DEBUG} ]] &amp;&amp; printf &#8220;Boot image does NOT point to correct volume group\\t\\t\\033[1;31m[FAIL]\\033[0m\\n&#8221;<br>         ERR=1<br>      fi<br><br>      # This is painfully annoying. lvdisplay command just lacks sensible output.<br><br>      while read lv parm value<br>      do<br><br>         # If parm is &#8220;Path&#8221;, store value in case UUID matches what we are looking for.<br><br>         if [[ &#8220;${parm}&#8221; == &#8220;Path&#8221; ]]<br>         then<br>            final_path=&#8221;$(ls -l ${value} | awk &#8216;{ print $NF }&#8217;)&#8221;<br>         fi<br><br>         if [[ &#8220;${parm}&#8221; == &#8220;UUID&#8221; ]]<br>         then<br>            if [[ &#8220;${value}&#8221; == &#8220;${lvid}&#8221; ]]<br>            then<br>               break<br>            fi<br>         fi<br>      done &lt; &lt;(\/sbin\/lvdisplay | grep -E &#8220;LV Path|LV UUID&#8221;)<br><br>      if [[ &#8220;${final_path}&#8221; == &#8220;$(ls -l ${rootlv} | awk &#8216;{ print $NF }&#8217;)&#8221; ]]<br>      then<br>         [[ ${DEBUG} ]] &amp;&amp; printf &#8220;Boot image points to correct logical volume\\t\\t\\033[1;32m[OK]\\033[0m\\n&#8221;<br>      else<br>         [[ ${DEBUG} ]] &amp;&amp; printf &#8220;Boot image does NOT point to correct logical volume\\t\\t\\033[1;31m[FAIL]\\033[0m\\n&#8221;<br>         ERR=1<br>      fi<br><br>   done<br><br>   # Last check, grub file<br><br>   grub_file=&#8221;$(\/usr\/local\/bin\/dd_wrapper ${boot_LV} 2&gt;\/dev\/null | strings | grep lvmid | grep grub2 | awk -F \/ &#8216;{ print &#8220;\/&#8221;$(NF-1)&#8221;\/&#8221;$NF&#8221;\/grub.cfg&#8221; }&#8217;)&#8221;<br><br>   if [[ -s ${grub_file} ]]<br>   then<br>      [[ ${DEBUG} ]] &amp;&amp; printf &#8220;grub.cfg exists in correct location\\t\\t\\t\\033[1;32m[OK]\\033[0m\\n&#8221;<br>   else<br>      [[ ${DEBUG} ]] &amp;&amp; printf &#8220;grub.cfg does NOT exist in correct location\\t\\t\\033[1;31m[FAIL]\\033[0m\\n&#8221;<br>      ERR=1<br>   fi<br><br>[[ &#8220;${ERR}&#8221; == &#8220;&#8221; ]] &amp;&amp; echo &#8220;Success&#8221; || echo &#8220;Fail&#8221;<br><br>exit 0<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This little script checks the GRUB boot image for the VG\/LV\/file string pointing to the correct place, e.g. \/boot\/grub\/grub.cfg. This works on SUSE \/ SLES on POWER. # SLES bootability monitor## Henrik Morsing 1.0 24-FEB-2023 Initial ver=1.0 [[ &#8220;${1}&#8221; == &hellip; <a href=\"https:\/\/www.aixperts.co.uk\/?p=483\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[147,4],"tags":[51,163,164,141,162,161],"class_list":["post-483","post","type-post","status-publish","format-standard","hentry","category-ibm-power","category-linux","tag-boot","tag-bootability","tag-grub","tag-power","tag-sles","tag-suse"],"_links":{"self":[{"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=483"}],"version-history":[{"count":3,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/483\/revisions"}],"predecessor-version":[{"id":498,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/483\/revisions\/498"}],"wp:attachment":[{"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aixperts.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}