I wanted to write about automating a Citrix Hypervisor aka XenServer installation for a long time but never had the time to put all the information together. If you are looking for a guide how to silent install a XenServer with the latest updates and NVIDIA vGPU driver you came to the right place. This deployment is only working with XenServer 7.1 and later. Citrix changed the hotfix format from ‘.xsupdate’ to ‘.ISO’. If there should be any reason for deploying XenServer 7.0 (EOL – May 2021) feel free to edit the provided bash script.
Table of Contents
General
Before installing and configuring the needed components we need to understand the procedure for an unattended installation.
- Server is powered on
- Server is getting an ip address from a DHCP server with PXE boot information
- PXELINUX is started and a boot menu is presented (TFTP)
- Citrix Hypervisor base installation is triggered with an answer configuration file (FTP)
- After the first boot of the server a post script action is triggered
This is a screenshot of the the PXELinux boot menu.
Now lets get started with setting up the deployment server. Im using a Windows Server 2019 machine in my environment but it could be any other Windows Server release. There is no need to join the machine to a domain it can be member of a local workgroup. Its up to you.
Please download the following sources:
Setup the DHCP Server
The first thing we need to do is to install the DHCP server role and configure a scope for our deployment network. Im using the subnet 192.168.2.0/24 and the ip address of my deployment server is 192.168.2.149.
Powershell Commands
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$DNSDomain="deployment.local" $DHCPServerIP="192.168.2.0" $StartRange="192.168.2.150" $EndRange="192.168.2.200" $Subnet="255.255.255.0" $Router="192.168.2.1" $DNSServerIP="192.168.2.10" Install-WindowsFeature -Name "DHCP" -IncludeManagementTools Add-DhcpServerV4Scope -Name "Deployment" -StartRange $StartRange -EndRange $EndRange -SubnetMask $Subnet Set-DhcpServerV4OptionValue -DnsDomain $DNSDomain -DnsServer $DNSServerIP -Router $Router Set-DhcpServerv4OptionValue -OptionId 66 -Value "192.168.2.149" -ComputerName $Env:COMPUTERNAME Set-DhcpServerv4OptionValue -OptionId 67 -Value "pxelinux.0" -ComputerName $Env:COMPUTERNAME Set-DhcpServerv4Scope -ScopeId $DHCPServerIP -LeaseDuration 1.00:00:00 |
Prepare the FTP Server
Now its time to install the WebServer and FTP feature which will provide the Citrix Hypervisor installation sources during the TFTP boot stage.
1 2 |
Install-WindowsFeature Web-FTP-Server -IncludeAllSubFeature Install-WindowsFeature Web-Server -IncludeAllSubFeature -IncludeManagementTools |
Create the FTP directories in the filesystem.
1 2 3 4 5 6 7 8 |
$Root = "C:\FTP" mkdir $Root mkdir "$Root\xenserver" mkdir "$Root\xenserver\7.1" mkdir "$Root\xenserver\config" mkdir "$Root\xenserver\files\7.1" mkdir "$Root\xenserver\scripts" icacls $Root /grant "Everyone:(OI)(CI)F" |
Start the IIS Management Console and add a new FTP site.
Verify if the FTP server is working while accessing “ftp://localhost/xenserver” in Windows Explorer.
Import Citrix Hypervisor Sources
Mount the Citrix Hypervisor ISO and copy the files to “C:\FTP\xenserver\7.1”
Copy the needed hotfixes (.ISO) to “C:\FTP\xenserver\files\7.1\Hotfix”.
Copy the NVIDIA GRID driver to “C:\FTP\xenserver\files\7.1\GRID”
Build the Answerfile
Now it is time to create the XML answerfile file which is providing the install parameters > “C:\FTP\xenserver\config\XEN-01.xml”
https://github.com/citrixguyblog/XenServerAutomation/blob/master/XEN-01.xml
Post Script & First Boot Script
You can see in the answerfile is a parameter called “<script stage>” which is providing a “post-script.sh” script which will be triggered after the succesfull base installation of the hypervisor. This script is calling the first-boot-script.sh after the next reboot, where the automation magic is happening. Thanks to my colleague Michael Winkler who was working together with me on the script. We included the following features:
- Set TimeZone
- Download Hotfixes and NVIDIA GRID driver
- Set Licence Server
- Enable Multipathing
- Install Hotfixes and NVIDIA GRID driver
- Cleanup the system
- Reboot
post-script.sh
https://github.com/citrixguyblog/XenServerAutomation/blob/master/post-script.sh
PXELinux and TFTP Server
Create the following folder structure
1 2 3 4 |
$Root = "C:\TFTP" mkdir $Root mkdir "$Root\pxelinux.cfg" mkdir "$Root\xs7.1" |
Extract the tftpd64.xxx.zip to C:\TFTP
Copy the needed boot files to the TFTP folder.
1 2 3 4 |
Copy-Item "C:\FTP\xenserver\7.1\install.img" "C:\TFTP\xs7.1" Copy-Item "C:\FTP\xenserver\7.1\boot\vmlinuz" "C:\TFTP\xs7.1" Copy-Item "C:\FTP\xenserver\7.1\boot\xen.gz" "C:\TFTP\xs7.1" Copy-Item "C:\FTP\xenserver\7.1\boot\pxelinux\*.*" "C:\TFTP" |
Create the boot menu config file “C:\TFTP\pxelinux.cfg\default” and edit the ftp url for the answerfile > ‘answerfile=ftp://192.168.2.149/xenserver/config/XEN-01.xml’
https://github.com/citrixguyblog/XenServerAutomation/blob/master/default
Select “tftpd64.exe” for starting the TFTP server. Make sure “C:\TFTP” is selected as current directory and the “TFTP Server” service is activated under “Settings”.
Deployment Example
Server is booting into PXE. I am choosing “Install Citrix XenServer 7.1 CU1”.
Unattended installation is starting with the answerfile “XEN-01.xml”
You can check the transfered files with Tftpd64. We can see that the “install.img” got transmited to our server.
After the succesfull base installation of the Citrix XenServer the “first-boot-script.sh” will be executed and a final reboot will occure. You can check the log file “/var/log/xenautomation.log” for getting more information.
Lets add the fresh installed server to XenCenter and check if everything went well –> Licensed, Cumulative Updates got applied and the GRID driver is available 🙂
Scalability
In an environment where you have to install many servers it is better to create a custom boot menu for each server. Otherwise you need to create an entry for every server which could end up with a list of 100 labels or more. Example:
- Name of the boot menu file: 01-MACAddress –> “01-88-99-aa-bb-cc-dd”
- Name of the answer file: 01-MACAddress.xml –> “01-88-99-aa-bb-cc-dd.xml”
During the boot phase PXELinux will first look for a file with is matching the server MAC address in the “pxelinux.cfg” directory. If the MAC address is not matching there will always be a fallback to the “default” file.
Nested Virtualization
If you want to play arround with the hypervisor deployment in a virtual environment you can go for a nested virtualization on VMware ESXi. It is easier to start with a virtual machine then deploying directly on bare-metal.
– Choose “CentOS 6 (64-bit) as Guest OS
– Active Hardware virtualization
– Change the SCSI Controller to “LSI Logic Parallel”
Hi Julian, thank you for the good guidance and your great work.
I’m trying to create an automated unattended installation of hypervisor 8.
I created a TFTP and FTP server to provide the necessary data.
I also set the .xml configurations according to the documentation from you and official citrix docs:
https://docs.citrix.com/en-us/citrix-hypervisor/install/network-boot.html
Unfortunately the following part is not executed in the configuration:
ftp://*ip*/xenserver/scripts/post-script.sh
(also the syntax as described in your documentation does not work)
I see in the ftp server logs, that he’s downloading the file.
My Post Install Script looks like this. This is apparently not executed, because the directory in line 1 is not created at all.
#!/bin/bash -x
touch $1/tmp/post-executed
wget ftp://*ip*/xenserver/scripts/first-boot-script.sh -O $1/tmp/first-boot-script.sh
chmod 777 $1/tmp/first-boot-script.sh
touch $1/etc/system/system/postinstall.service
chmod 777 $1/etc/system/system/postinstall.service
cat > $1/etc/system/system/postinstall.service <<EOF
[Unit]
After=xapi.service
[Service]
ExecStart=/tmp/first-boot-script.sh
TimeoutStartSec=infinity
[Install]
WantedBy=multi-user.target
EOF
ln -s -s /etc/systemd/system/postinstall.service $1/etc/systemd/system/multi-user.target.wants/postinstall.service
All other configurations in the config XML file are taken over. It fails only to execute the post-install script.
Do you have any idea what I can do?
I guess it’s a problem with the encoding (ASCII, UNICODE). Try to create the bash script directly with „vi“ on the XenServer and try to execute it.