Monday, February 22, 2016

SmartOS first steps

Recently I was looking at SmartOS because I read an article on the net.
At first, I didn't quite understand what it was exactly. Then I decided to install it and see what it is.

So here is some information from a beginner point of view. What I will say is maybe not 100% accurate, but I will try my best. The goal of this post is to show you how to start playing with SmartOS. What I will show is just good for testing purposes!

Here is a quick explanation for someone who is used to work with VirtualBox:

SmartOS is like if VirtualBox is transformed into a OS.

And from Wikipedia:

SmartOS is a free and open-source SVR4 hypervisor, based on the UNIX operating system that combines OpenSolaris technology with Linux's KVM virtualization.

With SmartOS you can create virtual machines really easily. It is an operating system with the very minimum. The size of the ISO is around 155Mb.

In the setup described below, we will use VirtualBox to host a virtual machine using SmartOS called SmartOS Manager.

Here is a little schema:

So "SmartOS manager" is a guest (for VirtualBox) and it is also a host to manage SmartOS VMs.

How to setup something really basic

  • install VirtualBox
  • download the latest ISO file for SmartOS
  • open VirtualBox and create a new VM with these settings
    • Name: SmartOS manager
    • Type: Solaris 
    • Version: Oracle Solaris 11 (64-bit)
    • 2GB of ram
    • VDI disk of 16GB
Don't start the VM yet. Go to the settings of this VM and click on Network. Then select:
  • Attached to: Bridged Adapter
  • Adapter type: Intel PRO/1000 MT Desktop
  • Promiscuous Mode: Allow All
Now you can start the VM. It will ask you to select the installation disk. Just choose the ISO file downloaded earlier.

SmartOS will ask you some questions about your setup:
  • IP address
  • Default gateway
  • DNS
  • NTP server
  • Host
  • Default DNS search Domain
  • Password for root account
  • Data pool (where VM's will be installed), just type "y"
That's it! Now you should see that:
The system will now finish configuration and reboot. Please wait...
rebooting...
Great. Now let's see how to create a VM. By the way, in the world of SmartOS, a VM is called a zone.

Now, ssh to the VM and run the command to see all pre-configured zones:
$ imgadm avail
UUID                                  NAME     VERSION     OS       TYPE          PUB
f669428c-a939-11e2-a485-b790efc0f0c1  base     13.1.0      smartos  zone-dataset  2013-04-26
9eac5c0c-a941-11e2-a7dc-57a6b041988f  base64   13.1.0      smartos  zone-dataset  2013-04-26
...

As you can see there are a lot available. The one that we will use is (because it is the latest "base-64"):
96bcddda-beb7-11e5-af20-a3fb54c8ae29  base-64-lts  15.4.0  smartos  zone-dataset  2016-01-19

Import (download) the VM and wait a little bit:
$ imgadm import 96bcddda-beb7-11e5-af20-a3fb54c8ae29
Create a VM manifest file:
$ vi /root/web01.json
{
 "brand"              : "joyent",
 "image_uuid"         : "5c7d0d24-3475-11e5-8e67-27953a8b237e",
 "alias"              : "web01",
 "hostname"           : "web01",
 "max_physical_memory": 512,
 "quota"              : 7,
 "resolvers"          : ["8.8.8.8", "208.67.220.220"],
 "nics"               : [
                         {
                           "nic_tag": "admin",
                           "ip"     : "10.88.88.52",
                           "netmask": "255.255.255.0",
                           "gateway": "10.88.88.2"
                         }
                        ]
}

Resolvers: set the same DNS servers as you did for the SmartOS manager
IP: use an IP in the same network as the SmartOS manager
Gateway: same as the SmartOS manager

Create the VM:
$ vmadm create -f web01.json

Now you can list the existing VM;
$ vmadm list
UUID                                  TYPE  RAM      STATE             ALIAS
25ac9366-21ad-4942-a98d-f35373c3cf40  OS    512      running           web01

And to login:
$ zlogin 25ac9366-21ad-4942-a98d-f35373c3cf40

From there, you should be able to ping google:
$ ping google.com
google.com is alive

Now you can play with this VM. To install packages:
$ pkgin up
$ pkgin in vim
$ pkgin in gcc47
$ pkgin in gmake

As a sidenote, to install Java, you can download the archive from Oracle website. In my case, I used the Solaris x86 64-bit JDK.

To exit zlogin, press "~." (without double quotes).

No comments: