-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New blog post, automated SmartOS VirtualBox setup.
- Loading branch information
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/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 }') | ||
|
||
# | ||
# 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 $1 }') | ||
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}" & |
30 changes: 30 additions & 0 deletions
30
_posts/2012-04-12-automated-virtualbox-smartos-installs.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
layout: post | ||
title: Automated VirtualBox SmartOS installs | ||
tags: [smartos, virtualbox] | ||
--- | ||
|
||
This is a quick script I wrote to: | ||
* Download the latest live ISO image of SmartOS | ||
* Create a VirtualBox VM, or update an existing VM with the latest ISO | ||
* Configure the VM with a zones disk, and boot it! | ||
|
||
For the first install you'll need to: | ||
* Configure the network (likely just 'dhcp') | ||
* Add `c0d0` as the zones disk | ||
* Set a root password | ||
|
||
After that it will just update the live ISO and use existing settings. By | ||
default it will create a port forward so that you can `ssh -p 8322 | ||
root@localhost` into the VM. | ||
|
||
Here's the script in full (or you can download it | ||
[here](http://www.perkin.org.uk/files/mksmartvm)): | ||
|
||
{% highlight bash %} | ||
{% include mksmartvm %} | ||
{% endhighlight %} | ||
|
||
Hopefully there will be a follow-up post which updates my [pkgsrc on | ||
Solaris](http://www.perkin.org.uk/posts/pkgsrc-on-solaris.html) for SmartOS, | ||
including zone setup etc. |