Skip to main content
added 138 characters in body
Source Link
Chris Davies
  • 128k
  • 16
  • 178
  • 323

Here's a possible approach. Determine the root partition. Then identify its device. Finally exclude it from the list of devices.

partition=$(
    mount |
    awk '$3 == "/" { print substr($1,6) }'
)
echo "Root partition: $partition"

device=$(
    lsblk -i -o NAME |
    tac |
    awk -v partition="$partition" '
        BEGIN { re = "-" partition "$" }
        $0 ~ re { x++ }
        x && /^[a-z]/
    '
)
echo "Root device: $device"

lsblk -d -o NAME,SIZE --sort SIZE |
    awk -v device="$device" '$1 != device'

It may not work where root is on an indirect filesystem such as LVM, LUKS or RAID. I don't have a system to hand where I can test that

Here's a possible approach. Determine the root partition. Then identify its device. Finally exclude it from the list of devices.

partition=$(
    mount |
    awk '$3 == "/" { print substr($1,6) }'
)
echo "Root partition: $partition"

device=$(
    lsblk -i -o NAME |
    tac |
    awk -v partition="$partition" '
        BEGIN { re = "-" partition "$" }
        $0 ~ re { x++ }
        x && /^[a-z]/
    '
)
echo "Root device: $device"

lsblk -d -o NAME,SIZE --sort SIZE |
    awk -v device="$device" '$1 != device'

Here's a possible approach. Determine the root partition. Then identify its device. Finally exclude it from the list of devices.

partition=$(
    mount |
    awk '$3 == "/" { print substr($1,6) }'
)
echo "Root partition: $partition"

device=$(
    lsblk -i -o NAME |
    tac |
    awk -v partition="$partition" '
        BEGIN { re = "-" partition "$" }
        $0 ~ re { x++ }
        x && /^[a-z]/
    '
)
echo "Root device: $device"

lsblk -d -o NAME,SIZE --sort SIZE |
    awk -v device="$device" '$1 != device'

It may not work where root is on an indirect filesystem such as LVM, LUKS or RAID. I don't have a system to hand where I can test that

Source Link
Chris Davies
  • 128k
  • 16
  • 178
  • 323

Here's a possible approach. Determine the root partition. Then identify its device. Finally exclude it from the list of devices.

partition=$(
    mount |
    awk '$3 == "/" { print substr($1,6) }'
)
echo "Root partition: $partition"

device=$(
    lsblk -i -o NAME |
    tac |
    awk -v partition="$partition" '
        BEGIN { re = "-" partition "$" }
        $0 ~ re { x++ }
        x && /^[a-z]/
    '
)
echo "Root device: $device"

lsblk -d -o NAME,SIZE --sort SIZE |
    awk -v device="$device" '$1 != device'