lspart - an alternative to fdisk -l

It looks the same as fdisk -l but …

[ul]
[li]it doesn’t require root privileges (except for option -b) [/li][li]it lists mount points of mounted partitions [/li][li]it works with GPT [/li][li]it optionally displays bootloaders (requires sudo). It only list Grub stage1. Use findgrub if you need info about stage2. [/li][li]it can display all partition names (option -l) [/li][li]it can display any partition property available in udev. [/li][/ul]

Here’s the code:

#! /bin/bash
#: Title       : lspart
#: Date Created: Mon Apr 30 13:58:35 PDT 2012
#: Last Edit   : Sat May  5 18:47:18 PDT 2012
#: Author      : Agnelo de la Crotche (please_try_again) 
#: Version     : 1.1
#: License     : GPL
#: Description : list partition properties from udev 
#:             : this is based of halinfo but using udev as default 
#: usage       : lspart [ -h|-l|-g ] [-] [ property [ property ] ... ]
#: options:    : -h --help    : lists available properties
#:             : -l --links   : shows DEVLINKS only
#:             : -b --boot    : tries to identify the bootsectors 
#:             :                (requires root privileges)
#: Requires:   : udev & udisks
#:
#: Copyright (C) 2012 by Agnelo de la Crotche
#: ------------------------------------------------------------------

# default properties if lspart is run without arguments (Do not chnange!)
properties="ID_MODEL ID_PART_TABLE_TYPE ID_PART_ENTRY_SCHEME ID_BUS UDISKS_PARTITION_FLAGS MAJOR MINOR UDISKS_PARTITION_OFFSET UDISKS_PARTITION_SIZE ID_PART_ENTRY_SIZE ID_FS_TYPE UDISKS_PARTITION_TYPE ID_FS_VERSION ID_FS_USAGE"

# color for hdd devices 
HDDC=$(tput sgr0)$(tput setaf 1)  # red

# (Some) Boot sector signatures
BS5272="Grub1"
BSaa75="Grub1"
BS48eb="Grub1"
BS63eb="Grub2"
BS7c3c="Grub2"
BS020="Grub2"
BS6616="FAT16"
BS19d="FAT32"
BS6f74="FAT32"
BS745="FAT32"
BSe3e1="FreeBSD"
BS6639="NetBSD"
BS8c7="openBSD"
BS8cd="Win XP"
BS55aa="Win7/Vista"
BSc031="Generic"
BSc033="Generic"
BS8ec031="SUSE Gen"
BS8ec033="MS Gen"
BSb8fa="None"

udevadm=/sbin/udevadm
udisks=$(which udisks 2>/dev/null)

[ -x $udevadm ] || exec echo "udevadm not found"
[ -x $udisks ]  || exec echo "udisks not found"

# Make sure we have root privileges for option -g
if [ "$1" == "-b" -o "$1" == "--boot" ] ; then
    if [[ $UID -ne 0 ]]; then
      id -Gn | grep -q wheel && exec sudo $0 $@ || exec echo "Root User Permissions are required with option -b"
    fi
fi

case $1 in
    "-h"|"--help")
        P=""
        for dev in $(cat /proc/partitions | awk 'NR>2{ print $4}')  ; do 
            P="$P $($udevadm info --query=property --name=$dev | awk -F "=" '{print $1};')"
        done
        echo $P | tr " " "
" | sort -u | tr "
" " "
        echo ; exit ;;
    "-l"|"--links") properties="DEVLINKS" ;;
    "-b"|"--boot") shift ; HEADER=1 ; BS=1 ;;
    "-") shift ; uproperties="$@" ; properties="$properties $@" ;;
    "")     HEADER=1 ;;
    *) uproperties="$@" ; properties="$@" ;;
esac

properties=$(echo $properties | tr -cd "[:alnum:]_[:space:]")
PROPERTIES=$(echo $properties | tr " " "|")
properties="DEV $properties"

i=-1
for dev in $(cat /proc/partitions | awk 'NR>2{ if ($1 != 11) print $4}')  ; do
    let i++
    DEV[$i]=$dev
    eval $($udevadm info --query=property --name=$dev | awk -F "=" 'BEGIN {I='$i'} ; /'$PROPERTIES'/ {printf "%s[%s]=\"%s\";", $1, I, $2}')
done

echo ${ID_PART_TABLE_TYPE
[li]} | grep -q 'gpt' && ID_width=38 || ID_width=6[/li]Fs_width=$(($(echo ${ID_FS_TYPE
[li]} | tr " " "[/li]" | wc -L)+2))
Ver_width=$(($(echo ${ID_FS_VERSION
[li]} | tr " " "[/li]" | wc -L)+2))

if [ "$HEADER" ]; then
    [ "$BS" ] && Model="BS         Model/Mount" || Model="Model/Mount"
    printf "Dev  Boot Maj Min  Bsize/Start         Size%${Fs_width}s%${ID_width}s%${Ver_width}s  %s
" "Fs" "ID" "Ver" "$Model"
fi

for (( j=0 ; j <= $i ; j++ )) ; do
    dev=${DEV[$j]}
    C=$(tput sgr0) ; MP=""
    
    if [ ${#dev} -eq 3 ]; then
        C=$HDDC
        MP="  ${ID_MODEL[$j]}"
        bsize=$(udisks --show-info /dev/$dev | sed -n 's/.*block size:[^0-9]*//p')
        bsize=${bsize:-512}
    else
        C=$(tput sgr0)
        mounted=$($udisks --show-info /dev/$dev | awk '/is mounted/ { print $NF }')
        if [ $mounted -eq 1 ] ; then
            C=$C$(tput bold)
            MP=$($udisks --show-info /dev/$dev | sed -n 's/mount paths:[     ]*//p')
        fi
    fi

    for p in ${properties} ; do
        L=0 ; P=""
        case "$p" in
        "ID_PART_ENTRY_SIZE"|"ID_MODEL"|"ID_PART_TABLE_TYPE"|"ID_PART_ENTRY_SCHEME"|"ID_BUS"|"ID_FS_USAGE") 
            [ "${uproperties}" == "${uproperties##*$p}" ] && continue ;;
        "DEVLINKS") echo " ${DEVLINKS[$j]}" | tr " " "
