Linux – How to determine the block device booted from in a shell script

block-devicelinuxshell-scripting

I'm crafting up a shell script (to be called by cron) that runs smartctl on the booted disk on a weekly basis. Is there a fairly universal way to determine what the boot block device is (IE – /dev/sda, /dev/hdb, etc)? The expected install would be standard, I think I could get away with using grep " / " on /etc/fstab, I'm just wondering if there's a more graceful way.

This script will specifically be deployed on Fedora and possibly Ubuntu boxes.

Best Answer

df -P / | tail -n 1 | awk '/.*/ { print $1 }'

Will return the root FS block device. Not necessarily the boot device though.

Better question might be why you're not scanning SMART on all the disks in the server?