Indeed it is! Here's an improved function:
Code:
function getrootname() { # returns a string for the device name local rootfs=$(findmnt -n -o SOURCE /) echo $rootfs return # To get the system disk instead of the root device, you can do something like this (remove the `return` above of course) [[ "$rootfs" =~ "mmcblk" ]] && sd=${rootfs%p2} [[ "$rootfs" =~ "/dev/sd" ]] && sd=${rootfs%2} [[ "$rootfs" =~ "nvme0n" ]] && sd=${rootfs%p2} echo $sd}Thanks for that, rpdom. Always better to use a supported function than parsing the data yourself.
Statistics: Posted by bls — Wed Jan 17, 2024 4:01 am