Showing posts with label Provisioning Server. Show all posts
Showing posts with label Provisioning Server. Show all posts

Saturday, February 22, 2014

Updated XenServer Bash Script

Originally I had written a script to eject all ISOs from every VM that has an ISO attached as well as insert an ISO into every VM in a XenServer pool. The purpose was to assist in attaching a boot ISO to Provisioning Services (PVS) Target Devices, or removing the ISO image from all VMs in a pool. You can find the original script here. I have updated the script to provide more functionality, namely to assist in transitioning away from PVS boot ISOs to network boot using TFTP, and back again if you need to roll back for any reason. Below are the features of the updated script:

  • List VMs with an ISO attached in a XenServer pool.
  • List VMs with no ISO attached in a XenServer pool.
  • Eject all ISOs and set the VMs to network boot in XenServer pool. Only VMs with ISOs will be affected.
  • Insert an ISO and set the VMs to boot from ISO in a XenServer pool. Only VMs with no ISO will be affected.
  • Eject all ISOs from all VMs in a XenServer pool.
  • Insert an ISO to all VMs in a XenServer pool. Only VMs with no ISO will be affected.

Normally, to transition from ISO boot to network TFTP boot, you need to remove the boot ISO and then set the boot order on the VM to network. Instead of thousands of clicks for hundreds of desktops, this script automates this task. It will search all VMs with ISOs attached, eject the ISO, and switch the boot device to network. Warning, this script does this for every VM in the pool that has an ISO attached. So, if you have some VMs that you don't want this to run against, make sure to remove any ISO attached to them. If for some reason, a VM does get altered, its an easy fix through XenCenter GUI to set the correct boot device and attach an ISO if so desired. As part of any migration, a roll back plan is always necessary, and this script delivers. If for some reason you need to roll back to a boot ISO, this script will set the boot device to the ISO as well as insert a named ISO into every VM that does not have an ISO attached. Again, please be cautious if you have other VMs that you don't want to alter by adding an ISO to them or change them back after the script finishes.

During a XenServer upgrade, the upgrade process likes all ISOs to be ejected from all VMs in the XenServer pool. If you only have a few servers, going to each one in XenCenter is not a big deal. But, what if you have a lot of VMs that you need to eject the ISO from ahead of time? This script automates the process, so you don't have to go to each VM and figure out if there is an ISO attached and eject if found. I recently used this as part of a XenServer 5.6 FP1 to 6.2 upgrade which worked flawlessly.

To run the script:

  1. Upload the script to a XenServer host using WinSCP (or some other method) to /usr/local/bin (or whatever other location you want).
  2. From the XenServer CLI type the following to allow execution of the script:
    1. chmod +x xenserver.sh
  3. From the XenServer CLI type the following to run the script:
    1. ./xenserver.sh
  4. Once the script executes, you will see the following menu:


To navigate, just type the number of the option you want and press enter. The only input required is the name of the ISO dependent on the option you choose.

Download the script here.

This post was written in reference to the following platforms and versions:

  • XenServer 5.6 FP1 - 6.2 SP1.





Monday, August 19, 2013

How to Update The Provisioning Services (PVS) Agent or Hypervisor Tools The Easy Way

Either you are updating the Provisioning Services (PVS) client on a target device or you are updating the hypervisor tools, there are a few methods to choose from.  One of the quickest and least error prone (in my opinion) methods to perform this is by using the VHD attach method.  This method works with XenServer, Hyper-V, and VMware.  I have also used this method using PVS 5.6 and 6.1.  Instead of reverse imaging, or keeping a master VM to re-image from, all you need is the latest merged VHD.  I say merged because you will need to perform a merge (versions + base) into a single VHD if using PVS 6.1. Below are the steps to perform this in a XenServer or VMware environment.  Hyper-V is almost self-explanatory, as you can boot to the VHD without much effort.

VMware

I have used this method to migrate PVS images from VMware 4.x to 5.x, updating the VMware tools and hardware versions as well as applying PVS agent hotfixes.  This method is a bit more involved than using Hyper-V or XenServer, but it works well.
  1. Merge all versions and the base image into one VHD from within PVS.
  2. Download and install WinImage.  There is a 30 day trial for WinImage, which should be fine to complete this process.
  3. Using WinImage, convert the VHD file to VMDK.
  4. Copy the VMDK file to the VMware datastore.
  5. Create a new VM using the VMDK you just copied.
  6. Log in with the local administrator account (you may have to rejoin the domain).
  7. Uninstall the PVS agent and reboot.
  8. Install any VMware tools updates or VMware hardware version updates.
  9. Install the PVS agent.
  10. At this point you can either copy the VMDK image and use WinImage to convert the image back to VHD, or use the PVS agent wizard.

