lsblk

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

$ lsblk
NAME                     MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda                      253:0    0   40G  0 disk 
└─vda1                   253:1    0   40G  0 part /
vdb                      253:16   0  500G  0 disk 
└─vdb1                   253:17   0  500G  0 part 
  └─dsp--disk01-dsp--adx 252:0    0  499G  0 lvm  /Data
vdc

df

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

$ df -h
Filesystem                        Size  Used Avail Use% Mounted on
/dev/vda1                          40G  6.3G   32G  17% /
devtmpfs                          7.8G     0  7.8G   0% /dev
tmpfs                             7.8G     0  7.8G   0% /dev/shm
tmpfs                             7.8G  456K  7.8G   1% /run
tmpfs                             7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/dsp--disk01-dsp--adx  499G  5.9G  493G   2% /Data
tmpfs

需要注意的是 df 只能输出已挂载的磁盘分区信息,不能显示未挂载的硬盘。
另一个相似的命令是 du,用来显示占用的硬盘空间,例如统计当前目录下文件大小:du -sh *

fdisk

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

$ fdisk -l

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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
Disk label type: dos
Disk identifier: 0x000a5a8a

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    83886079    41942016   83  Linux

Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 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
Disk label type: dos
Disk identifier: 0x4dcd9f83

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   209715199   104856576   83  Linux

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

parted

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

$ parted -l
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  42.9GB  42.9GB  primary  xfs          boot


Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End    Size   Type     File system  Flags
 1      1049kB  107GB  107GB  primary  ext4

lsscsi

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

$ 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 命令可以打印块设备的信息:

$ blkid
/dev/vda1: UUID="4fb2f21e-8b37-4461-9163-eced787a0565" TYPE="xfs" 
/dev/vdb1: UUID="76c15e1b-37bb-4fa0-b1c0-3dc1884ae23a" TYPE="ext4" 

lshw

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

$ 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

exportfs

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

$ 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)

mount

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

$ mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,size=3993864k,nr_inodes=998466,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,net_cls)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/vda1 on / type xfs (rw,relatime,attr2,inode64,noquota)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
/dev/vdb1 on /jddata1 type ext4 (rw,relatime,data=ordered)
tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=800940k,mode=700,uid=1000,gid=1000)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=800940k,mode=700)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=40,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=165670537)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,relatime)

发表评论