2

The simple way to check if disk include filesystem is to do:

mount /grid/sdb /mnt

and if sdb or other /dev/sdx have file-system then mount will be succeeded, if not. Probably file system exists!

But this is an ugly way to check that.

What the other elegant alternative to check file-system on disk?

My target is to check if file-system already configured on disk's as /dev/sdb - /dev/sdx.

peterh
  • 4,914
  • 13
  • 29
  • 44
shalom
  • 451
  • 12
  • 26

1 Answers1

2

Your best shot to check filesystem on disks is the lsblk --output NAME,FSTYPE,LABEL,UUID,MODE

It is a list block devices command which will output all your block, hard devices on your machine. With theese option you will get something you want to achieve:

$ sudo lsblk --output NAME,FSTYPE,LABEL,UUID,MODE
NAME        FSTYPE LABEL     UUID                                 MODE
sda                                                               brw-rw----
├─sda1      ntfs   WinHyperX 2D6BFC4E0CDCFAD8                     brw-rw----
├─sda2      ext4   HyperX    ef761208-bab3-4a26-87d2-ed21a7f5a1bb brw-rw----
└─sda3      swap             74259007-a80b-4866-b059-0bdbe6331040 brw-rw----
sdb                                                               brw-rw----
└─sdb1      ext4   4TB       91e32977-0656-45b8-bcf5-14acce39d9c2 brw-rw----
sr0                                                               brw-rw----
mmcblk0                                                           brw-rw----
└─mmcblk0p1 exfat            9C33-6BBC                            brw-rw----

Just to add, if you just simply want to see if there is or not a filesystem on a disk and you dont want to know which or what is it you could also use this command file -s /dev/sda1 or even list fdisk -l which I think shows all disks and returns error when disk has no filesystem on it.

Andrej
  • 34
  • 3