Last active
December 13, 2015 23:49
-
-
Save trentster/4994915 to your computer and use it in GitHub Desktop.
PURPOSE: turn a KVM vm into a dataset
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
#!/bin/bash | |
# | |
# SCRIPT: do-kvm-dataset.sh | |
# AUTHOR: Mark Slatem | |
# DATE: 26 January 2013 | |
# REV: 1.0 | |
# | |
# PLATFORM: SmartOS | |
# REQUIREMENTS: SmartOS | |
# | |
# PURPOSE: turn a zone vm into a dataset | |
# USAGE: do-smartmachine-dataset.sh UUID | |
UUID="$1" | |
GENUUID=`uuid` | |
CLOUDNAME="smartos" | |
DATE=`date +%FT%H:%M:%S.0Z` | |
echo -n "What do you want to call the new dataset: " | |
read -e DNAME | |
echo -n "Enter a 3 letter abbreviation for the dataset name: " | |
read -e DNAMABBR | |
echo -n "What is the version number you want to use: " | |
read -e VERSION | |
echo -n "Enter a short description for the dataset: " | |
read -e DESCR | |
echo -n "creator name: " | |
read -e CREATOR | |
#lets do the actual snapshots | |
zfs snapshot zones/$UUID-disk0@prepare | |
echo "Creating zfs archive ($GENUUID.$DNAME.$VERSION.zfs.gz)..." | |
#lets do the actual zfs send | |
zfs send zones/$UUID-disk0@prepare | gzip > $GENUUID.$DNAME.$VERSION.zfs.gz | |
SIZE=`ls -l $GENUUID.$DNAME.$VERSION.zfs.gz | awk '{ print $5 }'` | |
CHKSUM=`cksum -xsha1 $GENUUID.$DNAME.$VERSION.zfs.gz | awk '{ print $1 }'` | |
echo "Creating manifest ($DNAME.$VERSION.dsmanifest)..." | |
cat kvmmachine.tpl |\ | |
sed -e "s/#DNAME/$DNAME/g" |\ | |
sed -e "s/#VERSION/$VERSION/g" |\ | |
sed -e "s/#DESCR/$DESCR/g" |\ | |
sed -e "s/#DATE/$DATE/g" |\ | |
sed -e "s/#GENUUID/$GENUUID/g" |\ | |
sed -e "s/#CHKSUM/$CHKSUM/g" |\ | |
sed -e "s/#SIZE/$SIZE/g" |\ | |
sed -e "s/#CLOUDNAME/$CLOUDNAME/g" |\ | |
sed -e "s/#CREATOR/$CREATOR/g" |\ | |
sed -e "s/#DNAMABBR/$DNAMABBR/g" > $DNAME.$VERSION.dsmanifest | |
#lets delete the snapshot | |
zfs destroy zones/$UUID-disk0@prepare | |
##optional | |
#echo "Installing New Dataset ($DNAME.$VERSION uuid: $GENUUID)..." | |
#imgadm install -m $DNAME.$VERSION.dsmanifest -f $GENUUID.$DNAME.$VERSION.zfs.gz | |
exit 0 |
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
{ | |
"name": "#DNAME", | |
"version": "#VERSION", | |
"type": "zvol", | |
"cpu_type": "host", | |
"description": "#DESCR", | |
"published_at": "#DATE", | |
"os": "freebsd", | |
"image_size": VOL_SIZE, | |
"files": [ | |
{ | |
"path": "#GENUUID.#DNAME.#VERSION.zfs.gz", | |
"sha1": "#CHKSUM", | |
"size": #SIZE, | |
"url": "#GENUUID.#DNAME.#VERSION.zfs.gz" | |
} | |
], | |
"requirements": { | |
"networks": [ | |
{ | |
"name": "net0", | |
"description": "public" | |
} | |
] | |
}, | |
"disk_driver": "ide", | |
"nic_driver": "e1000", | |
"uuid": "#GENUUID", | |
"creator_uuid": "3952e6b6-b61a-11e1-9a8a-2f58dc6d1291", | |
"cloud_name": "#CLOUDNAME", | |
"creator_name": "#CREATOR", | |
"platform_type": "smartos", | |
"urn": "smartos:mts:#DNAMABBR:#VERSION", | |
"created_at": "#DATE", | |
"updated_at": "#DATE" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On latest SmartOS, "os":"windows" and imgadm did not like the publshed date with .0Z but with just Z after second it did take it.