Skip to content

Instantly share code, notes, and snippets.

@geek
Last active December 1, 2020 12:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save geek/5398734 to your computer and use it in GitHub Desktop.
Save geek/5398734 to your computer and use it in GitHub Desktop.
Installing and running SmartOS on OSX with VirtualBox

Install SmartOS in VirtualBox

http://www.perkin.org.uk/posts/automated-virtualbox-smartos-installs.html

save the following as setup.sh and run it:

#!/bin/sh
#
# Configurables:
#
#  - Disk size is in GB
#  - Memory size is in MB
#  - SSH port is the local forwarded port to the VM:22
#
disksize="32"
memsize="1024"
sshport="8322"
vmname="SmartOS"
dlsite="https://download.joyent.com/pub/iso"

vboxdir=$(VBoxManage list systemproperties \
            | awk '/^Default.machine.folder/ { print $4 }')

#
# Find a suitable md5sum program.
#
if type md5 >/dev/null 2>&1; then
    md5sum='md5'
    column='NF'
elif type digest >/dev/null 2>&1 &&
     digest md5 /dev/null >/dev/null 2>&1; then
    md5sum='digest md5'
    column='NF'
elif type digest >/dev/null 2>&1 &&
     digest -a md5 /dev/null >/dev/null 2>&1; then
    md5sum='digest -a md5'
    column='1'
elif type md5sum >/dev/null 2>&1; then
    md5sum='md5sum'
    column='1'
elif type openssl >/dev/null 2>&1 &&
     openssl md5 -hex /dev/null >/dev/null 2>&1; then
    md5sum='openssl md5 -hex'
    column='NF'
else
    echo "ERROR: Sorry, could not find an md5 program" 1>&2
    exit 1
fi

#
# Download MD5 file and parse it for the latest ISO image and checksum
#
curl -o smartos-sums.txt ${dlsite}/md5sums.txt 2>/dev/null
latest_md5=$(awk '/latest.iso/ { print $1 }' smartos-sums.txt)
smartos_version=$(sed -ne "/^${latest_md5}/s/.*-\(.*\).iso/\1/p" \
                    smartos-sums.txt)
if [ -z "${smartos_version}" ]; then
  echo "ERROR: Couldn't determine latest version"
  exit 1
fi

#
# Download the latest ISO image and verify
#
mkdir -p "${vboxdir}/${vmname}"
if [ ! -f "${vboxdir}/${vmname}/smartos-${smartos_version}.iso" ]; then
  echo "Downloading ${dlsite}/smartos-${smartos_version}.iso"
  curl -o "${vboxdir}/${vmname}/smartos-${smartos_version}.iso" \
          ${dlsite}/smartos-${smartos_version}.iso
  dl_md5=$(${md5sum} "${vboxdir}/${vmname}/smartos-${smartos_version}.iso" \
             | awk '{ print $'${column}' }')
  if [ -z "${dl_md5}" ]; then
    echo "ERROR: Couldn't fetch ISO image"
    exit 1
  fi
  if [ "${latest_md5}" != "${dl_md5}" ]; then
    echo "ERROR: md5 checksums do not match"
    exit 1
  fi
fi

#
# Create VirtualBox VM
#
echo "Creating/Updating Virtual Machine"
VBoxManage showvminfo "${vmname}" >/dev/null 2>&1
if [ $? -eq 0 ]; then
    # VM already exists, just update the ISO image
    VBoxManage storageattach "${vmname}" --storagectl "IDE Controller" \
      --port 1 --device 0 --type dvddrive \
      --medium "${vboxdir}/${vmname}/smartos-${smartos_version}.iso"
else
    # Create the VM
    VBoxManage createvm --name "${vmname}" --ostype OpenSolaris_64 --register
    VBoxManage storagectl "${vmname}" --name "IDE Controller" --add ide

    # Attach the ISO image
    VBoxManage storageattach "${vmname}" --storagectl "IDE Controller" \
      --port 1 --device 0 --type dvddrive \
      --medium "${vboxdir}/${vmname}/smartos-${smartos_version}.iso"

    # Create and attach the zone disk
    VBoxManage createhd --filename "${vboxdir}/${vmname}/smartos-zones.vdi" \
      --size $(echo "${disksize}*1024" | bc)
    VBoxManage storageattach "${vmname}" --storagectl "IDE Controller" \
      --port 0 --device 0 --type hdd \
      --medium "${vboxdir}/${vmname}/smartos-zones.vdi"

    # Set misc settings
    VBoxManage modifyvm "${vmname}" --boot1 dvd --boot2 disk --boot3 none
    VBoxManage modifyvm "${vmname}" --memory ${memsize}
    VBoxManage modifyvm "${vmname}" --natpf1 "SSH,tcp,,${sshport},,22"
fi

#
# Start it up
#
echo "Starting Virtual Machine"
VirtualBox --startvm "${vmname}" &

Launch the (text) option

ssh with

ssh -p 8322 root@127.0.0.1

once logged in with ssh create a new script with the following contents then run it:

## Set up SmartOS in VirtualBox
# http://www.perkin.org.uk/posts/automated-virtualbox-smartos-installs.html
 
# set up global zone with Joyent datasets
if [[ ! -e /var/db/imgadm/sources.list || `grep -v "https://datasets.joyent.com/datasets" /var/db/imgadm/sources.list` ]]; then
  echo "https://datasets.joyent.com/datasets" >> /var/db/imgadm/sources.list
fi
 
imgadm update
 
# download sdc:sdc:base64:1.7.1 dataset
imgadm import 8da4bc54-d77f-11e1-8f6f-cfe8e7177a23
 
# find gateway based on global zone gateway
export GATEWAY=$(netstat -r | grep default | awk '{ print $2 }')
 
# create a 'manage' zone
if [[ ! `vmadm list -H alias=manage` ]]; then
  echo "{
    \"brand\": \"joyent\",
    \"dataset_uuid\": \"8da4bc54-d77f-11e1-8f6f-cfe8e7177a23\",
    \"quota\": 1,
    \"max_physical_memory\": 64,
    \"alias\": \"manage\",
    \"nics\": [
      {
        \"nic_tag\": \"admin\",
        \"ip\": \"dhcp\",
        \"netmask\": \"dhcp\",
        \"gateway\": \"${GATEWAY}\"
      }
    ]
  }" | vmadm create
fi
 
export MANAGE_ZONE="$(vmadm list -H alias=manage | awk '{ print $1 }')"
 
cd /zones/${MANAGE_ZONE}
mkdir -p local/bin
mkdir -p local/data/zones
 
echo "{
  \"brand\": \"joyent\",
  \"dataset_uuid\": \"8da4bc54-d77f-11e1-8f6f-cfe8e7177a23\",
  \"quota\": 10,
  \"max_physical_memory\": 1024,
  \"nics\": [
    {
      \"nic_tag\": \"admin\",
      \"ip\": \"dhcp\",
      \"netmask\": \"dhcp\",
      \"gateway\": \"${GATEWAY}\"
    }
  ]
}" > local/data/zones/zone.json

Now install the zone.json config with:

vmadm create -f  local/data/zones/zone.json

Use zlogin [UUID from last step to login to the zone

Now run pkgin search git to update and search for git. use pkgin install [git name] to install git.

@geek
Copy link
Author

geek commented Aug 13, 2013

update to use resolvers:

"resolvers": [
"10.1.1.1",
"8.8.8.8"
],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment