Linux查看硬盘信息方法总结

本文简要总结Linux查看硬盘信息的方法,基本涵盖普通用户、系统管理员所能接触到的各种命令。

lsblk

lsblk命令用来查看接入到系统中的块设备,默认输出分区、大小、挂载点等信息,一目了然:

tlanyan@node1:~$ lsblk
sda      8:0    0 558.9G  0 disk
├─sda1   8:1    0   488M  0 part
├─sda2   8:2    0     1K  0 part
├─sda5   8:5    0   7.6G  0 part
└─sda6   8:6    0 550.8G  0 part /
sdb      8:16   0 558.9G  0 disk
├─sdb1   8:17   0     1K  0 part
└─sdb5   8:21   0 558.9G  0 part /journal
sdc      8:32   0   1.8T  0 disk /work
sr0     11:0    1  1024M  0 rom

df

df命令用来查看硬盘的使用情况,经常配合-h给出友好的输出:

tlanyan@node1:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev             24G     0   24G   0% /dev
tmpfs           4.8G  2.1M  4.8G   1% /run
/dev/sda6       542G  148G  366G  29% /
tmpfs            24G     0   24G   0% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs            24G     0   24G   0% /sys/fs/cgroup
/dev/sdc        1.8T  1.2T  582G  67% /work
/dev/sdb5       551G  245G  278G  47% /journal

需要注意的是df只能输出已挂载的磁盘分区信息,不能显示未挂载的硬盘。

另一个相似的命令是du,用来显示占用的硬盘空间,例如统计当前目录下文件大小:du -sh *

fdisk

fdisk是常用的硬盘、分区操作工具,需要root权限执行,-l参数可以打印硬盘信息:

root@node1:~# fdisk -l
Disk /dev/sda: 558.9 GiB, 600127266816 bytes, 1172123568 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: 0xdf3a7994

Device     Boot    Start        End    Sectors   Size Id Type
/dev/sda1  *        2048    1001469     999422   488M 83 Linux
/dev/sda2        1001470 1172121599 1171120130 558.4G  5 Extended
/dev/sda5        1001472   17000447   15998976   7.6G 82 Linux swap / Solaris
/dev/sda6       17002496 1172121599 1155119104 550.8G 83 Linux

Disk /dev/sdb: 558.9 GiB, 600127266816 bytes, 1172123568 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: 0x0006c4c0

Device     Boot Start        End    Sectors   Size Id Type
/dev/sdb1          63 1172118464 1172118402 558.9G  5 Extended
/dev/sdb5         126 1172118464 1172118339 558.9G 83 Linux


Disk /dev/sdc: 1.8 TiB, 2000398934016 bytes, 3907029168 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: 0x7af0ba03

fdisk不支持GPT分区,需要要到下文的parted查看。

parted

parted是一个分区操作工具,需要root权限,否则输出为空:

root@node1:~# parted -l
Model: HITACHI HUS156060VLS600 (scsi)
Disk /dev/sda: 600GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type      File system     Flags
 1      1049kB  513MB   512MB   primary   ext4            boot
 2      513MB   600GB   600GB   extended
 5      513MB   8704MB  8191MB  logical   linux-swap(v1)
 6      8705MB  600GB   591GB   logical   ext4


Model: HITACHI HUS156060VLS600 (scsi)
Disk /dev/sdb: 600GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End    Size   Type      File system  Flags
 1      32.3kB  600GB  600GB  extended
 5      64.5kB  600GB  600GB  logical   ext4


Model: SEAGATE ST2000NM0023 (scsi)
Disk /dev/sdc: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start  End  Size  Type  File system  Flags

lsscsi

lsscsi可以打印SCSI硬盘信息,该命令在Ubuntu中默认没有安装:

