{"id":852,"date":"2013-09-22T17:54:23","date_gmt":"2013-09-22T22:54:23","guid":{"rendered":"http:\/\/nodakengineering.com\/?page_id=852"},"modified":"2014-03-13T10:07:27","modified_gmt":"2014-03-13T15:07:27","slug":"centos-vagrant-base-box","status":"publish","type":"page","link":"https:\/\/nodakengineering.com\/?page_id=852","title":{"rendered":"CentOS Vagrant Base Box"},"content":{"rendered":"<p>I will show how to create a headless\u00a0<a title=\"The Community ENTerprise Operating System\" href=\"http:\/\/www.centos.org\/\" target=\"_blank\"><strong>CentOS<\/strong>\u00a0<\/a>minimal installation \u201cbox\u201d using\u00a0<a title=\"Development environments made easy.\" href=\"http:\/\/www.vagrantup.com\/\" target=\"_blank\"><strong>Vagrant<\/strong>\u00a0<\/a>and\u00a0<strong><a href=\"https:\/\/www.virtualbox.org\/\" target=\"_blank\">VirtualBox<\/a><\/strong>. Similar results can be accomplished without Vagrant, but I find that with a little extra work, Vagrant adds enough value to make the effort worth it. According to their website:<\/p>\n<p>Vagrant is a tool for building complete development environments. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases development\/production parity, and makes the \u201cworks on my machine\u201d excuse a relic of the past.<\/p>\n<p>Here\u2019s what you\u2019ll need (version used in this tutorial):<\/p>\n<ul>\n<li>Latest version of\u00a0<strong><a title=\"VirtualBox Downloads\" href=\"https:\/\/www.virtualbox.org\/wiki\/Downloads\" target=\"_blank\">VirtualBox<\/a>\u00a0<\/strong>(4.2.18)<\/li>\n<li><a title=\"CentOS 6.4 i386 minimal install\" href=\"http:\/\/mirrors.kernel.org\/centos\/6.4\/isos\/i386\/\" target=\"_blank\"><strong>CentOS<\/strong>\u00a0<\/a>Linux operating system\u201332-bit minimal installation ISO (6.4)<\/li>\n<li><strong><a title=\"Vagrant Downloads\" href=\"http:\/\/downloads.vagrantup.com\/\" target=\"_blank\">Vagrant<\/a>\u00a0<\/strong>(1.3.3)<\/li>\n<li><a title=\"Download PuTTY\" href=\"http:\/\/www.chiark.greenend.org.uk\/~sgtatham\/putty\/download.html\" target=\"_blank\"><strong>PuTTY<\/strong>\u00a0<\/a>(0.62) or\u00a0<strong><a href=\"http:\/\/git-scm.com\/\" target=\"_blank\">Git<\/a>\u00a0<\/strong>(1.8.4)<\/li>\n<\/ul>\n<p>Keep in mind, while I did this in Windows 7, I\u2019ve also done the same in OSX and Linux. So let\u2019s get started and see how it\u2019s done.<\/p>\n<p>Note: If all you want is the Vagrant box you can download it <a title=\"CentOS 6.4 minimal Vagrant box\" href=\"http:\/\/nodakengineering.com\/wp-content\/uploads\/2013\/09\/centos64-32.box\" target=\"_blank\"><strong>here<\/strong><\/a>.<\/p>\n<p>If not already done, install VirtualBox, Vagrant, and PuTTY and\/or Git&#8230;reboot.<\/p>\n<p>Start up VirtualBox and create a new VM for the CentOS minimal that will be the basis for our Vagrant base box:<\/p>\n<ul>\n<li>Name the VM &#8220;<strong>vagrant-centos64-32<\/strong>&#8220;<\/li>\n<li>Set OS Type: <strong>Linux<\/strong><\/li>\n<li>Set Version: <strong>Red Hat<\/strong><\/li>\n<li>Memory: <strong>392 MB<\/strong> (Minimum recommended on CentOS Wiki for CLI)<\/li>\n<li>Hard Drive: <strong>40 GB<\/strong> dynamically allocated vdi<\/li>\n<li>Disable <strong>Audio<\/strong> &amp; <strong>USB<\/strong><\/li>\n<li>Mount <strong>CentOS-6.4-i386-minimal.iso<\/strong> in virtual CD\/DVD drive<\/li>\n<li>Add description &#8220;<strong>CentOS 6.4 Minimal Vagrant Base<\/strong>&#8220;<\/li>\n<\/ul>\n<p><a href=\"http:\/\/nodakengineering.com\/wp-content\/uploads\/2013\/09\/vagrant-vm.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-861\" alt=\"vagrant-vm\" src=\"http:\/\/nodakengineering.com\/wp-content\/uploads\/2013\/09\/vagrant-vm-276x300.jpg\" width=\"276\" height=\"300\" srcset=\"https:\/\/nodakengineering.com\/wp-content\/uploads\/2013\/09\/vagrant-vm-276x300.jpg 276w, https:\/\/nodakengineering.com\/wp-content\/uploads\/2013\/09\/vagrant-vm.jpg 710w\" sizes=\"auto, (max-width: 276px) 100vw, 276px\" \/><\/a><\/p>\n<p><strong>NOTE<\/strong>: \u00a0If you leave the memory at 392 MB, the CentOS installer will fail with the error &#8220;not enough memory&#8221;. As a workaround, bump memory temporarily to 1024 MB so that we get the graphical installer and can get everything setup easily (we&#8217;ll change it back to 392 MB after the install).<\/p>\n<p>Start the VM and install CentOS 6.4:<\/p>\n<p>On the name this computer page change the hostname to <strong>vagrant-centos64<\/strong> and click &#8220;<strong>Configure Network<\/strong>&#8220;, highlight &#8220;<strong>System eth0<\/strong>&#8221; and click &#8220;<strong>Edit&#8230;<\/strong>&#8221; Place a checkmark in the checkbox next to &#8220;<strong>Connect automatically<\/strong>&#8220;:<\/p>\n<p><a href=\"http:\/\/nodakengineering.com\/wp-content\/uploads\/2013\/09\/centos-setup-hostname.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-865\" alt=\"centos-setup-hostname\" src=\"http:\/\/nodakengineering.com\/wp-content\/uploads\/2013\/09\/centos-setup-hostname-300x244.jpg\" width=\"300\" height=\"244\" srcset=\"https:\/\/nodakengineering.com\/wp-content\/uploads\/2013\/09\/centos-setup-hostname-300x244.jpg 300w, https:\/\/nodakengineering.com\/wp-content\/uploads\/2013\/09\/centos-setup-hostname-1024x834.jpg 1024w, https:\/\/nodakengineering.com\/wp-content\/uploads\/2013\/09\/centos-setup-hostname.jpg 1040w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Set the root password to <strong>vagrant<\/strong> (ignore the warning about it being a weak dictionary password).<\/p>\n<p>After the install completes reboot and login as root.<\/p>\n<p>Issue the following commands to setup and start ssh:<\/p>\n<pre>[root@vagrant-centos64 ~]# chkconfig sshd on\r\n[root@vagrant-centos64 ~]# service sshd start<\/pre>\n<p>Let&#8217;s update and get some stuff installed and reboot (since the kernel was most likely updated too):<\/p>\n<pre>[root@vagrant-centos64 ~]# yum update\r\n[root@vagrant-centos64 ~]# yum install nano wget gcc bzip2 make kernel-devel-`uname -r`\r\n[root@vagrant-centos64 ~]# shutdown -r now<\/pre>\n<p>And now we&#8217;re ready to install the guest additions. Right-click to release the mouse from the guest and click &#8220;Devices&#8221; on the VirtualBox menu bar and select &#8220;Install Guest Additions&#8230;&#8221; (which mounts the guest additions installation image in the VM):<\/p>\n<p><a href=\"http:\/\/nodakengineering.com\/wp-content\/uploads\/2013\/09\/guest-additions.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-876\" alt=\"guest-additions\" src=\"http:\/\/nodakengineering.com\/wp-content\/uploads\/2013\/09\/guest-additions-300x195.jpg\" width=\"300\" height=\"195\" srcset=\"https:\/\/nodakengineering.com\/wp-content\/uploads\/2013\/09\/guest-additions-300x195.jpg 300w, https:\/\/nodakengineering.com\/wp-content\/uploads\/2013\/09\/guest-additions.jpg 736w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Then issue the following commands to install the guest additions:<\/p>\n<pre>[root@vagrant-centos64 ~]# mkdir \/mnt\/cdrom\r\n[root@vagrant-centos64 ~]# mount \/dev\/cdrom \/mnt\/cdrom\r\n[root@vagrant-centos64 ~]# sh \/mnt\/cdrom\/VBoxLinuxAdditions.run --nox11\r\n[root@vagrant-centos64 ~]# shutdown -r now<\/pre>\n<p><strong>NOTE<\/strong>: Do not worry about the &#8220;Installing the Window System drivers &#8212; FAILED&#8221;&#8230;this is expected.<\/p>\n<p>After the reboot, the guest additions are installed and running.<\/p>\n<p>Now add the vagrant user (with password vagrant):<\/p>\n<pre>[root@vagrant-centos64 ~]# useradd vagrant\r\n[root@vagrant-centos64 ~]# passwd vagrant<\/pre>\n<p><strong>NOTE<\/strong>: You can safely ignore the error concerning a simple\/dictionary password and simply type it again.<\/p>\n<p>And add vagrant user to the VirtualBox shared folders and admin group:<\/p>\n<pre>[root@vagrant-centos64 ~]# usermod -a -G vboxsf vagrant\r\n[root@vagrant-centos64 ~]# usermod -a -G wheel vagrant<\/pre>\n<p>Time to setup sudo for vagrant user:<\/p>\n<pre>[root@vagrant-centos64 ~]# visudo<\/pre>\n<p>And make the following changes:<\/p>\n<ul>\n<li>Comment out the &#8220;<strong>Defaults \u00a0 \u00a0 \u00a0requiretty<\/strong>&#8221; line<\/li>\n<li>Add &#8220;<strong>Defaults \u00a0 \u00a0 env_keep += &#8220;SSH_AUTH_SOCK<\/strong>&#8220;<\/li>\n<li>Uncomment the &#8220;<strong>%wheel \u00a0 ALL=(ALL) \u00a0 \u00a0 NOPASSWD: ALL<\/strong>&#8221; line<\/li>\n<\/ul>\n<p>Now logout root and login as vagrant and add vagrant user public key:<\/p>\n<pre>[vagrant@vagrant-centos64 ~]$ mkdir .ssh\r\n[vagrant@vagrant-centos64 ~]$ curl -k https:\/\/raw.github.com\/mitchellh\/vagrant\/master\/keys\/vagrant.pub &gt; .ssh\/authorized_keys\r\n[vagrant@vagrant-centos64 ~]$ chmod 0700 .ssh\r\n[vagrant@vagrant-centos64 ~]$ chmod 0600 .ssh\/authorized_keys<\/pre>\n<p>We need to setup the software Vagrant relies on. The\u00a0<em>required<\/em>\u00a0software is listed below:<\/p>\n<ul>\n<li><strong>Ruby<\/strong>\u00a0&#8211; Use the dev package so mkmf is present for Chef to compile<\/li>\n<li><strong>RubyGems<\/strong>\u00a0&#8211; To install the Chef gem<\/li>\n<li><strong>Puppet<\/strong>\u00a0&#8211; To install Puppet (also ensure that a \u2018puppet\u2019 group is present!)<\/li>\n<li><strong>Chef<\/strong>\u00a0gem &#8211; For provisioning support (gem install chef)<\/li>\n<li><strong>SSH<\/strong> &#8211; Install PuTTY and\/or Git<\/li>\n<\/ul>\n<pre>[vagrant@vagrant-centos64 ~]$ sudo rpm -ivh http:\/\/yum.puppetlabs.com\/el\/6\/products\/i386\/puppetlabs-release-6-7.noarch.rpm\r\n[vagrant@vagrant-centos64 ~]$ sudo yum install ruby rubygems puppet\r\n[vagrant@vagrant-centos64 ~]$ sudo gem install chef<\/pre>\n<p>And finally do a little housecleaning and power down the VM:<\/p>\n<pre>[vagrant@vagrant-centos64 ~]$ sudo yum clean all\r\n[vagrant@vagrant-centos64 ~]$ sudo poweroff<\/pre>\n<p>Now would be a good time to change the memory size of the VM back to 392 MB and remove the guest additions installer iso from the CD\/DVD drive.<\/p>\n<p>If we look at the size of the vdi file, it is almost 1.5 GB&#8230;let&#8217;s start up the VM and run some commands to zero out the sectors so we can make it smaller by compacting it:<\/p>\n<pre>[vagrant@vagrant-centos64 ~]$ sudo dd if=\/dev\/zero of=\/bigemptyfile bs=4096k\r\n[vagrant@vagrant-centos64 ~]$ sudo rm -rf \/bigemptyfile\r\n[vagrant@vagrant-centos64 ~]$ sudo poweroff<\/pre>\n<p>Open a run box and paste in the following to compact the vdi:<\/p>\n<pre>\"C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe\" modifyhd \"%USERPROFILE%\\VirtualBox VMs\\vagrant-centos64-32\\vagrant-centos64-32.vdi\" compact<\/pre>\n<p><strong>NOTE<\/strong>: The compacting reduced my VM to less than 1 GB (Vagrant will compact even more during its conversion).<\/p>\n<p>Now it&#8217;s time to package the box and add it to your vagrant boxes (recommend opening command prompt in vagrant directory created under windows user profile):<\/p>\n<pre>C:\\Users\\nodakbarnes\\Vagrant&gt; vagrant package --output centos64-32.box --base vagrant-centos64-32\r\nC:\\Users\\nodakbarnes\\Vagrant&gt; vagrant box add centos64-32 centos64-32.box<\/pre>\n<p>You should now have a centos64-32 base box in your vagrant boxes:<\/p>\n<pre>C:\\Users\\nodakbarnes\\Vagrant&gt; vagrant box list\r\ncentos64-32 (virtualbox)<\/pre>\n<p><strong>NOTE<\/strong>: The resultant &#8220;box&#8221; is less than 300 MB<\/p>\n<p>Now you can quickly create a Vagrant VM in any directory with:<\/p>\n<pre>C:\\Users\\nodakbarnes\\Vagrant&gt; vagrant init centos64-32\r\nC:\\Users\\nodakbarnes\\Vagrant&gt; vagrant up\r\nC:\\Users\\nodakbarnes\\Vagrant&gt; vagrant ssh<\/pre>\n<p><strong>NOTE<\/strong>: If the &#8220;<strong>vagrant ssh<\/strong>&#8221; command did not work one of two things may have gone wrong. First did you install Git? If so, then you need to add &#8220;<strong>C:\\Program Files (x86)\\Git\\bin<\/strong>&#8221; to your path and reboot to make it take effect. Alternately you can use PuTTY to connect to the vagrant box (do not use the &#8220;vagrant ssh&#8221; command in this case).<\/p>\n<p>If you opt for the PuTTY route, the public key from the vagrant installation can be copied to the desktop with the following command in a command prompt:<\/p>\n<pre>C:\\Windows\\system32&gt; copy %USERPROFILE%\\.vagrant.d\\insecure_private_key %USERPROFILE%\\Desktop<\/pre>\n<p>Then PuTTYgen can be used to open the file and then save it as a ppk file which can then be used in PuTTY to authorize the connection without needing password.<\/p>\n<p>To use the VM on a new host machine, copy the centos64-32.box file to the new host and from the new host&#8217;s shell run the <strong>vagrant box add<\/strong> command on it, now you should see the centos64-32 box in vagrant box list on the new host and you can use the <strong>box vagrant init<\/strong>\u00a0command to initialize it.<\/p>\n<p>Download this Vagrant box\u00a0<a title=\"CentOS 6.4 minimal Vagrant box\" href=\"http:\/\/nodakengineering.com\/wp-content\/uploads\/2013\/09\/centos64-32.box\" target=\"_blank\"><strong>here<\/strong><\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I will show how to create a headless\u00a0CentOS\u00a0minimal installation \u201cbox\u201d using\u00a0Vagrant\u00a0and\u00a0VirtualBox. Similar results can be accomplished without Vagrant, but I find that with a little extra work, Vagrant adds enough value to make the effort worth it. According to their website: Vagrant is a tool for building complete development environments. With an easy-to-use workflow and &#8230; <a title=\"CentOS Vagrant Base Box\" class=\"read-more\" href=\"https:\/\/nodakengineering.com\/?page_id=852\" aria-label=\"Read more about CentOS Vagrant Base Box\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":199,"menu_order":0,"comment_status":"open","ping_status":"open","template":"page-without-sidebar.php","meta":{"footnotes":""},"class_list":["post-852","page","type-page","status-publish"],"_links":{"self":[{"href":"https:\/\/nodakengineering.com\/index.php?rest_route=\/wp\/v2\/pages\/852","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nodakengineering.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/nodakengineering.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/nodakengineering.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nodakengineering.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=852"}],"version-history":[{"count":54,"href":"https:\/\/nodakengineering.com\/index.php?rest_route=\/wp\/v2\/pages\/852\/revisions"}],"predecessor-version":[{"id":934,"href":"https:\/\/nodakengineering.com\/index.php?rest_route=\/wp\/v2\/pages\/852\/revisions\/934"}],"up":[{"embeddable":true,"href":"https:\/\/nodakengineering.com\/index.php?rest_route=\/wp\/v2\/pages\/199"}],"wp:attachment":[{"href":"https:\/\/nodakengineering.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}