rendered paste body#!/bin/bash
KERNEL=`uname -r | cut -c1-3`
is_physical_disk() {
# This also screens lines that already use UUIDs
FSTAB_ENT=${1}
return `echo "${FSTAB_ENT}" |
awk 'BEGIN { RC = 0 }
{ if ( $3 ~ /devpts|proc|tmpfs|sysfs|auto/ ) RC=1 ;
if ( $2 ~ /cdrom|floppy/ ) RC=1 ;
if ( $1 ~ /^UUID|^#/ ) RC=1 ;
print RC }'`
}
rhel3_dev_uuid() {
DEV=${1}
/usr/bin/partition_uuid ${DEV}
}
rhel4_dev_uuid() {
DEV=${1}
/sbin/blkid ${DEV} | sed -e 's/^.* UUID="//' -e 's/" .*$//'
}
get_device() {
FS_ENTRY=${1}
if test -n "`echo ${FS_ENTRY} | grep /dev/`"
then
echo "${FS_ENTRY}"
return 0
fi
if test -n "`echo ${FS_ENTRY} | grep LABEL=`"
then
echo `/sbin/findfs ${FS_ENTRY}`
return 0
fi
echo ""
return 1
}
while read FS_LINE
do
if is_physical_disk "${FS_LINE}"
then
echo "#${FS_LINE}"
THIS_DEVICE=`echo ${FS_LINE} | awk '{print $1}'`
REAL_DEVICE=`get_device "${THIS_DEVICE}"`
case ${KERNEL} in
2\.4) THIS_UUID=`rhel3_dev_uuid ${REAL_DEVICE}` ;;
2\.6) THIS_UUID=`rhel4_dev_uuid ${REAL_DEVICE}` ;;
esac
echo "UUID=${THIS_UUID}"`echo ${FS_LINE} | awk '{ gsub(/.*/,"",$1) ; print $0 }'`
else
echo "${FS_LINE}"
fi
done < fstab