#!/bin/sh [ "$(id -u)" = 0 ] || exec sudo $0 "$@" get() { btrfs filesystem show / | sed -Ene 's?^\t*devid +([^ ]+) .* path ([^ ]+)?\1 \2?p' } go() { set -- found= while read id path do case "$path" in /dev/ram*) return ;; /dev/mapper/samizdatcrypt) found=y; continue ;; *) set -- "$@" "$id" esac done [ $# = 0 ] && return [ ! "$found" ] && return btrfs device remove "$@" / } get | go