记录日常工作关于系统运维,虚拟化云计算,数据库,网络安全等各方面问题。

How to Reinstall XenServer and Preserve Virtual Machines on a Local Disk

Document ID: CTX120962    /   Created On: 2009-6-2    /   Updated On: 2010-2-4
Average Rating: 5 (2 ratings)

Summary

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

Requirements

• Basic XenServer knowledge

• Basic LVM knowledge

• XenServer host (4.1 or 5.0) with two local hard drives

Background

Sometimes, reinstallation of XenServer is required to obtain a clean system state or to recover from a serious failure (such as database file corruption), where Virtual Machines (VMs) residing on local storage must be preserved and recovered within a reasonable amount of time.

Procedure

To achieve the above goal, perform the following steps:

1. If possible, collect VM metadata with the command below and store it offline (such as on a USB drive). This step requires a working XAPI stack.
xe vm-export metadata=true --multiple filename=VMEXPORT


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

2. Using the XenServer installation media, reboot the host and launch the XenServer installer.

3. Choose Install or upgrade XenServer host as shown on the screen shot below:


You are prompted to either perform a clean reinstall or refresh the existing installation.

4. Choose the clean reinstall option.
Proceed to the point where the installer asks which drive to use for Dom0 installation.


See the Note on XenServer hosts with one hard disk (HDD) section in the end of this article.

5. Select the drive to use for Dom0 installation (usually the first detected physical HDD) and press Ok to proceed.

6. 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 in the Note on XenServer hosts with one hard disk (HDD) section.


Press Ok to proceed.

7. Press Continue to ignore the warning advising that no VM storage has been chosen – this is expected behavior.


8. Follow the rest of the installation process.

9. Once reinstalled, log on to the host using an SSH client (such as PuTTY). You can perform the following commands from XenCenter, however, given the console constraints, the output might be difficult to read compared to an SSH client.

10. Restore the Physical Volume (PV) (introduce Storage Repository [SR]) using the commands below.

      a. Using the pvscan command, identify the Volume Group (VG) name on the local drive (/dev/sda3).

    Example:
    # 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 ]

Note 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 Universally Unique Identifier (UUID) that resides on this storage media. In this case, the UUID is 39baf126-a535-549f-58d6-feeda55f7801.

      b. 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”.

      c. 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 XenServer host and the SR) is created.

      d. Create a PBD (see above) for the SR. Start with xe host-list command to find 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

      e. 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

      f. Attach the PBD created with xe pbd-plug command:
      # 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.

11. To restore VM to VDI mappings (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

How to restore the mappings using VM metadata backup

1. 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>

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

3. In the event of missing VM metadata backup information, the following procedure may be performed to restore VMs and disk mappings.
One procedure restores VMs using available templates. The Example below shows a real life situation with GUI screen shots. Create a VM using a template (deselect Start VM automatically - it is unnecessary), then delete default drives in the VM’s Storage tab. The result is an empty VM with no storage attached.

Example:

          a. Two Debian Linux VMs were created on a XenServer host. The host was subsequently reinstalled, preserving the local storage. After reintroduced the local storage, four VDIs are available: two 4GB and two 512MB. A root and a swap partition are used per VM.

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

Note for XenServer hosts with one hard disk (HDD)

The above procedures works on XenServer hosts with one local hard drive. The system automatically assumes /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.

An alternative to the above procedure is to delete the XenServer internal database and recreate it.

1. Delete the Xenserver database:
# rm /var/xapi/state.db

2. Restart XAPI service – this will recreate a new XenServer database. Bear in mind that this database does not contain any storage/network/VM related data and that everything must be restored manually:
# xe-toolstack-restart

3. Follow the procedure above from step 11.

4. Proceed using the VM template restore procedure.

5. Restore the DVD drive with the following command:
# xe sr-create host-uuid=<uuid> content-type=iso name-label=”DVD drives” type=udev device-config:location=/dev/xapi/cd

6. Restore removable storage with the following command:
# xe sr-create host-uuid=<uuid> content-type=disk name-label=”Removable storage” type=udev device-config:location=/dev/xapi/block




转载请标明出处【How to Reinstall XenServer and Preserve Virtual Machines on a Local Disk】。

《www.micoder.cc》 虚拟化云计算,系统运维,安全技术服务.

网站已经关闭评论