Skip to content

Instantly share code, notes, and snippets.

@bassu
Forked from fnichol/smartos-virtio-windows-xp.sh
Created November 21, 2013 09:51
Show Gist options
  • Save bassu/7578857 to your computer and use it in GitHub Desktop.
Save bassu/7578857 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
if [ -z "$iso" ] ; then
printf -- ">>> You must invoke with iso=/path/to/winxp.iso $(basename $0)\n"
exit 1
fi
if [ -z "$url" ] ; then
# a download url for the floppy image
url="http://autosetup1.googlecode.com/files/virtio-win-1.1.16.vfd"
fi
if [ -z "dns_domain" ] ; then
resolver="example.com"
fi
if [ -z "resolver" ] ; then
resolver="8.8.8.8"
fi
log() { printf -- "-----> $*\n" ; return $? ; }
log "Preparing a master json template"
mkdir -p /usbkey/json
cat <<MASTER_JSON > /usbkey/json/winxpsp3-master.json
{
"brand": "kvm",
"alias": "winxpsp3",
"hostname": "winxpsp3",
"dns_domain": "${dns_domain}",
"resolvers": ["${resolver}"],
"vcpus": 1,
"ram": 1024,
"zfs_root_compression": "off",
"vnc_port": 60001,
"autoboot": false,
"disk_driver": "virtio",
"nic_driver": "virtio",
"disks": [
{
"boot": true,
"size": 8192
}
],
"nics": [
{
"primary": true,
"nic_tag": "admin",
"ip": "dhcp"
}
]
}
MASTER_JSON
log "Creating an empty VM instance"
vmadm create < /usbkey/json/winxpsp3-master.json
# grab a reference to the vm
vm=$(vmadm lookup alias=winxpsp3)
log "Copying the Windows ISO to the VM instance root"
rsync -viP $iso /zones/$vm/root/
log "Downloading the disk image to the VM instance root"
vfd="/zones/$vm/root/${url##http*/}"
curl -L "$url" -o "$vfd"
log "Attaching the floppy image to the VM instance"
echo "{ \"qemu_extra_opts\": \"-fda /$(basename $vfd)\" }" | vmadm update $vm
log "Booting up the VM instance with the Windows ISO attached"
vmadm start $vm order=cd,once=d cdrom=/$(basename $iso),ide
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment