cClaude.rocks ☕ Le blog

L'informatique et les nouvelles technologies

Menu

J’ai dernièrement fait appel au support QNAP qui comme toujours est très attentif aux demandes de ces clients, mais comme souvent ne me donne pas réellement de réponse complètement satisfaisante.

Pour permettre l’identification précise de mon problème j’ai du lors donner accès à mon NAS, SIC ! Avoir une seconde solution de sauvegarde préconisé par tous les fabricants de NAS est indispensable également pour ce cas de figure.

Voici quelques utilitaires qu’ils ont installés et ainsi les procédures d’installation.

Premier petit outil de diagnostique

curl https://download.qnap.com/Storage/tsd/utility/cleanme.sh | sh

Ce premier script permet de télécharger un petit outil de nettoyage, voici son contenu :

#!/bin/sh
#
# cleanme.sh
#

case "$(uname -m)" in
  *x86_64*)
    arch=x64
    ;;
  *aarch*)
    arch=arm64
    ;;
  *armv7*)
    arch=armv7
    ;;
  *armv5*)
    arch=armv5
    ;;
  *i*86*)
    arch=x86
    ;;
  *)
    echo "not supported"
    exit 1
    ;;
esac

bin="clean.$arch"
ts=$(date +%s)
wget -nv -O "$bin" "https://download.qnap.com/Storage/tsd/utility/clean/${bin}?t=${ts}"
chmod +x "./$bin" && "./$bin"

Installation du second outil

wget http://download.qnap.com/Storage/tsd/utility/qck
chmod +x qck
./qck all

Contenu de ce second script :

#!/bin/sh

##############################
#   QNAP checker             #
#   Version 0.2              #
#   Daniel Orme 01-06-2015   #
#   Qnap Systems, Inc.       #
##############################

rd='\033[0;91m'
rdB='\033[1;91m'
gr='\033[0;32m'
yl='\033[0;33m'
bl='\033[0;94m'
nc='\033[0m' # No Color
tab='\t'

CONFIG='/mnt/HDA_ROOT/.config'
DEF_CONFIG='/etc/default_config'
CONF='/mnt/HDA_ROOT/.conf'

#====================
function status () {
#====================

#==== FW STATUS ====#
echo
domModel=`/sbin/getcfg "System" "Model" -f /etc/default_config/uLinux.conf -d "???"`
halModel=`/sbin/getcfg "Enclosure_0" "model" -f /etc/hal.conf`

echo -e NAS type: $tab $domModel

if [ -e /sbin/storage_util ]; then
    fwType="${bl}HAL${nc}"
    echo -e HAL model: $tab $halModel
else
    fwType="${yl}Legacy${nc}"
fi

echo -e FW type: $tab $fwType

domVersion=`/sbin/getcfg "System" "Version" -f /etc/default_config/uLinux.conf -d "???"`
domBuild=`/sbin/getcfg "System" "Build Number" -f /etc/default_config/uLinux.conf -d "???"`
echo -e FW version: $tab $domVersion
echo -e FW build: $tab $domBuild


#==== MD9 STATUS ====#
if grep md9 /proc/mdstat &>/dev/null; then
    md9Online="${gr}yes${nc}"
else
    md9Online="${rd}no${nc}"
fi

echo -e md9 online: $tab $md9Online

if df /dev/md9 &>/dev/null; then
    md9Mount="${gr}yes${nc}"
    md9=1
else
    md9Mount="${rd}no${nc}"
    md9=0
fi

echo -e md9 mounted: $tab $md9Mount


[ ${md9} -eq 1 ] && echo md9 initialised: `dumpe2fs -h /dev/md9 2>/dev/null | awk '/created/ {print $4, $5, $6, $7}'`
#==== MD13 STATUS ====#
if grep md13 /proc/mdstat &>/dev/null; then
        md13Online="${gr}yes${nc}"
else
        md13Online="${rd}no${nc}"
fi

echo -e md13 online: $tab $md13Online

if df /dev/md13 &>/dev/null; then
        md13Mount="${gr}yes${nc}"
    md13=1
elif df /dev/sda4 &>/dev/null; then
    md13Mount="${gr}yes${nc} (sda4)"
    md13=1
else
        md13Mount="${rd}no${nc}"
    md13=0
fi

echo -e md13 mounted: $tab $md13Mount

}

