{"id":937,"date":"2013-11-27T12:19:15","date_gmt":"2013-11-27T19:19:15","guid":{"rendered":"http:\/\/jaredrobinson.com\/blog\/?p=937"},"modified":"2013-12-02T21:27:02","modified_gmt":"2013-12-03T04:27:02","slug":"vcloud-director-linux-guest-os-customization-script","status":"publish","type":"post","link":"https:\/\/jaredrobinson.com\/blog\/vcloud-director-linux-guest-os-customization-script\/","title":{"rendered":"vCloud Director CentOS Guest OS Customization Script"},"content":{"rendered":"<p>I needed to customize a custom Linux VM image with a static IP address in vCloud Director. Here&#8217;s the script I came up with. It doesn&#8217;t work unless VMWare tools is installed and running in the VM (kernel upgrades tend to break it). The VM should be stopped, then paste the script into the &#8220;Guest OS Customization&#8221; script area. Boot the VM with the &#8220;Power On and Force Recustomization&#8221; option.<\/p>\n<p>&nbsp;<\/p>\n<pre>#!\/bin\/bash\r\nHOSTNAME=YourHostNameHere\r\nIPADDR=StaticIpAddressGoesHere\r\nNETMASK=255.255.255.0\r\n(\r\necho \"------------------------------------------------------------------------------\"\r\ndate\r\nif [ x$1 == x\"precustomization\" ]; then\r\n  set -e\r\n  echo \"Running Pre-Customization tasks...\"\r\n  if [ x$HOSTNAME != x ]; then\r\n    echo \"Configuring hostname as $HOSTNAME\"\r\n    sed -i \"\/HOSTNAME\/d\" \/etc\/sysconfig\/network\r\n    echo \"HOSTNAME=$HOSTNAME\" &gt;&gt; \/etc\/sysconfig\/network \r\n    hostname $HOSTNAME\r\n    hostname\r\n  else\r\n    # Set it so it can be used below\r\n    HOSTNAME=`hostname`\r\n  fi\r\n  if [ x$IPADDR != x ]; then\r\n    echo \"Configuring network IP=$IPADDR NETMASK=$NETMASK\"\r\n    rm \/etc\/udev\/rule.d\/70-persistent-net.rules\r\n    sed -i \"\/IPADDR\/d\" \/etc\/sysconfig\/network-scripts\/ifcfg-eth0\r\n    sed -i \"\/NETMASK\/d\" \/etc\/sysconfig\/network-scripts\/ifcfg-eth0\r\n    sed -i \"\/HWADDR\/d\" \/etc\/sysconfig\/network-scripts\/ifcfg-eth0\r\n    sed -i \"\/BOOTPROTO\/d\" \/etc\/sysconfig\/network-scripts\/ifcfg-eth0\r\n    sed -i \"\/DHCPHOSTNAME\/d\" \/etc\/sysconfig\/network-scripts\/ifcfg-eth0\r\n    cat &gt;&gt; \/etc\/sysconfig\/network-scripts\/ifcfg-eth0 &lt;&lt;ENDCFG\r\nBOOTPROTO=static\r\nIPADDR=$IPADDR\r\nNETMASK=$NETMASK\r\nDHCPHOSTNAME=$HOSTNAME\r\nENDCFG\r\n  fi\r\n  echo \"Done with Pre-Customization\"\r\nelif [ x$1 == x\"postcustomization\" ]; then\r\n  echo \"Running Post-Customization tasks...\"\r\nfi\r\n) | tee -a \/root\/customize.log\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Update: It turns out that having VMWare Tools functioning properly is enough for vCloud Director to configure the network settings all by itself, without the help of a script.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I needed to customize a custom Linux VM image with a static IP address in vCloud Director. Here&#8217;s the script I came up with. It doesn&#8217;t work unless VMWare tools is installed and running in the VM (kernel upgrades tend to break it). The VM should be stopped, then paste the script into the &#8220;Guest &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/jaredrobinson.com\/blog\/vcloud-director-linux-guest-os-customization-script\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;vCloud Director CentOS Guest OS Customization Script&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,17],"tags":[],"class_list":["post-937","post","type-post","status-publish","format-standard","hentry","category-linux","category-tech"],"_links":{"self":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts\/937","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/comments?post=937"}],"version-history":[{"count":11,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts\/937\/revisions"}],"predecessor-version":[{"id":948,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts\/937\/revisions\/948"}],"wp:attachment":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/media?parent=937"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/categories?post=937"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/tags?post=937"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}