" ;;
        "DEV") [ ${#dev} -eq 3 ] && printf "
" ; printf "%s%-7s" $C $dev ; continue ;;
        "UDISKS_PARTITION_OFFSET")
            L=11
            if [ ${#dev} -gt 3 -a "${UDISKS_PARTITION_OFFSET[$j]}" ]; then
                P="$((${UDISKS_PARTITION_OFFSET[$j]}/$bsize))" 
            elif [ ${#dev} -eq 3 ]; then
                P="$bsize B"
            fi ;;
        "UDISKS_PARTITION_SIZE")
            L=11
            if [ ${#dev} -eq 3 ]; then
                P=$(($($udisks --show-info /dev/$dev | sed -n 's/^ *size: *//p')*1))
                P=${P:-0} ; P=$(($P*1)); P=$((P/1048576))
                printf "%'12.0f" $P ; continue
            elif [ "${ID_FS_TYPE[$j]}" == "ufs" ]; then
                if [ "${ID_PART_ENTRY_SIZE[$j]}" ]; then
                    P="${ID_PART_ENTRY_SIZE[$j]}"
                elif [ "${UDISKS_PARTITION_SIZE[$j]}" ];then 
                    P="$((${UDISKS_PARTITION_SIZE[$j]}/$bsize))"
                else
                    P="-"
                fi
                if [ "${ID_PART_ENTRY_SCHEME[$j]}" == "dos" ] ; then
                    psize=$P
                else
                    [ $P -eq $psize ] && P="?"
                fi 
            else
                [ "${UDISKS_PARTITION_SIZE[$j]}" ] && P="$((${UDISKS_PARTITION_SIZE[$j]}/$bsize))"
                [ "$psize" ] && [ $P -eq $psize ] && [ "x${ID_FS_USAGE[$j]}" == "x" ] && P="?"
            fi ;;
        "UDISKS_PARTITION_FLAGS")
            [ "${UDISKS_PARTITION_FLAGS[$j]}" ] && P="*" || P=" " ; L=1 ;;
        "UDISKS_PARTITION_TYPE")
            if [ ${#dev} -eq 3 ]; then
                P=${ID_PART_TABLE_TYPE[$j]} ; P=${P/dos/mbr}
            else
                P=${UDISKS_PARTITION_TYPE[$j]} ; P=${P/0x/}
            fi ;;
        "ID_FS_TYPE")
            if [ ${#dev} -eq 3 ]; then
                printf " %-${Fs_width}s" "GB" ; continue
            fi ;;
        "ID_FS_VERSION")
            if [ ${#dev} -eq 3 ]; then
                P=${ID_BUS[$j]} 
            fi ;;
        "MAJOR"|"MINOR") L=2 ;
        esac
        [ "$P" ] || eval 'P=${'$p[$j]} ; P=${P:--}
        [ $L -eq 0 ] && L=$(eval echo '${'$p'[@]}' | tr " " "
" | wc -L)
        let L++
        printf "%s%${L}s " "$C" "$P"
    done

    if [ "$BS" ] ; then
        if [ ${#dev} -eq 3 ] ; then
            B=$(hexdump -v -n 2 -e '"%02x"' /dev/$dev)
        else
            B=$(hexdump -v -s 128 -n  2 -e '/1 "%x"' /dev/$dev)
        fi
        bs=BS${B} ; bs=${!bs} ; bs=${bs:-0x$B}
        if [ "$bs" == "Generic" ];then
            B=$(hexdump -v -n 3 -e '"%02x"' /dev/$dev)
            bs=BS${B} ; bs=${!bs} ; bs=${bs:-0x$B}
        fi
        [ "$bs" == "0x00" ] && bs="-"
        printf " %-9s" "$bs"
    fi

    printf "%s%s
" $C "$MP"
done

If you have an OS boot sector signature not included in the script, I will be glad to add it.

As* fdisk -l* needs root priviliges because the partition table is (in a normal system) only readable by root and members of the disk group (which should not incluse normal uers):

henk@boven:~> l /dev/sda
brw-rw---- 1 root disk 8, 0 26 mei 09:13 /dev/sda
henk@boven:~> 

This is of course also valid for any other program. This means IMHO that your script get it’s information about the partitioning elsewhere and not straight from the partition table (you mention* udev*). Is that a caveat?

This is correct. It queries the udev daemon. It doesn’t read the partition table. Only the option -b requires root privileges because it needs to access the devices to read the boot sectors.

Is that a caveat?

No. It relies on udev, but just like everything else. When you use /dev/disk/by-uuid syntax in /etc/fstab, you rely on udev as well. (An alternative is to use UUID= instead, which reads the superblocks but is slower. That’s what I use). If udev doesn’t create the symlinks, nothing get mounted and nothing will work. udev might occasionnaly fail to create all devices but in my experience - except when the hardware is broken - if affects only Unix partitions (which can only be created after the kernel has read the disklabels, such as BSD or Solaris). Those partitions are not even displayed by fdisk -l, but are listed by lspart, although some size information are missing in the example below, due to the complexity of my disklabels. The size information was originally not missing but incorrect in udev. I did replace incorrect size information with a question mark*.

This example illustrates the differences between fdisk -l and lspart (without any option).

fdisk -l


$ **sudo /sbin/fdisk -l**

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c6dd2

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1              63      514079      257008+   6  FAT16
/dev/sda2        73947195   359229464   142641135   a5  FreeBSD
/dev/sda3       361398240   462061529    50331645   a5  FreeBSD
/dev/sda4       462061591   976768064   257353237    f  W95 Ext'd (LBA)
/dev/sda5       462061593   466254494     2096451   82  Linux swap / Solaris
/dev/sda6       466254558   523156724    28451083+  83  Linux
/dev/sda7       523156788   539944649     8393931   83  Linux
/dev/sda8       539944713   552523544     6289416   83  Linux
/dev/sda9       552523608   586078207    16777300   83  Linux
/dev/sda10      586080256   648556543    31238144   83  Linux
/dev/sda11      648558592   665282559     8361984   83  Linux
/dev/sda12      665284608   712929279    23822336   83  Linux
/dev/sda13  *   712931328   770891775    28980224   83  Linux
/dev/sda14      770893824   783538175     6322176   83  Linux
/dev/sda15      783538308   792197279     4329486   83  Linux
/dev/sda16      792197343   976768064    92285361   83  Linux

lspart


$ **lspart**
Dev  Boot Maj Min  Bsize/Start         Size    Fs    ID    Ver  Model/Mount

sda         8   0        512 B      476,940 GB      mbr    ata   WDC_WD5000AAKS-00A7B2
sda1        8   1           63       514017  vfat    06  FAT16
sda2        8   2     73947195    285282270   ufs    a5      1
sda3        8   3    361398240    100663290   ufs    a5      2
sda4        8   4    462061591    514706474     -    0f      -
sda5        8   5    462061593      4192902  swap    82      2
sda6        8   6    466254558     56902167  ext4    83    1.0
sda7        8   7    523156788     16787862  ext4    83    1.0
sda8        8   8    539944713     12578832  ext4    83    1.0   /tmp
sda9        8   9    552523608     33554600  ext3    83    1.0   /home
sda10       8  10    586080256     62476288  ext4    83    1.0  /
sda11       8  11    648558592     16723968  ext4    83    1.0   /local
sda12       8  12    665284608     47644672  ext4    83    1.0
sda13   *   8  13    712931328     57960448  ext4    83    1.0
sda14       8  14    770893824     12644352  ext4    83    1.0
sda15       8  15    783538308      8658972  ext3    83    1.0
sda16     259   0    792197343    184570722  ext4    83    1.0   /srv
sda17     259   1     82335803    285282270     -    a5      -
sda18     259   2    149444667    134284651   ufs    a5      2
sda19     259   3    283729318     16777216   ufs    a5      2
sda20     259   4    300506534     16777216   ufs    a5      1
sda21     259   5     73947195      8388608   ufs    a5      1
sda22     259   6    325672358     33557107   ufs    a5      1
sda23     259   7    317283750      8388608   ufs    a5      1
sda24     259   8    361398240            ?   ufs    a5      2
sda25     259   9    369786848            ?   ufs    a5      2
sda26     259  10    378175456            ?   ufs    a5      2
sda27     259  11    411729885            ?   ufs    a5      1
sda28     259  12    420118493            ?   ufs    a5      1
sda29     259  13    453672925            ?   ufs    a5      1

This is just the basic ouput of lspart. It can provide much more info. Another example with labels and uuid properties:


$ **lspart - ID_FS_LABEL ID_FS_UUID
**
sda         8   0        512 B      476,940 GB      mbr    ata          -                                     -   WDC_WD5000AAKS-00A7B2
sda1        8   1           63       514017  vfat    06  FAT16     OS_DOS                             46EB-E757
sda2        8   2     73947195    285282270   ufs    a5      1          -                                     -
sda3        8   3    361398240    100663290   ufs    a5      2          -                                     -
sda4        8   4    462061591    514706474     -    0f      -          -                                     -
sda5        8   5    462061593      4192902  swap    82      2          -  0ac89ec3-41c4-4bdb-82c1-bd4a3b11465d
sda6        8   6    466254558     56902167  ext4    83    1.0   UBU_ROOT  1b5bb74c-ecbc-4f19-8d3e-923bd43bb17a
sda7        8   7    523156788     16787862  ext4    83    1.0  UBU_LOCAL  ec552c60-427c-44ec-995c-d569a8eba380
sda8        8   8    539944713     12578832  ext4    83    1.0        TMP  feb186ed-24e2-444d-8a55-6d9fcf6505fb   /tmp
sda9        8   9    552523608     33554600  ext3    83    1.0       HOME  5cd4e12e-fd55-4015-bf4d-b5a78a5f11a2   /home
sda10       8  10    586080256     62476288  ext4    83    1.0   SUS_ROOT  335d63b5-14d8-42d5-97d1-bf8d2108e6b2   /
sda11       8  11    648558592     16723968  ext4    83    1.0  SUS_LOCAL  89cb1fb1-0168-4ebd-a89c-fa3335c41aa7   /local
sda12       8  12    665284608     47644672  ext4    83    1.0       MINT  2c08f8a1-0445-485f-81c1-0c6e5a0b02fd
sda13   *   8  13    712931328     57960448  ext4    83    1.0   FED_ROOT  06448ff2-04ea-453d-9f1c-e3803d9ea77a
sda14       8  14    770893824     12644352  ext4    83    1.0  FED_LOCAL  7c43ab2d-92d3-4dd1-9369-392f3f47f0e8
sda15       8  15    783538308      8658972  ext3    83    1.0   DEB_ROOT  5bb0f8cc-229b-45db-a06c-f7bcb45483ee
sda16     259   0    792197343    184570722  ext4    83    1.0        SRV  f16d1fcb-27a4-4028-8c29-2297d39000b0   /srv, /export/nfs4/srv
sda17     259   1     82335803    285282270     -    a5      -          -                                     -
sda18     259   2    149444667    134284651   ufs    a5      2          -                                     -
sda19     259   3    283729318     16777216   ufs    a5      2          -                                     -
sda20     259   4    300506534     16777216   ufs    a5      1          -                                     -
sda21     259   5     73947195      8388608   ufs    a5      1          -                                     -
sda22     259   6    325672358     33557107   ufs    a5      1          -                                     -
sda23     259   7    317283750      8388608   ufs    a5      1          -                                     -
sda24     259   8    361398240            ?   ufs    a5      2          -                                     -
sda25     259   9    369786848            ?   ufs    a5      2          -                                     -
sda26     259  10    378175456            ?   ufs    a5      2          -                                     -
sda27     259  11    411729885            ?   ufs    a5      1          -                                     -
sda28     259  12    420118493            ?   ufs    a5      1          -                                     -
sda29     259  13    453672925            ?   ufs    a5      1          -                                     -

And here’s a listing of the bootloaders - this option requires root privileges:

$ **lspart -b**
Root User Permissions are required with option -b

$ **sudo lspart -b**
Dev  Boot Maj Min  Bsize/Start         Size    Fs    ID    Ver  BS         Model/Mount

sda         8   0        512 B      476,940 GB      mbr    ata  Grub2      WDC_WD5000AAKS-00A7B2
sda1        8   1           63       514017  vfat    06  FAT16  FAT16    
sda2        8   2     73947195    285282270   ufs    a5      1  FreeBSD  
sda3        8   3    361398240    100663290   ufs    a5      2  FreeBSD  
sda4        8   4    462061591    514706474     -    0f      -  Grub1    
sda5        8   5    462061593      4192902  swap    82      2  -        
sda6        8   6    466254558     56902167  ext4    83    1.0  Grub2    
sda7        8   7    523156788     16787862  ext4    83    1.0  -        
sda8        8   8    539944713     12578832  ext4    83    1.0  -          /tmp
sda9        8   9    552523608     33554600  ext3    83    1.0  -          /home
sda10       8  10    586080256     62476288  ext4    83    1.0  Grub1      /
sda11       8  11    648558592     16723968  ext4    83    1.0  -          /local
sda12       8  12    665284608     47644672  ext4    83    1.0  -        
sda13   *   8  13    712931328     57960448  ext4    83    1.0  Grub2    
sda14       8  14    770893824     12644352  ext4    83    1.0  -        
sda15       8  15    783538308      8658972  ext3    83    1.0  Grub1    
sda16     259   0    792197343    184570722  ext4    83    1.0  -          /srv
sda17     259   1     82335803    285282270     -    a5      -  -        
sda18     259   2    149444667    134284651   ufs    a5      2  -        
sda19     259   3    283729318     16777216   ufs    a5      2  -        
sda20     259   4    300506534     16777216   ufs    a5      1  -        
sda21     259   5     73947195      8388608   ufs    a5      1  FreeBSD  
sda22     259   6    325672358     33557107   ufs    a5      1  -        
sda23     259   7    317283750      8388608   ufs    a5      1  openBSD  
sda24     259   8    361398240            ?   ufs    a5      2  FreeBSD  
sda25     259   9    369786848            ?   ufs    a5      2  -        
sda26     259  10    378175456            ?   ufs    a5      2  -        
sda27     259  11    411729885            ?   ufs    a5      1  NetBSD  
sda28     259  12    420118493            ?   ufs    a5      1  -        
sda29     259  13    453672925            ?   ufs    a5      1  -        

Last but not least, fdisk -l and lspart with GPT disk:

fdisk -l (can not read GPT)


$ **sudo /sbin/fdisk -l
**
WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/sda: 120.0 GB, 120034123776 bytes
256 heads, 63 sectors/track, 14536 cylinders, total 234441648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x9080940a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1  4294967295  2147483647+  ee  GPT

WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT

Disk /dev/sdb: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders, total 234441648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1   234441647   117220823+  ee  GPT


lspart (no problem):


$ **lspart**
Dev  Boot Maj Min  Bsize/Start         Size    Fs                                    ID    Ver  Model/Mount

sda         8   0        512 B      114,473 GB                                      gpt    ata   ADATA_SSD_S510_120GB
sda1        8   1         2048       204800  vfat  C12A7328-F81F-11D2-BA4B-00A0C93EC93B  FAT32 
sda2        8   2       206848       262144     -  E3C9E316-0B5C-4DB8-817D-F92DF00215AE      - 
sda3        8   3       468992    233971712  ntfs  EBD0A0A2-B9E5-4433-87C0-68B6B72699C7      - 

sdb         8  16        512 B      114,473 GB                                      gpt    ata   ADATA_SSD_S510_120GB
sdb1        8  17         2048       319488  vfat  C12A7328-F81F-11D2-BA4B-00A0C93EC93B  FAT32   /boot/efi
sdb2        8  18       321536      4208640  swap  0657FD6D-A4AB-43C4-84E5-0933C84B4F4F      2 
sdb3        8  19      4530176     83892224  ext4  EBD0A0A2-B9E5-4433-87C0-68B6B72699C7    1.0   /
sdb4        8  20     88422400    146018304  ext4  EBD0A0A2-B9E5-4433-87C0-68B6B72699C7    1.0   /home

Notice that partitions ids in GUID are quite different. These are not filesysten UUIDs, just regular partition ids (where MBR would use a single byte, such as 0x83 for Linux or 0x07 for ntfs).

  • I mean, the script does replace incorrect size of ufs partitions with a question mark.

Here’s how to install lspart from repo:

Install my repo if you don’t have it already:


sudo zypper ar [noparse]http://download.opensuse.org/repositories/home:/please_try_again/openSUSE_12.1/[/noparse]  PTA
sudo zypper refresh -r PTA

install the package:


sudo zypper in lspart

The package includes a man page. It’s the only difference with the code posted in #1… and you’ll get updates if any.
The package has no dependencies.

It provides a nice and usefull combination of data from different places in a very understandable table. Things you can of course find by executing several commands and looking at several places. But after all programing was invented to do these menial tasks for you :wink: And I like this one.

On 2012-05-26 16:36, please try again wrote:
>
> It looks the same as fdisk -l but …

Nice script! :slight_smile:

Is this correct?


> Telcontar:~ # lspart --help
> DEVLINKS DEVNAME DEVPATH DEVTYPE DM_DEPS DM_LAST_EVENT_NR DM_MAJOR DM_MINOR DM_NAME DM_OPENCOUNT DM_SBIN_PATH DM_STATE DM_SUSPENDED DM_TABLE_STATE DM_TARGET_COUNT DM_TARGET_TYPES DM_TYPE DM_UDEV_PRIMARY_SOURCE_FLAG DM_UDEV_RULES_VSN DM_UUID FSCK_STATE FSTAB_DIR FSTAB_FREQ FSTAB_NAME FSTAB_OPTS FSTAB_PASSNO FSTAB_TYPE ID_ATA ID_ATA_DOWNLOAD_MICROCODE ID_ATA_FEATURE_SET_AAM ID_ATA_FEATURE_SET_AAM_CURRENT_VALUE ID_ATA_FEATURE_SET_AAM_ENABLED ID_ATA_FEATURE_SET_AAM_VENDOR_RECOMMENDED_VALUE ID_ATA_FEATURE_SET_HPA ID_ATA_FEATURE_SET_HPA_ENABLED ID_ATA_FEATURE_SET_PM ID_ATA_FEATURE_SET_PM_ENABLED ID_ATA_FEATURE_SET_SECURITY ID_ATA_FEATURE_SET_SECURITY_ENABLED ID_ATA_FEATURE_SET_SECURITY_ENHANCED_ERASE_UNIT_MIN ID_ATA_FEATURE_SET_SECURITY_ERASE_UNIT_MIN ID_ATA_FEATURE_SET_SECURITY_FROZEN ID_ATA_FEATURE_SET_SMART ID_ATA_FEATURE_SET_SMART_ENABLED ID_ATA_ROTATION_RATE_RPM ID_ATA_SATA ID_ATA_SATA_SIGNAL_RATE_GEN1 ID_ATA_SATA_SIGNAL_RATE_GEN2 ID_ATA_WRITE_CACHE ID_ATA_WRITE_CACHE_ENABLED ID_BUS
ID_EDD ID_FS_LABEL ID_FS_LABEL_ENC ID_FS_TYPE ID_FS_USAGE ID_FS_UUID ID_FS_UUID_ENC ID_FS_UUID_SUB ID_FS_UUID_SUB_ENC ID_FS_VERSION ID_MODEL ID_MODEL_ENC ID_PART_ENTRY_FLAGS ID_PART_ENTRY_NUMBER ID_PART_ENTRY_SCHEME ID_PART_ENTRY_TYPE ID_PART_TABLE_TYPE ID_PATH ID_REVISION ID_SCSI_COMPAT ID_SERIAL ID_SERIAL_SHORT ID_TYPE ID_WWN ID_WWN_WITH_EXTENSION MAJOR MD_DEVICES MD_DEV_UUID MD_EVENTS MD_LEVEL MD_METADATA MD_NAME MD_UPDATE_TIME MD_UUID MINOR SUBSYSTEM UDEV_LOG UDISKS_DM_TARGETS_COUNT UDISKS_DM_TARGETS_LENGTH UDISKS_DM_TARGETS_START UDISKS_DM_TARGETS_TYPE UDISKS_PARTITION UDISKS_PARTITION_ALIGNMENT_OFFSET UDISKS_PARTITION_NUMBER UDISKS_PARTITION_OFFSET UDISKS_PARTITION_SCHEME UDISKS_PARTITION_SIZE UDISKS_PARTITION_SLAVE UDISKS_PARTITION_TYPE UDISKS_PRESENTATION_NOPOLICY
> Telcontar:~ #

I was looking for the description of the options.


> Telcontar:~ # lspart -b
> Dev  Boot Maj Min  Bsize/Start         Size                 Fs    ID  Ver  BS         Model/Mount
>
> sda         8   0        512 B       476940 GB                   mbr  ata  SUSE Gen   ST3500418AS
> sda1        8   1            -            -               ext2     -  1.0  Grub1      /other/test_a1/boot
> sda2        8   2            -            -               ext2     -  1.0  Grub1      /boot
> sda3        8   3            -            -               ext2     -  1.0  Grub1
....

Notice the size? It can not be that big!

sda1 and sda2 print bold, sda3 prints normal. Does it means something?

Something else… sizes should be GiB, because the current definition of GB
is 10^9 bytes, not 2^30 bytes.


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

On 2012-05-27 00:53, Carlos E. R. wrote:

> Is this correct?
>
>


>> Telcontar:~ # lspart --help
>> DEVLINKS DEVNAME DEVPATH DEVTYPE DM_DEPS DM_LAST_EVENT_NR DM_MAJOR DM_MINOR DM_NAME DM_OPENCOUNT DM_SBIN_PATH DM_STATE DM_SUSPENDED DM_TABLE_STATE DM_TARGET_COUNT DM_TARGET_TYPES DM_TYPE DM_UDEV_PRIMARY_SOURCE_FLAG DM_UDEV_RULES_VSN DM_UUID FSCK_STATE FSTAB_DIR FSTAB_FREQ FSTAB_NAME FSTAB_OPTS FSTAB_PASSNO FSTAB_TYPE ID_ATA ID_ATA_DOWNLOAD_MICROCODE ID_ATA_FEATURE_SET_AAM ID_ATA_FEATURE_SET_AAM_CURRENT_VALUE ID_ATA_FEATURE_SET_AAM_ENABLED ID_ATA_FEATURE_SET_AAM_VENDOR_RECOMMENDED_VALUE ID_ATA_FEATURE_SET_HPA ID_ATA_FEATURE_SET_HPA_ENABLED ID_ATA_FEATURE_SET_PM ID_ATA_FEATURE_SET_PM_ENABLED ID_ATA_FEATURE_SET_SECURITY ID_ATA_FEATURE_SET_SECURITY_ENABLED ID_ATA_FEATURE_SET_SECURITY_ENHANCED_ERASE_UNIT_MIN ID_ATA_FEATURE_SET_SECURITY_ERASE_UNIT_MIN ID_ATA_FEATURE_SET_SECURITY_FROZEN ID_ATA_FEATURE_SET_SMART ID_ATA_FEATURE_SET_SMART_ENABLED ID_ATA_ROTATION_RATE_RPM ID_ATA_SATA ID_ATA_SATA_SIGNAL_RATE_GEN1 ID_ATA_SATA_SIGNAL_RATE_GEN2 ID_ATA_WRITE_CACHE ID_ATA_WRITE_CACHE_ENABLED ID_BUS

> ID_EDD ID_FS_LABEL ID_FS_LABEL_ENC ID_FS_TYPE ID_FS_USAGE ID_FS_UUID ID_FS_UUID_ENC ID_FS_UUID_SUB ID_FS_UUID_SUB_ENC ID_FS_VERSION ID_MODEL ID_MODEL_ENC ID_PART_ENTRY_FLAGS ID_PART_ENTRY_NUMBER ID_PART_ENTRY_SCHEME ID_PART_ENTRY_TYPE ID_PART_TABLE_TYPE ID_PATH ID_REVISION ID_SCSI_COMPAT ID_SERIAL ID_SERIAL_SHORT ID_TYPE ID_WWN ID_WWN_WITH_EXTENSION MAJOR MD_DEVICES MD_DEV_UUID MD_EVENTS MD_LEVEL MD_METADATA MD_NAME MD_UPDATE_TIME MD_UUID MINOR SUBSYSTEM UDEV_LOG UDISKS_DM_TARGETS_COUNT UDISKS_DM_TARGETS_LENGTH UDISKS_DM_TARGETS_START UDISKS_DM_TARGETS_TYPE UDISKS_PARTITION UDISKS_PARTITION_ALIGNMENT_OFFSET UDISKS_PARTITION_NUMBER UDISKS_PARTITION_OFFSET UDISKS_PARTITION_SCHEME UDISKS_PARTITION_SIZE UDISKS_PARTITION_SLAVE UDISKS_PARTITION_TYPE UDISKS_PRESENTATION_NOPOLICY
>> Telcontar:~ #
> 

I re-installed from the repo instead, to see the man page. May I suggest
that you change “-h --help” to display that help text, and add a new option
like “–help prop” to display the properties?

There is some info that could also be interesting: start/end sector of the
partition table, for those that ask about resizing questions. I don’t know
if that is available in the properties list, I’m not familiar with it.

I’m looking at the columns and I see the size column is empty for most
partitions :-?


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

Very nice please_try_again and great addition to findgrub. lspart will be another recommended download for our users.

Thank You,

On 2012-05-27 01:46, jdmcdaniel3 wrote:
>
> Very nice please_try_again and great addition to findgrub. lspart will
> be another recommended download for our users.

You know what? It would be nice to have a downloadable rescue iso that
included such tools as usually needed to rescue an openSUSE system, with
those typical problems users have and that we see here :wink:


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

Well, as the author of these scripts, I should let others be the judge, but I tend to agree. Having findgrub and lspart on the live system would save helpers and users a lot of time by debuging and solving boot problems, IMO. Well … what can I say? It’s free.

Carlos, I’ve seen your other posts and will answer your questions later (we don’t sleep but we do eat. lol!)

On 2012-05-27 03:56, please try again wrote:
> (we don’t sleep but we do eat. lol!)

I agree. I’m putting on weight with these nights!


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

Darn good idea

Excellent work @PTA

Oooops! It should have been MB, but I finally decided to print the size in GB, using a floating point division if bc is found, otherwise using bash integer arithmetic.

Offset and partition sizes are missing in your output because these infos are either not available or the properties are different in your udev version. Are you again one or two udev versions behind? lspart ouput on my old Mandriva is similar to the one in your post. It is not fatal. If some properties are not found, they won’t be displayed. The script works fine on openSUSE 12.1, Fedora 16, Ubuntu 11.01/12.04, Mint 12 and ArchLinux.

I don’t have many 11.4 systems anymore, but my iMac is still running 11.4. Interestingly, when I run lspart on it, the start and sizes of partitions are displayed correctly. It’s an hybrid MBR though (dualbooting with OSX).

# lspart -b
Dev  Boot Maj Min  Bsize/Start         Size       Fs                                    ID    Ver  BS         Model/Mount

sda         8   0        512 B       232.88 GB                                         gpt    ata  SUSE Gen   ST3250820AS_Q
sda1        8   1           40       409600     vfat  C12A7328-F81F-11D2-BA4B-00A0C93EC93B  FAT32  FAT32    
sda2        8   2       409640    351051992  hfsplus  48465300-0000-11AA-AA11-00306543ECAC      -  -        
sda3        8   3    351461632      1269544  hfsplus  426F6F74-0000-11AA-AA11-00306543ECAC      -  -        
**sda4        8   4    352731176    135403808     ext4  EBD0A0A2-B9E5-4433-87C0-68B6B72699C7    1.0  Grub1      /export/nfs4, /**

# udevadm --version
166

# rpm -qa udev   
udev-166-6.7.1.x86_64

sda1 and sda2 are mounted.

GB is correct then. I get the size in bytes from udisks and divide it by 2^30 (1073741824) - in the new version (1.2).

which bc &>/dev/null && P=$(echo "scale=3; $P / 1073741824" | bc) || P=$(( $P / 1073741824))

But in the first version, I divided by 2^20. The label should have been “MB”.

Thank you for your help with debugging.

And I think you got it: we will always use lspart with the option -b :wink:

Done in version 1.2.
Looking at the man page of the previous version, it seems that I intended and forgot to do that.

Yes, I answered already. Same problem here on my fileserver running 11.4 and udev 166, but the 11.4 iMac with the same udev version is fine (maybe because of the GPT).

I checked on another server running 12.1 and udev 173. It looks OK (at least the non lvm part)

# lspart -b
Dev  Boot Maj Min  Bsize/Start         Size                 Fs    ID          Ver  BS         Model/Mount

sda         8   0        512 B       232.88 GB                   mbr          ata  SUSE Gen   ST3250310AS
sda1    *   8   1         2048     67100672               ext4    83          1.0  Grub1      /export/nfs4, /
sda2        8   2     67102720     67104768               ext4    83          1.0  Grub2    
sda3        8   3    134207488     16771072               ext4    83          1.0  -        
sda4        8   4    150978560    337416192                  -    0f            -  -        
sda5        8   5    150980608     16771072               ext4    83          1.0  -          /local, /export/nfs4/local
sda6        8   6    167753728     16769024               ext4    83          1.0  -        
sda7        8   7    184524800    134221824               ext4    83          1.0  -          /srv
sda8        8   8    318748672    134219776               ext4    83          1.0  -          /home
sda9        8   9    452970496     16771072               ext4    83          1.0  -          /tmp, /export/nfs4/tmp
sda10       8  10    469743616     18632704               swap    82            2  -        

sdb         8  16        512 B     1,863.02 GB                   mbr          ata  None       WDC_WD20EARS-00MVWB0
sdb1        8  17         2048   3907026944  linux_raid_member    fd          1.0  -        

sdc         8  32        512 B     1,863.02 GB                   mbr          ata  None       WDC_WD20EARS-00MVWB0
sdc1        8  33         2048   3907026944  linux_raid_member    fd          1.0  -        

md0         9   0        512 B     1,863.02 GB                     -  LVM2\x20001  -          
dm-0      253   0            -            -               ext4     -          1.0  -          /export/nfs4/data, /data
dm-1      253   1            -            -               ext4     -          1.0  -          /shome, /export/nfs4/home
dm-2      253   2            -            -               ext4     -          1.0  -          /src, /export/nfs4/src
dm-3      253   3            -            -               ext4     -          1.0  -          /ssrv, /export/nfs4/srv

Maybe you could try lspart on 12.1 next time you boot a live system. You should see these info.

On 05/27/2012 12:16 PM, please try again wrote:
> Done in version 1.2.

probably obvious to all others, but i have no idea where 1.2 lives…
(i guess the script in the of this thread’s post #1 is pre-1.2 ?)


dd

Version 1.2 is available in repo. I fixed the HDD size issue and the options for short help and listing all properties. Ufs partition type now includes file system version (1 or 2). I don’t know why I didn’t print this info in standard output, because this is the reason why I originally wrote this script.

Here’s the latest code:

#! /bin/bash
#: Title       : lspart
#: Date Created: Mon Apr 30 13:58:35 PDT 2012
#: Last Edit   : Sun May 27 00:43:25 PDT 2012
#: Author      : Agnelo de la Crotche (please_try_again) 
#: Version     : 1.2
#: License     : GPL
#: Description : list partition properties from udev 
#:             : this is based of halinfo but using udev as default 
#: Requires:   : udev & udisks
#:
#: Copyright (C) 2012 by Agnelo de la Crotche
#: ------------------------------------------------------------------

# default properties if lspart is run without arguments (Do not chnange!)
properties="ID_MODEL ID_PART_TABLE_TYPE ID_PART_ENTRY_SCHEME ID_BUS UDISKS_PARTITION_FLAGS MAJOR MINOR UDISKS_PARTITION_OFFSET UDISKS_PARTITION_SIZE ID_PART_ENTRY_SIZE ID_FS_TYPE UDISKS_PARTITION_TYPE ID_FS_VERSION ID_FS_USAGE"

# color for hdd devices 
HDDC=$(tput sgr0)$(tput setaf 1)  # red

# (Some) Boot sector signatures
BS5272="Grub1"
BSaa75="Grub1"
BS48eb="Grub1"
BS63eb="Grub2"
BS7c3c="Grub2"
BS020="Grub2"
BS6616="FAT16"
BS19d="FAT32"
BS6f74="FAT32"
BS745="FAT32"
BSe3e1="FreeBSD"
BS6639="NetBSD"
BS8c7="openBSD"
BS8cd="Win XP"
BS55aa="Win7/Vista"
BSc031="Generic"
BSc033="Generic"
BS8ec031="SUSE Gen"
BS8ec033="MS Gen"
BSb8fa="None"

udevadm=/sbin/udevadm
udisks=$(which udisks 2>/dev/null)

[ -x $udevadm ] || exec echo "udevadm not found"
[ -x $udisks ]  || exec echo "udisks not found"

# Make sure we have root privileges for option -g
if [ "$1" == "-b" -o "$1" == "--boot" ] ; then
	if [[ $UID -ne 0 ]]; then
	  id -Gn | grep -q wheel && exec sudo $0 $@ || exec echo "Root User Permissions are required with option -b"
	fi
fi

prg=$(basename $0)


function syntax {
exec cat << EOFSYNTAX
$prg list partitions on standard output

usage:   lspart [options] [-] [property property ...]

options: 
       -b --boot                 prints boot sector signatures (requires sudo or root).
       -l --links                prints all device links.
       -p --properties           lists available properties.
       -h --help                 displays this help.
       - property [property...]  displays additional properties.
EOFSYNTAX
}

case $1 in
	"-h"|"--help") syntax ;;
	"-p"|"--properties")
		P=""
		for dev in $(cat /proc/partitions | awk 'NR>2{ print $4}')  ; do 
			P="$P $($udevadm info --query=property --name=$dev | awk -F "=" '{print $1};')"
		done
		echo $P | tr " " "
" | sort -u | tr "
" " "
		echo ; exit ;;
	"-l"|"--links") properties="DEVLINKS" ;;
	"-b"|"--boot") shift ; HEADER=1 ; BS=1 ;;
	"-") shift ; uproperties="$@" ; properties="$properties $@" ;;
	"")	 HEADER=1 ;;
	*) uproperties="$@" ; properties="$@" ;;
esac

properties=$(echo $properties | tr -cd "[:alnum:]_[:space:]")
PROPERTIES=$(echo $properties | tr " " "|")
properties="DEV $properties"

i=-1
for dev in $(cat /proc/partitions | awk 'NR>2{ if ($1 != 11) print $4}')  ; do
	let i++
	DEV[$i]=$dev
	eval $($udevadm info --query=property --name=$dev | awk -F "=" 'BEGIN {I='$i'} ; /'$PROPERTIES'/ {printf "%s[%s]=\"%s\";", $1, I, $2}')
done

echo ${ID_PART_TABLE_TYPE[li]} | grep -q 'gpt' && ID_width=38 || ID_width=6
[/li]Fs_width=$(($(echo ${ID_FS_TYPE[li]} | tr " " "[/li]" | wc -L)+2))
Ver_width=$(($(echo ${ID_FS_VERSION[li]} | tr " " "[/li]" | wc -L)+2))

if [ "$HEADER" ]; then
	[ "$BS" ] && Model="BS         Model/Mount" || Model="Model/Mount"
	printf "Dev  Boot Maj Min  Bsize/Start         Size%${Fs_width}s%${ID_width}s%${Ver_width}s  %s
" "Fs" "ID" "Ver" "$Model"
fi

for (( j=0 ; j <= $i ; j++ )) ; do
	dev=${DEV[$j]}
	C=$(tput sgr0) ; MP=""
	
	if [ ${#dev} -eq 3 ]; then
		C=$HDDC
		MP="  ${ID_MODEL[$j]}"
		bsize=$(udisks --show-info /dev/$dev | sed -n 's/.*block size:[^0-9]*//p')
		bsize=${bsize:-512}
	else
		C=$(tput sgr0)
		mounted=$($udisks --show-info /dev/$dev | awk '/is mounted/ { print $NF }')
		if [ $mounted -eq 1 ] ; then
			C=$C$(tput bold)
			MP=$($udisks --show-info /dev/$dev | sed -n 's/mount paths:[ 	]*//p')
		fi
	fi

	for p in ${properties} ; do
		L=0 ; P=""
		case "$p" in
		"ID_PART_ENTRY_SIZE"|"ID_MODEL"|"ID_PART_TABLE_TYPE"|"ID_PART_ENTRY_SCHEME"|"ID_BUS"|"ID_FS_USAGE") 
			[ "${uproperties}" == "${uproperties##*$p}" ] && continue ;;
		"DEVLINKS") echo " ${DEVLINKS[$j]}" | tr " " "
" ;;
		"DEV") [ ${#dev} -eq 3 ] && printf "
" ; printf "%s%-7s" $C $dev ; continue ;;
		"UDISKS_PARTITION_OFFSET")
			L=11
			if [ ${#dev} -gt 3 -a "${UDISKS_PARTITION_OFFSET[$j]}" ]; then
				P="$((${UDISKS_PARTITION_OFFSET[$j]}/$bsize))" 
			elif [ ${#dev} -eq 3 ]; then
				P="$bsize B"
			fi ;;
		"UDISKS_PARTITION_SIZE")
			L=11
			if [ ${#dev} -eq 3 ]; then
				P=$(($($udisks --show-info /dev/$dev | sed -n 's/^ *size: *//p')*1))
				P=${P:-0} ; P=$(($P*1));
				which bc &>/dev/null && P=$(echo "scale=3; $P / 1073741824" | bc) || P=$(( $P / 1073741824))
				printf "%'12.2f" $P ; continue

			elif [ "${ID_FS_TYPE[$j]}" == "ufs" ]; then
				if [ "${ID_PART_ENTRY_SIZE[$j]}" ]; then
					P="${ID_PART_ENTRY_SIZE[$j]}"
				elif [ "${UDISKS_PARTITION_SIZE[$j]}" ];then 
					P="$((${UDISKS_PARTITION_SIZE[$j]}/$bsize))"
				else
					P="-"
				fi
				if [ "${ID_PART_ENTRY_SCHEME[$j]}" == "dos" ] ; then
					psize=$P
				else
					[ $P -eq $psize ] && P="?"
				fi 
			else
				[ "${UDISKS_PARTITION_SIZE[$j]}" ] && P="$((${UDISKS_PARTITION_SIZE[$j]}/$bsize))"
				[ "$psize" ] && [ $P -eq $psize ] && [ "x${ID_FS_USAGE[$j]}" == "x" ] && P="?"
			fi ;;
		"UDISKS_PARTITION_FLAGS")
			[ "${UDISKS_PARTITION_FLAGS[$j]}" ] && P="*" || P=" " ; L=1 ;;
		"UDISKS_PARTITION_TYPE")
			if [ ${#dev} -eq 3 ]; then
				P=${ID_PART_TABLE_TYPE[$j]} ; P=${P/dos/mbr}
			else
				P=${UDISKS_PARTITION_TYPE[$j]} ; P=${P/0x/}
			fi ;;
		"ID_FS_TYPE")
			if [ ${#dev} -eq 3 ]; then
				printf " %-${Fs_width}s" "GB" ; continue
			else
				[ "${ID_FS_TYPE[$j]}" == "ufs" ] && P="${ID_FS_TYPE[$j]}${ID_FS_VERSION[$j]}"
			fi ;;
		"ID_FS_VERSION")
			if [ ${#dev} -eq 3 ]; then
				P=${ID_BUS[$j]}
			fi ;;
		"MAJOR"|"MINOR") L=2 ;
		esac
		[ "$P" ] || eval 'P=${'$p[$j]} ; P=${P:--}
		[ $L -eq 0 ] && L=$(eval echo '${'$p'[@]}' | tr " " "
" | wc -L)
		let L++
		printf "%s%${L}s " "$C" "$P"
	done

	if [ "$BS" ] ; then
		if [ ${#dev} -eq 3 ] ; then
			B=$(hexdump -v -n 2 -e '"%02x"' /dev/$dev)
		else
			B=$(hexdump -v -s 128 -n  2 -e '/1 "%x"' /dev/$dev)
		fi
		bs=BS${B} ; bs=${!bs} ; bs=${bs:-0x$B}
		if [ "$bs" == "Generic" ];then
			B=$(hexdump -v -n 3 -e '"%02x"' /dev/$dev)
			bs=BS${B} ; bs=${!bs} ; bs=${bs:-0x$B}
		fi
		[ "$bs" == "0x00" ] && bs="-"
		printf " %-9s" "$bs"
	fi

	printf "%s%s
" $C "$MP"
done

Thank you, Carl.

Wonderful script, PTA, thanks a lot.

@Carlos: on the rescue iso idea: yep, brilliant idea.
Ever done experimenting with SUSE Studio? That should be capable of doing such a job, i.e. pick some default template, like a KDE LiveCD, have the scripts installed in the live environment. Since they’re available in PTA’s repo, that’s not too hard to do. Maybe a thorough survey on what should be available in such a openSUSELiveRescueImage would be a good starter. I bet James can come up with a name that delivers one of these nice abreviations :smiley:

To add to the idea of a rescue CD: I’ve been walking around far too busy working to start working on some thought I already had: to create a script that finds the “/” partition(s) on a machine, finds out the openSUSE (linux distro) version(s) installed, then provides a simple menu “take over” the installed openSUSE version. I’ve been using this an awful lot, for things like bootloader repair, kernel downgrades etc.
The code I use after booting from a liveCD, opening a terminal window, and finding sdX# as the “/” of the installed openSUSE


mount /dev/sdX#
mount --bind /dev /mnt/dev
chroot /mnt
mount /proc
mount /sys

still love the simplicity of this. The rescue scripts could easily be included in the “take over”.

You could have used os-prober, I guess (maybe you did?). If not, take a look at the file /usr/lib/os-probes/mounted/90linux-distro in package os-prober. You can add other probes in this file or add other scripts in this directory (I did add some to detect the BSD OSes) This is the method I have been using in updategrub since the beginning and this is also the method used by Grub2 to create boot entries for other distros/releases. It skips the root partition of the running system, meaning it won’t add a boot entry for openSUSE in the boot menu of a running openSUSE of the same release, but if you’re on a live system, it should find all your linux root partitions. You can then use the output of os-prober to create menus in other scripts. Here’s an example of an os-prober output:

# os-prober
  No volume groups found
/dev/sda1:Windows NT/2000/XP (loader):Windows:chain
/dev/sda13:Arch Linux (rolling):archlinux:linux
/dev/sda16:Debian GNU/Linux (squeeze/sid):Debian:linux
/dev/sda2:OpenBSD:OpenBSD 4.7:openbsd
/dev/sda3:FreeBSD:FreeBSD 8.1-RELEASE:freebsd
/dev/sda6:Ubuntu 12.04 LTS (12.04):Ubuntu:linux
/dev/sdb1:Windows NT/2000/XP (loader):Windows1:chain
/dev/sdb3:FreeBSD:FreeBSD 7.0-RC1:freebsd
/dev/sdb6:Mandriva Linux 2010.2 (2010.2):MandrivaLinux:linux

It didn’t find openSUSE because I am on openSUSE. Thus it skipped openSUSE root partition. It didn’t find Mint (this time), because of a bug I intend to solve. The os-prober version in my repo includes my own patches and bug fixes*: it would allow openSUSE to detect Ubuntu, Mint, etc and provides support for ufs2 file sytem and BSD OSes.

  • against version 1.52 actually, while the version in 12.2 is 1.49 and in 12.1 … I don’t know, but I’m afraid it’s old.