#==================
function conf () {
#==================
echo
if ! df /dev/md9 &>/dev/null; then
    echo md9 not mounted, unable to check config!
    return 9
fi

domModel=`/sbin/getcfg "System" "Model" -f /etc/default_config/uLinux.conf -d "???"`
halModel=`/sbin/getcfg "Enclosure_0" "model" -f /etc/hal.conf`
domVersion=`/sbin/getcfg "System" "Version" -f /etc/default_config/uLinux.conf -d "???"`
domBuild=`/sbin/getcfg "System" "Build Number" -f /etc/default_config/uLinux.conf -d "???"`

#==== check /mnt/HDA_ROOT/ vital files ====#

uLinux=`head -1 ${CONFIG}/uLinux.conf 2>/dev/null`
[ ${uLinux} == "[System]" ] && uLinux="${gr}ok${nc}" || uLinux="${rd}damage${nc}"
echo -e uLinux.conf: $tab $uLinux

md9Version=`/sbin/getcfg "System" "Version" -f /mnt/HDA_ROOT/.config/uLinux.conf -d "???"`
md9Build=`/sbin/getcfg "System" "Build Number" -f /mnt/HDA_ROOT/.config/uLinux.conf -d "???"`
md9Model=`/sbin/getcfg "System" "Model" -f /mnt/HDA_ROOT/.config/uLinux.conf -d "???"`
[ ${md9Version} != ${domVersion} -o ${md9Build} != ${domBuild} ] && echo -e ${rd}WARNING${nc}: uLinux version on md9 mismatched!
[ ${md9Model} != ${domModel} ] && echo -e ${rd}WARNING${nc}: uLinux model on md9 mismatched!

smbConf=`head -1 ${CONFIG}/smb.conf 2>/dev/null`
[ ${smbConf} == "[global]" ] && smbConf="${gr}ok${nc}" || smbConf="${rd}damage${nc}"
echo -e smb.conf: $tab $smbConf

cronConf=`head -1 ${CONFIG}/crontab 2>/dev/null | awk '{print $7}'`
[ ${cronConf} = "cmd" ] && cronConf="${gr}ok${nc}" || cronConf="${rd}damage${nc}"
echo -e crontab: $tab $cronConf

[ -e ${CONFIG}/Model_Name.conf ] && modelName="${gr}ok${nc}" || modelName="${rd}missing${nc}"
echo -e Model_Name: ${tab} ${modelName} \(`cat ${CONFIG}/Model_Name.conf`\)

[ -e ${CONFIG}/BOOT.conf ] && bootConf="${gr}ok${nc}" || bootConf="${rd}missing${nc}"
echo -e BOOT.conf: ${tab} ${bootConf} \(`cat ${CONFIG}/BOOT.conf`\)

}

