title: How to reliably know disk name if one of its partition's name is known
body: <p>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:</p>
  <pre><code># Must be run as root
  if [[ $(fdisk -l $DISKNAME | grep -i 'Disklabel type') = &quot;Disklabel type: gpt&quot; ]]; then
    echo &quot;Yes, its GPT&quot;
  fi
  </code></pre>
  <p>The variable <code>DISKNAME</code> 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 <code>/dev/nvme0</code> and drive name can be <code>/dev/nvme0p1</code>.</p>
  <p>I am searching for a reliable way (not string manipulation) to know the drive name when a partition name is already known.</p>
  <p><strong>EDIT:</strong> I could also ask the user for the drive name but then there is space for user errors.</p>