Auto Start VM after XenServer reboot

SSH or gain command line access to XenServer

First we need to enable the Pool to allow auto starting
Second we will need to turn on the auto_poweron to true

In the following examples replace the UUIDs with your UUIDs

Find Pool UUID

You can find the pool UUID by running the “xe pool-list” Command. Note: you’ll still have a pool even if there is only a single server.

# xe pool-list
uuid ( RO) : 2e587aeb-de94-hf29-3eda-923d8he634fe

Enable auto_poweron for the pool

xe pool-param-set uuid=2e587aeb-de94-hf29-3eda-923d8he634fe other-config:auto_poweron=true

Verify that it is enabled

xe pool-param-list uuid=2e587aeb-de94-hf29-3eda-923d8he634fe  | grep auto_poweron

List VM UUID’s

Locate the UUID’s of the VM’s you want to start

# xe vm-list
uuid ( RO)           : 521be58a-3495-ea29-02a0-85ffcda06583
     name-label ( RW): CentOS 7
    power-state ( RO): running

Enable auto start

Run the following command for each VM you want to auto start. Change the UUID to the UUID of the vm you want to start.

xe pool-param-set uuid=521be58a-3495-ea29-02a0-85ffcda06583  other-config:auto_poweron=true

Print parameter settings

Use the following command to verify that the auto_poweron option is enabled.

xe vm-param-list uuid=521be58a-3495-ea29-02a0-85ffcda06583 | grep -i poweron | cut -d";" -f1

Example output

                      other-config (MRW): auto_poweron: true

https://support.citrix.com/article/CTX133910

Setup Windows File Share for Citrix XenServer

Setup Share in windows

You may need to enable the Network Sharing and discovery in the network sharing center before proceeding with the following steps.

Create a new directory, right click and hit properties.

Under Sharing, hit Advanced Sharing…

Enable the Check mark for “Share this folder” and verify the share name is correct. In this example we are sharing a folder called XenServerShare

Setup Share in XenCenter

From XenCenter, hit add new Storage Repository and run through the wizard. When you get to the Share path put in \\share-ip-address\Share\Path

Example: If the IP address of the computer with the Share is 192.168.1.2 and you shared your Downloads folder, the path would be as follows

\\192.168.1.2\Downloads

Use the share computers username and password to log in to it.

How To Reset root Password on CentOS VM – XenServer

Basic steps are as follows.

  1. Shutdown VM
  2. From XenCenter, insert the CentOS iso into the VM’s Virtual DVD drive.
  3. Boot the CentOS VM in recovery mode.  If you need help with that check this post out.
  4. On the grub menu, select recover OS Installation.
  5. Run through the recovery and mount the VM’s disk where CentOS is installed
  6. You should now be able to drop to a prompt and chroot /sysimage
  7. Change the root password with passwd
  8. Shutdown the VM
  9. Eject the CentOS iso
  10. Boot up the VM and login with the new password

XenServer Commands

List, unplug, or destroy PBD storage repository

xe pbd-list
xe pbd-unplug uuid=[UUID for VM]
xe sr-destroy uuid=[UUID for VM]

List, unplug, or destroy storage repository.

xe sr-list
xe sr-unplug uuid=[UUID for VM]
xe sr-destroy uuid=[UUID for VM]

List VM’s

xe vm-list

Shutdown VM

xe vm-shutdown uuid=[UUID for VM]

Force shutdown VM

xe vm-shutdown -–force uuid=[UUID for VM]

List Task

xe task-list

Cancel Task

xe task-cancel uuid=[task uuid]

External Links

http://www.queryadmin.com/801/useful-storage-repository-commands-xenserver/

https://www.serveroperations.net/citrix/shutdown-a-hung-vm-on-xenserver

https://linuxconfig.org/how-to-take-and-restore-vm-snapshot-using-command-line-on-xenserver

Recovering LibreNMS from crashed XenServer VM

Had a LibreNMS instance crash, or the VM crashed, not bootable anymore.  Was able to boot it up on a CentOS iso with rescue mode, which gave me access to the files.  So the idea is to manually copy off the LibreNMS files and LibreNMS database and import them to a new LibreNMS instance

