How to reinstall a Xenserver host and preserve VMs on the local storage

SOP: How to reinstall a Xenserver

host and preserve VMs on the local



This document explains how to reinstall a Xenserver host and preserve VMs on the local storage.



Sometimes reinstallation of Xenserver is required in order to obtain a clean system state or to recover from a serious failure (e.g. database file corruption), where VMs residing on local storage need to be preserved and recovered within a reasonable amount of time.


Procedure or Steps

To achieve the above goal, perform the following steps:


1. If at all possible, collect VM metadata and store it offline (e.g. a USB drive). This step requires a working XAPI stack – i.e. that one can run xe commands.

xe vm-export metadata=true --multiple filename=VMEXPORT


This will create a set of files (VMEXPORT0 and so on) containing VM metadata. Having this metadata available speeds up VM recovery considerable as it creates the VM itself and restores the mappings between VMs and their disks (VDIs) – something that otherwise must be done manually.


2. Using Xenserver install media reboot the host and launch the Xenserver installer. First, choose “Install or upgrade Xenserver host” as shown on the image below:



You will be prompted to choose between performing a clean reinstall or freshening the existing installation. Choose the “clean reinstall” option.


Proceed to the point where the installer is asking which drive is to be used for Dom0 installation 1



See “Note on Xenserver hosts with 1 HDD” section in the end of this document.

3. Select the drive to be used for Dom0 installation (usually the first detected physical HDD). Press “Ok” to proceed.


4. The next step is to select the storage for virtual guests. It is important NOT to select any drives in this screen so that the installer skips those during drive/partition initialization and thereby preserves the data on those partitions,

as shown below 2:


Press “Ok” to proceed.



See “Note on Xenserver hosts with 1 HDD” section in the end of this document.


5. A warning will be displayed advising that no VM storage has been chosen. This is normal and can be ignored. Press “Continue”.


6. Follow the rest of the installation process as usual.


7. Once reinstalled, log in to the host using an SSH client (e.g. PuTTY). One can perform the following commands from Xencenter, however given the console constraints the output may be difficult to read as compared to an SSH client.


8. Restore PV (introduce SR) using the commands below.


First, using pvscan, identify the VG name on the local drive: (could also use pvdisplay to yield same info)


# pvscan

PV /dev/sda3 VG VG_XenStorage-39baf126-a535-549f-58d6-feeda55f7801 lvm2 [66.87 GB / 57.87 GB free]

Total: 1 [66.87 GB] / in use: 1 [66.87 GB] / in no VG: 0 [0 ]


As you can see from the output above, the VG name of the local drive /dev/sda3 is VG_XenStorage-39baf126-a535-549f-58d6-feeda55f7801 . The VG name contains the SR uuid that resides on this storage media. In this case, the uuid is 39baf126-a535-549f-58d6-feeda55f7801.


Next, re-introduce the SR using the uuid detected above:

# xe sr-introduce uuid=39baf126-a535-549f-58d6-feeda55f7801 type=lvm name-label=”Local storage” content-type=user

The command above sets up database records for the SR named “Local storage”.


Locate the SCSI Id of the device/partition where the SR data is stored:

# ls -l /dev/disk/by-id/

total 0

lrwxrwxrwx 1 root root 9 Jan 15 09:44 scsi-SATA_ST3500320AS_9QM13WP2 -> ../../sdb

lrwxrwxrwx 1 root root 10 Jan 15 09:44 scsi-SATA_ST3500320AS_9QM13WP2-part1 -> ../../sdb1

lrwxrwxrwx 1 root root 9 Jan 15 09:44 scsi-SATA_ST380815AS_6QZ5Z1AM -> ../../sda

lrwxrwxrwx 1 root root 10 Jan 15 09:44 scsi-SATA_ST380815AS_6QZ5Z1AM-part1 -> ../../sda1

lrwxrwxrwx 1 root root 10 Jan 15 09:44 scsi-SATA_ST380815AS_6QZ5Z1AM-part2 -> ../../sda2

lrwxrwxrwx 1 root root 10 Jan 15 09:44 scsi-SATA_ST380815AS_6QZ5Z1AM-part3 -> ../../sda3

In this case, the SCSI Id of the device /dev/sda3 is scsi-SATA_ST380815AS_6QZ5Z1AM-part3. This is the device name to be used in the next command where a PBD (physical block device – a connector between the XS host and the SR) is created.


Next, create a PBD (see above) for the SR. Start with finding out the host uuid for the local host:

# xe host-list

uuid ( RO) : 83f2c775-57fc-457b-9f98-2b9b0a7dbcb5

name-label ( RW): xenserver1

name-description ( RO): Default install of XenServer


Then, create the PBD using the device SCSI Id, host uuid and SR uuid detected above:

# xe pbd-create sr-uuid=39baf126-a535-549f-58d6-feeda55f7801 device-config:device=/dev/disk/by-id/scsi-

SATA_ST380815AS_6QZ5Z1AM-part3 host-uuid=83f2c775-57fc-457b-9f98-2b9b0a7dbcb5



# aec2c6fc-e1fb-0a27-2437-9862cffe213e


Attach the PBD:

# xe pbd-plug uuid=aec2c6fc-e1fb-0a27-2437-9862cffe213e

At this time, the SR should be connected to the Xenserver host and be visible in Xencenter.


9. To restore VM to VDI mappings (i.e. which VMs use which disks), two alternatives are available:

- importing VM metadata from backup copies

- restoring the mappings manually, if metadata backup is not available



This subsection describes how to restore the mappings using VM metadata backup.


Run the following command to reinstate the VM metadata (VM records, VCPU/RAM allocation, VDI mappings):

# xe vm-import metadata=true filename=<METADATA-BACKUP-FILE>

If a warning is shown about no default SRs, set your local SR to be the default one (in the GUI).


10. In the event of missing VM metadata backup information, the following procedure may be performed in order to restore VMs and disk mappings.


First, one will have to restore VMs using available templates. Examples below show a real life situation with GUI screenshots. Create a VM using a template (deselect “Start VM automatically” – this is unnecessary), then delete default drives in the VM’s “Storage” tab. This will result in an empty VM with no storage attached. Reattaching VDIs can be a problem in large installations where many VMs exist and may have multiple VDIs attached.


For example, two Windows 2003 VMs were created on a Xenserver host and then subsequently the host was reinstalled, preserving the local storage. Having reintroduced the local storage, 4 VDIs are available – 2x4Gb and 2x512Mb – a root and a swap partition per VM.



Use the GUI to create the VMs as described above and then attach available VDIs – see image below.





Note for Xenserver hosts with 1 HDD

The above procedures will not work on Xenserver hosts with 1 local hard drive only as the system will automatically assume /dev/sda (on HP systems /dev/cciss/c0d0p0) as the Dom0 partition and /dev/sda3 (on HP systems /dev/cciss/c0d0p3) as the VM storage partition and will not display the VM storage selection dialogue at all, rendering the

above procedure impossible.


In order to circumvent this, one has to delete the Xenserver internal database and recreate it from the beginning, using the procedure above starting from point 8.


Delete the Xenserver database:

# rm /var/xapi/state.db


Restart XAPI service – this will recreate a new Xenserver database. Bear in mind that this data base will not contain any storage/network/VM related data and that everything will have to be restored manually:

# xe-toolstack-restart

Follow the procedure above from point 8.


This document applies to:

Xenserver 4.1

Xenserver 5.0