5

On my up-to-date Arch Linux, lsblk works fine without sudo:

$ lsblk -o NAME,FSTYPE
NAME   FSTYPE
sda    
├─sda1 ext4
├─sda2 ext4
├─sda3 swap
├─sda4 
└─sda5 ext4
sr0    
$ lsblk --version     
lsblk from util-linux 2.26.2

On my Ubuntu 14.04, getting the filesystem types needs sudo:

$ lsblk -o NAME,FSTYPE
NAME                    FSTYPE
sda                     
├─sda1                  
├─sda2                  
├─sda3                  
├─sda4                  
├─sda5                  
├─sda6                  
│ └─lvmg-homelvm (dm-0) 
└─sda7                  
sdb                     
└─sdb1                  
  └─lvmg-homelvm (dm-0) 
$ sudo lsblk -o NAME,FSTYPE
NAME                    FSTYPE
sda                     
├─sda1                  ntfs
├─sda2                  ntfs
├─sda3                  ext4
├─sda4                  
├─sda5                  btrfs
├─sda6                  LVM2_member
│ └─lvmg-homelvm (dm-0) btrfs
└─sda7                  swap
sdb                     
└─sdb1                  LVM2_member
  └─lvmg-homelvm (dm-0) btrfs
$ apt-cache policy util-linux
util-linux:
  Installed: 2.20.1-5.1ubuntu20.4
  Candidate: 2.20.1-5.1ubuntu20.4

Why? And which other columns need sudo?


Additional info:

On Arch:

$ ls -l /dev/sd*
brw-rw---- 1 root disk 8, 0 Jun 19 16:19 /dev/sda
brw-rw---- 1 root disk 8, 1 Jun 19 16:19 /dev/sda1
brw-rw---- 1 root disk 8, 2 Jun 19 16:19 /dev/sda2
brw-rw---- 1 root disk 8, 3 Jun 19 16:19 /dev/sda3
brw-rw---- 1 root disk 8, 4 Jun 19 16:19 /dev/sda4
brw-rw---- 1 root disk 8, 5 Jun 19 16:19 /dev/sda5
$ groups
wheel locate systemd-journal networkmanager fuse muru

(My primary group is muru, not wheel, despite what the order may suggest.)

On Ubuntu:

$ ls -l /dev/sd*
brw-rw---- 1 root disk 8,  0 Jun 12 17:05 /dev/sda
brw-rw---- 1 root disk 8,  1 Jun 12 17:05 /dev/sda1
brw-rw---- 1 root disk 8,  2 Jun 12 17:05 /dev/sda2
brw-rw---- 1 root disk 8,  3 Jun 12 17:05 /dev/sda3
brw-rw---- 1 root disk 8,  4 Jun 12 17:05 /dev/sda4
brw-rw---- 1 root disk 8,  5 Jun 12 17:05 /dev/sda5
brw-rw---- 1 root disk 8,  6 Jun 12 17:05 /dev/sda6
brw-rw---- 1 root disk 8,  7 Jun 12 17:05 /dev/sda7
brw-rw---- 1 root disk 8, 16 Jun 12 17:05 /dev/sdb
brw-rw---- 1 root disk 8, 17 Jun 12 17:05 /dev/sdb1
$ groups
muru adm cdrom sudo dip plugdev lpadmin sambashare debian-tor libvirtd autopilot

On Arch:

$ stat -c "%A %U %G" `which lsblk`
-rwxr-xr-x root root

On Ubuntu:

$ stat -c "%A %U %G" `which lsblk`
-rwxr-xr-x root root
muru
  • 69,900
  • 13
  • 192
  • 292
  • What do `ls -l /dev/sd*` and `groups` produce on both systems? – Stephen Kitt Jun 19 '15 at 19:15
  • @StephenKitt added output. – muru Jun 19 '15 at 19:19
  • is `lsblk` sgid disk or sgid root on Arch? – Jeff Schaller Jun 20 '15 at 00:45
  • It's possible that Arch and Ubuntu compiled the package with different flags that then cause a difference in non-root runtime behavior. In fact, I see them reporting different versions of util-linux altogether! Perhaps the behavior of lsblk changed in between. – Jeff Schaller Jun 20 '15 at 03:08
  • See https://launchpad.net/ubuntu/+source/util-linux/+changelog at section 2.25.2-4 – Jeff Schaller Jun 20 '15 at 03:11
  • 1
    `lsblk` has always worked for regular users on arch (all columns available) so it's not a version problem. The properties are read via udev db or, if that's not available, via libblkid if you're root (see [lsblk.c](https://github.com/karelzak/util-linux/blob/master/misc-utils/lsblk.c) lines 497-607). Most likely debian/ubuntu & co have different policies/permissions/whatever on their udev... I don't know, I don't use those distros... Are you able to get those properties (UUID, FSTYPE etc) as a regular user via _udevadm_ on ubuntu/debian e.g `udevadm info -x /dev/sdb1` ? – don_crissti Jun 20 '15 at 10:32
  • @JeffSchaller yes, `lsblk -o NAME,FSTYPE,LSBLK` does work on 15.04. – muru Jun 20 '15 at 12:22
  • @don_crissti yes, `ID_FS_UUID` and `ID_FS_TYPE` are listed with correct values when I ran `udevadm info -x /dev/sdaN`. – muru Jun 20 '15 at 12:24
  • @don_crissti per the link in my previous comment: "util-linux (2.25.2-4ubuntu2) vivid; urgency=low * Add missing libudev-dev build-dependency. This makes the "LABEL" information of lsblk available for non-root users (closes: #776905) -- Michael Vogt – Jeff Schaller Jun 20 '15 at 14:52
  • @JeffSchaller Ok, that, combined with manual testing showing that `FSTYPE`, `UUID`, `LABEL` are the only fields which need `sudo` answers the question. Could you post an answer? – muru Jun 21 '15 at 23:37

1 Answers1

2

The behavior of lsblk changed in util-linux at version 2.25.2-4:

util-linux (2.25.2-4ubuntu2) vivid; urgency=low

  • Add missing libudev-dev build-dependency. This makes the "LABEL" information of lsblk available for non-root users

(closes: #776905)

-- Michael Vogt Tue, 03 Feb 2015 09:06:46 +0100

@muru did additional testing to determine that FSTYPE, UUID, and LABEL are the only fields which need sudo in util-linux version 2.20.1-5.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
  • I think the post should clearly say _"The behavior changed in util-linux at version_ **2.25.2-4ubuntu/debian** as this was never a `lsblk/util-linux` problem (as I said in my comment below the answer) but [stuff specific to those distros](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=776905). The versions you mention in the answer have actually nothing to do with `lsblk/util-linux` upstream version number and changelog. Similarly, _FSTYPE, UUID, and LABEL are the only fields which need sudo in util-linux version_ **2.20.1-5ubuntu/debian** – don_crissti Oct 24 '15 at 12:24