How to check the filesystem type of a logical volume using lvm or any other utility?

For example, if my logical volume is /dev/vg1/lv1 then how to check its filesystem type?

I have made a ext4 filesystem in the logical volume using mkfs -t ext4 /dev/vg1/lv1. But don't know how to verify it. I could not see any option for thin is lvm?

  • Does anyone know how this is done on C/C++ level ? – Lothar May 14 '19 at 12:22

Same as you would with any other block device. e.g.

file -s /dev/vg1/lv1

If it's ext4, it'll say something like:

/dev/vg1/lv1: Linux rev 1.0 ext4 filesystem data, UUID=xxxx, volume name "yyyy" (needs journal recovery) (extents) (large files) (huge files)

Alternatively, you could run blkid /dev/vg1/lv1. That would report something like:

/dev/vg1/lv1: LABEL="yyyy" UUID="xxxx" TYPE="ext4"

From man file:

-s, --special-files

Normally, file only attempts to read and determine the type of argument files which stat(2) reports are ordinary files. This prevents problems, because reading special files may have peculiar consequences. Specifying the -s option causes file to also read argument files which are block or character special files.

This is useful for determining the filesystem types of the data in raw disk partitions, which are block special files. This option also causes file to disregard the file size as reported by stat(2) since on some systems it reports a zero size for raw disk partitions.

  • above commmands worked. Just wondering , there is no lvm command for this ? – sps Oct 10 '15 at 14:26
  • Doing this on my /dev/sdb1,2,5 - which are LVM partitions outputs /dev/sdb#: block special – Adeerlike Dec 18 '16 at 13:47
  • did you run just file, or file -s? -s (or --special-files) tells file to identify block or character special files. see man file and search for --special-files. – cas Dec 19 '16 at 0:10
  • my file needed --dereference so it could see through the symbolic link of /dev/vg0/lv0 – Felipe Alvarez Jan 31 '17 at 5:46

Use lsblk -f.

$ lsblk -f
    NAME            FSTYPE      LABEL          UUID                                   FSAVAIL FSUSE% MOUNTPOINT
    ├─sda1          ext4                       d2123fec-6c94-426f-b505-8cf3441122cf    742,6M    17% /boot
    └─sda2          LVM2_member                BLt1F3-S5E3-hBRX-Eqya-AUOx-wyxc-a5Yaf4                
      ├─fedora-root xfs                        59935050-8e89-4f7f-bf0f-2f448c4c680b     12,8G    15% /
      └─fedora-swap swap                       5fbca8c7-fd22-4acf-a411-d96a100c8ab2                  [SWAP]
    sr0             iso9660     VBox_GAs_6.0.8 2019-05-13-13-58-35-65  

If the logical volume has multiple partitions, knowing the partition offsets can be helpful.

Use fdisk to read the volume's partition info:

linux1:~ # fdisk -l /dev/vg01/lv001
Disk /dev/vg01/lv001: 80 GiB, 85899345920 bytes, 167772160 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000825ab

Device           Boot   Start       End   Sectors  Size Id Type
/dev/vg01/lv0011           63   3132674   3132612  1.5G 82 Linux swap / Solaris
/dev/vg01/lv0012 *    3132675 167734664 164601990 78.5G 83 Linux

Then use blkid to determine the filesystem type. The -p option performs a deep probe bypassing the local blkid cache file, and capital -O determines the byte offset to inspect. The offset is determined by multiplying the start sector by the sector size; e.g.,

 `expr 3132675 \* 512`

where the backticks are for inlining the expression, and the backslash \* prevents bash from eating the asterisk.

Here's the blkid command used to determine the target filesystem:

linux1:~ # blkid -pO `expr 3132675 \* 512`   /dev/vg01/lv001
/dev/vg01/lv001: UUID="..." VERSION="1.0" TYPE="ext3" USAGE="filesystem" PTTYPE="dos"

which in this example is: ext3.

To access the filesystem, mount the offset:

mount -o offset=`expr 3132675 \* 512`  /dev/vg01/lv001 /mnt/lv001

The above operations performed on SLES 12.4:

linux1:~ # uname -a
Linux linux1 4.12.14-95.6-default #1 SMP Thu Jan 17 06:04:39 UTC 2019 (6af4ef8) x86_64 x86_64 x86_64 GNU/Linux

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.