{"id":737,"date":"2009-06-02T08:02:14","date_gmt":"2009-06-02T13:02:14","guid":{"rendered":"http:\/\/blogs.law.harvard.edu\/hoanga\/?p=737"},"modified":"2009-06-10T05:38:56","modified_gmt":"2009-06-10T10:38:56","slug":"automating-zone-creation-in-opensolaris-200906","status":"publish","type":"post","link":"https:\/\/archive.blogs.harvard.edu\/hoanga\/2009\/06\/02\/automating-zone-creation-in-opensolaris-200906\/","title":{"rendered":"Automating Zone creation in OpenSolaris 2009.06"},"content":{"rendered":"<p>With the <a href=\"http:\/\/www.sun.com\/aboutsun\/pr\/2009-06\/sunflash.20090601.1.xml\">announcement of OpenSolaris 2009.06<\/a> I thought it would be appropriate to blog a little about a tool I had been writing to help myself play with Zones a bit easier.  <\/p>\n<p>My overall goals were the following:<\/p>\n<ul>\n<li>Have each zone configured with its own virtual NIC (<a href=\"http:\/\/opensolaris.org\/os\/project\/crossbow\/\">Crossbow<\/a>)<\/li>\n<li>Allow easy creation of zones without having to type zonecfg crap over and over again<\/li>\n<li>Make it a stepping stone to automatically creating zones<\/li>\n<li>See how well ipkg branded Zones work<\/li>\n<li>Allow a Zone to get its IP and DNS configuration from DHCP<\/li>\n<\/ul>\n<p>I had tried going through tutorials that I found on the web (See references below) for setting up Zones but sadly none of them worked to my frustration.  After a lot of experimentation I finally pieced together a way to create zones quickly and (almost) automatically for simple configurations.<\/p>\n<h3>Howto<\/h3>\n<ol>\n<li>Create a template zone that will be used as the main clone Zone<\/li>\n<li>Download <a href=\"http:\/\/gist.github.com\/122220\">setup-zone-exclusive.sh<\/a> and modify lines 34-35 to match the name of your template zone and the real interface you want the zones to bind to<\/li>\n<li>Download the DHCP event hook script from <a href=\"http:\/\/www.linuxtopia.org\/online_books\/opensolaris_2008\/SYSADV3\/html\/extkj.html\">here<\/a> and name it dhcp-client-event.sh if you want DHCP configuration<\/li>\n<li>Run setup-zone-exclusive with the zonename and the virtual nic interface that you want<\/li>\n<\/ol>\n<p>In more detail here are the steps below<\/p>\n<h4>First create a template zone (I call it barebones here)<\/h4>\n<blockquote><p>\n# Create \/zones as its own ZFS filesystem<br \/>\n$ pfexec zfs create rpool\/zones<br \/>\n$ pfexec zfs set mountpoint=\/zones rpool\/zones<br \/>\n$ pfexec zfs create rpool\/zones\/barebones<br \/>\n$ pfexec chmod 0700 \/zones\/barebones<br \/>\n$ pfexec dladm create-vnic -l $REAL_IF vnic0<br \/>\n$ pfexec zonecfg -z barebones<br \/>\nbarebones: No such zone configured<br \/>\nUse &#8216;create&#8217; to begin configuring a new zone.<br \/>\nzonecfg:barebones&gt; create<br \/>\nzonecfg:barebones&gt; set zonepath=\/zones\/barebones<br \/>\nzonecfg:barebones&gt; set ip-type=exclusive<br \/>\nzonecfg:barebones&gt; add net<br \/>\nzonecfg:barebones:net&gt; set physical=vnic0<br \/>\nzonecfg:barebones:net&gt; end<br \/>\nzonecfg:barebones&gt; exit<\/p>\n<p>$ pfexec zoneadm -z barebones install\n<\/p><\/blockquote>\n<h4>Get the script<\/h4>\n<p>I would suggest you create a project directory to hold things such as <em>zonecreations<\/em>.<\/p>\n<p>Download from Github gists <a href=\"http:\/\/gist.github.com\/122220\">here<\/a>.   Name it setup-zone-exclusive.sh. Don&#8217;t forget to chmod +x the file so you can execute it<\/p>\n<h4>Download the DHCP event hook script<\/h4>\n<p>You can get that <a href=\"http:\/\/www.linuxtopia.org\/online_books\/opensolaris_2008\/SYSADV3\/html\/extkj.html\">here<\/a>.  Make sure this script is in the same directory as wherever you saved setup-zone-exclusive.sh<\/p>\n<h4>Create a zone<\/h4>\n<p>You can now create zones like this:<\/p>\n<blockquote><p>\ncd zonecreations<br \/>\npfexec .\/setup-zone-exclusive.sh mycoolnewzone  virtualnic1\n<\/p><\/blockquote>\n<p>Have fun!<\/p>\n<p>Update:  Fixed an error in the example for using dladm.  It should be correct now.  Thanks!<\/p>\n<h3> References <\/h3>\n<h4>Downloads<\/h4>\n<p><a href=\"http:\/\/gist.github.com\/122220\">http:\/\/gist.github.com\/122220 (setup-zone-exclusive.sh)<\/a><br \/>\n<a href=\"http:\/\/www.linuxtopia.org\/online_books\/opensolaris_2008\/SYSADV3\/html\/extkj.html\">A DHCP event script to make sure DNS is configured when DHCP acquires an IP<\/a><\/p>\n<h4>Older docs on setting up Zones on Solaris<\/h4>\n<p><a href=\"http:\/\/www.mail-archive.com\/zones-discuss@opensolaris.org\/msg04174.html\">How to use sysidcfg file in OpenSolaris 2008.11<\/a><br \/>\n<a href=\"http:\/\/docs.sun.com\/app\/docs\/doc\/819-2450\/z.login.ov-14?a=view\">Internal Zone Configuration docs<\/a> <br \/>\n<a href=\"http:\/\/docs.sun.com\/app\/docs\/doc\/819-2450\/z.login.task-31?a=view\">Performing the Initial Zone configuration<\/a> <br \/>\n<a href=\"http:\/\/docs.sun.com\/app\/docs\/doc\/819-5776\/6n7r9js2j?a=view\">Preconfiguring with sysidcfg file<\/a> <br \/>\n<a href=\"http:\/\/opensolaris.org\/os\/community\/zones\/faq\/#cfg_sysidcfg\">OpenSolaris FAQ on sysidcfg<\/a> <br \/>\n<a href=\"http:\/\/www.cuddletech.com\/blog\/pivot\/entry.php?id=751\">Ben Rockwood&#8217;s blogpost on Zone creation<\/a>  <br \/>\n<a href=\"http:\/\/docs.sun.com\/app\/docs\/doc\/819-2450\/gbrmi?a=view\">About \/etc\/.UNCONFIGURED<\/a> <\/p>\n<h4>Helpful for understanding Zones and Crossbow<\/h4>\n<p><a href=\"http:\/\/blogs.sun.com\/stw\/entry\/crossbow_is_delivered_traveling_vnics\">Crossbow on vnics<\/a><\/p>\n<h4>Finding out that there is a change in policy for setting root_password in sysidcfg files<\/h4>\n<p><a href=\"http:\/\/opensolaris.org\/os\/community\/on\/flag-days\/pages\/2008111501\/\">PASSREQ is enforced<\/a> <br \/>\n<a href=\"https:\/\/www.opensolaris.org\/jive\/thread.jspa?messageID=329028&amp;#329028\">zlogin failure after zone setup<\/a> <\/p>\n<h4>The following helped in understanding the role of IPS and ipkg inside a non-global Zone<\/h4>\n<p><a href=\"http:\/\/blogs.sun.com\/jerrysblog\/entry\/updating_zones_on_opensolaris_2008\">Updating Zones in OpenSolaris 2008.x<\/a> <br \/>\n<a href=\"http:\/\/blogs.sun.com\/dp\/date\/20080512\">A field guide to Zones in OpenSolaris 2008.05<\/a> <br \/>\n<a href=\"https:\/\/www.opensolaris.org\/jive\/thread.jspa?threadID=102287&amp;tstart=15\">OpenSolaris forum on sysidcfg and Zones<\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the announcement of OpenSolaris 2009.06 I thought it would be appropriate to blog a little about a tool I had been writing to help myself play with Zones a bit easier. My overall goals were the following: Have each zone configured with its own virtual NIC (Crossbow) Allow easy creation of zones without having [&hellip;]<\/p>\n","protected":false},"author":703,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1101,3771,4115,1099],"tags":[],"class_list":["post-737","post","type-post","status-publish","format-standard","hentry","category-geek","category-solaris","category-sysadmin","category-unix"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/posts\/737","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/users\/703"}],"replies":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/comments?post=737"}],"version-history":[{"count":12,"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/posts\/737\/revisions"}],"predecessor-version":[{"id":759,"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/posts\/737\/revisions\/759"}],"wp:attachment":[{"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/media?parent=737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/categories?post=737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/tags?post=737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}