This script displays partitions (volumes) properties, including device names, mount status, filesystem, label, uuid and - when used with the --verbose option - partitions start sector and size. The point is not to gather informations about partitions - as fdisk and blkid would be faster and more appropriate for that purpose - but to get these informations from Hardware Abstraction Layer as they are passed to the applications (like the dolphin filemanager among others) through the message bus.
Usage: halinfo [ -c | --color ] [ -v | --verbose ]
The --color option produced a two colors output (might be easier to read if you have a lot of partitions). Since escape sequences get lost by copying/pasting, I removed them from the code before posting. A compressed version of the script with preserved escape sequences is available here: http://www.unixversal.com/linux/openSUSE/halinfo.gz.
The --verbose options displays two more columns: the partitions start sector (in sector - 512 or 4096 byte according to the value of volume.block_size property) and the size in MB, rather than sectors (as it would get too confusing on system with hard disks of different sector size). Both values are originally written in byte in the hal properties.
#! /bin/bash
#: Title : halinfo
#: Date Created: Mon Dec 27 22:48:05 PST 2010
#: Last Edit : Mon Dec 27 22:48:05 PST 2010
#: Author : please_try_again
#: Version : 1.0
#: Description : displays hal volume (partitions) properties
# using volume_uuid for Linux and DOS partitions and volume_part for others (like ufs)
#: usage : halinfo
#: options: -v --verbose : verbose output (display offset and size of the partitions)
# -c --color : more readable colored ouput
#
# Copy and paste this text into a text file and save it in your home area, bin folder (~/bin) as the file halinfo
# Once the file is saved, you must make the file executable using the terminal command: chmod +u ~/bin/halinfo
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prg=`basename $0`
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# This function uses lsb_release to determine the distro
# This package is not installed by default on openSUSE.
# Btw this function is completely useless.
# Just don't use it.
function alternate_color {
# set default alternate color
color=33
# set alternate color according to Linux distro.
suse=32 ; ubuntu=33 ; fedora=34 ; gentoo=35 ; mandriva=36 ; arch=36
dist=$(lsb_release -si | tr "[:upper:]" "[:lower:]" | sed 's| *linux||')
[ "$dist" == "n/a" -a -f /etc/arch-release ] && dist=arch
ocolor=${!dist}
color=${ocolor:-$color}
echo $color
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function syntax {
cat << EOFSYNTAX
usage:
$prg [options]
options:
-v --verbose: verbose output (display partions offset and size)
-c --color : colored output
EOFSYNTAX
exit
}
# primary partitions color
pricolor=37
# alternate color
# color=$(alternate_color)
color=32
# parsing options
flag=0
args=$(echo "$@ --" | sed s'|-\([cv]\)\([cv]\)|-\1 -\2|;s|^-| -|')
ARGS=`getopt -q -o cv --long verbose,color -- "$@"`
eval set -- "$ARGS"
[ "$ARGS" == "$args" ] || syntax
while true ; do
case "$1" in
-c|--color) flag=$(($flag | 1)) ; shift ;;
-v|--verbose) flag=$(($flag | 2)) ; shift ;;
--) shift ; break ;;
esac
done
# get hal volumes
for vol in `lshal -s | grep -e volume_part -e volume_uuid` ; do
dev=/org/freedesktop/Hal/devices/$vol
par=$(hal-get-property --udi $dev --key block.device)
devs=(${devs[li]} ${par}~${dev})
[/li]done
# get device properties of all partitions sorted numerically by device name (sda1, sda2, ... sdb1, sdb2, etc)
if [ $flag -lt 2 ] ; then
printf "|------------------------------------------------------------------------------|
\
| dev mount fs label uuid |
\
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
"
else
printf "|-----------------------------------------------------------------------------------------------------------|
\
| dev mount fs label uuid start size |
\
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
"
fi
i=0
for vol in $(echo ${devs[li]} | tr " " "[/li]" | sed 's|\([0-9]\)| \1|;s|~| |;s| \([0-9]\) | 0\1 |' | sort -n | awk '{ print $3 }') ; do
# get volume properties
par=$(hal-get-property --udi $vol --key block.device)
mnt=$(hal-get-property --udi $vol --key volume.is_mounted)
mp=$(hal-get-property --udi $vol --key volume.mount_point)
lbl=$(hal-get-property --udi $vol --key volume.label)
fs=$(hal-get-property --udi $vol --key volume.fstype)
fsver=$(hal-get-property --udi $vol --key volume.fsversion)
offset=$(hal-get-property --udi $vol --key volume.partition.start)
size=$(hal-get-property --udi $vol --key volume.size)
uuid=$(hal-get-property --udi $vol --key volume.uuid)
fsusage=$(hal-get-property --udi $vol --key volume.fsusage)
blocksize=$(hal-get-property --udi $vol --key volume.block_size)
num=$(hal-get-property --udi $vol --key volume.partition.number)
mnt=${mnt/true/*}
# skip unsupported partitions (like BSD swap slices)
[ "x$fs" == "x" -a "x$fsusage" == "x" ] && continue
# Add ufs version for BSD slices ; set
if [ "$fs" == "ufs" ] ; then
if [ $num -le 4 ] ; then
fs="BSD pri"
else
fs=${fs}${fsver}
fi
fi
# set extended partition fs to "DOS Ext"
[ "$fsusage" == "partitiontable" ] && fs="DOS Ext"
# convert offset in sectors (could be 512 or 4096 sectors, according to blocksize)
offset=$(($offset/$blocksize))
# convert size in MB
size=$(($size/1048576))
case $flag in
0) # normal output
printf "| %-8s%-5s%-8s%-15s%-40s |
" ${par##*/} "${mnt/false/ }" "$fs" "$lbl" "$uuid" ;;
1) # colored output
let i++
if [ $num -le 4 ] ; then
printf "| %-8s%-5s%-9s%-15s%-40s|
" ${par##*/} "${mnt/false/ }" "$fs" "$lbl" "$uuid"
else
if [ $(($i % 2)) -eq 0 ] ; then
printf "| %-8s%-5s%-9s%-15s%-40s|
" ${par##*/} "${mnt/false/ }" "$fs" "$lbl" "$uuid"
else
printf "| %-8s%-5s%-9s%-15s%-40s|
" ${par##*/} "${mnt/false/ }" "$fs" "$lbl" "$uuid"
fi
fi
;;
2) # verbose output
printf "| %-8s%-5s%-9s%-15s%-40s%14s%11s MB |
" ${par##*/} "${mnt/false/ }" "$fs" "$lbl" "$uuid" $offset $size;;
3) # verbose coloured output
let i++
if [ $num -le 4 ] ; then
printf "| %-8s%-5s%-9s%-15s%-40s%14s%11s MB |
" ${par##*/} "${mnt/false/ }" "$fs" "$lbl" "$uuid" $offset $size
else
if [ $(($i % 2)) -eq 0 ] ; then
printf "| %-8s%-5s%-9s%-15s%-40s%14s%11s MB |
" ${par##*/} "${mnt/false/ }" "$fs" "$lbl" "$uuid" $offset $size
else
printf "| %-8s%-5s%-9s%-15s%-40s%14s%11s MB |
" ${par##*/} "${mnt/false/ }" "$fs" "$lbl" "$uuid" $offset $size
fi
fi
esac
done
if [ $flag -lt 2 ] ; then
printf "|------------------------------------------------------------------------------|
"
else
printf "|-----------------------------------------------------------------------------------------------------------|
"
fi
Screenshot of a system with many partitions:
You can ignore or remove the text in gray. I didn’t want to write/maintain several scripts for my different linux distros.