Added support for RedHat 8.x, redesign of the code
This commit is contained in:
Родитель
717f0aaa28
Коммит
4a26601715
|
@ -9,10 +9,10 @@
|
||||||
# Two partitions with one of it a LVM flagged one -> RedHAt with LVM
|
# Two partitions with one of it a LVM flagged one -> RedHAt with LVM
|
||||||
|
|
||||||
# Global redirection for ERR to STD
|
# Global redirection for ERR to STD
|
||||||
exec 2>&1
|
#exec 2>&1
|
||||||
|
|
||||||
# Declare array
|
# Declare array
|
||||||
a_part_info=()
|
declare -A a_part_info
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
# ---------
|
# ---------
|
||||||
|
@ -36,16 +36,19 @@ fsck_partition() {
|
||||||
# $2 holds the partiton info
|
# $2 holds the partiton info
|
||||||
Log-Info "File system check start"
|
Log-Info "File system check start"
|
||||||
if [[ "$1" == "xfs" ]]; then
|
if [[ "$1" == "xfs" ]]; then
|
||||||
|
Log-Info "fsck part $2"
|
||||||
xfs_repair -n "$2" > /dev/null 2>&1
|
xfs_repair -n "$2" > /dev/null 2>&1
|
||||||
elif [[ "$1" == "fat16" ]]; then
|
elif [[ "$1" == "fat16" ]]; then
|
||||||
|
Log-Info "fsck part $2"
|
||||||
fsck.vfat -p "$2" > /dev/null 2>&1
|
fsck.vfat -p "$2" > /dev/null 2>&1
|
||||||
else
|
else
|
||||||
|
Log-Info "fsck part $2"
|
||||||
fsck."$1" -p "$2" > /dev/null 2>&1
|
fsck."$1" -p "$2" > /dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$?" == 4 ]]; then
|
if [[ "$?" == 4 ]]; then
|
||||||
# error 4 is returned by fsck.ext4 only
|
# error 4 is returned by fsck.ext4 only
|
||||||
Log-Info "${root_rescue} is not able to be automatically recovered. Aborting ALAR"
|
Log-Info "Partition ${2} is not able to be automatically recovered. Aborting ALAR"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -62,18 +65,23 @@ fsck_partition() {
|
||||||
|
|
||||||
verifyRedHat() {
|
verifyRedHat() {
|
||||||
if [[ ! -d /tmp/assert ]]; then
|
if [[ ! -d /tmp/assert ]]; then
|
||||||
mkdir /tmp/assert
|
mkdir /tmp/assert;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${isLVM}" == "true" ]]; then
|
if [[ "${isLVM}" == "true" ]]; then
|
||||||
|
Log-Info "Verifying LVM setup"
|
||||||
pvscan > /dev/null 2>&1
|
pvscan > /dev/null 2>&1
|
||||||
vgscan > /dev/null 2>&1
|
vgscan > /dev/null 2>&1
|
||||||
lvscan > /dev/null 2>&1
|
lvscan > /dev/null 2>&1
|
||||||
local fs=$(parted $(lvscan | grep rootlv | awk '{print $2}' | tr -d "'") print | grep -E '^ ?[0-9]{1,2} *' | awk '{print $5}')
|
root_part_fs=$(parted $(lvscan | grep rootlv | awk '{print $2}' | tr -d "'") print | grep -E '^ ?[0-9]{1,2} *' | awk '{print $5}')
|
||||||
# Set variable rescue_root to the right LV name
|
# Set variable rescue_root to the right LV name
|
||||||
rescue_root=$(lvscan | grep rootlv | awk '{print $2}' | tr -d "'")
|
rescue_root=$(lvscan | grep rootlv | awk '{print $2}' | tr -d "'")
|
||||||
fsck_partition "${fs}" "${rescue_root}"
|
rescue_usr=$(lvscan | grep usrlv | awk '{print $2}' | tr -d "'")
|
||||||
|
fsck_partition "${root_part_fs}" "${rescue_root}"
|
||||||
|
# We can use the same FS type in this case
|
||||||
|
fsck_partition "${root_part_fs}" "${rescue_usr}"
|
||||||
mount $(lvscan | grep rootlv | awk '{print $2}' | tr -d "'") /tmp/assert
|
mount $(lvscan | grep rootlv | awk '{print $2}' | tr -d "'") /tmp/assert
|
||||||
|
mount $(lvscan | grep usrlv | awk '{print $2}' | tr -d "'") /tmp/assert/usr
|
||||||
else
|
else
|
||||||
# The file system got globally defiend before
|
# The file system got globally defiend before
|
||||||
fsck_partition "${root_part_fs}" "${rescue_root}"
|
fsck_partition "${root_part_fs}" "${rescue_root}"
|
||||||
|
@ -83,6 +91,7 @@ verifyRedHat() {
|
||||||
if [[ -e /tmp/assert/etc/os-release ]]; then
|
if [[ -e /tmp/assert/etc/os-release ]]; then
|
||||||
PRETTY_NAME="$(grep PRETTY_NAME /tmp/assert/etc/os-release)"
|
PRETTY_NAME="$(grep PRETTY_NAME /tmp/assert/etc/os-release)"
|
||||||
PRETTY_NAME="${PRETTY_NAME##*=}"
|
PRETTY_NAME="${PRETTY_NAME##*=}"
|
||||||
|
echo "PRETTY NAME : ${PRETTY_NAME}"
|
||||||
case "${PRETTY_NAME}" in
|
case "${PRETTY_NAME}" in
|
||||||
*CentOS* | *Red\ Hat*)
|
*CentOS* | *Red\ Hat*)
|
||||||
isRedHat="true"
|
isRedHat="true"
|
||||||
|
@ -105,15 +114,15 @@ verifyRedHat() {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# clean up
|
# clean up
|
||||||
|
umount /tmp/assert/usr
|
||||||
umount /tmp/assert
|
umount /tmp/assert
|
||||||
rm -fr /tmp/assert
|
rm -fr /tmp/assert
|
||||||
}
|
}
|
||||||
|
|
||||||
verifyUbuntu() {
|
verifyUbuntu() {
|
||||||
if [[ ! -d /tmp/assert ]]; then
|
if [[ ! -d /tmp/assert ]]; then
|
||||||
mkdir /tmp/assert
|
mkdir /tmp/assert;
|
||||||
fi
|
fi
|
||||||
fsck_partition "${root_part_fs}" "${rescue_root}"
|
|
||||||
mount "${rescue_root}" /tmp/assert
|
mount "${rescue_root}" /tmp/assert
|
||||||
if [[ -e /tmp/assert/etc/os-release ]]; then
|
if [[ -e /tmp/assert/etc/os-release ]]; then
|
||||||
PRETTY_NAME="$(grep PRETTY_NAME /tmp/assert/etc/os-release)"
|
PRETTY_NAME="$(grep PRETTY_NAME /tmp/assert/etc/os-release)"
|
||||||
|
@ -137,9 +146,8 @@ verifyUbuntu() {
|
||||||
|
|
||||||
verifySuse() {
|
verifySuse() {
|
||||||
if [[ ! -d /tmp/assert ]]; then
|
if [[ ! -d /tmp/assert ]]; then
|
||||||
mkdir /tmp/assert
|
mkdir /tmp/assert;
|
||||||
fi
|
fi
|
||||||
fsck_partition "${root_part_fs}" "${rescue_root}"
|
|
||||||
mount "$rescue_root" /tmp/assert
|
mount "$rescue_root" /tmp/assert
|
||||||
if [[ -e /tmp/assert/etc/os-release ]]; then
|
if [[ -e /tmp/assert/etc/os-release ]]; then
|
||||||
PRETTY_NAME="$(grep PRETTY_NAME /tmp/assert/etc/os-release)"
|
PRETTY_NAME="$(grep PRETTY_NAME /tmp/assert/etc/os-release)"
|
||||||
|
@ -164,19 +172,72 @@ verifySuse() {
|
||||||
# -----
|
# -----
|
||||||
|
|
||||||
# Get partition info/details
|
# Get partition info/details
|
||||||
for i in $(sudo echo I | parted "$(readlink -f /dev/disk/azure/scsi1/lun0)" print | grep -E '^ ?[0-9]{1,2} *' | awk '{print $1 ":" $5 ":" $6 ":" $7 ":" $8 "$"}'); do
|
|
||||||
a_part_info+=($i)
|
|
||||||
done
|
|
||||||
|
|
||||||
#for i in $(echo I | parted /dev/sda print | grep -E '^ ?[0-9]{1,2} *' | awk '{print $1 ":" $5 ":" $6 ":" $7 ":" $8 "$"}'); do
|
# parted -m /dev/sda print | grep -E '^ ?[0-9]{1,2} *' | cut -d ':' -f1,5,6,7
|
||||||
#a_part_info+=($i)
|
# 14:::bios_grub;
|
||||||
#done
|
# 15:fat16:EFI System Partition:boot, esp;
|
||||||
|
# 1:xfs::;
|
||||||
|
# 2:::lvm;
|
||||||
|
# NAME="CentOS Linux"
|
||||||
|
# VERSION="8 (Core)"
|
||||||
|
|
||||||
|
# parted -m /dev/sda print | grep -E '^ ?[0-9]{1,2} *' | cut -d ':' -f1,5,6,7
|
||||||
|
# 14:::bios_grub;
|
||||||
|
# 15:fat16:EFI System Partition:boot;
|
||||||
|
# 1:ext4::;
|
||||||
|
# 2:::lvm;
|
||||||
|
# [root@alar-cent1 ~]# cat /etc/os-release
|
||||||
|
# NAME="CentOS Linux"
|
||||||
|
# VERSION="7 (Core)"
|
||||||
|
|
||||||
|
# parted -m /dev/sda print | grep -E '^ ?[0-9]{1,2} *' | cut -d ':' -f1,5,6,7
|
||||||
|
# 1:fat16:EFI System Partition:boot;
|
||||||
|
# 2:xfs::;
|
||||||
|
# 3:::bios_grub;
|
||||||
|
# 4:::lvm;
|
||||||
|
# [root@alar1 ~]# cat /etc/os-release
|
||||||
|
# NAME="Red Hat Enterprise Linux Server"
|
||||||
|
# VERSION="7.8 (Maipo)"
|
||||||
|
|
||||||
|
# parted -m /dev/sda print | grep -E '^ ?[0-9]{1,2} *' | cut -d ':' -f1,5,6,7
|
||||||
|
# 14:::bios_grub;
|
||||||
|
# 15:fat16:EFI System Partition:boot, esp;
|
||||||
|
# 1:xfs::;
|
||||||
|
# 2:::lvm;
|
||||||
|
# [root@alar2 ~]# cat /etc/os-release
|
||||||
|
# NAME="Red Hat Enterprise Linux"
|
||||||
|
# VERSION="8.2 (Ootpa)"
|
||||||
|
|
||||||
|
OLDIFS=$IFS
|
||||||
|
IFS=; # overwriting IFS to use the semicolon as a line seperator
|
||||||
|
j=0 # Needed as counter
|
||||||
|
while read _partition; do a_part_info[$j]=$_partition; let j++; done <<< $( parted -m "$(readlink -f /dev/disk/azure/scsi1/lun0)" print | grep -E '^ ?[0-9]{1,2} *')
|
||||||
|
IFS=$OLDIFS
|
||||||
|
|
||||||
|
getPartitionNumberDetail(){
|
||||||
|
# $1 key
|
||||||
|
local result
|
||||||
|
result=$(cut -d ':' -f1 <<< ${a_part_info[$1]})
|
||||||
|
|
||||||
|
echo $result
|
||||||
|
}
|
||||||
|
|
||||||
|
getPartitionFilesystemDetail(){
|
||||||
|
# $1 key
|
||||||
|
local result
|
||||||
|
result=$(cut -d ':' -f5 <<< ${a_part_info[$1]})
|
||||||
|
|
||||||
|
echo $result
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Old Ubuntu?
|
# Old Ubuntu?
|
||||||
if [[ "${#a_part_info[@]}" -eq 1 ]]; then
|
if [[ "${#a_part_info[@]}" -eq 1 ]]; then
|
||||||
Log-Info "This could be an old Ubuntu image"
|
Log-Info "This could be an old Ubuntu image"
|
||||||
root_part_number=$(for i in "${a_part_info[@]}"; do grep boot <<<"$i"; done | cut -d':' -f1)
|
|
||||||
root_part_fs=$(for i in "${a_part_info[@]}"; do grep boot <<<"$i"; done | cut -d':' -f3)
|
for k in ${!a_part_info[@]}; do
|
||||||
|
grep -q boot <<< ${a_part_info[$k]} && root_part_number=$(getPartitionNumberDetail $k) && root_part_fs=$(getPartitionFilesystemDetail $k);
|
||||||
|
done
|
||||||
|
|
||||||
rescue_root=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${root_part_number}")
|
rescue_root=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${root_part_number}")
|
||||||
verifyUbuntu
|
verifyUbuntu
|
||||||
|
@ -185,10 +246,16 @@ fi
|
||||||
# RedHat 6.x or 7.x?
|
# RedHat 6.x or 7.x?
|
||||||
if [[ "${#a_part_info[@]}" -eq 2 ]]; then
|
if [[ "${#a_part_info[@]}" -eq 2 ]]; then
|
||||||
Log-Info "This could be a RedHat/Centos 6/7 image"
|
Log-Info "This could be a RedHat/Centos 6/7 image"
|
||||||
boot_part_number=$(for i in "${a_part_info[@]}"; do grep boot <<<"$i"; done | cut -d':' -f1)
|
|
||||||
boot_part_fs=$(for i in "${a_part_info[@]}"; do grep boot <<<"$i"; done | cut -d':' -f3)
|
for k in ${!a_part_info[@]}; do
|
||||||
root_part_number=$(for i in "${a_part_info[@]}"; do grep -v boot <<<"$i"; done | cut -d':' -f1)
|
grep -q boot <<< ${a_part_info[$k]} && boot_part_number=$(getPartitionNumberDetail $k) && boot_part_fs=$(getPartitionFilesystemDetail $k);
|
||||||
root_part_fs=$(for i in "${a_part_info[@]}"; do grep -v boot <<<"$i"; done | cut -d':' -f3)
|
grep -qv boot <<< ${a_part_info[$k]} && root_part_number=$(getPartitionNumberDetail $k) && root_part_fs=$(getPartitionFilesystemDetail $k);
|
||||||
|
done
|
||||||
|
|
||||||
|
# Check whether we have a LVM system.
|
||||||
|
for k in ${!a_part_info[@]}; do
|
||||||
|
grep -q lvm <<< ${a_part_info[$k]} && isLVM="true";
|
||||||
|
done
|
||||||
|
|
||||||
# RedHat 6.x does have ext4 filesystem
|
# RedHat 6.x does have ext4 filesystem
|
||||||
# Whereas RedHat 7.x does have the XFS filesystem
|
# Whereas RedHat 7.x does have the XFS filesystem
|
||||||
|
@ -198,17 +265,16 @@ if [[ "${#a_part_info[@]}" -eq 2 ]]; then
|
||||||
isXFS="true"
|
isXFS="true"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check whether we have a LVM system.
|
|
||||||
if [[ "$root_part_fs" == "lvm" ]]; then
|
|
||||||
isLVM="true"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Set root_rescue and boot_part in order to mount the disk correct
|
# Set root_rescue and boot_part in order to mount the disk correct
|
||||||
# In case we have a LVM system we handle this in more detail in base.sh
|
# In case we have a LVM system we handle this in more detail in base.sh
|
||||||
rescue_root=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${root_part_number}")
|
rescue_root=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${root_part_number}")
|
||||||
|
if [[ "$isLVM" == "false" ]]; then
|
||||||
|
fsck_partition "${root_part_fs}" "${root_part}"
|
||||||
|
fi
|
||||||
boot_part=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${boot_part_number}")
|
boot_part=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${boot_part_number}")
|
||||||
fsck_partition "${boot_part_fs}" "${boot_part}"
|
fsck_partition "${boot_part_fs}" "${boot_part}"
|
||||||
verifyRedHat # In case we have LVM partitions after this point the variable "rescue_root" is overwritten with the correct value
|
verifyRedHat
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -221,41 +287,64 @@ if [[ "${#a_part_info[@]}" -eq 3 ]]; then
|
||||||
Log-Error "Freebsd is not a supported OS. ALAR tool is stopped"
|
Log-Error "Freebsd is not a supported OS. ALAR tool is stopped"
|
||||||
osNotSupported="true"
|
osNotSupported="true"
|
||||||
else
|
else
|
||||||
boot_part_number=$(for i in "${a_part_info[@]}"; do grep boot <<<"$i"; done | cut -d':' -f1)
|
for k in ${!a_part_info[@]}; do
|
||||||
efi_part_number=$(for i in "${a_part_info[@]}"; do grep bios <<<"$i"; done | cut -d':' -f1)
|
grep -q boot <<< ${a_part_info[$k]} && efi_part_number=$(getPartitionNumberDetail $k) && efi_part_fs=$(getPartitionFilesystemDetail $k);
|
||||||
root_part_number=$(for i in "${a_part_info[@]}"; do grep -v bios <<<"$i" | grep -v boot; done | cut -d':' -f1)
|
grep -qv 'bios\|boot' <<< ${a_part_info[$k]} && root_part_number=$(getPartitionNumberDetail $k) && root_part_fs=$(getPartitionFilesystemDetail $k);
|
||||||
root_part_fs=$(for i in "${a_part_info[@]}"; do grep -v bios <<<"$i" | grep -v boot; done | cut -d':' -f2)
|
done
|
||||||
boot_part_fs=$(for i in "${a_part_info[@]}"; do grep -v boot <<<"$i"; done | cut -d':' -f2)
|
|
||||||
efi_part_fs=$(for i in "${a_part_info[@]}"; do grep -v bios <<<"$i"; done | cut -d':' -f2)
|
|
||||||
|
|
||||||
# Set root_rescue and boot_part in order to mount the disk correct
|
# Set root_rescue and boot_part in order to mount the disk correct
|
||||||
rescue_root=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${root_part_number}")
|
rescue_root=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${root_part_number}")
|
||||||
boot_part=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${boot_part_number}")
|
fsck_partition "${root_part_fs}" "${rescue_root}"
|
||||||
fsck_partition "${boot_part_fs}" "${boot_part}"
|
|
||||||
efi_part=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${efi_part_number}")
|
efi_part=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${efi_part_number}")
|
||||||
|
isUbuntuEFI="true"
|
||||||
fsck_partition "${efi_part_fs}" "${efi_part}"
|
fsck_partition "${efi_part_fs}" "${efi_part}"
|
||||||
verifyUbuntu
|
verifyUbuntu
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Suse 12 or 15?
|
|
||||||
if [[ "${#a_part_info[@]}" -eq 4 ]]; then
|
|
||||||
Log-Info "This could be a SUSE 12 or 15 image"
|
|
||||||
# Get boot partition
|
|
||||||
boot_part_number=$(for i in "${a_part_info[@]}"; do grep lxboot <<<"$i"; done | cut -d':' -f1)
|
|
||||||
efi_part_number=$(for i in "${a_part_info[@]}"; do grep UEFI <<<"$i"; done | cut -d':' -f1)
|
|
||||||
root_part_number=$(for i in "${a_part_info[@]}"; do grep lxroot <<<"$i"; done | cut -d':' -f1)
|
|
||||||
root_part_fs=$(for i in "${a_part_info[@]}"; do grep lxroot <<<"$i"; done | cut -d':' -f2)
|
|
||||||
boot_part_fs=$(for i in "${a_part_info[@]}"; do grep lxboot <<<"$i"; done | cut -d':' -f2)
|
|
||||||
efi_part_fs=$(for i in "${a_part_info[@]}"; do grep UEFI <<<"$i"; done | cut -d':' -f2)
|
|
||||||
|
|
||||||
# Set root_rescue and boot_part in order to mount the disk correct
|
if [[ "${#a_part_info[@]}" -eq 4 ]]; then
|
||||||
rescue_root=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${root_part_number}")
|
# Not sure whethe this is a RedHat or CENTOS with LVM or it is a Suse 12/15 instead
|
||||||
boot_part=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${boot_part_number}")
|
# Need to make a simple test
|
||||||
fsck_partition "${boot_part_fs}" "${boot_part}"
|
for k in ${!a_part_info[@]}; do
|
||||||
efi_part=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${efi_part_number}")
|
grep -s lxboot <<< ${a_part_info[$k]} && isSuseBoot=true;
|
||||||
fsck_partition "${efi_part_fs}" "${efi_part}"
|
done
|
||||||
verifySuse
|
|
||||||
|
if [[ "$isSuseBoot" == "true" ]]; then
|
||||||
|
#Suse 12 or 15?
|
||||||
|
Log-Info "This could be a SUSE 12 or 15 image"
|
||||||
|
for k in ${!a_part_info[@]}; do
|
||||||
|
grep -q lxboot <<< ${a_part_info[$k]} && boot_part_number=$(getPartitionNumberDetail $k) && boot_part_fs=$(getPartitionFilesystemDetail $k);
|
||||||
|
grep -q UEFI <<< ${a_part_info[$k]} && efi_part_number=$(getPartitionNumberDetail $k) && efi_part_fs=$(getPartitionFilesystemDetail $k);
|
||||||
|
grep -q lxroot <<< ${a_part_info[$k]} && root_part_number=$(getPartitionNumberDetail $k) && root_part_fs=$(getPartitionFilesystemDetail $k);
|
||||||
|
done
|
||||||
|
|
||||||
|
# Set root_rescue and boot_part in order to mount the disk correct
|
||||||
|
rescue_root=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${root_part_number}")
|
||||||
|
fsck_partition "${root_part_fs}" "${rescue_root}"
|
||||||
|
boot_part=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${boot_part_number}")
|
||||||
|
fsck_partition "${boot_part_fs}" "${boot_part}"
|
||||||
|
efi_part=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${efi_part_number}")
|
||||||
|
fsck_partition "${efi_part_fs}" "${efi_part}"
|
||||||
|
verifySuse
|
||||||
|
else
|
||||||
|
Log-Info "This is a recent RedHat or CentOS image with 4 partitions"
|
||||||
|
for k in ${!a_part_info[@]}; do
|
||||||
|
grep -q EFI <<< ${a_part_info[$k]} && efi_part_number=$(getPartitionNumberDetail $k) && efi_part_fs=$(getPartitionFilesystemDetail $k);
|
||||||
|
grep -v EFI <<< ${a_part_info[$k]} | grep -v lvm | grep -v bios && boot_part_number=$(getPartitionNumberDetail $k) && boot_part_fs=$(getPartitionFilesystemDetail $k);
|
||||||
|
grep -q lvm <<< ${a_part_info[$k]} && lvm_part_number=$(getPartitionNumberDetail $k);
|
||||||
|
done
|
||||||
|
# Those images are LVM based
|
||||||
|
isLVM="true"
|
||||||
|
# Not a RedHat 6.x system
|
||||||
|
isRedHat6="false"
|
||||||
|
boot_part=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${boot_part_number}")
|
||||||
|
fsck_partition "${boot_part_fs}" "${boot_part}"
|
||||||
|
efi_part=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${efi_part_number}")
|
||||||
|
fsck_partition "${efi_part_fs}" "${efi_part}"
|
||||||
|
verifyRedHat
|
||||||
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# No standard image
|
# No standard image
|
||||||
|
@ -264,3 +353,5 @@ if [[ "${#a_part_info[@]}" -gt 4 ]]; then
|
||||||
osNotSupported="true"
|
osNotSupported="true"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# DEBUG
|
||||||
|
# printenv
|
|
@ -31,9 +31,15 @@ recover_redhat() {
|
||||||
# rebuild the initrd
|
# rebuild the initrd
|
||||||
dracut -f /boot/initramfs-"${kernel_version}".img "$kernel_version"
|
dracut -f /boot/initramfs-"${kernel_version}".img "$kernel_version"
|
||||||
else
|
else
|
||||||
depmod ${kernel_version}
|
if [[ $(grep -qe 'VERSION_ID="8.[1-2]"' /etc/os-release) -eq 0 ]]; then
|
||||||
mkinitrd --force /boot/initramfs-"${kernel_version}".img "$kernel_version"
|
for installed_kernel in $(rpm -qa kernel); do
|
||||||
grub2-mkconfig -o /boot/grub2/grub.cfg
|
kernel-install add $(sed 's/kernel-//' <<< $installed_kernel) /lib/modules/$(sed 's/kernel-//' <<< $installed_kernel)/vmlinuz
|
||||||
|
done
|
||||||
|
else
|
||||||
|
depmod ${kernel_version}
|
||||||
|
mkinitrd --force /boot/initramfs-"${kernel_version}".img "$kernel_version"
|
||||||
|
grub2-mkconfig -o /boot/grub2/grub.cfg
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,16 +7,8 @@
|
||||||
set_grub_default() {
|
set_grub_default() {
|
||||||
# if not set to saved, replace it
|
# if not set to saved, replace it
|
||||||
sed -i "s/GRUB_DEFAULT=[[:digit:]]/GRUB_DEFAULT=saved/" /etc/default/grub
|
sed -i "s/GRUB_DEFAULT=[[:digit:]]/GRUB_DEFAULT=saved/" /etc/default/grub
|
||||||
echo GRUB_DISABLE_OS_PROBER=true >>/etc/default/grub
|
|
||||||
#GRUB_DEFAULT=saved
|
|
||||||
#GRUB_SAVEDEFAULT=true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# at first alter the grub configuration to set GRUB_DEFAULT=saved if needed
|
|
||||||
if [[ $isRedHat6 == "false" ]]; then
|
|
||||||
set_grub_default
|
|
||||||
fi
|
|
||||||
|
|
||||||
# set the default kernel accordingly
|
# set the default kernel accordingly
|
||||||
# This is different for RedHat and Ubuntu/SUSE distros
|
# This is different for RedHat and Ubuntu/SUSE distros
|
||||||
# Ubuntu and SLES use sub-menues
|
# Ubuntu and SLES use sub-menues
|
||||||
|
@ -24,20 +16,26 @@ fi
|
||||||
# the variables are defined in base.sh
|
# the variables are defined in base.sh
|
||||||
if [[ $isRedHat == "true" ]]; then
|
if [[ $isRedHat == "true" ]]; then
|
||||||
if [[ $isRedHat6 == "true" ]]; then
|
if [[ $isRedHat6 == "true" ]]; then
|
||||||
sed -i 's/default=0/default=1/' /boot/grub/grub.conf
|
grubby --set-default=1 # This is the previous kernel
|
||||||
else
|
else
|
||||||
grub2-set-default 1 # This is the last previous kernel
|
set_grub_default
|
||||||
grub2-mkconfig -o /boot/grub2/grub.cfg
|
grubby --set-default=1 # This is the previous kernel
|
||||||
|
|
||||||
|
# Fix for a bug in RedHat 8.1/8.2
|
||||||
|
# This needs to be fixed as soon as the bug with grub2-mkconfig is solved too
|
||||||
|
# grub2-mkconfig must not be executed because of this bug
|
||||||
|
$(grep -qe 'VERSION_ID="8.[1-2]"' /etc/os-release) && $(sed -i 's/set default="0"/set default="${saved_entry}"/' grub.cfg)
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $isUbuntu == "true" ]]; then
|
if [[ $isUbuntu == "true" ]]; then
|
||||||
|
set_grub_default
|
||||||
sed -i -e 's/GRUB_DEFAULT=.*/GRUB_DEFAULT="1>2"/' /etc/default/grub
|
sed -i -e 's/GRUB_DEFAULT=.*/GRUB_DEFAULT="1>2"/' /etc/default/grub
|
||||||
update-grub
|
update-grub
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $isSuse == "true" ]]; then
|
if [[ $isSuse == "true" ]]; then
|
||||||
#grub2-set-default "1>2"
|
set_grub_default
|
||||||
sed -i -e 's/GRUB_DEFAULT=.*/GRUB_DEFAULT="1>2"/' /etc/default/grub
|
sed -i -e 's/GRUB_DEFAULT=.*/GRUB_DEFAULT="1>2"/' /etc/default/grub
|
||||||
grub2-mkconfig -o /boot/grub2/grub.cfg
|
grub2-mkconfig -o /boot/grub2/grub.cfg
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -6,6 +6,7 @@ export isRedHat="false"
|
||||||
export isRedHat6="false"
|
export isRedHat6="false"
|
||||||
export isSuse="false"
|
export isSuse="false"
|
||||||
export isUbuntu="false"
|
export isUbuntu="false"
|
||||||
|
export isUbuntuEFI="false"
|
||||||
export tmp_dir=""
|
export tmp_dir=""
|
||||||
export recover_action=""
|
export recover_action=""
|
||||||
export boot_part=""
|
export boot_part=""
|
||||||
|
@ -19,6 +20,7 @@ export osNotSupported="true" # set to true by default, gets changed to false if
|
||||||
export tmp_dir=""
|
export tmp_dir=""
|
||||||
export global_error="false"
|
export global_error="false"
|
||||||
export actions="fstab initrd kernel" # These are the basic actions at the moment
|
export actions="fstab initrd kernel" # These are the basic actions at the moment
|
||||||
|
export root_part_fs # set in distro-test
|
||||||
|
|
||||||
# Functions START
|
# Functions START
|
||||||
# Define some helper functions
|
# Define some helper functions
|
||||||
|
@ -42,6 +44,7 @@ recover_action() {
|
||||||
[[ ${global_error} == "true" ]] && return 11
|
[[ ${global_error} == "true" ]] && return 11
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
isInAction() {
|
isInAction() {
|
||||||
#be quiet, just let us know this action exists
|
#be quiet, just let us know this action exists
|
||||||
grep -q "$1" <<<"$actions"
|
grep -q "$1" <<<"$actions"
|
||||||
|
@ -49,8 +52,8 @@ isInAction() {
|
||||||
}
|
}
|
||||||
|
|
||||||
copyRecoverScriptsToTemp() {
|
copyRecoverScriptsToTemp() {
|
||||||
cp -r ./src/linux/common/helpers/alar/* ${tmp_dir}
|
cp -Lr ./src/linux/common/helpers/alar/* ${tmp_dir}
|
||||||
cp -r ./src/linux/common/* ${tmp_dir}
|
cp -Lr ./src/linux/common/* ${tmp_dir}
|
||||||
mkdir -p ${tmp_dir}/src/linux/common
|
mkdir -p ${tmp_dir}/src/linux/common
|
||||||
ln -s ${tmp_dir}/helpers ${tmp_dir}/src/linux/common/helpers
|
ln -s ${tmp_dir}/helpers ${tmp_dir}/src/linux/common/helpers
|
||||||
ln -s ${tmp_dir}/setup ${tmp_dir}/src/linux/common/setup
|
ln -s ${tmp_dir}/setup ${tmp_dir}/src/linux/common/setup
|
||||||
|
@ -90,12 +93,14 @@ else
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Mount the root part
|
# Prepare and mount the partitions. Take into account what distro we have to deal with
|
||||||
#====================
|
# At first we have to mount the root partion of the VM we need to recover
|
||||||
|
|
||||||
if [[ ! -d /mnt/rescue-root ]]; then
|
if [[ ! -d /mnt/rescue-root ]]; then
|
||||||
mkdir /mnt/rescue-root
|
mkdir /mnt/rescue-root
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# At the moment we handle only LVM on RedHat/CentOS
|
||||||
if [[ ${isLVM} == "true" ]]; then
|
if [[ ${isLVM} == "true" ]]; then
|
||||||
pvscan
|
pvscan
|
||||||
vgscan
|
vgscan
|
||||||
|
@ -106,15 +111,16 @@ if [[ ${isLVM} == "true" ]]; then
|
||||||
usrlv=$(lvscan | grep usrlv | awk '{print $2}' | tr -d "'")
|
usrlv=$(lvscan | grep usrlv | awk '{print $2}' | tr -d "'")
|
||||||
varlv=$(lvscan | grep varlv | awk '{print $2}' | tr -d "'")
|
varlv=$(lvscan | grep varlv | awk '{print $2}' | tr -d "'")
|
||||||
|
|
||||||
# ext4 i used together with LVM, so no further handling is required
|
# The mount tool is automatically able to handle other fs-types
|
||||||
mount ${rootlv} /mnt/rescue-root
|
mount ${rootlv} /mnt/rescue-root
|
||||||
mount ${tmplv} /mnt/rescue-root/tmp
|
#mount ${tmplv} /mnt/rescue-root/tmp
|
||||||
mount ${optlv} /mnt/rescue-root/opt
|
#mount ${optlv} /mnt/rescue-root/opt
|
||||||
mount ${usrlv} /mnt/rescue-root/usr
|
mount ${usrlv} /mnt/rescue-root/usr
|
||||||
mount ${varlv} /mnt/rescue-root/var
|
mount ${varlv} /mnt/rescue-root/var
|
||||||
|
# No LVM, thus do the normal mount steps
|
||||||
elif [[ "${isRedHat}" == "true" || "${isSuse}" == "true" ]]; then
|
elif [[ "${isRedHat}" == "true" || "${isSuse}" == "true" ]]; then
|
||||||
# noouid is valid for XFS only
|
# noouid is valid for XFS only
|
||||||
|
# The extra step is only performed to be sure we have no overlaps with any UUID on an XFS FS
|
||||||
if [[ "${isExt4}" == "true" ]]; then
|
if [[ "${isExt4}" == "true" ]]; then
|
||||||
mount -n "${rescue_root}" /mnt/rescue-root
|
mount -n "${rescue_root}" /mnt/rescue-root
|
||||||
elif [[ "${isXFS}" == "true" ]]; then
|
elif [[ "${isXFS}" == "true" ]]; then
|
||||||
|
@ -122,39 +128,31 @@ elif [[ "${isRedHat}" == "true" || "${isSuse}" == "true" ]]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [[ "$isUbuntu" == "true" ]]; then
|
if [[ "$isUbuntu" == "true" ]]; then
|
||||||
mount -n "$rescue_root" /mnt/rescue-root
|
mount -n "$rescue_root" /mnt/rescue-root
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Mount the boot part
|
#Mount the boot part
|
||||||
#===================
|
#===================
|
||||||
if [[ ! -d /mnt/rescue-root/boot ]]; then
|
|
||||||
mkdir /mnt/rescue-root/boot
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ${isLVM} == "true" ]]; then
|
# Ubuntu does not have an extra boot partition
|
||||||
boot_part_number=$(for i in "${a_part_info[@]}"; do grep boot <<<"$i"; done | cut -d':' -f1)
|
if [[ "$isRedHat" == "true" || "$isSuse" == "true" ]]; then
|
||||||
boot_part=$(readlink -f /dev/disk/azure/scsi1/lun0-part"${boot_part_number}")
|
# noouid is valid for XFS only
|
||||||
mount ${boot_part} /mnt/rescue-root/boot
|
if [[ "${isExt4}" == "true" || "${isExt3}" == "true" ]]; then
|
||||||
else
|
mount "${boot_part}" /mnt/rescue-root/boot
|
||||||
if [[ "$isRedHat" == "true" || "$isSuse" == "true" ]]; then
|
elif [[ "${isXFS}" == "true" ]]; then
|
||||||
# noouid is valid for XFS only
|
mount -o nouuid "${boot_part}" /mnt/rescue-root/boot
|
||||||
if [[ "${isExt4}" == "true" || "${isExt3}" == "true" ]]; then
|
|
||||||
mount "${boot_part}" /mnt/rescue-root/boot
|
|
||||||
elif [[ "${isXFS}" == "true" ]]; then
|
|
||||||
mount -o nouuid "${boot_part}" /mnt/rescue-root/boot
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Mount the EFI part if Suse
|
# EFI partitions are only able to be mounted after we have mounted the boot partition
|
||||||
if [[ "${isSuse}" == "true" ]]; then
|
if [[ -n "$efi_part" ]]; then
|
||||||
if [[ ! -d /mnt/rescue-root/boot/efi ]]; then
|
|
||||||
mkdir /mnt/rescue-root/boot/efi
|
|
||||||
fi
|
|
||||||
mount "${efi_part}" /mnt/rescue-root/boot/efi
|
mount "${efi_part}" /mnt/rescue-root/boot/efi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#Mount the support filesystems
|
#Mount the support filesystems
|
||||||
#==============================
|
#==============================
|
||||||
#see also http://linuxonazure.azurewebsites.net/linux-recovery-using-chroot-steps-to-recover-vms-that-are-not-accessible/
|
#see also http://linuxonazure.azurewebsites.net/linux-recovery-using-chroot-steps-to-recover-vms-that-are-not-accessible/
|
||||||
|
@ -205,23 +203,22 @@ for i in dev/pts proc tmp sys dev; do umount /mnt/rescue-root/"$i"; done
|
||||||
if [[ "$isUbuntu" == "true" || "$isSuse" == "true" ]]; then
|
if [[ "$isUbuntu" == "true" || "$isSuse" == "true" ]]; then
|
||||||
#is this really needed for Suse?
|
#is this really needed for Suse?
|
||||||
umount /mnt/rescue-root/run
|
umount /mnt/rescue-root/run
|
||||||
if [[ -d /mnt/rescue-root/boot/efi ]]; then
|
|
||||||
umount /mnt/rescue-root/boot/efi
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${isLVM}" == "true" ]]; then
|
if [[ "${isLVM}" == "true" ]]; then
|
||||||
umount /mnt/rescue-root/tmp
|
# umount /mnt/rescue-root/tmp
|
||||||
umount /mnt/rescue-root/opt
|
# umount /mnt/rescue-root/opt
|
||||||
umount /mnt/rescue-root/usr
|
umount /mnt/rescue-root/usr
|
||||||
umount /mnt/rescue-root/var
|
umount /mnt/rescue-root/var
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ $(mountpoint -q /mnt/rescue_root/boot) -eq 0 ]] && umount /mnt/rescue-root/boot && rm -d /mnt/rescue-root/boot
|
if [[ -n "$efi_part" ]]; then
|
||||||
|
umount "${efi_part}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
umount /mnt/rescue-root/boot
|
||||||
umount /mnt/rescue-root
|
umount /mnt/rescue-root
|
||||||
rm -fr /mnt/rescue-root
|
rmdir /mnt/rescue-root
|
||||||
rm -fr "${tmp_dir}"
|
rm -fr "${tmp_dir}"
|
||||||
|
|
||||||
if [[ "${recover_status}" == "11" ]]; then
|
if [[ "${recover_status}" == "11" ]]; then
|
||||||
|
|
Загрузка…
Ссылка в новой задаче