![]() | New! March 26, 2012: VM Guest tools contains scripts and drivers that are used to create virtualized machine images in SmartOS. |
In SmartOS, virtual machines are created using the vmadm create tool. This tool takes a JSON payload and creates either a 'kvm' or 'joyent' brand zone with the properties specified in the input JSON. Normal output is a series of single-line JSON objects with type set to one of:
- success
- failure
- update
- notice
each object having at least the 'type' and 'message' fields. A message of type 'success' or 'failure' will be followed by the process exiting with the exit status 0 indicating success and all other exits indicating failure.
Getting Started
You will need
- The latest copy of SmartOS, available from http://download.joyent.com (release details here)
- The ISO of your OS of choice
- A VNC client
The Machine JSON Description
Save the code snippet below to a file called "vmspec.json". You can make changes to the networks and other variables as appropriate. This is by no means an exhaustive list of all options. For all options see vmadm(1m). (Sizes are listed in MiB)
![]() | For releases before December 15, 2011, you will need to include the default_gateway attribute in the root:
This must match the gateway of one of the nics so that the default gateway and resolvers will be set via DHCP in the VM. |
![]() | When installing OS's that do not ship with virtio support instead of using virtio on the disk for the model use ide and e1000 for the network model. |
Create the Empty Virtual Machine
Create the empty virtual machine using the create-machine tool. Please note that the virtual machine will not be running.
Note the UUID in the last step. This UUID is the ID of the VM and will be used to reference it for the rest of its lifecycle.
Copy your OS ISO to the zone
Ensure permissions are correct on the ISO
Boot the VM from the ISO Image
vmadm is the virtual machine administration tool. It is used to manage the lifecycle of a virtual machine after it already exists. We will boot the virtual machine we have just created, but tell it to boot off of the ISO image the first time it comes up.
Please note that the path for the ISO image will be the relative path of the ISO to the zone you are in. This is why it starts with the '/'
Use VNC to Connect to the VM
The vmadm tool can print out the information on the VM. You can also append a section to print specificially.
Your VM is now running. You can shutdown your virtual machine and it will still remain on disk. To learn more about managing the lifecycle of a virtual machine, run vmadm --help.
Troubleshooting
Zone Networking Issues
If you are running SmartOS as a guest vm then you might have networking issues with your zones. In order to fix this we need to create a bridge.
If you look at https://github.com/joyent/smartos-overlay/blob/master/lib/svc/method/net-physical#L179 You can see that the script will create a bridge for vmare products but if you are using VirtualBox or Parallells then you need to do it manually.
Your zones should now be able to access the network. You don't need to change the nic_tag for any of the zones, leave them as "admin" or "external".
There is a way to make this happen on boot with my adding an smf script to /opt/custom/smf. Here is a nice write up that shows you how it's done. http://www.psychicfriends.net/blog/archives/2012/03/21/smartosorg_run_things_at_boot.html#003979
Further Reading
Those versed in JavaScript can learn a lot more by reading the vmadm.js source.
7 Comments
comments.show.hideOct 25, 2011
Geoff Cardamone
I am having some issue's setting up multiple VM's on smartos. The problem is that whenever I try to boot up a VM with one already running I get the following in my /var/adm/messages:
I have looked high and low for any documentation pertaining to networking setup for VM's and haven't been able to find anything as of yet. Is there documentation somewhere where I would be able to find out how to assign VM's virtual nics? I attempted to add additional vnics with:
This created the vnic, however I cannot figure out how to assign a VM to use that vnic instead of net0. Any help is appreciated.
/GC
Oct 25, 2011
Kevin Pierce
I was tripped up by this as well.
SmartOs seems to do the vnic wiring automatically if you provide "admin" as the physical device.
In the json config for creating the zone use "nic_tag": "admin"
After the fact I was able to modify my /etc/zones/{guid}.xml by changing
to:
The end result after a zoneadm boot is
I am using smartosplus64 machines. Hope this helps for the KVM ones.
/KP
Oct 25, 2011
Geoff Cardamone
Kevin,
Thanks for taking the time to respond. I attempted to boot a second vm and the following is what I am still seeing:
Also:
So it appears that a single KVM is working correctly, however I am unable to get a second to boot. I suppose that I could try some of the Joynet datasets and see if I get a different result. I also tried to set the /etc/zones/57f55e19-253f-4d98-baf8-7ebab4af17c7.xml to:
and it produced the same output in syslog. I then tried by creating a net1 vnic and it still wouldn't boot. Is there another log somewhere were there may be additional info? I haven't found anything just yet.
Thanks again,
/GC
Oct 25, 2011
Kevin Pierce
When I have 2 zones booted they both have net0.
Try allowing smartos to use net0 for all of you VMs.
The original documentation published on one of the other pages recommended the dladm create-vnic -l <phys> <vnic>. That was removed in favour of the "nic_tag": "admin"
The autoboot started working when I put everything back to net0 and admin.
You may want to try using a pair of new VMs created using the create-machine command.
Hope this helps.
/KP
Oct 25, 2011
Geoff Cardamone
Kevin,
Something is still keeping the second VM from booting. I started two fresh VM's up:
I am going to keep looking for some additional info, my logs again only show the following,
VM boots:
doesnt boot:
not sure if maybe its something to do with the amount of RAM I am giving each host, or the number of vcpus
/GC
Oct 25, 2011
Geoff Cardamone
Just to update; when i use a joyent dataset for centos6 as a second VM, the VM does boot.
Oct 30, 2011
Michael Smith
Is there a current mechanism to clone an existing VM?