#==================
function disk () {
#==================
echo
if [ -e /etc/hal.conf ]; then
    for ((k=0;k<16;k++)); do
        HDDs=`getcfg "Enclosure_${k}" "max_disk_num" -f /etc/hal.conf -d 0`
        if [ $HDDs != 0 ]; then
            printf  "%3s  %4s  %8s   %9s  %10s  %-20s \n" enc port device signature partitions model

            for((i=1;i<=HDDs;i++)); do
                sysName=`hal_app --pd_get_sys_name enc_id=${k},port_id=${i} || echo "   --   "`
                sysNm=`echo $sysName | cut -d '/' -f 3`
                sigQnap=`dd if=${sysName}4 bs=1c skip=402653184 count=4 2>/dev/null`
                sigFlex=`dd if=${sysName}4 bs=1c skip=469893184 count=4 2>/dev/null`
                [ "${sigQnap}" != "QNAP" ] && sigQnap="    "
                                [ "${sigFlex}" != "FLEX" ] && sigFlex="    "
                partCount=`parted -s ${sysName} print | awk '/primary/' | wc -l | tr -d ' ' | sed 's/0/--/'`
                diskModel=`cat /sys/block/${sysNm}/device/model 2>/dev/null`
                printf "%3s  %4s  %-9s  %4s %4s  %10s  %-20s \n" ${k} ${i} "${sysName}" "${sigQnap}" "${sigFlex}" ${partCount} "${diskModel}"
            done #i
        fi
    done #k
else
    HDDs=`getcfg "Storage" "Disk Drive Number" -f /etc/default_config/uLinux.conf -d 0`
    j=0
    printf  "%4s  %8s   %9s  %10s  %-20s \n" port device signature partitions model
    for n in {a..p}; do
        [ $j = ${HDDs} ] && break
        ((j++))
        [ -e /sys/block/sd${n} ] && sysName="/dev/sd${n}" || sysName="   --   "
        sysNm=`echo $sysName | cut -d '/' -f 3`
        sigQnap=`dd if=${sysName}4 bs=1c skip=402653184 count=4 2>/dev/null`
        sigFlex=`dd if=${sysName}4 bs=1c skip=469893184 count=4 2>/dev/null`
        [ -z $sigQnap ] && sigQnap="    "
        [ -z $sigFlex ] && sigFlex="    "
        partCount=`parted -s ${sysName} print | awk '/primary/' | wc -l | tr -d ' ' | sed 's/0/--/'`
        diskModel=`cat /sys/block/${sysNm}/device/model 2>/dev/null`
        printf "%4s  %-9s  %4s %4s  %10s  %-20s \n" ${j} "${sysName}" "${sigQnap}" "${sigFlex}" ${partCount} "${diskModel}"


    done #n
fi
}

#==================
function md_scan () {
#==================
echo
## md_list=`ls -1 /dev/md* | awk '!/md9|md13|md256/'`
md_list=`cat /proc/mdstat | awk '/md/ {print $1}' | awk '!/md9|md13|md256/'`

[ -z "${md_list}" ] && echo No active md device! && return
echo -e Device${tab}${tab}Status
echo -e -------${tab}${tab}------

for i in $md_list; do
        printf "$i\t\t"
        if pvdisplay /dev/${i} &>/dev/null; then echo LVM device \(`pvdisplay /dev/${i} | grep 'VG Name' | awk '{print $3}'`\)
    elif cryptsetup isLuks /dev/${i} &>/dev/null; then echo "Encrypted device"
        elif dumpe2fs_64 -h /dev/${i} &>/dev/null; then echo "Filesystem found!"
    elif dumpe2fs_64 -h -o superblock=32768 /dev/${i} &>/dev/null; then echo "Filesystem found (backup superblock 32768)!"
    else echo "Filesystem not found!"
    fi
done
}

#==================
function cachedev_scan () {
#==================
echo
cachedev_list=`ls -1 /dev/mapper/ | grep 'cachedev[1-9][0-9]\{0,1\}$'`

[ -z "${cachedev_list}" ] && echo No active cachedev device! && return
echo -e Device${tab}${tab}Status
echo -e -------${tab}${tab}------
for i in $cachedev_list; do
    printf "$i\t"
    if cryptsetup isLuks /dev/mapper/${i} &>/dev/null; then echo "Encrypted device"
    elif dumpe2fs_64 -h /dev/mapper/${i} &>/dev/null; then dumpe2fs_64 -h /dev/mapper/$i 2>/dev/null | grep name | cut -d ':' -f 2 | tr -d ' '
    elif dumpe2fs_64 -h -o superblock=32768 /dev/mapper/${i} &>/dev/null; then printf "[backup superblock 32768] "; dumpe2fs_64 -h -o superblock=32768 /dev/mapper/$i 2>/dev/null | grep name | cut -d ':' -f 2 | tr -d ' '
    else echo "Filesystem not found!"
    fi
done
}