tlanyan@node1:~$ lsscsi
[0:0:0:0]    cd/dvd  PLDS     DVD+-RW DH-16ACS JD11  /dev/sr0
[6:0:0:0]    disk    HITACHI  HUS156060VLS600  E516  /dev/sda
[6:0:1:0]    disk    HITACHI  HUS156060VLS600  E516  /dev/sdb
[6:0:2:0]    disk    SEAGATE  ST2000NM0023     0003  /dev/sdc

blkid

blkid命令可以打印块设备的信息:

tlanyan@node1:~$ blkid
/dev/sda6: UUID="93875607-7910-43d3-ac02-32200cfcea1a" TYPE="ext4" PARTUUID="df3a7994-06"
/dev/sda1: UUID="90cfad05-f84b-49fd-ac60-06c5d9c7382c" TYPE="ext4" PARTUUID="df3a7994-01"
/dev/sda5: UUID="66c522a8-b0eb-4a44-9ba9-2765b70eff28" TYPE="swap" PARTUUID="df3a7994-05"
/dev/sdb5: UUID="8a400f90-2390-4b5d-9fd2-58331c1230e2" TYPE="ext4" PARTUUID="0006c4c0-05"
/dev/sdc: LABEL="M-fM-^VM-0M-eM-^MM-7" UUID="8bd7100c-4120-4cf3-8d1e-268d4cf12bac" TYPE="ext4" PTUUID="7af0ba03" PTTYPE="dos"

lshw

lshw命令用来打印硬件的详细信息,打印硬盘信息需要root权限:

root@node1:~# lshw -class disk
  *-disk:0
       description: SCSI Disk
       product: HUS156060VLS600
       vendor: HITACHI
       physical id: 0.0.0
       bus info: scsi@6:0.0.0
       logical name: /dev/sda
       version: E516
       serial: LXWMTVTM
       size: 558GiB (600GB)
       capacity: 690GiB (741GB)
       capabilities: 15000rpm partitioned partitioned:dos
       configuration: ansiversion=6 logicalsectorsize=512 sectorsize=512 signature=df3a7994
  *-disk:1
       description: SCSI Disk
       product: HUS156060VLS600
       vendor: HITACHI
       physical id: 0.1.0
       bus info: scsi@6:0.1.0
       logical name: /dev/sdb
       version: E516
       serial: LXWMTWAM
       size: 558GiB (600GB)
       capacity: 690GiB (741GB)
       capabilities: 15000rpm partitioned partitioned:dos
       configuration: ansiversion=6 logicalsectorsize=512 sectorsize=512 signature=0006c4c0
  *-cdrom
       description: DVD-RAM writer
       product: DVD+-RW DH-16ACS
       vendor: PLDS
       physical id: 0.0.0
       bus info: scsi@0:0.0.0
       logical name: /dev/cdrom
       logical name: /dev/cdrw
       logical name: /dev/dvd
       logical name: /dev/dvdrw
       logical name: /dev/sr0
       version: JD11
       capabilities: removable audio cd-r cd-rw dvd dvd-r dvd-ram
       configuration: ansiversion=5 status=nodisc

mount

mount常用来挂载硬盘、分区等,自然也就可以查看挂载信息:

tlanyan@node1:~$ mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=24697992k,nr_inodes=6174498,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=4944076k,mode=755)
/dev/sda6 on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
/dev/sdc on /work type ext4 (rw,relatime,data=ordered)
/dev/sdb5 on /journal type ext4 (rw,relatime,data=ordered)

exportfs

exportfs命令用来查看NFS共享文件夹,需要root权限:

root@node1:~# exportfs -s
/work  192.168.1.12(rw,wdelay,no_root_squash,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
/work  192.168.1.13(rw,wdelay,no_root_squash,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
/opt  192.168.1.12(ro,wdelay,no_root_squash,no_subtree_check,sec=sys,ro,secure,no_root_squash,no_all_squash)
/opt  192.168.1.13(ro,wdelay,no_root_squash,no_subtree_check,sec=sys,ro,secure,no_root_squash,no_all_squash)

如果你还知道其他命令,欢迎指教。

留言评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Captcha Code