This is meant as a more detailed guide to setting up SmartOS as a VirtualBox VM. This is the original guide:
https://wiki.smartos.org/display/DOC/SmartOS+as+a+Sandboxed+VirtualBox+Guest
Download and install:
https://www.virtualbox.org/wiki/Downloads
Download the latest USB image:
https://wiki.smartos.org/display/DOC/Download+SmartOS
Convert the image to a vmdk using the tool installed with Virtualbox:
CSEAL-M101196:vms natefitch$ bunzip2 smartos-latest-USB.img.bz2
CSEAL-M101196:vms natefitch$ ls
smartos-latest-USB.img
CSEAL-M101196:vms natefitch$ VBoxManage convertfromraw smartos-latest-USB.img smartos-latest-USB.vmdk --format VMDK
Converting from raw image file="smartos-latest-USB.img" to file="smartos-latest-USB.vmdk"...
Creating dynamic image with size 2000000000 bytes (1908MB)...
CSEAL-M101196:vms natefitch$ ls
smartos-latest-USB.img smartos-latest-USB.vmdk
- Click the
New
icon.- Name:
- Type:
Solaris
- Version:
Oracle Solaris 11 (64 bit)
- Click
Continue
- Memory
- Click
Continue
- Hard Drive
- Choose
Create a virtual hard drive now
, clickCreate
- For the next few screens:
- Hard Drive File Type:
VDI
- Storage on Physical Hard Drive:
dynamically allocated
- File Location and Size: Enter name, you can leave the size the same or increase, depending on your needs.
- Hard Drive File Type:
- Choose
You should now have a new virtual machine, not powered on. There are a few more settings to take care of before powering it on for the first time:
- Click the
Settings
icon- Enable PAE/NX
- Click the
System
icon - Click the
Processor
"tab" - Click the checkbox next to
Enable PAE/NX
- Click the
- Add the usb image to
Storage
- Click the
Storage
icon - Click the
Controller: SATA
in the left pane - Click the
Add Hard Disk
icon to the right ofController: SATA
- Click
Choose Existing Disk
- Browse to the
smartos-latest-USB.vmdk
, clickopen
- Click the
- Change the boot order so that smartos-latest-USB.vmdk is on
SATA 0
- Click on the
smartos-latest-USB.vmdk
drive in the left pane - Change the
smartos-latest-USB.vmdk
drive toSATA Port 3
- Click on the Empty
cd/dvd
drive in left pane - Change
cd/dvd
drive toSATA Port 2
- Click on the
.vdi
drive in the left pane - Change the
.vdi
drive toSATA Port 1
- Click on the
smartos-latest-USB.vmdk
drive in the left pane - Change the
smartos-latest-USB.vmdk
drive toSATA Port 0
- Click on the
- Disable Audio
- Click the
Audio
icon - Uncheck
Enable Audio
- Click the
- Enable PAE/NX
- Power on the VM by double clicking on the
Powered Off
vm in the left hand pane. - At the GRUB menu choose
Live 64-bit (text)
- Configure
- For IP address choose DHCP
- For hard drive, choose second device (eg,
c0t1d0
) - Choose a root password
- Verify values
- Watch it setup and reboot
Getting to the host via ssh will allow you to use you favorite terminal rather than working through the VirtualBox console, which doesn't allow some very basic things (like copy/paste). The easiest thing to do is to turn on port forwarding on your new SmartOS vm. By default your SmartOS vm should be set up behind a virtual NAT. You can verify:
- Click on the
Settings
icon - Click on the
Network
icon Adapter 1
should have theAttach to
set toNAT
Now you'll set up port forwarding for SSH by:
- Under the same
Adapter 1
"tab", click on thePort Forwarding
button - Set Name to
SSH
- Set Protocol to
TCP
- Leave Host IP blank
- Set Host Port to
2222
- Leave Guest IP blank
- Set Guest Port to
22
Now you can ssh to your vm:
$ ssh root@localhost -p 2222
When you log into SmartOS from the VirtualBox console, you are logging into the
Global Zone (GZ). Since SmartOS is a "cloud first" operating system, work on
the host is performed within zones
, or virtual OS spaces. In other words,
we're going to create a VM within a VM. There you'll install node.js, etc.
First make sure that you can get out to the internet:
[root@08-00-27-9a-8b-92 ~]# ping 8.8.8.8
8.8.8.8 is alive
Then make sure you have resolvers:
[root@08-00-27-9a-8b-92 ~]# ping www.google.com
ping: unknown host www.google.com
[root@08-00-27-9a-8b-92 ~]# cat /etc/resolv.conf
[root@08-00-27-9a-8b-92 ~]# echo 'nameserver 8.8.8.8' >/etc/resolv.conf
[root@08-00-27-9a-8b-92 ~]# ping www.google.com
www.google.com is alive
Now look for an available image:
[root@08-00-27-9a-8b-92 ~]# imgadm avail | grep base64 | tail -1
62f148f8-6e84-11e4-82c5-efca60348b9f base64 14.3.0 smartos 2014-11-17T18:06:00Z
Download and install the image:
[root@08-00-27-9a-8b-92 ~]# imgadm import 62f148f8-6e84-11e4-82c5-efca60348b9f
Importing 62f148f8-6e84-11e4-82c5-efca60348b9f ([email protected]) from "https://images.joyent.com"
...
Imported image 62f148f8-6e84-11e4-82c5-efca60348b9f ([email protected])
The manifest describes what the resulting VM should look like. Here is an example, using the image uuid imported above:
[root@08-00-27-9a-8b-92 ~]# echo '{
"brand": "joyent",
"image_uuid": "62f148f8-6e84-11e4-82c5-efca60348b9f",
"alias": "dev-1",
"hostname": "dev-1",
"max_physical_memory": 1024,
"quota": 16,
"resolvers": ["8.8.8.8", "8.8.4.4"],
"nics": [{
"nic_tag": "admin",
"ip": "dhcp"
}]
}' >manifest.json
vmadm
is the tool used to manage vms. You can start, stop, create, etc using
vmadm
. First, use vmadm to create the VM:
[root@08-00-27-9a-8b-92 ~]# cat manifest.json | vmadm create
Successfully created VM 3c021e8c-6a38-412c-b48c-d535cc6eaa19
Now you can see that the vm is running using vmadm list
:
[root@08-00-27-9a-8b-92 ~]# vmadm list
UUID TYPE RAM STATE ALIAS
3c021e8c-6a38-412c-b48c-d535cc6eaa19 OS 1024 running dev-1
To login, use the zlogin
command:
[root@08-00-27-9a-8b-92 ~]# zlogin 3c021e8c-6a38-412c-b48c-d535cc6eaa19
[Connected to zone '3c021e8c-6a38-412c-b48c-d535cc6eaa19' pts/3]
__ . .
_| |_ | .-. . . .-. :--. |-
|_ _| ;| || |(.-' | | |
|__| `--' `-' `;-| `-' ' ' `-'
/ ; Instance (base64 14.3.0)
`-' http://wiki.joyent.com/jpc2/Base+Instance
[root@dev-1 ~]#
All of the actual work you'll do should be done from within this zone.
First verify that you can reach the outside world:
[root@dev-1 ~]# ping 8.8.8.8
8.8.8.8 is alive
[root@dev-1 ~]# ping www.google.com
www.google.com is alive
The package manager for SmartOS is pkgin
. It is like apt-get
in Debian.
To upgrade all packages:
[root@dev-1 ~]# pkgin update
reading local summary...
...
updating database: 100%
[root@dev-1 ~]# pkgin upgrade
calculating dependencies... done.
... (follow the prompts)
pkg_install warnings: 0, errors: 0
reading local summary...
processing local summary...
updating database: 100%
[root@dev-1 ~]#
Node.js is already installed and should be a recent version:
[root@dev-1 ~]# node --version
v0.10.36
You should be all set at this point to run Node.js applications in your SmartOS dev VM.
There is some leg work you need to do to get per-process cores from your node.js applications. First, run these two commands:
[root@dev-1 ~]# coreadm -i core.%f.%p
[root@dev-1 ~]# coreadm -e process
Now you should be able to --abort-on-uncaught-exception
and see a core:
[root@dev-1 ~]# cat die.js
var obj = {
myproperty: "Hello World",
count: 0,
};
function increment() {
obj.count++;
if (obj.count === 1000)
throw new Error("sad trombone");
setImmediate(increment);
}
setImmediate(increment);
[root@dev-1 ~]# node --abort-on-uncaught-exception die.js
Uncaught Error: sad trombone
FROM
Object.increment [as _onImmediate] (/root/die.js:10:5)
processImmediate [as _immediateCallback] (timers.js:354:15)
Abort (core dumped)
[root@dev-1 ~]# ls
core.node.8353 die.js
[root@dev-1 ~]# mdb core.node.8353
Loading modules: [ libumem.so.1 libc.so.1 ld.so.1 ]
> ::load v8
V8 version: 3.14.5.9
Autoconfigured V8 support from target
C++ symbol demangling enabled
> ::jsstack
fffffd7fffdff5b0 libc.so.1`_lwp_kill+0xa
fffffd7fffdff5e0 libc.so.1`raise+0x20
fffffd7fffdff630 libc.so.1`abort+0x98
...