Depois de cavar um pouco mais, encontrei várias informações do sistema em /proc
disponíveis para
visualizando quando a seção %pre
em ks.cfg
é executada. Faça o check-in do dmidecode e dos arquivos em / proc para obter todas as informações de que você precisa. Aqui está o que funcionou para mim:
%pre --log=/tmp/ks_pre.log
#!/bin/sh
#----------------------------------------------
# echos message to console screen and a log file
#----------------------------------------------
echo_screen_n_log() {
msg=$1
# Send to console screen
(echo "$msg") >/dev/tty1
# Send to log
echo "$msg"
}
echo_screen_n_log ""
echo_screen_n_log "Analyzing Hardware..."
echo_screen_n_log ""
#----------------------------------------------
# System Memory
#----------------------------------------------
IFS=$'\n'
mem_info=('dmidecode --type memory')
unset IFS
sys_mem_sizes=""
sys_mem_banks=""
sys_tot_mem=0
cntr=0
bank_cntr=0
for i in "${mem_info[@]}"
do
# echo_screen_n_log "i: $i"
# Maximum system memory that can be placed on the motherboard
REG_EX="Maximum Capacity: (.*)$"
if [[ $i =~ $REG_EX ]]
then
sys_mem_max=${BASH_REMATCH[1]}
fi
# How many memory slots are on the motherboard
REG_EX="Number Of Devices: (.*)$"
if [[ $i =~ $REG_EX ]]
then
sys_mem_slots=${BASH_REMATCH[1]}
fi
REG_EX="^[[:space:]]+Size: (.*)$"
if [[ $i =~ $REG_EX ]]
then
sys_mem_sizes[cntr]=${BASH_REMATCH[1]}
cntr=$(( $cntr + 1 ))
fi
REG_EX="^[[:space:]]+Bank Locator: (.*)$"
if [[ $i =~ $REG_EX ]]
then
sys_mem_banks[bank_cntr]=${BASH_REMATCH[1]}
bank_cntr=$(( $bank_cntr + 1 ))
fi
done
cntr=$(( $cntr - 1 ))
echo_screen_n_log "Max system memory: $sys_mem_max"
echo_screen_n_log "Total system slots: $sys_mem_slots"
i=0
while [ $i -le $cntr ]
do
echo_screen_n_log "Memory Bank Location ${sys_mem_banks[$i]} : ${sys_mem_sizes[$i]}"
REG_EX="No Module Installed$"
if [[ ! ${sys_mem_sizes[$i]} =~ $REG_EX ]]
then
REG_EX="^([0-9]+) [A-Z][A-Z]$"
if [[ ${sys_mem_sizes[$i]} =~ $REG_EX ]]
then
sys_tot_mem=$(( $sys_tot_mem + ${BASH_REMATCH[1]} ))
fi
fi
i=$(( $i + 1 ))
done
echo_screen_n_log "System Total Memory: $sys_tot_mem MB"
#--------------------------------------------
# Get Disk size information
#--------------------------------------------
IFS=$'\n'
disk_info=('cat /proc/partitions')
unset IFS
total_disk_space=0
type=""
# Grab from minor column starting with 0 ending in 3 letters (drive node)
REG_EX="0\s+([0-9]+) [a-z][a-z][a-z]$"
for i in "${disk_info[@]}"
do
# echo_screen_n_log "i: $i"
if [[ $i =~ $REG_EX ]]
then
total_disk_space=${BASH_REMATCH[1]}
total_disk_space=$(( $total_disk_space * 1024 ))
type="GB"
div_num=1000000000
if [ "$total_disk_space" -lt $div_num ]
then
type="MB"
div_num=1000000
fi
total_disk_space=$(( $total_disk_space / $div_num ))
fi
done
echo_screen_n_log "Disk Space: $total_disk_space $type"
#-----------------------------------------------------
# Get CPU model name
#-----------------------------------------------------
cpu_grep='grep 'model name' /proc/cpuinfo'
cpu_model_nm="Not Found!"
REG_EX="^.*: (.*)$"
if [[ $cpu_grep =~ $REG_EX ]]
then
cpu_model_nm=${BASH_REMATCH[1]}
fi
echo_screen_n_log "CPU Model: $cpu_model_nm"
#-------------------------------------------------------
# Get number of physical CPUs
#-------------------------------------------------------
IFS=$'\n'
cpu_count=('grep "physical id" /proc/cpuinfo')
unset IFS
last_cpu_id=""
total_cpu_cnt=0
# Add up all cores of the CPU to get total MIPS
total_cpus=0
REG_EX="^physical id\s+: ([0-9]+)$"
for i in "${cpu_count[@]}"
do
# echo_screen_n_log "i: $i"
if [[ $i =~ $REG_EX ]]
then
cpu_id=${BASH_REMATCH[1]}
if [ ! "$last_cpu_id" = "$cpu_id" ]
then
total_cpu_cnt=$(( $total_cpu_cnt + 1 ))
last_cpu_id=$cpu_id
fi
fi
done
echo_screen_n_log "System physical CPUs: $total_cpu_cnt"
#-------------------------------------------------------
# Get number of CPU cores
#-------------------------------------------------------
IFS=$'\n'
cpu_cores=('grep -m 1 "cpu cores" /proc/cpuinfo')
unset IFS
total_cpu_cores=0
REG_EX="^cpu cores\s+: ([0-9]+)$"
for i in "${cpu_cores[@]}"
do
# echo_screen_n_log "i: $i"
if [[ $i =~ $REG_EX ]]
then
total_cpu_cores=${BASH_REMATCH[1]}
fi
done
echo_screen_n_log "CPU cores: $total_cpu_cores"
#-------------------------------------------------------
# CPU MHz
#-------------------------------------------------------
IFS=$'\n'
dmi_cpu_MHz=('dmidecode --string processor-frequency')
unset IFS
cpu_MHz=0
REG_EX="^[0-9]+ "
for i in "${dmi_cpu_MHz[@]}"
do
# echo_screen_n_log "i: $i"
if [[ $i =~ $REG_EX ]]
then
cpu_MHz=${BASH_REMATCH[1]}
fi
done
echo_screen_n_log "CPU MHz: ${dmi_cpu_MHz:0:1}.${dmi_cpu_MHz:1:$(( ${#dmi_cpu_MHz} - 1 ))}"
#-------------------------------------------------------
# Get CPU bogomips (Millions of instructions per second)
#-------------------------------------------------------
IFS=$'\n'
cpu_mips=('grep "bogomips" /proc/cpuinfo')
unset IFS
# Add up all cores of the CPU to get total MIPS
total_mips=0
REG_EX="\s([0-9]+)\..*$"
for i in "${cpu_mips[@]}"
do
# echo_screen_n_log "i: $i"
if [[ $i =~ $REG_EX ]]
then
cpu_bogomips=${BASH_REMATCH[1]}
total_mips=$(( $total_mips + $cpu_bogomips ))
fi
done
echo_screen_n_log "Total CPU MIPS (Millions of instructions per second) : $total_mips"
echo_screen_n_log ""
(echo -n "Press <enter> to continue..") >/dev/tty1
read text
%end
Eu só preciso adicionar os critérios para determinar como deve ser um sistema básico para as nossas instalações e estou pronto .....
Atualize isso com mais informações ... Você também pode fazer o seguinte para informações de disco na seção% pre:
IFS=$'\n'
parted_txt=('parted -l')
unset IFS
for i in "${parted_txt[@]}"
do
# (echo "i: \"$i\"") >/dev/tty1
REG_EX="^Model: (.*)$"
if [[ $i =~ $REG_EX ]]
then
disk_model=${BASH_REMATCH[1]}
# (echo "Disk Model: \"$disk_model\"") >/dev/tty1
fi
REG_EX="^Disk (.*): ([0-9]+).[0-9]([A-Z][A-Z])$"
if [[ $i =~ $REG_EX ]]
then
disk_device=${BASH_REMATCH[1]}
disk_capacity=${BASH_REMATCH[2]}
disk_capacity_type=${BASH_REMATCH[3]}
(echo "Device: \"$disk_device\" \"$disk_capacity\" $disk_capacity_type") >/dev/tty1
IFS=$'\n'
disk_txt=('udevadm info --query=all --name=$disk_device')
unset IFS
is_USB_drive=0
for j in "${disk_txt[@]}"
do
#(echo "j: \"$j\"") >/dev/tty1
REG_EX="^ID_BUS=usb$"
if [[ $j =~ $REG_EX ]]
then
# USB keys are not to be included in total disk space
# (echo "$disk_device is a USB drive!") >/dev/tty1
is_USB_drive=1
fi
done
if [ "$is_USB_drive" = "0" ]
then
total_capacity=$(( $total_capacity + $disk_capacity ))
fi
fi
done
(echo "Disk Model: $disk_model") >/dev/tty1
(echo "Disk $disk_device Capacity: $total_capacity $disk_capacity_type") >/dev/tty1