0

I need to find out on what disk a specific filesystems on my server is located. For this case, let's use my /home directory as an example:

[root@master playbooks]# df -h /home
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/rl-home  4.0G   62M  4.0G   2% /home

[root@master playbooks]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 16.7G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 15.7G 0 part ├─rl-root 253:0 0 10G 0 lvm / ├─rl-swap 253:1 0 1.7G 0 lvm [SWAP] └─rl-home 253:2 0 4G 0 lvm /home sr0 11:0 1 1024M 0 rom

So for the /home filesystem, I would like to get sda or sda2 at least.

I would like to restrain from some complex awk commands.

Artur Meinild
  • 31,035
John Ronald
  • 2,526

2 Answers2

4

Use the df command combined with a very simple grep and awk:

df | grep "search string" | awk '{ print $1 }'

So for instance:

df | grep "/home" | awk '{ print $1 }'

Result in:

/dev/sda2

In the case of an LVM volume, you'll the volume as a result instead of the physical disk (since this is the way LVM works).

Artur Meinild
  • 31,035
4

You can use findmnt to get the device (well, whatever's listed in df) using:

findmnt /home -n -o source

(See also, this other answer by me for looking up the UUID of the source.)

muru
  • 207,228