SmartOS as a virtualization platform

Clever and Smart

Access via VNC

To access the remote desktop on Linux, call the VNC viewer with:


In this way, you can use VNC to discover which IP address was assigned by DHCP, if you do not use static IP addresses or have not permanently assigned an IP address for the MAC address on your DHCP server. It makes sense, in any case, to consider a structured solution for managing the VMs' IP addresses.

Incidentally, VNC access is not safeguarded by default. It is thus not advisable to run a SmartOS host in the default state on the Internet. For individual VMs, a call to

vmadm update <VM-UUID> vnc_password=<password>

sets a password.

If you're using an non-US keyboard, you might be unable to type important characters in the VNC display because the keymap is wrong. To resolve this problem, you can tell Qemu to pass in the keymap as a parameter. The command

vmadm update <VM-UUID> qemu_extra_opts = "-k <yourkeyboard>"

sets the keymap for a VM. In my case, this was "-k de".

Installing Operating Systems

As an alternative to prebuilt image templates, you can use your own templates or install operating systems from scratch (e.g., for Windows VMs, for which there are no templates). The recommended approach is first to create a new VM without a template and then boot from the installation medium. The required JSON file looks almost exactly like Listing 1, but instead of the image UUID in the disks section, you enter the size of the virtual hard disk:

"disks": [
    "boot": true,
    "model": "virtio",
    "size": 15000

For the VM to find the installation medium, you need to copy the ISO image to its root directory, which is located below /zones/<VM-UUID>/root. The vmadm command has special options for booting the VM once only from this image for installation purposes:

vmadm start <VM-UUID> order=cd,once=d cdrom=/centos.iso,ide

Now you can use VNC to install the operating system, as you would on a physical machine, and start the VM from the new system after rebooting the guest.

If you have inserted a CD or DVD into the SmartOS machine, you could also burn an ISO image to it for booting the VM. This is easily done with the Unix dd command:

dd if=/dev/dsk/c0t4d0s2 of=/zones/<VM-UUID>/root/<OS>.iso

The only difficulty is thus finding the device name of the drive: The iostat -En command will help.

To avoid the need to install each guest system individually, you can create your own templates from a system and use them to create new instances. To do this, you need to discover the UUID of the corresponding machine with vmadm list. A call to zfs list shows the ZFS volumes, including the ones on the VM (Figure 5).

Figure 5: A gaggle of ZFS volumes: SmartOS makes use of the Solaris filesystem's snapshot capabilities.

After shutting down the VM, you can create a snapshot of the guest volumes using zfs snapshot. In a second step, run zfs send to generate a file from the snapshot and compress the file:

zfs snapshot zones/5562fffe-96b1-454e-aff0-6d8782875f2e-disk0@image
zfs send zones/5562fffe-96b1-454e-aff0-6d8782875f2e-disk0@image | gzip > centos6.5.zvol.gz

A complete VM template is nothing more than a compressed image, together with a file containing the metadata – again in JSON format. An example of this is shown in Listing 3. Most of the entries should be self-explanatory. The UUIDs that you enter (e.g., for uuid, creator_uuid, and vendor_uuid) can be created with the uuid command. Entering ls -l shows the disk size. The SHA1 hash is somewhat more difficult because you create it with the digest command:

/usr/bin/digest -a sha1 centos6.5.zvol.gz

The timestamps do not need to be accurate. It's fine just to adjust the date. After completing the manifest file, import the template into your own store:

imgadm install -m centos6.5.dsmanifest -f centos6.5.zvol.gz

and then the template is ready for creating new VMs.

Listing 3


01 {
02     "name": "centos-6.5",
03   version: "1.0.0",
04     "type": "zvol",
05     "cpu_type": "qemu64",
06     "description": "Centos 6.5 VM 1.0.0",
07     "created_at": "2013-12-04T02:51:46.994Z",
08     "updated_at": "2013-12-04T02:51:46.994Z",
09     "os": "linux",
10     "image_size": 10000,
11     "files": [
12       {
13         "path": "centos6.5.zvol.gz",
14         "sha1": "92a100d8eb2c2fd436db1d2b539aa26894f919cb",
15         "size": 285111272
16       }
17     ],
18     "requirements": {
19       "networks": [
20         {
21           "name": "net0",
22           "description": "public"
23         }
24       ],
25       "ssh_key": true
26     },
27     "disk_driver": "virtio",
28     "nic_driver": "virtio",
29     "uuid": "555793a9-3c32-4eb9-ae81-f60176d8a8e3",
30     "creator_uuid": "352971aa-31ba-496c-9ade-a379feaecd52",
31     "vendor_uuid": "352971aa-31ba-496c-9ade-a379feaecd52",
32     "creator_name": "ADMIN",
33     "platform_type": "smartos",
34     "cloud_name": "sdc",
35     "urn": "sdc:ADMIN:centos-6.5:1.0.0",
36     "published_at": "2013-12-04T02:51:46.994Z"
37   }

Home-Grown Migration

In a similar way, you manage a kind of home-grown virtual machine migration, for which you need to convert the image of the VM to RAW format on the originating host if it is not already stored this way. To do this on Linux, for example, you would use qemu-img convert then copy the RAW image to the SmartOS host on which you create a new VM with the appropriate disk size, as described. The last step is to copy the data directly into the ZFS raw device using dd or cat:

dd if=centos.img of=/dev/zvol/rdsk/zones/<UUID>

This approach is described without any warranty and only recommended for experiments.

Buy ADMIN Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs

Support Our Work

ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.