Issues

  • Need to access the the system files
  • MySQL doesn’t start in a chroot environment, so no way to do a mysqldump —  (Has to do with systemv or something)

Steps

  1. Create new LibreNMS VM with a new instance of LibreNMS installed
  2. Gain access to the crashed system
  3. Copy over LibreNMS MySQL databases to new LibreNMS instance
  4. Copy over LibreNMS files “/opt/librenms” to new LibreNMS instance
  5. Clean up.  Set users on directories, check SELinux etc.

1. Installing New LibreNMS VM

  • Guide for Ubuntu/Debian distro’s here
  • Guide for for Fedora/CentOS/RedHat here

2. Gaining access to crashed VM

There can be a couple of ways to gain access to a crashed XenServer VM.  One of the easiest ways is to boot up in recovery mode and go through the installers rescue mode.  Guide to boot up XenServer VM in recovery mode here.

The installer rescue mode should detect the OS and mount everything.  If not you should be able to mount the root partition manually.

Once booted up, you’ll need to enable network access if your going to use sftp or scp to copy files.  There are a few different ways to do this

  • Run “dhclient” to pull an address via DHCP
  • Set a static IP address
    • Guide for Ubuntu/Debian distro’s here
    • Guide for fedora/CentOS/RedHat here

3.Copy LibreNMS Mysql Database

Backup the LibreNMS MySQL database directory

tar czvf librenms_mysql.tgz /var/lib/mysql

Use scp or sftp to copy it to the new LibreNMS instance

scp librenms_mysql.tgz user@new_LibreNMS_ip

Now on the new LibreNMS instance we need to run the following few commands

systemctl stop mariadb
rm -rf /var/lib/mysql/*
tar xzvf librenms_mysql.tgz -C /
chown -R mysql:mysql /var/lib/mysql

4. Copy LibreNMS directory

Backup the LibreNMS directory

tar czvf librenms.tgz /opt/librenms

Use scp or sftp to copy it to the new LibreNMS instance

scp librenms.tgz user@new_LibreNMS_ip

Now on the new LibreNMS instance we need to run the following few commands

rm -rf /opt/librenms/*
tar xzvf librenms.tgz -C /
chown -R librenms:librenms /opt/librenms

5. Clean up

Disable SELinux if you have not already.  Guide here

Restart apache, and start mysql.  If your on Ubuntu, the services are named apache2 and mysql

systemctl restart httpd
systemctl restart mariadb

That should get it working, if not try a reboot.

Special notes

The whole MySQL directory needs to be copied, there are innodb files that will keep MySQL from starting if they are not copied.

There is some good info here
https://stackoverflow.com/questions/1795176/how-to-change-mysql-data-directory

Setup SNMP on XenServer

log into the Xenserver via SSH, or get a console through XenCenter.

Open up the snmpd.conf file with your favorite text editor, nano, vi etc.

vi /etc/snmp/snmpd.conf

Find the line the following line

com2sec notConfigUser default public

and change the source “default” to the allowed IP ranges and the community “public” to whatever you want your new community string to be.

Example:

com2sec notConfigUser 192.168.1.0/24 privateString

Save, exit and start snmpd

service snmpd start

Add the following line in your iptables config.  It needs to be above the COMMIT line.

-A RH-Firewall-1-INPUT -s 0.0.0.0/0 -m udp -p udp --dport 161 -j ACCEPT

Restart iptables

service iptables restart

You should be good to go.

Increase hard disk size on Windows VM in XenServer

To increase a Windows VM disk size you’ll first need to shut down the VM and then increase the disk size from XenCenter.  When you boot back up into the VM, the extra space shows up as unallocated.  All that needs to be done is the main partition needs to be extended.

Open up the Windows Disk Management Utility.  You can do this by clicking on the start button, typing in disk management and hit enter.  This will bring up the Disk Management program.

In disk manager, you should see the Unallocated space at the end of Disk 0, i.e. your main drive.  Right click on your main partition (C:) and click Extend Volume.  You will be presented with a wizard that will walk you through extending your disk.

Example:

Before increasing the VM’s disk size.

0

The unallocated space is the extra space that we added via XenCenter.  Right click on the middle partition (C:), and click extend.

1

After were are finished extending the partition, we see that our main partition is about 8GB larger.

3