Solve Problems Related to disordering of disks in CentOS

Source: Internet
Author: User
Tags symlink

Solve Problems Related to disordering of disks in CentOS

When using linux, you must have encountered disk disorder. In general, there are several possible causes of disk disorder. For example, if a disk is connected to a server through a RAID card and the RAID card has no battery, the disk may be out of order if the server loses power. Another example is the new server, but the raid driver is a relatively old version. Once it is restarted, there is often a possibility of disorder. In addition, if there are many server disks and sata/ssd instances are mixed, there may be disorder.

How should we solve this sort of disorder? Here I have summarized a better ending method. The following script uses udevinfo (centos5) or udevadm (centos6) to obtain the device Number of the disk. The device number will not change with the restart of the server. After obtaining this device number, the corresponding device that is activated with slot0 is generated under/dev/, for example, 5 disks generate 5 devices such as slot0-4. At this time, when mounting again, use these slots to mount them. The script is as follows:

#! /Bin/bash

# Set-x

Function get_release ()

{

While read I

Do

Release = 'echo "$ I" | grep "release" | awk '{print $3 ;}''

Main_version =$ {release: 0: 1}

If [! -Z $ main_version]

Then

Echo $ main_version

Return 0

Fi

Done <"/etc/redhat-release"

Return 1

}

Function get_id_serial ()

{

Device = $1;

If [-z "$ device"]

Then

Return-1

Fi

Device = 'basename $ device'

Main_version = 'get _ release'

If [$? -Ne 0]

Then

Echo "get centos release versionerror" 1> & 2

Return $?

Fi

Case $ main_version in

"5") cmd = "/usr/bin/udevinfo-q all-n $ device ";;

"6") cmd = "/sbin/udevadminfo -- query = all -- name = $ device ";;

Esac

ID_SERIAL = $ ($ cmd | grep "ID_SERIAL =" | awk-F' = ''{print $2 ;}')

If [-z $ ID_SERIAL]

Then

Return 1

Fi

Echo-n "$ ID_SERIAL"

Return 0

}

Diskctl_config = "/etc/udev/rules. d/99-hd.rules"

Rm-rf $ diskctl_config

Diskctl_db = "/usr/diskctl. db"

Rm-rf $ diskctl_db

Mkdir-p/usr/diskctl

Touch $ diskctl_db

Index = 0

For I in/dev/sd * [a-z]

Do

Device = 'basename $ I'

ID_SERIAL = 'get _ id_serial $ I'

If [$? -Ne 0]

Then

Echo "FATAL: get ID_SERIAL error" 1> & 2

Exit 1

Fi

Slot = 'printf "slot % 02d" $ Index'

Echo "KERNEL = \" sd * [a-z] \ ", ACTION = \" add \ ", ENV {ID_SERIAL }==\" $ ID_SERIAL \", SYMLINK + = \ "$ slot \" "> $ diskctl_config

Echo "KERNEL = \" sd * [0-9] \ ", ACTION = \" add \ ", ENV {ID_SERIAL }==\" $ ID_SERIAL \", SYMLINK + = \ "$ slot-part % n \" "> $ diskctl_config

Echo "KERNEL = \" sd * [a-z] \ ", ACTION = \" remove \ ", ENV {ID_SERIAL }==\" $ ID_SERIAL \", RUN + = \ "/bin/rm-f/dev/$ slot-part * \" "> $ diskctl_config

Echo "# split $ ID_SERIAL ###############################" >>$ diskctl_config

ID_SN = 'smartctl-I $ I 2>/dev/null | grep "Serial \ s * number"-I | awk '{print $3 ;}''

If [-z "$ ID_SN"]

Then

ID_SN = "error"

Fi

Echo "$ slot $ ID_SERIAL $ ID_SN"> $ diskctl_db

(Index = index + 1 ))

Done

/Sbin/udevcontrolreload_rules

/Sbin/start_udev

Mount the file in/etc/fstab in a similar way as follows:

/Dev/slot02/data02ext4 defaults 0 0

/Dev/slot03/data03ext4 defaults 0 0

/Dev/slot04/data04ext4 defaults 0 0

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.