檢查 Linux 磁碟分割槽和使用情況的實用工具


如果您是一名系統管理員,那麼您應該瞭解這些管理磁碟空間的工具。本文介紹瞭如何在 Linux 中檢查 Linux 磁碟分割槽和使用情況。

Fdisk

Fdisk 是一個基於文字的實用程式。透過使用 fdisk,您可以建立新的分割槽,刪除現有分割槽或更改現有分割槽。

要獲取有關 fdisk 的更多資訊,請使用以下命令:

$ fdisk

示例輸出如下:

Usage:
fdisk [options] change partition table
fdisk [options] -l [] list partition table(s)

Display or manipulate a disk partition table.

Options:
-b, --sector-size          physical and logical sector size
-B, --protect-boot         don't erase bootbits when create a new label
-c, --compatibility[=]     mode is 'dos' or 'nondos' (default)
-L, --color[=]             colorize output (auto, always or colors are enabled by default
-l, --list                 display partitions end exit
-o, --output               output columns
-t, --type                 recognize specified partition table type only
-u, --units[=]             display units: 'cylinders' or 'sectors' (default)
-s, --getsz                display device size in 512-byte sectors [DEPRECATED]
    --bytes                print SIZE in bytes rather than in human readable format

-C, --cylinders            specify the number of cylinders
-H, --heads                specify the number of heads
-S, --sectors              specify the number of sectors per track

-h, --help               display this help and exit
-V, --version output version information and exit

Available columns (for -o):
   gpt: Device Start End Sectors Size Type Type-UUID Attrs Name UUID
   dos: Device Start End Sectors Cylinders Size Type Id Attrs Boot End-C/H/S Start-C/H/S
   bsd: Slice Start End Sectors Cylinders Size Type Bsize Cpg Fsize
   sgi: Device Start End Sectors Cylinders Size Type Id Attrs
   sun: Device Start End Sectors Cylinders Size Type Id Flags

..........................................................................................

要獲取裝置列表,請使用以下命令:

$ sudo fdisk -l

示例輸出如下:

Disk /dev/ram0: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/ram1: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/ram2: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

sfdisk

sfdisk 是一個基於指令碼的工具,用於顯示或操作磁碟分割槽表。

要獲取有關 sfdisk 的更多資訊,請使用以下命令:

$ man sfdisk

示例輸出如下:

SFDISK(8) System Administration SFDISK(8)

NAME
   sfdisk - display or manipulate a disk partition table

SYNOPSIS
   sfdisk [options] device [-N partition-number]

   sfdisk [options] command

DESCRIPTION
   sfdisk is a script-oriented tool for partitioning any block device.

   Since version 2.26 sfdisk supports MBR (DOS), GPT, SUN and SGI disk labels, but no longer provides any       tionality for CHS (Cylinder-Head-Sector) addressing. CHS has never been important for Linux, and this      
addressing concept does not make any sense for new devices.

   sfdisk (since version 2.26) aligns the start and end of partitions to block-device I/O limits when     relative
   sizes are specified, or when the default values are used.

   sfdisk does not create the standard system partitions for SGI and SUN disk labels like fdisk(8) does. It necessary to explicitly create all partitions including whole-disk system partitions.

........................................................................................

要獲取裝置列表,請使用以下命令:

$ sfdisk -l

示例輸出如下:

Disk /dev/ram0: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/ram1: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/ram2: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

lsblk

lsblk 提供有關所有或特定塊裝置的資訊。要獲取有關 lsblk 的更多資訊,請使用以下命令:

$ man lsblk

示例輸出如下:

LSBLK(8) System Administration LSBLK(8)

NAME
   lsblk - list block devices

SYNOPSIS
   lsblk [options] [device...]

DESCRIPTION
   lsblk lists information about all available or the specified block devices. The lsblk command reads the     sysfs filesystem and
   udev db to gather information.

   The command prints all block devices (except RAM disks) in a tree-like format by default. Use lsblk --help    to get a list of all
   available columns.

   The default output, as well as the default output from options like --fs and --topology, is subject to       change. So whenever pos‐sible, you should avoid using default outputs in your scripts. Always explicitly       define expected columns by using --output col‐umns-list in environments where a stable output is    required.

   Note that lsblk might be executed in time when udev does not have all information about recently added or    modified devices yet.
   In this case it is recommended to use udevadm settle before lsblk to synchronize with udev.
.................................................................................................

要獲取裝置列表,請使用以下命令:

$ lsblk

示例輸出如下:

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 465.8G 0 disk
├─sda1 8:1 0 462.3G 0 part /
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 3.4G 0 part [SWAP]
sr0 11:0 1 1024M 0 rom

lsscsi

它提供有關當前連線到系統的 SCSI 裝置(或主機)列表的資訊。要獲取有關 lsscsi 的更多資訊,請使用以下命令:

$ man lsscsi

示例輸出如下:

NAME
lsscsi - list SCSI devices (or hosts) and their attributes

SYNOPSIS
   lsscsi [--classic] [--device] [--generic] [--help] [--hosts] [--kname] [--list] [--lunhex] [--long] [--      protection] [--protmode]
   [--scsi_id] [--size] [--sysfsroot=PATH] [--transport] [--verbose] [--version] [--wwn] [H:C:T:L]

DESCRIPTION
   Uses information in sysfs (Linux kernel series 2.6 and later) to list SCSI devices (or hosts) currently       attached to the system.Options can be used to control the amount and form of information provided for       each device.
   If a H:C:T:L argument is given then it acts as a filter and only devices that match it are listed. The       colons don't have to be
   present, and '-', '*', '?' or missing arguments at the end are interpreted as wildcards. The default is       '*:*:*:*' which means to
   match everything. Any filter string using '*' of '?' should be surrounded by single or double quotes to       stop shell expansions.
   If '-' is used as a wildcard then the whole filter argument should be prefixed by '-- ' to tell this       utility there are no more
   options on the command line to be interpreted. A leading '[' and trailing ']' are permitted (e.g.    '[1:0:0]' matches all LUNs on
  1:0:0). May also be used to filter --hosts in which case only the H is active and may be either a number or    in the form
 "host" where is a host number.
............................................................................................

要獲取當前連線的 SCSI 裝置(或主機)列表,請使用以下命令:

$ lsscsi

示例輸出如下:

[0:0:0:0] disk ATA WDC WD5000LPVX-7 1A01 /dev/sda
[1:0:0:0] cd/dvd TSSTcorp DVD+-RW SU-208FB D200 /dev/sr0

在這篇文章中,我們學習了一些非常有用的工具——“在 Linux 中檢查 Linux 磁碟分割槽和使用情況”。在我們的下一篇文章中,我們將提供更多基於 Linux 的技巧和提示。繼續關注!

更新於: 2019年10月22日

407 次瀏覽

開啟您的 職業生涯

透過完成課程獲得認證

開始學習
廣告

© . All rights reserved.