7

Hello the pvs command gives me the following output:

 PV         VG     Fmt  Attr PSize  PFree
 /dev/sd**  ***** lvm2 a-   59.49g 47.49g
 /dev/sd**  ***** lvm2 a-   25.00g  8.00m

This only works if I am root user.

Can a different command be used to get this info as a non-root user.

3
  • I'm not familiar with the pvs command, but maybe fdisk -l /dev/sda or even df command might help you.
    – plesiv
    Mar 9, 2015 at 15:19
  • Probably not. Have you considered using sudo? Mar 9, 2015 at 15:48
  • I used sudo /sbin/pvs, but the non root user had root priviliges, i'm looking for a way that any user can get disk info
    – HSV
    Mar 9, 2015 at 16:08

2 Answers 2

10

Any user can get information with lsblk.  It has options that allow you to get simple output, full detailed or customized.

Try:

  • lsblk

    $ lsblk
    
    NAME                            MAJ:MIN  RM    SIZE  RO  TYPE  MOUNTPOINT
    sda                               8:0     0  238,5G   0  disk
    ├─sda1                            8:1     0      2M   0  part
    ├─sda2                            8:2     0    700M   0  part  /boot
    └─sda3                            8:3     0  206,4G   0  part
      ├─fed21_ssd_pcsolo-swap       253:0     0   29,8G   0  lvm   [SWAP]
      ├─fed21_ssd_pcsolo-root       253:1     0     80G   0  lvm   /
      ├─fed21_ssd_pcsolo-home       253:2     0     50G   0  lvm   /home
      └─fed21_ssd_pcsolo-tmp        253:3     0   46,6G   0  lvm   /tmp
    sdb                               8:16    0    2,7T   0  disk
               ⋮
    
  • lsblk -f (Output info about filesystems)

  • lsblk -b (Print the SIZE column in bytes rather than in a human-readable format) or lsblk -m (Output info about device owner, group and mode)
  • lsblk -O (capital "o") this is full detailed
  • lsblk -o (Specify which output columns to print) you can define custom format
1
  • Yeah but this doesn't show the LVM stats, like cache hits
    – jpalecek
    Mar 20 at 15:51
4

The pvs command is part of lvm. If you, as root, need to enable non-root users this funtionality, you can use setcap, to set the lvm executable permissions to perform actions that are restricted to root by default.
This goes to any executable that needs to do root-privileged actions.

Read more about the file capabilities: http://man7.org/linux/man-pages/man7/capabilities.7.html

An example: BEFORE setcap

 $ pvs
 WARNING: Running as a non-root user. Functionality may be unavailable.
 /run/lvm/lvmetad.socket: connect failed: Permission denied
 WARNING: Failed to connect to lvmetad: Permission denied. Falling back to internal     scanning.
 /run/lvm/lvmetad.socket: connect failed: Permission denied
 /run/lock/lvm/P_global:aux: open failed: Permission denied
 Unable to obtain global lock.

AFTER

setcap "cap_dac_override,cap_dac_read_search,cap_fowner,cap_fsetid,cap_setuid,cap_setpcap,cap_net_bind_service,cap_net_admin,cap_sys_chroot,cap_sys_admin,cap_sys_resource,cap_audit_control,cap_setfcap=+eip" /sbin/lvm 

$ pvs
WARNING: Running as a non-root user. Functionality may be unavailable.
PV         VG            Fmt  Attr PSize  PFree
/dev/sda2  centos        lvm2 a--  15.51g    0
/dev/sdb   DataPool      lvm2 a--  50.00g    0
/dev/sdc   DataPool      lvm2 a--  60.00g    0
/dev/sdd   DBArchivePool lvm2 a--  50.00g    0

Notice that I used much more caps than needed, probably, because I just copied something that I used once, but you might find your minimal set of caps...

Don't forget to quote the caps you want to set.

3
  • I typed in command: cap_dac_override,cap_dac_read_search,cap_fowner,cap_fsetid,cap_setuid,cap_setpcap,cap_net_bind_service,cap_net_admin,cap_sys_chroot,cap_sys_admin,cap_sys_resource,cap_audit_control,cap_setfcap=+eip" /sbin/lvm : but i get > as error. What am I doing wrong? Can I run this command as non root user.
    – HSV
    Mar 9, 2015 at 16:08
  • I edited my answer, so that the command will be clearer. And no, you can't run this command as a non-root user. I wrote that you have to be root to allow this access. After setting the caps, any non-root user should be able to run pvs
    – csny
    Mar 9, 2015 at 16:16
  • Actually I would think of this as a pretty dumb thing to do. For example this allows anyone on your system to modify logical volumes.
    – jpalecek
    Mar 20 at 15:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .