'How to reliably know disk name if one of its partition's name is known
I am working on a linux bash script that takes a disk partition name as user input. It then needs to check if the drive is using GPT or not, for which I use the following if statement:
# Must be run as root
if [[ $(fdisk -l $DISKNAME | grep -i 'Disklabel type') = "Disklabel type: gpt" ]]; then
echo "Yes, its GPT"
fi
The variable DISKNAME has to store the name of the disk drive and not the partition. I could just remove the number at the end of the partition name but that is not consistent with SSDs and NVMes. For example NVMe disk name can be /dev/nvme0 and drive name can be /dev/nvme0p1.
I am searching for a reliable way (not string manipulation) to know the drive name when a partition name is already known.
EDIT: I could also ask the user for the drive name but then there is space for user errors.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