#==================
function raid () {
#==================
echo
rm /tmp/noSuperblock 2>/dev/null
rm /tmp/md_uuid 2>/dev/null
echo Superblock information recorded at `date` > /mnt/HDA_ROOT/md_backup

## Record active data md device name and Online Disk ([UU_U]) status
/bin/cat /proc/mdstat | /bin/sed '/md/i \break' | /bin/tr '\n' ' ' | /bin/awk -v RS=break '/sd[a-z][a-z]*3/' | /bin/awk 'match ($0,/\[[U_]*\]|raid0|linear/) {print $1, substr($0,RSTART,RLENGTH)}' > /tmp/md_stat 2>/dev/null

## Record active data md device UUID
for q in `/bin/awk '{print $1}' /tmp/md_stat`; do
    mdadm -D /dev/$q 2>/dev/null | /bin/awk -v p=$q '/UUID/ {print p,$3}' >> /tmp/md_uuid
done

## Concatenate information into /tmp/md_online
## Format: md1 3e01bd32:31ce8a78:7e379936:6b216de2 [UUUUUU]
/bin/awk 'FNR==NR{a[$1]=$1 FS $2;next}{print a[$1],$2}' /tmp/md_uuid /tmp/md_stat > /tmp/md_online 2>/dev/null

## Checking all disk superblocks
HDDs=24

for((k=0;k<16;k++));do
    [ "$HDDs" == "" ] && HDDs=24

    echo "" > /tmp/RaidUUID
    echo "" > /tmp/mdinfo
    echo "" > /tmp/mdinfo_u

    if [ -e /etc/enclosure_$k.conf ]; then
    echo HAL firmware detected!
    echo Scanning Enclosure ${k} for RAID metadata...
        for((i=1;i<=$HDDs;i++));do
            PORTID=$(/bin/echo $(/bin/cat /etc/enclosure_$k.conf | /bin/grep port_id | /bin/sed -n "$i"p | /bin/cut -d "=" -f2))
            HDT=$(/bin/echo $(/bin/cat /etc/enclosure_$k.conf | /bin/grep pd_sys_name | /bin/sed -n "$i"p | /bin/cut -d "=" -f2))
            if [ -e $HDT ] && [ "$HDT" != "" ]; then
        mdadm -E ${HDT}3 >> /mnt/HDA_ROOT/md_backup 2> /dev/null
        if [ $? = 1 ]; then
            echo ${HDT}3 >> /tmp/noSuperblock
        else
            #kRaidUUID=`mdadm -E "$HDT"3 | /bin/awk '/Array UUID/ {print $4}'`
            kRaidUUID=`mdadm -E "$HDT"3 | /bin/grep 'UUID' | /bin/grep -v 'Device' | /bin/cut -d ':' -f '2-5' | /bin/tr -d ' '`
            kRaidLevel=`mdadm -E "$HDT"3 | /bin/awk '/Raid Level/ {print $4}'`
            kRaidDevices=`mdadm -E "$HDT"3 | /bin/awk '/Raid Devices/ {print $4}'`
            kRaidName=`mdadm -E "$HDT"3 | /bin/awk '/Name/ {print $3}'`
            if [ -z `echo $kRaidName` ]; then
                kRaidName=`mdadm -E "$HDT"3 | /bin/awk '/Preferred Minor/ {print $4}'`
            fi
            kRaidChunk=`mdadm -E "$HDT"3 | /bin/awk '/Chunk/ {print $4}'`
            if [ -z `echo $kRaidChunk` ]; then
                kRaidChunk="-"
            fi
            kRaidVersion=`mdadm -E "$HDT"3 | /bin/awk '/Version/ {print $3}'`
            kRaidCreation=`mdadm -E "$HDT"3 | /bin/awk '/Creation/ {print $5, $6, $7, $8}'`
            kDevName=$HDT"3"
            kDevNum=`mdadm -E "$HDT"3 | /bin/awk '/Role/ {print $6}'`
            if [ -z `echo $kDevNum` ]; then ## Handle 0.9 superblock
                kDevNum=`mdadm -E "$HDT"3 | /bin/awk '/this/ {print $5}'`
                if [ -z `echo $kDevNum` ]; then ## Handle 32-bit mdadm output
                    kDevNum=`mdadm -E "$HDT"3 | /bin/awk '/Slot/ {print $4}'`
                fi
            fi
            kRole=`mdadm -E "$HDT"3 | /bin/awk '/Role/ {print $4}'`
            if [ -z `echo $kRole` ]; then ## Handle 0.9 superblock
                kRole=`mdadm -E "$HDT"3 | /bin/awk '/this/ {print $6}'`
                if [ -z `echo $kRole` ]; then ## Handle 32-bit mdadm ouput
                    kRole="Active"
                fi
            fi
            mdadm -E "$HDT"3 | /bin/grep -q Recovery
            if [ $? = 0 ]; then
                kRole="Rebuild"
            fi

            #####                                    #####
            # Reminder: Still need to handle the rebuild/spare case for md version 0.90! #
            #####                                    #####

            kUpdateTime=`mdadm -E "$HDT"3 | /bin/awk '/Update/ {print $5, $6, $7, $8}'`
            kEvents=`mdadm -E "$HDT"3 | /bin/awk '/Events/ {print $3}'`
            kArrayState=`mdadm -E "$HDT"3 | /bin/awk '/Array State/ {print $4}'`
            if [ -z `echo $kArrayState` ]; then
                kArrayState=`mdadm -E "$HDT"3 | grep '^[ ]*[0-9]' | awk '{print $6}' | cut -c 1 | awk -v ORS= '{print}'`
            fi
            /bin/grep -q $kRaidUUID /tmp/RaidUUID
            if [ $? = 1 ]; then
                echo $kRaidUUID $kRaidLevel $kRaidDevices $kRaidName $kRaidChunk $kRaidVersion $kRaidCreation >> /tmp/RaidUUID
            fi
            echo $PORTID$'\t'$kRaidUUID$'\t'$kRaidLevel$'\t'$kRaidDevices$'\t'$kRaidName$'\t'$kRaidVersion$'\t'$kDevName$'\t'$kDevNum$'\t'$kRole$'\t'$'\t'$kUpdateTime$'\t'$kEvents$'\t'$kArrayState >> /tmp/mdinfo
        fi
            fi

        done
    #cat /tmp/mdinfo
    for RaidUUID in `/bin/cat /tmp/RaidUUID | /bin/awk '{print $1}'`;do
        echo
        echo RAID metadata found!
        echo UUID:$'\t'$'\t'$RaidUUID
        echo Level:$'\t'$'\t'`/bin/grep $RaidUUID /tmp/RaidUUID | /bin/awk '{print $2}'`
        echo Devices:$'\t'`/bin/grep $RaidUUID /tmp/RaidUUID | /bin/awk '{print $3}'`
        echo Name:$'\t'$'\t'md`/bin/grep $RaidUUID /tmp/RaidUUID | /bin/awk '{print $4}'`
        echo Chunk Size:$'\t'`/bin/grep $RaidUUID /tmp/RaidUUID | /bin/awk '{print $5}'`
        echo md Version:$'\t'`/bin/grep $RaidUUID /tmp/RaidUUID | /bin/awk '{print $6}'`
        echo Creation Time:$'\t'`/bin/grep $RaidUUID /tmp/RaidUUID | /bin/awk '{print $7, $8, $9, $10}'`
        /bin/grep -q $RaidUUID /tmp/md_online 2>/dev/null
        if [ $? = 0 ]; then
            /bin/grep $RaidUUID /tmp/md_online | /bin/awk '{print "Status:         \033[1;32mONLINE\033[1;0m (" $1 ")", $3}'
        else
            echo -e "Status:\t\t${rdB}OFFLINE${nc}"
        fi
        echo ===============================================================================
        echo " Disk | Device | # | Status |   Last Update Time   | Events | Array State"
        echo ===============================================================================
        grep $RaidUUID /tmp/mdinfo | grep -v spare | awk '{print $8, $1,$7,$8,$9,$10,$11,$12,$13,$14,$15}' | sort -n | cut -d ' ' -f 2-11 > /tmp/mdinfo_u

        n=`/bin/grep $RaidUUID /tmp/RaidUUID | /bin/awk '{print $3}'`  ## total RAID devices
                m=0  ## RAID device index
                dup_array=() ## duplicate device record
                while [ $m -lt $n ]; do
                        cat /tmp/mdinfo_u | awk '{print $3}' | grep -q $m
                        if [ $? = 0 ]; then
                                /bin/awk -v m=$m '$3==m' /tmp/mdinfo_u | /bin/awk \
                                '{ \
                                        if ($4=="Rebuild") printf "  %2s %10s %2s %8s %5s %2s %s %s %8s   %-24s \n", $1, $2, $3, " \033[0;93m" $4 "\033[0m", $5, $6, $7, $8, $9, $10; \
                                        else if ($4~"[Aa]ctive") printf "  %2s %10s %2s %7s %5s %2s %s %s %8s   %-24s \n", $1, $2, $3, "  \033[0;94m" $4 "\033[0m", $5, $6, $7, $8, $9, $10; \
                                        else printf "  %2s %10s %2s %8s %5s %2s %s %s %8s   %-24s \n", $1, $2, $3, $4, $5, $6, $7, $8, $9, $10; \
                                }'
                if [ `awk -v m=$m '$3==m' /tmp/mdinfo_u | wc -l` -gt 1 ]; then ## Record duplicate device
                                        dup_array+=($m)
                                fi
                                (( m+=1 ))
                        else
                                printf " -------------- %2i  "${rd}"Missing"${nc}"   -------------------------------------------\n" $m
                                (( m+=1 ))
                        fi
                done
                echo ===============================================================================
                if [[ -n ${dup_array[*]} ]]; then
                        echo -e ${rdB} WARNING${nc}: Duplicate device detected for \#\(${dup_array[*]}\)!
                fi
                echo
    done

    else
        if [ $k == 0 ]; then
        echo Legacy Firmware Detected!
        echo Scanning disks for RAID metadata...
            for((i=1;i<=$HDDs;i++));do
                HDT=sd$(/bin/echo abcdefghijklmnop | /bin/cut -c $i)
                if [ -e /sys/block/$HDT ]; then
            HDT=/dev/${HDT}
                    mdadm -E ${HDT}3 >> /mnt/HDA_ROOT/md_backup 2> /dev/null
                    if [ $? = 1 ]; then
                            echo ${HDT}3 >> /tmp/noSuperblock
                    else
            #kRaidUUID=`mdadm -E "$HDT"3 | /bin/awk '/Array UUID/ {print $4}'`
            kRaidUUID=`mdadm -E "$HDT"3 | /bin/grep 'UUID' | /bin/grep -v 'Device' | /bin/cut -d ':' -f '2-5' | /bin/tr -d ' '`
            kRaidLevel=`mdadm -E "$HDT"3 | /bin/awk '/Raid Level/ {print $4}'`
            kRaidDevices=`mdadm -E "$HDT"3 | /bin/awk '/Raid Devices/ {print $4}'`
            kRaidName=`mdadm -E "$HDT"3 | /bin/awk '/Name/ {print $3}'`
            if [ -z `echo $kRaidName` ]; then
                kRaidName=`mdadm -E "$HDT"3 | /bin/awk '/Preferred Minor/ {print $4}'`
            fi
            kRaidChunk=`mdadm -E "$HDT"3 | /bin/awk '/Chunk/ {print $4}'`
            if [ -z `echo $kRaidChunk` ]; then
                kRaidChunk="-"
            fi
            kRaidVersion=`mdadm -E "$HDT"3 | /bin/awk '/Version/ {print $3}'`
            kRaidCreation=`mdadm -E "$HDT"3 | /bin/awk '/Creation/ {print $5, $6, $7, $8}'`
            kDevName=$HDT"3"
            kDevNum=`mdadm -E "$HDT"3 | /bin/awk '/Role/ {print $6}'`
            if [ -z `echo $kDevNum` ]; then ## Handle 0.9 superblock
                kDevNum=`mdadm -E "$HDT"3 | /bin/awk '/this/ {print $5}'`
                if [ -z `echo $kDevNum` ]; then ## Handle 32-bit mdadm output
                    # kDevNum=`mdadm -E "$HDT"3 | /bin/awk '/Slot/ {print $4}'`
                    slot=`mdadm -E "$HDT"3 | awk '/Array Slot/ {print $4}'`
                    if [ $slot ]; then
                        slot_pos=$(( $slot + 1 ))
                            kDevNum=`mdadm -E "$HDT"3 | awk '/Array Slot/' | sed 's/.*(\(.*[0-9]\).*)/\1/' | cut -d ',' -f $slot_pos | tr -d ' '`
                    fi
                fi
            fi
            kRole=`mdadm -E "$HDT"3 | /bin/awk '/Role/ {print $4}'`
            if [ -z `echo $kRole` ]; then ## Handle 0.9 superblock
                kRole=`mdadm -E "$HDT"3 | /bin/awk '/this/ {print $6}'`
                if [ -z `echo $kRole` ]; then ## Handle 32-bit mdadm output
                    kRole="Active"
                fi
            fi
            mdadm -E "$HDT"3 | /bin/grep -q Recovery
            if [ $? = 0 ]; then
                kRole="Rebuild"
            fi

            #####                                    #####
            # Reminder: Still need to handle the rebuild/spare case for md version 0.90! #
            #####                                    #####

            kUpdateTime=`mdadm -E "$HDT"3 | /bin/awk '/Update/ {print $5, $6, $7, $8}'`
            kEvents=`mdadm -E "$HDT"3 | /bin/awk '/Events/ {print $3}'`
            kArrayState=`mdadm -E "$HDT"3 | /bin/awk '/Array State/ {print $4}'`
            if [ -z `echo $kArrayState` ]; then
                kArrayState=`mdadm -E "$HDT"3 | grep '^[ ]*[0-9]' | awk '{print $6}' | cut -c 1 | awk -v ORS= '{print}'`
            fi
            /bin/grep -q $kRaidUUID /tmp/RaidUUID
            if [ $? = 1 ]; then
                echo $kRaidUUID $kRaidLevel $kRaidDevices $kRaidName $kRaidChunk $kRaidVersion $kRaidCreation >> /tmp/RaidUUID
            fi
            echo $i$'\t'$kRaidUUID$'\t'$kRaidLevel$'\t'$kRaidDevices$'\t'$kRaidName$'\t'$kRaidVersion$'\t'$kDevName$'\t'$kDevNum$'\t'$kRole$'\t'$'\t'$kUpdateTime$'\t'$kEvents$'\t'$kArrayState >> /tmp/mdinfo
        fi
            fi

        done
    #cat /tmp/mdinfo
    for RaidUUID in `/bin/cat /tmp/RaidUUID | /bin/awk '{print $1}'`;do
        echo
        echo RAID metadata found!
        echo UUID:$'\t'$'\t'$RaidUUID
        echo Level:$'\t'$'\t'`/bin/grep $RaidUUID /tmp/RaidUUID | /bin/awk '{print $2}'`
        echo Devices:$'\t'`/bin/grep $RaidUUID /tmp/RaidUUID | /bin/awk '{print $3}'`
        echo Name:$'\t'$'\t'md`/bin/grep $RaidUUID /tmp/RaidUUID | /bin/awk '{print $4}'`
        echo Chunk Size:$'\t'`/bin/grep $RaidUUID /tmp/RaidUUID | /bin/awk '{print $5}'`
        echo md Version:$'\t'`/bin/grep $RaidUUID /tmp/RaidUUID | /bin/awk '{print $6}'`
        echo Creation Time:$'\t'`/bin/grep $RaidUUID /tmp/RaidUUID | /bin/awk '{print $7, $8, $9, $10}'`
        /bin/grep -q $RaidUUID /tmp/md_online 2>/dev/null
        if [ $? = 0 ]; then
            /bin/grep $RaidUUID /tmp/md_online | /bin/awk '{print "Status:         \033[1;32mONLINE\033[1;0m (" $1 ")", $3}'
        else
            echo -e "Status:\t\t${rdB}OFFLINE${nc}"
        fi
        echo ===============================================================================
        echo " Disk | Device | # | Status |   Last Update Time   | Events | Array State"
        echo ===============================================================================
        grep $RaidUUID /tmp/mdinfo | grep -v spare | awk '{print $8, $1,$7,$8,$9,$10,$11,$12,$13,$14,$15}' | sort -n | cut -d ' ' -f 2-11 > /tmp/mdinfo_u

        n=`/bin/grep $RaidUUID /tmp/RaidUUID | /bin/awk '{print $3}'`  ## total RAID devices
        m=0  ## RAID device index
        dup_array=() ## duplicate device record
        while [ $m -lt $n ]; do
            cat /tmp/mdinfo_u | awk '{print $3}' | grep -q $m
            if [ $? = 0 ]; then
                awk -v m=$m '$3==m' /tmp/mdinfo_u | awk \
                '{ \
                    if ($4=="Rebuild") printf "  %2s %10s %2s %8s %5s %2s %s %s %8s   %-24s \n", $1, $2, $3, " \033[0;93m" $4 "\033[0m", $5, $6, $7, $8, $9, $10; \
                    else if ($4~"[Aa]ctive") printf "  %2s %10s %2s %7s %5s %2s %s %s %8s   %-24s \n", $1, $2, $3, "  \033[0;94m" $4 "\033[0m", $5, $6, $7, $8, $9, $10; \
                    else printf "  %2s %10s %2s %8s %5s %2s %s %s %8s   %-24s \n", $1, $2, $3, $4, $5, $6, $7, $8, $9, $10; \
                }'
                if [ `awk -v m=$m '$3==m' /tmp/mdinfo_u | wc -l` -gt 1 ]; then ## Record duplicate device
                    dup_array+=($m)
                fi
                (( m+=1 ))
            else
                printf " -------------- %2i  "${rd}"Missing"${nc}"   -------------------------------------------\n" $m
                (( m+=1 ))
            fi
        done
        echo ===============================================================================
        if [[ -n ${dup_array[*]} ]]; then
            echo -e ${rdB} WARNING${nc}: Duplicate device detected for \#\(${dup_array[*]}\)!
        fi
        echo
    done


            break
        else
            k=16
        fi
    fi
done


}