XenServer


Using XenServer is a bit quicker than using VMware as you don't have to perform any VHD conversions.

  1. Create a NFS share on the PVS server:
    1. Windows 2003:
      1. Using WinSCP, copy the following files from XenServer to the desktop:
        1. /etc/passwd
        2. /etc/group
      2. Install NFS on Windows:
        1. Launch the Add/Remove Windows Components Wizard in the Control Panel
        2. Select the following:
          1. Other Network File and Print Services | Microsoft Services for NFS
          2. Other Network File and Print Services | Microsoft Services for NFS | User name mapping
      3. Configure NFS:
        1. Open Microsoft Services for NFS.
        2. Right-click "User name mapping" and click "Properties".
        3. Select "Use password and group files".
        4. Browse to the passwd file you downloaded to your desktop for the password file.
        5. Browse to the group file you downloaded to your desktop for the group file.
        6. Click "OK".
        7. Right-click "User maps" and click "Create map".
        8. Verify the domain and select an administrator account.
        9. For the Unix user specify "root".
        10. Click "Add".
      4. Create a NFS share:
        1. Create a new directory.
        2. Right-click the new directory and select "NFS Sharing" tab.
        3. Select "Share this folder".
        4. Check "Allow anonymous access".
        5. Click "Permissions".
        6. Check "Allow root access".
        7. Set the "Type of access:" to "Read-Write".
        8. Click "OK".
        9. Click "OK".
    2. Windows 2008:
      1. Install the file role service "Services for Network File System".
      2. Create a NFS share:
        1. Create a directory.
        2. Right-click the directory and select "NFS Sharing" tab.
        3. Enable sharing and specify a name.
        4. Click "Manage NFS Sharing".
        5. Click "Permissions".
        6. Set "Type of access" to "Read-Write"
        7. Check "Allow root access".
        8. Click "OK".
        9. Click "OK".
        10. Click "OK".
  2. Create a new SR in XenServer and point to the NFS share you created earlier.  Remember, the NFS share is case sensitive.
  3. Create a new VM in XenServer with the same specifications as the existing target devices.  Choose the new NFS SR to hold the vDisk for this VM.  Do not start this VM automatically.
  4. Within PVS, set the image you want to update to private mode.
  5. Copy or cut the VHD to the NFS share directory.  You should see another VHD in the NFS share directory with the UUID of that VHD.
  6. Rename the VHD you just copied into the NFS share directory with the same name of the VHD that was created when you created the VM within XenServer.
  7. Boot the VM within XenServer.
  8. Uninstall the PVS agent.
  9. Restart the VM and update any hypervisor tools.
  10. Install the new PVS agent.
  11. Shutdown the VM and cut or copy the VHD back to the PVS store and rename it appropriately back to the original name.
  12. Boot to the image using one of your target devices to make sure all is working and then close the image as you normally do.

Wednesday, January 2, 2013

Eject / Insert an ISO to All Guest VMs in a Resource Pool at Once


3/28/14 - This post and script has been updated and you can find it here.

In a XenDesktop / XenServer (5.6 - 6.1) environment, there are a couple ways to boot virtual desktops using Provisioning Services.  I usually setup a load balanced TFTP virtual server on NetScaler and load balance between multiple Provisioning Servers.  I have written a post on configuring load balanced TFTP via NetScaler here.  But, I do run across some environments where they are using boot to ISOs for all their virtual desktops.  This works fine, but what happens if the virtual desktops loose the ISO mapping because of an issue with the ISO store.  This isn't a big deal if you are only dealing with a few virtual desktops, you just re-add the ISO through XenCenter.  But, what if you have hundreds or more of virtual desktops?  Without an automated way of either ejecting or inserting ISOs you will waste probably hours and end up with some really sore wrists.

I wrote a bash script to handle this type of situation.  The script is menu driven for ease of use.  The following are the features of the script:

  • Able to list all VMs in a resource pool with an ISO attached.  This does not include the name of the ISO, just the name of the VM.
  • Able to list all VMs in a resource pool without an ISO attached.
  • Able to eject an ISO from every VM in the resource pool.
  • Able to insert an ISO to every VM in the resource pool.
