Skip to content

Instantly share code, notes, and snippets.

@reiddraper
Created July 11, 2012 14:39
Show Gist options
  • Save reiddraper/3090799 to your computer and use it in GitHub Desktop.
Save reiddraper/3090799 to your computer and use it in GitHub Desktop.

on the guest SmartOS VM

pkg_add http://pkgsrc.joyent.com/sdc6/2012Q1/i386/All/smtools
# note this is going to shut down the VM
sm-prepare-image

on the global zone

# b996c578-c4fc-46ef-81cc-d2eb3489ebc6 is the UUID
# of the zone I want to snapshot and clone. `uuid`
# returns a new UUID.
zfs snapshot zones/b996c578-c4fc-46ef-81cc-d2eb3489ebc6@`uuid`

# we can see the snapshot we made
zfs list -t snapshot

# create a new UUID for the clone
export CLONE_UUID=`uuid`

# clone!

# the UUID after the `@` is the UUID for from our snapshot version
zfs send zones/b996c578-c4fc-46ef-81cc-d2eb3489ebc6@81e67092-cb63-11e1-b0f3-fbc4021003b3 | zfs recv zones/$CLONE_UUID

# now you should be able to use $CLONE_UUID as a "dataset_uuid" in a VM json spec.

Getting ssh access again

After stopping and running the prepare script on my machine, I was unable to log in via ssh again. I saw this ssh error:

Unable to negotiate a key exchange method

I fixed this by zlogin'ing back into the machine and running the following:

ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
svcadm restart ssh
@matthiasg
Copy link

i am not a big fan of running sm-prepare-image in the machine to clone beforehand, since it alters the machine state before cloning. a clone of a running machine should clone as is (meaning it would be similar to a hard shutoff), a clone of a stopped machine would be more benign of course. and the cloned machine should remain unaware of the cloning process.

so if sm-prepare-image is really required i would assume you could do it twice, first clone and import without, then run sm-prepare-image in the clone and start over ? why is prepare image required ? cant it be done via zfs directly (e.g. deleting files in the clone before importing it as a vm from the GZ as in /zones/clone-uuid/root/ ?

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