Wednesday, February 13, 2013

A different approach to iSCSI and virtualization

In this post I will explain how you can use Microsoft iSCSI Software Target to virtualize the disks for your VMs. I will describe how to use differencing disks, controlled by the iSCSI server, and not by your virtualization software. This can be valuable, specially in a test environment.

I will start off by telling you what this approach does not do. I will not describe how to use iSCSI as a virtual SAN. Although this is an interesting subject, which will give you the option of testing live migration and stuff like that, I'd rather point you to Rickster's blog on Technet for his description, and detailed howto on another post. If you haven't bookmarked his blog before, I recommend you do so now.

I will use a different, in some ways higher level of virtualization than what Rickster describes. When we talk about SAN for virtualization, we talk about a block-level storage. This post is about file-level storage, in the sense that the virtual disks for the VMs are not stored on a SAN, but each of the VM disks are represented by a virtual disk on the iSCSI server. In other words, instead of using one big virtual disk as a SAN, I will use multiple virtual disks, each dedicated to a single VM. This is how we can make use of snapshots and differencing disks on the iSCSI server.

The Microsoft iSCSI Software Target is a free addon to Microsoft Server 2008 R2. Download and installation is described very well on Jose Barreto's Blog, also on Technet.

This is more or less a walk-through of how I did this with a Windows iSCSI server and an ESXi virtualization server. I will follow up this post shortly, describing how you can utilize the same iSCSI server with different virtualization software.

After installing and configuring the software, I create a new VHD from the iSCSITarget management console.

This will run a wizard that is rather straight forward. My virtual disk will become a master disk for several VMs running Windows 7, 32-bit version. So I name it accordingly.

The size of the disk is critical, as the iSCSI target software does not let us use disks with dynamic size. Hopefully, this will change in the future. But for now, whatever size we give to the disk, will be fully allocated from the server storage. I am going for a ~30GB disk for this master disk.

I complete the wizard, giving a useful description of the disk, as the file name will not show up in the iSCSITarget management console overview. I do not connect the disk to any targets at this time.

The disk I have created, will after I am done, have an updated and sysprepped installation of Windows 7. You might choose a different way of getting this onto your VHD, perhaps you already have a Hyper-V installation with such a disk file available. But I'll go ahead and connect the disk to a VM in order to install Windows. I proceed to create a target for the disk. This is done using another wizard from the console.

I name the target "esxi01", as this will be my first target for my ESXi server. You might choose a different naming scheme suitable to your needs. After installing the iSCSI software adaptor on my ESXi server, I am able to copy the IQN identifier from my ESXi to identify the initiator.

Alternatively, I could use CHAP, IP number, or some other method of identifying the ESXi server to the iSCSI server. I just want to make sure nobody else connects to my target.

After creating my target, I connect the disk I created earlier to the target. If I then check the properties of the disk from the target view, I can see that each disk file is assigned a LUN number within the target. This is not important at the moment, as there is only one virtual disk, but later I will on my ESXi be able to choose from several disks after connecting to this single target.

ESXi requires a little more configuration to connect to the target I just created. I have the choice between dynamic and static discovery. But first I need the IQN of the target, which I find on the property page of the target on my iSCSI server.

As I don't like anything to happen dynamically these days, I configure my connection to the iSCSI server under "Static Discovery" after opening the properties of my iSCSI software adaptor, on the ESXi server. I add the target using the IP address of my iSCSI server and the IQN i collected above.

I didn't set any CHAP authentication when I created the target, so I don't configure this on the ESXi server either. When I close the properties after adding the target, it will be scanned for LUNs, and I should see my iSCSI disk listed in the detail window of the ESXi Storage Adapters configuration page.

Now I create a new VM in order to install Windows. I select "Custom" configuration in the ESXi wizard, else I will not be able to choose the iSCSI disk as storage for the new VM. When I get to choose the type of disk, I select "Raw Device Mappings".

After this, I get to select the LUN from my iSCSI target. There is only one to choose from at this stage.

Finally, I have to decide the compatibility mode of the LUN mapping. I will not go into detail about this here, but in this case I select "Physical", as I do not need the functionality of the second option.

Now I just finish the wizard and my VM is ready for OS installation. It is important to notice that the OS in the VM will not see the disk as an iSCSI disk, but as an IDE or SCSI disk, as per your choices made when you created the machine. After installing and sysprepping Windows in the VM, as I would before capturing an image for deployment, I make sure the VM is shut down and I remove the disk from the VM I created or delete the VM entirely. Then I detach the disk from the iSCSI target on my iSCSI server.

I now have a master disk I can use for deploying Windows 7 to new VMs. I will do so faster than using image deployment and faster than (vSphere) cloning a VM on the server. I will instead create a differencing disk on my iSCSI server for every new Windows 7 VM, based on my master disk.

In order to create a differencing disk, I use a Visual Basic script "CreateDiffVHD.vbs", link goes to Technet Script Center. In the figure below I create two differencing disks.

Checking the newly created files in my C:\VHD directory, I can see that the file sizes for the differencing disks are 62KB. Differencing disks has dynamic size, and will grow as soon as I boot my first client. The disks will show up in the iSCSITarget console automatically, I just have to add them to my target.

As soon as I add them to my target, they show up as "In Use", because my ESXi server is still connected to the target. To make the ESXi server aware of the new LUNs, I just rescan the target on my ESXi. The disks are now available for two new VMs, created in the same manner as before. Both will boot nicely to the next sysprep fase, and my master disk will be readily available for new differencing disks and new VMs whenever I need it. My VMware ESXi server will be happily unaware of my second level of virtualization and the use of differencing disks.