Bash – List partition type GUID’s for all disks from command line

bashblock-devicecommand linedisk

I need to list the partition type GUID's from the command line.

Note: This is not the same as the partition UUID.

Basically I'm needing to search for all disks that have the Ceph OSD type GUID:

4FBD7E29-9D25-41B8-AFD0-062C0CEFF05D

The intention is to emulate some things done with ceph-disk (python) in bash script on CoreOS. Why? so I can mount them to the appropriate place automatically with ceph-docker.

Best Answer

This was my ultimate solution using blkid -p

function find_osds()
{
    local osds
    declare -a dev_list
    mapfile dev_list < <(lsblk -l -n -o NAME --exclude 1,7,11) # note -I not available in all versions of lsblk, use exclude instead
    for dev in "${dev_list[@]}"; do
        dev=/dev/$(trim "$dev")
        if blkid -p "$dev" | fgrep -q '4fbd7e29-9d25-41b8-afd0-062c0ceff05d'; then
            osds+=($dev)
        fi
    done
    echo "${osds[@]}"
}
Related Question