2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2024-11-21 09:02:00 +00:00
10 determine_install_disk
xuweibj edited this page 2016-03-10 09:47:32 +08:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#Mini-design for determining proper install disk

##Background

For RedHat/Ubuntu/Sles/PowerKVM, the method to choose installation disk are different, but with similar logic. It is inconvenient for maintenance.

The current logic also contain a potential issue that it may choose different installation disk when reinstalling which will cause multiple OS be installed on the sever.

In the purpose of making maintenance easier and resolving the potential issue, a new single getinstdisk script is needed for all of those 4 OS.

##The current method

###For RedHat and Sles

  1. check /dev/vd*

check disk driver with “edd_id”, if the driver of the disk named as “int13_dev80”, the disk will be treat as install_disk and end checking.

If No install_disk get, go to step 2.

  1. check /dev/sd*

For each disk

  1. check disk driver with “edd_id”, if the driver of the disk named as “int13_dev80”, the disk will be treat as install_disk and end checking.

  2. if checking disk driver with “edd_id” failed, use “udevadm” to check the device driver, and then classify the drivers into 3 types and record the disk.

type1: "ata_piix4","PMC MaxRAID”,”ahci”,"megaraid_sas".

type2: “mptsas”,”mpt2sas”,"mpt3sas".

type3: others.

If No install_disk get, go to step 3.

  1. If the first disk with driver type1 exist, it will be treat as install_disk.

    Else, if the first disk with driver type2 exists, it will be treat as install_disk.

    Else, if the first disk with driver type3 exists, it will be treat as install_disk.

  2. If the install_disk still can not be found, the install_disk will be “/dev/sda”

The problems are:

  1. There is no edd_id command in RH7.x and Sles 12.x

  2. The disk name /dev/sd* may change, the current logic may return another hard disk when reinstalling.

###For PowerKVM

  1. check disks in /proc/partitions

Use “udevadm info” to check disk attributes, get DEVTYPE and ID_WWN attributes. For the disks with DEVTYPE equal “disk”, the disk with biggest ID_WWN will be choose as the install_disk.

If No install_disk found, go to step 2.

  1. check /dev/sd*

For each disk

use “udevadm info —attribute-walk” to check the disk drivers. The same logic as section 2 of step2 in Redhat and Sles prescript.

  1. The same with step3 in Redhat and Sles prescript.

  2. The same with step4 in Redhat and Sles prescript.

The problems are:

  1. If there is OS installed before, it may choose another disk to install OS which may cause multiple OS installed on the server.

  2. More steps are same with the script for Redhat and Sles.

###For Ubuntu

  1. check partitions that list by “list-devices partition”

For each partition, try to mount it and then check whether there is kernel file in the partition.

For the first partition have kernel file, choose its hard disk as the install_disk.

If No install_disk found, go to step 2.

  1. check disks list by list-devices disk

For each disk, use udevadm info —attribute-walk to check the disk drivers. The same logic as section 2 of step2 in Redhat and Sles prescript.

For disks with driver type 1("ata_piix4","PMC MaxRAID”,”ahci”,"megaraid_sas") and type2 ("mptsas”,”mpt2sas”,"mpt3sas"), collect their DEVPATH attribute with command udevadm info. At last, get the first disk (sort by number with DEVPATH) as the install_disk.

  1. If still No install_disk get, choose /dev/sda

The problems are:

  1. The mount command will fail if no filesystem type specified for xfs(used by RH), which mean the step1 doesnt work if there is RH/Sles have been installed before.
  2. Sort disk with DEVPATH will fail if the disk is put to another slot.

##The final solution

Based on the analysis above and the fact that each physical disk must have an unique WWN or PATH(for more info about WWN, pls reference https://en.wikipedia.org/wiki/World_Wide_Name), the new solution are like this:

  1. Check all partitions list in /proc/partitions(All information of /proc/partitions will show in log)

For each partition("Check the partition ***." will show in log)

1.1. Get its disk(move the num in the partition name out) and check whether the disk file(/tmp/xcat.getinstalldisk/$disk)exists. If exists, it means the disk must had OS installed, go to next partition("The disk *** had OS installed, check next partition." will show in log).

1.2. If the disk file (/tmp/xcat.getinstalldisk/$disk) of the partition doest exist:

1.2.1. Use *udevadm info --query=property —name=/dev/<The partition name> | grep -i ID_FS_TYPE* to check its filesystem type and then mount it to check whether there is kernel file in this partition.

1.2.2. If the partition have kernel file, write the disk file(/tmp/xcat.getinstalldisk/$disk). Add disk name into disk_array("The partition *** has kernel file." will show in log).

If there is disk_array, set disks as disk_array("The disks which have kernel: ***" will show in log). Else, get disks list in /proc/partitions.

  1. Check disks get last step

For each disk

2.1. Use udevadm info $disk| grep -i ID_WWN to check whether it have WWN. Use udevadm info $disk | grep -i DEVPATH to check whether it have PATH. Use udevadm info --attribute-walk --name /dev/$disk |grep DRIVERS|grep -v '""'|grep -v '"sd"' to get the disk driver.("The disk *** information: disk_wwn=*** disk_path=*** disk_driver=***" will show in log)

2.2. If has WWN information, the variable prefix as "wwn", has_wwn as 1, and disk_data as WWN information, go to 2.4. If not, check variable has_wwn. If it is 1, check next disk("The disk *** has no wwn info. There is other disk has wwn info, so don't record this disk.").

2.3. If has_wwn is 0, check whether it have PATH information. If has, set the variable prefix as "path", has_path as 1, and disk_data as PATH information, go to 2.4. If not, check variable has_path. If it is 1, check next disk("The disk *** has no wwn or path info. There is other disk has path info, so don't record this disk."). If it is 0, set prefix as "other" and disk_data as empty.

2.4. Classify disks based on disk driver into 3 types:

**type1: "ata_piix*", "PMC MaxRAID”, ”ahci”, "megaraid_sas"** For the disk whose driver belong to type1, the disk name and disk_data will be write into /tmp/xcat.getinstalldisk/prefix_class1.("Add disk: *** (disk_name) *** (disk_data) into *** (prefix) firstchoicedisks" will show in log) 

**type2: “mptsas”, ”mpt2sas”, "mpt3sas"** For the disk whose driver belong to type2, the disk name and disk_data will be write into /tmp/xcat.getinstalldisk/prefix_class2.("Add disk: *** (disk_name) *** (disk_data) into *** (prefix) secondchoicedisks" will show in log) 

**type3: others** For the disk whose driver belong to type3, the disk name and disk_data will be write into /tmp/xcat.getinstalldisk/prefix_class3.("Add disk: *** (disk_name) *** (disk_data) into *** (prefix) thirdchoicedisks" will show in log) 

After disks checking, check the files wrote in the step above.

If file /tmp/xcat.getinstalldisk/prefix_class1 exists, sort it and choose the disk with smallest disk_data as the install_disk.

Else, if file /tmp/xcat.getinstalldisk/prefix_class2 exists, sort it and choose the disk with smallest disk_data as the install_disk.

Else, if file /tmp/xcat.getinstalldisk/prefix_class3 exists, sort it and choose the disk with smallest disk_data as the install_disk.

("The install_disk is *** by sorting *** and DRIVER." will show in log.)

  1. If still no install_disk found, choose “/dev/sda” ("The default install_disk is ***." will show in log)

  2. Write install_disk into /tmp/install_disk in order to be used for the following scripts.