To be able to run the script, please do the following:

  1. After you download the script, upload the script to the XenServer host.  I recommend uploading the script to  /usr/local/bin.  To upload the script you can use WINSCP.
  2. Once the script is uploaded, you will need to enable the script to execute.  From either the console or a Putty session, type the following:
    1. cd /usr/local/bin
    2. chmod +x iso.sh
  3. To run the script, from either the console or a Putty session, type the following:
    1. ./iso.sh
Once the script executes, you will see the following menu:

To navigate, just type the number of the option you want and press enter.  The only other input required is when you want to insert an ISO.  This option will insert the ISO to every VM in the resource pool that does not have an ISO currently attached, so be careful.  To insert an ISO, perform the following:

  1. Type 4 and press enter.
  2. Enter the file name of the ISO you want to insert.  This must be the full ISO name, like xs-tools.iso.  This ISO must also be present in your ISO repository.  If you mistype the file name or the ISO does not exist in your ISO repository, you will see the error "Error: CD not found".
This is a basic automation script, but also has a lot of potential for added functionality.  Let me know if you have any questions or comments.


Download script here

This post was written in reference to the following platforms and versions:
  • XenServer 5.6, 6.02, and 6.1

Wednesday, April 4, 2012

TFTP Load Balancing on NetScaler using Direct Server Return

3/28/14 - A new post with updated information can be found here.

To be able to provide Provisioning Server (PVS) High Availability (HA), there are a few options.  One option stands out, direct server return (DSR).  With DSR, NetScaler provides the initial load balancing to an appropriate TFTP server, and then the TFTP and the client talk directly freeing up bandwidth on the NetScaler.  The process of the request is as follows:

  1. A DHCP request is sent by a client, at which the DHCP server responds with an IP address and 2 DHCP options, 66 and 67.  Option 66 holds the TFTP server IP, and option 67 holds the boot file name.
  2. The preboot execution environment (PXE) on the client then makes a request to the TFTP IP.
  3. NetScaler now makes a load balancing decision.  NetScaler uses the MAC address and forwards the request while not changing the destination IP.  The frame arrives at the TFTP server with the same destination IP as the VIP configured on NetScaler.  The TFTP is able to process this frame because of a loopback adapter with the same IP assigned.
  4. After the TFTP server receives the request, it forwards the request to the loopback adapter.  It then sends to the client the initial segment of its boot file.
The advantages of DSR for TFTP load balancing is that it provides robust scalability and availability.  The disadvantages of using DSR is that it requires a bit more effort in configuration and also requires a loopback interface on the TFTP servers.

Now on to the fun stuff.  Below you will find instructions on how to configure TFTP load balancing using NetScaler DSR.  In this scenario there are 2 PVSs with the TFTP service installed on each.  The PVSs have initially 2 network adapters.  The first network adapter is used to connect to the server VLAN.  The second adapter is to connect to the PVS VLAN for streaming images.  We are using 1 NetScaler (or you could use 2 in a HA pair) using subnet IP (SNIP) instead of mapped IP (MIP).  There are 3 VLANS connected to the NetScaler.  First, the management interface which is where the NetScaler IP (NSIP) is allocated.  Second, the server VLAN.  Finally, the PVS VLAN  So it logically looks like:


