FreeNAS & VMware Snapshots
FreeNas has had a VMware-Snapshot feature for a while but I’ve never found much real-world documentation on how to use it. Figured I’d put the logic down “on paper” for the next guy.
To start with, I have a zVol named “vm” on my FreeNAS machine that I’ve serve up via iSCSI for use by a VMware ESXi host. That gets mounted as a new datastore. I create VMs and store them there so I end up with a subdirectory for each VM. On FreeNAS, I setup a periodic snapshot task then add a VMware-Snapshot as well. Now, whenever the zVol snapshot is taken, FreeNAS first connects to the ESXi host and tells it to create a VM snapshot for each one stored on the datastore. The zVol snapshot is taken then FreeNAS connects to ESXi again to delete the VM snapshots. The zVol snapshots now contain consistent VMware snapshots for each VM.
Getting this far was pretty simple but I didn’t find much online or in documentation on how to actually use those snapshots. It turns out it’s pretty simple – clone the zVol snapshot on FreeNAS, add it as a new extent and LUN on the iSCSI share, attach it to the ESXi machine, copy the VM, and clean up.
The first step is to make a clone of the zVol snapshot. Find the one to clone, click the “Clone Snapshot” icon and the button with the same name in the dialog you get to accept the default name.
You’ll get a new entry in the volumes table named “vm-clone-something“.
Now I need to serve it up via iSCSI. I simply add it as a new iSCSI extent and LUN. First add it as a new extent. I named it “vm-clone”.
My initial instinct was to check Read-only but that didn’t work the first time because I need to allow VMware to redo the signatures later. The device was already selected so all I needed to do was enter the name.
Next step is to add a new extent Target/Extent. I already have an existing entry mapping my “vm” zVol extent as LUN 0 for the “vm” target. I add another mapping the “vm-clone” extent as LUN 1 for the same target.
I can now see see LUN 1 in the ESXi web UI which I use almost all of the time with VMware. However, I found that the next steps cannot be done using the new web interface in ESXi 6.5. it doesn’t appear to support attaching a datastore without formatting it. So, we need to use the vSphere client for these next steps.
In vSphere, select the ESXi host, open the Configuration tab, and select Storage in the left sidebar. Click the Add Storage like above the Datastores table. Click Next and wait for it to find the new LUN. Select it, click Next, select the “Assign a new signature” option, click Next again then Finish. You’l see a new datastore named something like “snap-*-vm” where the “*” is some hex string and “vm” is the name of the original datastore.
You should be able to access the current and the snapshot datastores now. To revert a VM to the one on the snapshot, we first need to deactivate the current one. Then we can rename the folder – i.e. append “-old”. (deleting it makes me nervous). Now we can pull up the snapshot datastore and move the folder to the main datastore. That’s taking about 20 mins to complete for me. Once done, we can activate the VM and fire it up.
To clean up, I unmount and delete the clone datastore in vSphere. Then back on the FreeNAS machine, remove the iSCSI extent and delete the zVol.
This took a total of about 25 minutes for a VM that has a single 20GB virtual drive.