#==========================
function restore_conf () {
#==========================

echo
if [ -e /etc/hal.conf ]; then
    echo "rebuilding .conf in HAL format..."
    ifconfig | awk '/eth0.*HWaddr/ {print "hw_addr="tolower($5)}' > /mnt/HDA_ROOT/.conf_restore
    echo "QNAP=TRUE" >> /mnt/HDA_ROOT/.conf_restore
    echo "mirror=0" >> /mnt/HDA_ROOT/.conf_restore
    echo "hal_support=yes" >> /mnt/HDA_ROOT/.conf_restore
    echo "sm_v2_support=yes" >> /mnt/HDA_ROOT/.conf_restore
    grep 'port_id\|wwn' /etc/enclosure_0.conf | tr -d ' ' | awk -v RS='port_id=' '/wwn/ {print $2, $1}' | sed 's/wwn=/pd_dev_wwn_/' | awk '{printf "%s=0x%x\n", $1, $2}' >> /mnt/HDA_ROOT/.conf_restore
else
    echo "rebuilding .conf in legacy format..."
    echo "QNAP = TRUE" > /mnt/HDA_ROOT/.conf_restore
    echo "hd_name = /dev/sda" >> /mnt/HDA_ROOT/.conf_restore
    echo "mirror = 1" >> /mnt/HDA_ROOT/.conf_restore
    j=1
    for n in {a..p}; do
        [ -e /sys/block/sd${n} ] && echo serial_no${j} = "`get_sn /dev/sd${n}`" >> /mnt/HDA_ROOT/.conf_restore
        ((j++))
    done
    ifconfig | awk '/eth0.*HWaddr/ {print "hw_addr = "tolower($5)}' >> /mnt/HDA_ROOT/.conf_restore
fi
echo "rebuilt .conf file to /mnt/HDA_ROOT/.conf_restore!"
}

#===========================
function write_sig_qnap() {
#===========================
echo
}

#===========================
function write_sig_flex() {
#===========================
echo
}

#===========================
function clear_sig_flex() {
#===========================
echo
}

case "$1" in
    stat) status
    ;;

    conf) conf
    ;;

    disk) disk
    ;;

    raid) raid
    ;;

    md) md_scan
    ;;

    cachedev) cachedev_scan
    ;;

    restore_conf) restore_conf
    ;;

    all) status; conf; disk; md_scan; cachedev_scan
    ;;

    *) echo "no argument supplied!"
    echo
    echo -e qck stat $tab Display basic system status
    echo -e qck conf $tab Check configuration files
    echo -e qck disk $tab Display disk information
    echo -e qck raid $tab RAID metadata report
    echo -e qck md $tab $tab md device list
    echo -e qck cachedev $tab cachedev list
    echo -e qck all $tab Combines stat conf disk md cachedev output
    echo
    echo -e qck restore_conf $tab Rebuild /mnt/HDA_ROOT/.conf file
    ;;
esac

echo

ᦿ


ℹ 2006 - 2020 | 🕸 Retour à l'accueil du domaine | 🏡 Retour à l'accueil du blog