Now for the configuration:
  1. Open the NetScaler GUI and login.
  2. Navigate to "System" | "Settings"
  3. Click on "Configure modes".
  4. Select "Use Source IP".
  5. Select "MAC Based Forwarding".
  6. Create the SNIP for the PVS VLAN if not already created.
  7. Create load balancing servers in NetScaler:
    1. Navigate to "Load Balancing" | "Servers" and click "Add".
    2. Enter a name and IP address, the click "Create".
    3. Repeat this for each TFTP server.
  8. Create a new service group:
    1. Navigate to "Load Balancing" | "Service Groups" and click "Add".
    2. Select "ANY" for Protocol.
    3. Select "Server based".
    4. Select the TFTP servers created earlier.
    5. Enter * for the port.
    6. Add a ping monitor, or create your own TFTP monitor.
    7. Navigate to the "Advanced" tab.
    8. Select "Use Source IP".
    9. Select "Client Keep-Alive".
    10. Select "TCP Buffering".
    11. De-select "Surge Protection".
    12. Click "Create".
  9. Create a new virtual server:
    1. Navigate to "Load Balancing" | "Virtual Servers".
    2. Type in a name and IP.  This is the IP that needs to be used in DHCP option 66.  This is also the IP address to be used for the loopback adapters.
    3. Set the protocol to "Any".
    4. Set the port to *.
    5. Navigate to the "Services Group" tab.
    6. Select the service group created earlier.
    7. Navigate to the "Method and Persistence" tab.
    8. Select "SOURCEIP" for persistence.
    9. Navigate to the "Advanced" tab.
    10. Set redirection mode to "MAC Based".
  10. Add the loopback adapter to the TFTP servers:
    1. Navigate to the device manager.
    2. Right-click the TFTP server name in the middle pane and choose "Add legacy hardware".
    3. Click "Next".
    4. Select "Install the hardware that I manually select from a list (Advanced)".
    5. Click "Next".
    6. Select "Network adapters".
    7. Click "Next".
    8. Select "Microsoft" for the manufacturer.
    9. Select "Microsoft Loopback Adapter" for the network adapter.
    10. Click "Next".
    11. Click "Finish".
    12. Navigate to the properties of the new loopback adapter and uncheck IPv6.
    13. Go to the properties of IPv4 and type in the IP address and subnet mask.  This is the same IP address when you created the virtual server earlier.  Do not enter a gateway or DNS servers.
    14. Disable DNS registration on this adapter.
    15. Disable NetBIOS on this adapter.
    16. Open a command prompt as an administrator.
    17. Enter the following commans for the loopback adapter and PVS VLAN adapter:
      1. netsh interface ipv4 set interface "[name of adapter]" weakhostreceive=enabled
    18. Enter the following command for just the loopback adapter:
      1. netsh interface ipv4 set interface "[name of adapter]" weakhostsend=enabled
  11. Set the TFTP service to listen on the new loopback adapter:
    1. Navigate to C:\Program Files\Citrix\Provisioning Services.
    2. Open tftpcpl.cpl as an administrator.
    3. Click on the "TFTP Network" tab.
    4. Select the loopback adapter created earlier and de-select any other adapters.
    5. Restart the Citrix TFTP service.
  12. Test TFTP load balancing with NetScaler DSR:
    1. Install the TFTP client feature on a server that is on the PVS VLAN but is not a TFTP server.
    2. Open a command prompt and enter the following:
      1. tftp [IP of TFTP virtual server created earlier] GET ardbp32.bin ardbp32.bin
Let me know if you have any comments, questions, or suggestions.

Tuesday, January 10, 2012

Change Which NIC Provisioning Server's TFTP Service Listens on

The easy way:


Run the following control panel file as an administrator:

C:\Program Files\Citrix\Provisioning Services\tftpcpl.cpl

The hard way:


To change which NIC the Provisioning Server's TFTP service listens on:

1. Verify which IP TFTP is listening on with the following command:

netstat -an -p udp | find ":69"

2. Go to the following registry location:

HKLM\SYSTEM\CurrentControlSet\services\BNTFTP\Parameters

3. Remember the Data for the value "Adapter"as this will help in the next step.
4. Go to the following registry location:

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards

5. Find the network card you want to use and copy the "ServiceName" data
6. Go back to the following registry location:

HKLM\SYSTEM\CurrentControlSet\services\BNTFTP\Parameters

7. Change the data for "Adapter" with what you just copied
8. Restart the "Citrix PVS TFTP Service"
9. Verify the new NIC is listening with the following command:

netstat -an -p udp | find ":69"

10. You can also verify TFTP further by using the TFTP client (Server Manager | Features | Add Features | TFTP Client)

tftp [host] GET ardbp32.bin ardbp32.bin

Wednesday, August 31, 2011

Provisioning Server 5.6 KMS CMID Issues

After you create your desktop image and set it up for KMS activation, you notice that the CMID does not change no matter how many times you reboot or issue the SLMGR /REARM command. The issue is with the order in which you enable/disable KMS in the File Properties of the vDisk in Provisioning Server. When you start the process of getting an image ready to update, make sure to disable KMS first, then set the mode to Private. After you have updated your image, enable KMS and then set the image to Standard. Now, every reboot an image makes, a new CMID is generated and you are finally able to activate against KMS (granted you meet the minimum requirements).