|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# GET THE INITITAL OUTPUT OF `ls /sys/block`
|
|
|
|
BLK_INFO="$(ls -l --color=never /sys/block | grep -v virtual | grep devices | cut -d\ -f9-)"
|
|
|
|
|
|
|
|
# STRIP OFF THE PCI BUS LOCATION INFORMATION
|
|
|
|
BLK_INFO="$(echo "${BLK_INFO}" | sed 's|\.\.\/devices/pci[0-9a-f:]\{7\}\(/[0-9a-f:.]\{12\}\)\+/||g')"
|
|
|
|
|
|
|
|
#STRIP OFF THE SUPERFLUOUS USB HOST INFORMATION
|
|
|
|
BLK_INFO="$(echo "${BLK_INFO}" | sed 's|\(usb[0-9]\+\)/.*/host|\1/host|g')"
|
|
|
|
|
|
|
|
# CONDENSE THE TARGET INFORMATION
|
|
|
|
BLK_INFO="$(echo "${BLK_INFO}" | sed 's|target[0-9:]\+/[0-9:]\+:\([0-9]\+\)|target\1|g')"
|
|
|
|
|
|
|
|
# STRIP OFF BLOCKS
|
|
|
|
BLK_INFO="$(echo "${BLK_INFO}" | sed 's|/block/.*||g')"
|
|
|
|
|
|
|
|
# CONVERT -> TO A SPACE
|
|
|
|
BLK_INFO="$(echo "${BLK_INFO}" | sed 's/ -> / /g')"
|
|
|
|
|
|
|
|
# SWAP COLUMNS
|
|
|
|
BLK_INFO="$(echo "${BLK_INFO}" | awk '{t=$1; $1=$2; $2=t; print;}')"
|
|
|
|
|
|
|
|
# NOW GET DEVICE IDs and SIZES
|
|
|
|
|
|
|
|
echo "${BLK_INFO}" | while read -r LOCATION BLOCKDEV; do
|
|
|
|
DEVICE_ID="$(ls -l --color=never /dev/disk/by-id | sed 's/ \+/ /g' | grep -v 'nvme-eui\|wwn-' | grep "${BLOCKDEV}$" | cut -d\ -f9)"
|
|
|
|
DEV_BYTES="$(lsblk -bnPo NAME,SIZE | grep "\"${BLOCKDEV}\"" | cut -d\" -f 4)"
|
|
|
|
if [ "${DEV_BYTES}" -ge $((1000**5)) ]; then
|
|
|
|
DEVICE_SZ="$(awk "BEGIN {print ${DEV_BYTES}/1000^5}" | cut -b1-5)T"
|
|
|
|
elif [ "${DEV_BYTES}" -ge $((1000**4)) ]; then
|
|
|
|
DEVICE_SZ="$(awk "BEGIN {print ${DEV_BYTES}/1000^4}" | cut -b1-5)T"
|
|
|
|
elif [ "${DEV_BYTES}" -ge $((1000**3)) ]; then
|
|
|
|
DEVICE_SZ="$(awk "BEGIN {print ${DEV_BYTES}/1000^3}" | cut -b1-5)G"
|
|
|
|
elif [ "${DEV_BYTES}" -ge $((1000**2)) ]; then
|
|
|
|
DEVICE_SZ="$(awk "BEGIN {print ${DEV_BYTES}/1000^2}" | cut -b1-5)M"
|
|
|
|
elif [ "${DEV_BYTES}" -ge 1000 ]; then
|
|
|
|
DEVICE_SZ="$(awk "BEGIN {print ${DEV_BYTES}/1000}" | cut -b1-5)K"
|
|
|
|
else
|
|
|
|
DEVICE_SZ="${DEV_BYTES}B"
|
|
|
|
fi
|
|
|
|
echo "${LOCATION} ${BLOCKDEV} ${DEVICE_SZ} ${DEVICE_ID}" >> /tmp/bdmap
|
|
|
|
done
|
|
|
|
|
|
|
|
column -t -R3 -o" " /tmp/bdmap
|
|
|
|
rm /tmp/bdmap
|