{"id":10,"date":"2007-09-04T16:04:48","date_gmt":"2007-09-04T06:04:48","guid":{"rendered":"https:\/\/www.penguinpunk.net\/blog\/?p=10"},"modified":"2007-11-30T13:30:59","modified_gmt":"2007-11-30T03:30:59","slug":"vmware-esx-patch-management","status":"publish","type":"post","link":"https:\/\/www.penguinpunk.net\/blog\/vmware-esx-patch-management\/","title":{"rendered":"VMware ESX patch management"},"content":{"rendered":"<p>Before VMware released ESX Server 3.0.2 (and, for the time being, removed the need for me to patch it), I was looking for a solution to patching ESX that didn&#8217;t involve rebooting after every patch, and didn&#8217;t involve a lot of manual intervention. I came up with a script that copies the tarballs from the base directory to another spot, extracts them, puts the host in maintenance mode, and then patches sequentially until it&#8217;s all done. The trick was to get the patches in the right order, or you&#8217;d be left with a bit of cleaning up to do (refer to <a href=\"http:\/\/kb.vmware.com\/kb\/10230\">http:\/\/kb.vmware.com\/kb\/10230<\/a> for more on that). To that end, instead of importing a listing of the extracted directories, I use text files and break it into phases. It&#8217;s ugly, but it kind of works. I&#8217;m sure I won&#8217;t ever have to resort to something so cludgy once version 3.5 is released. VMware have also announced, incidentally, that version 3.0.2 esxupdate now has the ability to cope with patches being installed in non-chronological order. Which negates the need for a lot of what I did with this script, and will instead make it easier to use something like <strong><em>ls<\/em><\/strong> to give you the output you need. I couldn&#8217;t find a nice way to exit maintenance mode once the host rebooted, and tried a few things with rc.local that never really worked out. Life goes on. Copy the script, the two phase files, and the tarballs to a nominated directory on the host.<br \/>\nThis is the script itself. I like to call mine barry.sh. Make sure it&#8217;s executable (<strong>chmod +x barry.sh<\/strong>).<\/p>\n<p><strong><em>[barry.sh]<\/em><\/strong><\/p>\n<p><strong>#!\/bin\/bash<\/strong><\/p>\n<p><strong># Set some variables<br \/>\ndir=`pwd`<\/strong><\/p>\n<p><strong># Logging is for whimps<\/strong><\/p>\n<p><strong># Check to see if the update directory exists, if not, make it<br \/>\necho &#8220;Creating updates directory&#8221;<br \/>\nif [ -d \/var\/updates ]<br \/>\nthen<br \/>\necho &#8220;Updates directory exists&#8221;<br \/>\nrm -rf \/var\/updates\/*<br \/>\nelse<br \/>\nmkdir \/var\/updates<br \/>\necho &#8220;Created updates directory&#8221;<br \/>\nfi<\/strong><\/p>\n<p><strong># Copy the patches to the update directory<br \/>\necho &#8220;Copying patches to updates directory&#8221;<br \/>\ncp &#8211;reply=y *.tgz \/var\/updates\/<br \/>\necho &#8220;Copied patches to updates directory&#8221;<\/strong><\/p>\n<p><strong># Get a list of patch files to extract<br \/>\necho &#8220;Locating patch files to extract&#8221;<br \/>\nls \/var\/updates &gt;$dir\/input.file<br \/>\necho &#8220;Found &#8217;em&#8221;<\/strong><\/p>\n<p><strong># Extract the files<br \/>\necho &#8220;Extracting the patch files&#8221;<br \/>\nfor i in `cat input.file`; do<br \/>\ncd \/var\/updates<br \/>\ntar xzvf $i<br \/>\ncd $dir<br \/>\ndone<br \/>\necho &#8220;Extracted patch files&#8221;<\/strong><\/p>\n<p><strong># Remove the tarballs<br \/>\necho &#8220;Removing the source tarballs&#8221;<br \/>\nrm -rf \/var\/updates\/*.tgz<br \/>\necho &#8220;Tarballs gone&#8221;<\/strong><\/p>\n<p><strong># Enter maintenance mode<br \/>\necho &#8220;Entering Maintenance Mode&#8221;<br \/>\nvimsh -n -e \/hostsvc\/maintenance_mode_enter<br \/>\necho &#8220;vi3 Host now in Maintenance mode&#8221;<\/strong><\/p>\n<p><strong># Patch &#8217;em &#8211; I like to call this Phase 1<br \/>\necho &#8220;Running patches in Phase 1&#8221;<br \/>\nfor i in `cat $dir\/phase1`; do<br \/>\ncd \/var\/updates\/<br \/>\ncd $i<br \/>\nesxupdate -n update<br \/>\ndone<\/strong><\/p>\n<p><strong># This one&#8217;s nasty &#8211; also known as a phasebreaker<br \/>\ncd \/var\/updates\/ESX-6431040\/<br \/>\n.\/install_patches &lt;&lt; FOO<br \/>\nall<br \/>\ny<br \/>\nn<br \/>\nFOO<\/strong><\/p>\n<p><strong># Patch &#8217;em &#8211; I like to call this Phase 2<br \/>\necho &#8220;Running patches in Phase 2&#8221;<br \/>\nfor i in `cat $dir\/phase2`; do<br \/>\ncd \/var\/updates\/<br \/>\ncd $i<br \/>\nesxupdate -n update<br \/>\ndone<\/strong><\/p>\n<p><strong>reboot<\/strong><\/p>\n<p>The next two files are called, respectively, phase1 and phase2. They need to be in the same directory as barry.sh to be useful.<\/p>\n<p><strong><em>[phase1]<\/em><\/strong><\/p>\n<p><strong>ESX-1006511<br \/>\nESX-1410076<br \/>\nESX-2158032<br \/>\nESX-2066306<br \/>\nESX-6921838<br \/>\nESX-8173580<br \/>\nESX-9986131<br \/>\nESX-1271657<br \/>\nESX-1917602<br \/>\nESX-2031037<br \/>\nESX-2092658<br \/>\nESX-3996003<br \/>\nESX-5497987<br \/>\nESX-6075798<br \/>\nESX-3199476<br \/>\nESX-5031800<br \/>\nESX-5885387<br \/>\nESX-6050503<br \/>\nESX-6856573<br \/>\nESX-9865995<br \/>\nESX-1541239<br \/>\nESX-2257739<br \/>\nESX-2559638<\/strong><\/p>\n<p><strong><em>[phase2]<\/em><\/strong><\/p>\n<p><strong>ESX-9916286<br \/>\nESX-4825991<br \/>\nESX-5095559<br \/>\nESX-5140477<br \/>\nESX-6657345<br \/>\nESX-6704314<br \/>\nESX-7281356<br \/>\nESX-7302867<br \/>\nESX-7408807<br \/>\nESX-7557441<br \/>\nESX-1000073<br \/>\nESX-1000070<br \/>\nESX-1000039<\/strong><\/p>\n<p>Thanks for reading &#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before VMware released ESX Server 3.0.2 (and, for the time being, removed the need for me to patch it), I was looking for a solution to patching ESX that didn&#8217;t involve rebooting after every patch, and didn&#8217;t involve a lot of manual intervention. I came up with a script that copies the tarballs from the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[9,13,786],"class_list":["post-10","post","type-post","status-publish","format-standard","hentry","category-vmware","tag-esx","tag-vi3","tag-vmware"],"_links":{"self":[{"href":"https:\/\/www.penguinpunk.net\/blog\/wp-json\/wp\/v2\/posts\/10","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.penguinpunk.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.penguinpunk.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.penguinpunk.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.penguinpunk.net\/blog\/wp-json\/wp\/v2\/comments?post=10"}],"version-history":[{"count":0,"href":"https:\/\/www.penguinpunk.net\/blog\/wp-json\/wp\/v2\/posts\/10\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.penguinpunk.net\/blog\/wp-json\/wp\/v2\/media?parent=10"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.penguinpunk.net\/blog\/wp-json\/wp\/v2\/categories?post=10"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.penguinpunk.net\/blog\/wp-json\/wp\/v2\/tags?post=10"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}