大网数据广告活动
服务器运维问答

How to know if some data already exists on a device disk?

· 52CE 我爱测

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 t…

问题原文

原帖链接 · shalom · CC BY-SA 3.0

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.

已采纳解答

原帖链接 · Andrej · CC BY-SA 3.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-08-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。