参考文献

常见的档案系统

  • 传统档案系统: ext2/minix/MS-DOS/FAT(用vfat模块)
  • 日志是档案系统: ext3/ReiserFS/Windos' NTFS/IBM's JFS/SGI's XFS
  • 网络档案系统: NFS/SMBFS

档案系统的简单操作

  • 磁盘与目录的容量: df, du
  • 连结档的介绍: ln

磁盘的分割、格式化、检验与挂载

  • 磁盘分割: fdisk
  • 磁盘格式化: mke2fs, mkbootdisk, fdformat
  • 磁盘检验: fsck, badblocks, sync
  • 磁盘挂载与卸载: mount, umount
  • 磁盘参数修订: mknod, e2label, tune2fs, hdparm

df

  • 磁盘空间查看工具,用于显示文件系统磁盘空间的使用情况

  • 命令说明

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    # df --help
    Usage: df [OPTION]... [FILE]...
    Show information about the file system on which each FILE resides,
    or all file systems by default.

    Mandatory arguments to long options are mandatory for short options too.
    -a, --all include pseudo, duplicate, inaccessible file systems
    -B, --block-size=SIZE scale sizes by SIZE before printing them; e.g.,
    '-BM' prints sizes in units of 1,048,576 bytes;
    see SIZE format below
    -h, --human-readable print sizes in powers of 1024 (e.g., 1023M)
    -H, --si print sizes in powers of 1000 (e.g., 1.1G)
    -i, --inodes list inode information instead of block usage
    -k like --block-size=1K
    -l, --local limit listing to local file systems
    --no-sync do not invoke sync before getting usage info (default)
    --output[=FIELD_LIST] use the output format defined by FIELD_LIST,
    or print all fields if FIELD_LIST is omitted.
    -P, --portability use the POSIX output format
    --sync invoke sync before getting usage info
    --total elide all entries insignificant to available space,
    and produce a grand total
    -t, --type=TYPE limit listing to file systems of type TYPE
    -T, --print-type print file system type
    -x, --exclude-type=TYPE limit listing to file systems not of type TYPE
    -v (ignored)
    --help display this help and exit
    --version output version information and exit

    Display values are in units of the first available SIZE from --block-size,
    and the DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
    Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

    The SIZE argument is an integer and optional unit (example: 10K is 10*1024).
    Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).

    FIELD_LIST is a comma-separated list of columns to be included. Valid
    field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent',
    'size', 'used', 'avail', 'pcent', 'file' and 'target' (see info page).

    • -a--all: 显示所有的文件系统,包括系统保留的文件系统.
    • -h--human-readable: 以易读的方式显示文件系统容量,例如使用 KB、MB、GB 等单位.
    • -H--si: 与 -h 相同,但是使用十进制单位,例如 1000B 代表 1KB.
    • -i--inodes: 显示 inode 的使用情况而不是磁盘空间的使用情况.
    • -k--block-size: 指定块的大小,例如 -k 1024 表示使用 1KB 的块.
    • -l--local: 仅显示本地文件系统.
    • -P--portability: 使用 POSIX 输出格式,以便于在不同系统之间进行移植.
    • -t--type: 仅显示指定类型的文件系统,例如 -t ext4 仅显示 ext4 文件系统.
    • -T--print-type: 显示每个文件系统的类型.
    • -x--exclude-type: 排除指定类型的文件系统,例如 -x tmpfs 排除 tmpfs 文件系统.
    • --sync: 在输出文件系统信息之前强制同步文件系统.

fdisk

  • 磁盘分区工具,用于创建、删除、调整磁盘分区等操作

  • 命令说明

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    holelin@minio-102:~$ fdisk --help

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

    Display or manipulate a disk partition table.

    Options:
    -b, --sector-size <size> physical and logical sector size
    -B, --protect-boot don't erase bootbits when creating a new label
    -c, --compatibility[=<mode>] mode is 'dos' or 'nondos' (default)
    -L, --color[=<when>] colorize output (auto, always or never)
    colors are enabled by default
    -l, --list display partitions and exit
    -o, --output <list> output columns
    -t, --type <type> recognize specified partition table type only
    -u, --units[=<unit>] 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
    -w, --wipe <mode> wipe signatures (auto, always or never)
    -W, --wipe-partitions <mode> wipe signatures from new partitions (auto, always or never)

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

    -h, --help display this help
    -V, --version display version

    Available output columns:
    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

    • -b: 指定扇区大小,例如 -b 512.
    • -c: 关闭 DOS 兼容模式.
    • -l: 列出所有磁盘分区的信息.
    • -u: 指定单位为扇区.
    • -v: 显示版本信息.
    • -x: 显示额外的信息.
    • -s: 显示磁盘分区的大小(以扇区为单位).
    • -t: 指定分区类型,例如 -t 83 表示 Linux 文件系统

mkfs(make filesystem)

  • -t:指定要创建的文件系统类型,例如 -t ext4 表示创建 ext4 文件系统.
  • -c:在创建文件系统时检查磁盘坏道.
  • -i:指定 inode 大小,例如 -i 2048.
  • -I:指定 inode 大小为默认大小.
  • -L:给文件系统添加标签,例如 -L myfs.
  • -n:显示将要执行的操作,但不实际执行.
  • -v:显示详细的信息.
  • -V:显示版本信息.

lsblk

  • lsblk命令 用于列出所有可用块设备的信息,而且还能显示他们之间的依赖关系,但是它不会列出RAM盘的信息.块设备有硬盘,闪存盘,CD-ROM等等.lsblk命令包含在util-linux-ng包中,现在该包改名为util-linux.这个包带了几个其它工具,如dmesg.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    Usage:
    lsblk [options] [<device> ...]

    List information about block devices.

    Options:
    -a, --all print all devices # 显示所有设备
    -b, --bytes print SIZE in bytes rather than in human readable format # 以bytes方式显示设备大小
    -d, --nodeps don't print slaves or holders # 不显示 slaves 或 holders
    -D, --discard print discard capabilities
    -z, --zoned print zone model
    -e, --exclude <list> exclude devices by major number (default: RAM disks) # 排除设备 (default: RAM disks)
    -f, --fs output info about filesystems # 显示文件系统信息
    -i, --ascii use ascii characters only
    -I, --include <list> show only devices with specified major numbers
    -J, --json use JSON output format
    -l, --list use list format output # 使用列表格式显示
    -T, --tree use tree format output
    -m, --perms output info about permissions # 显示权限信息
    -n, --noheadings don't print headings # 不显示标题
    -o, --output <list> output columns
    -O, --output-all output all columns
    -p, --paths print complete device path
    -P, --pairs use key="value" output format
    -r, --raw use raw output format # 使用原始格式显示
    -s, --inverse inverse dependencies
    -S, --scsi output info about SCSI devices
    -t, --topology output info about topology
    -x, --sort <column> sort output by <column>

    -h, --help display this help
    -V, --version display version
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    Available output columns:
    NAME device name
    KNAME internal kernel device name
    MAJ:MIN major:minor device number
    FSTYPE filesystem type
    MOUNTPOINT where the device is mounted
    LABEL filesystem LABEL
    UUID filesystem UUID
    PARTTYPE partition type UUID
    PARTLABEL partition LABEL
    PARTUUID partition UUID
    PARTFLAGS partition flags
    RA read-ahead of the device
    RO read-only device
    RM removable device
    HOTPLUG removable or hotplug device (usb, pcmcia, ...)
    MODEL device identifier
    SERIAL disk serial number
    SIZE size of the device
    STATE state of the device
    OWNER user name
    GROUP group name
    MODE device node permissions
    ALIGNMENT alignment offset
    MIN-IO minimum I/O size
    OPT-IO optimal I/O size
    PHY-SEC physical sector size
    LOG-SEC logical sector size
    ROTA rotational device
    SCHED I/O scheduler name
    RQ-SIZE request queue size
    TYPE device type
    DISC-ALN discard alignment offset
    DISC-GRAN discard granularity
    DISC-MAX discard max bytes
    DISC-ZERO discard zeroes data
    WSAME write same max bytes
    WWN unique storage identifier
    RAND adds randomness
    PKNAME internal parent kernel device name
    HCTL Host:Channel:Target:Lun for SCSI
    TRAN device transport type
    SUBSYSTEMS de-duplicated chain of subsystems
    REV device revision
    VENDOR device vendor
    ZONED zone model

示例

1
2
3
4
5
6
7
8
9
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 446.6G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 445.1G 0 part
└─ubuntu--vg-ubuntu--lv 253:0 0 440G 0 lvm /
sdb 8:16 0 7.3T 0 disk /home
sr0 11:0 1 1024M 0 rom
  • NAME :这是块设备名.
  • MAJ:MIN :本栏显示主要和次要设备号.
  • RM :本栏显示设备是否可移动设备.
  • SIZE :本栏列出设备的容量大小信息.
  • RO :该项表明设备是否为只读.
  • TYPE :本栏显示块设备是否是磁盘或磁盘上的一个分区.
  • MOUNTPOINT :本栏指出设备挂载的挂载点.

mke2fs

  • 当没有指定的时候, mke2fs 使用 ext2 为格式化档案格式,若加入 –j 时,则格式化为 ext3 这个Journaling filesystem
1
2
3
4
5
6
7
8
# mke2fs [-bicLj] 装置名称 
参数:
-b : 可以设定每个 block 的大小,目前支持 1024, 2048, 4096 bytes 三种;
-i : 多少容量给予一个 inode
-c : 检查磁盘错误,仅下达一次 -c 时,会进行快速读取测试;
如果下达两次 -c -c 的话,会测试读写(read-write),会很慢
-L : 后面可以接表头名称 (Label),这个 label 是有用的喔!
-j : 本来 mke2fs 是 EXT2 ,加上 -j 后,会主动加入 journal 而成为 EXT3.

hdparm

1
2
# 查看硬盘信息
hdparm -I /dev/sda

fsck

1
2
3
4
5
6
7
8
9
10
11
12
13
# fsck [-AtCary] 装置名称 
参数:
-t : fsck 可以检查好几种不同的 filesystem ,而 fsck 只是一支综合程序而已.
个别的 filesystem 的检验程序都在 /sbin 底下,您可以使用 ls -l /sbin/fsck*
去检查看看,就知道有几种 filesystem 啰.预设的 FC4 情况下,至少有:
ext2, ext3, vfat, msdos 等等 filesystem.
-A : 依据 /etc/fstab 的内容,将所有的装置都扫瞄一次 (通常开机过程中就会执行此一指令)
-a : 自动修复检查到的有问题的扇区,所以你不用一直按 y 啰!
-r : 一定要让使用者决定是否需要修复,这与上一个 -a 刚好相反!
-y : 与 -a 类似,但是某些 filesystem 仅支持 -y 这个参数,所以您也可以利用 -y 啦!
-C : 可以在检验的过程当中,使用一个长条图来显示目前的进度!
-f : 强制检查!一般来说,如果 fsck 没有发现任何 unclean 的旗标,不会主动进入
细部检查的,如果您想要强制 fsck 进入细部检查,就得加上 -f 旗标啰!

mount

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# mount [-tonL]  装置名称代号  挂载点 
参数:
-a : 依照 /etc/fstab 的内容将所有相关的磁盘都挂上来!
-n : 一般来说,当我们挂载档案系统到 Linux 上头时, Linux 会主动的将
目前的 partition 与 filesystem 还有对应的挂载点,都记录到 /etc/mtab
那个档案中.不过,有些时刻 (例如不正常关机导致一些问题,而进入单人模式)
系统无法写入 /etc/mtab 时,就可以加上 -n 这个参数来略过写入 mtab 的动作.
-L : 系统除了利用装置名称代号 (例如 /dev/hda1) 之外,还可以利用 partition
的表头名称 ( Label ) 来进行挂载喔!所以,最好为您的 partition 取一个
在您系统当中独一无二的名称吧!
-t : 您的 Linux 支持的档案格式,就写在这里吧!举例来说,我们在上面建立
/dev/hdb5 是 ext3 档案系统,那么要挂载时,就得要加上 -t ext3
来告知系统,用 ext3 的档案格式来挂载该 partition 呢!
至于系统支持的 filesystem 类型在 /lib/modules/`uname -r`/kernel/fs 当中.
常见的有:
ext2, ext3, reiserfs, 等 Linux 惯用 filesystem
vfat, msdos 等 Windows 常见 filesystem
iso9660 为光盘片的格式
nfs, smbfs 等为网络相关档案系统.这部分未来我们会在网络方面提及!
若 mount 后面没有加 -t 档案系统格式时,则 Linux 在预设的情况下,
会主动以 /etc/filesystems 这个档案内规范的档案系统格式
来尝试主动的挂载喔!
-o : 后面可以接一些挂载时,额外加上的参数喔!比方说账号、密码、读写权限等:
ro, rw: 此 partition 为只读(ro) 或可擦写(rw)
async, sync: 此 partition 为同步写入 (sync) 或异步 (async),这个与我们
之前提到的档案系统运作方式有关,预设是 async
auto, noauto: 允许此 partition 被以 mount -a 自动挂载(auto)
dev, nodev: 是否允许此 partition 上,可建立装置档案? dev 为可允许
suid, nosuid: 是否允许此 partition 含有 suid/sgid 的档案格式?
exec, noexec: 是否允许此 partition 上拥有可执行 binary 档案?
user, nouser: 是否允许此 partition 让 user 执行 mount ?一般来说,
mount 仅有 root 可以进行,但下达 user 参数,则可让
一般 user 也能够对此 partition 进行 mount .
defaults: 默认值为: rw, suid, dev, exec, auto, nouser, and async
remount: 重新挂载,这在系统出错,或重新更新参数时,很有用!
  • ⽀持UTF-8

    1
    mount -o iocharset=utf8 /dev/sda5 /mnt/usb
  • 禁⽌⽂件与⽬录的访问时间

    1
    mount -o noatime,nodiratime /dev/drbd0 /mnt

磁盘分区

  • 使用df -h以及sudo fdisk -l查看磁盘详情

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    root@minio-102:/home/holelin# df -h
    Filesystem Size Used Avail Use% Mounted on
    udev 1.9G 0 1.9G 0% /dev
    tmpfs 391M 1.6M 389M 1% /run
    /dev/mapper/ubuntu--vg-ubuntu--lv 19G 6.3G 12G 36% /
    tmpfs 2.0G 0 2.0G 0% /dev/shm
    tmpfs 5.0M 0 5.0M 0% /run/lock
    tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
    /dev/loop0 92M 92M 0 100% /snap/lxd/24061
    /dev/sda2 2.0G 108M 1.7G 6% /boot
    /dev/loop1 50M 50M 0 100% /snap/snapd/18357
    /dev/loop2 64M 64M 0 100% /snap/core20/1828
    tmpfs 391M 0 391M 0% /run/user/1000
    root@minio-102:/home/holelin# fdisk -l
    Disk /dev/loop0: 91.85 MiB, 96292864 bytes, 188072 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 /dev/loop1: 49.86 MiB, 52260864 bytes, 102072 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 /dev/loop2: 63.29 MiB, 66359296 bytes, 129608 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 /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
    Disk model: VMware Virtual S
    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: gpt
    Disk identifier: 20DCA599-D2CA-416E-89E5-02C0BB3FD69E

    Device Start End Sectors Size Type
    /dev/sda1 2048 4095 2048 1M BIOS boot
    /dev/sda2 4096 4198399 4194304 2G Linux filesystem
    /dev/sda3 4198400 83884031 79685632 38G Linux filesystem

    # 此处的/dev/sdb
    Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 sectors
    Disk model: VMware Virtual S
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes

    # 此处的/dev/sdc
    Disk /dev/sdc: 5 GiB, 5368709120 bytes, 10485760 sectors
    Disk model: VMware Virtual S
    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 /dev/mapper/ubuntu--vg-ubuntu--lv: 18.102 GiB, 20396900352 bytes, 39837696 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

    • 上面的/dev/sdb以及/dev/sdc为需要分区的磁盘
  • 切换到root权限,执行fdisk /dev/sdb

    • 使用m命令来进行提示
    • 使用先n命令再执行p命令来创建分区,此处只创建一个分区,则全部使用默认
    • 使用w命令来保存
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    root@minio-102:/home/holelin# fdisk /dev/sdb

    Welcome to fdisk (util-linux 2.34).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.

    Device does not contain a recognized partition table.
    Created a new DOS disklabel with disk identifier 0xf894433b.

    Command (m for help): m

    Help:

    DOS (MBR)
    a toggle a bootable flag
    b edit nested BSD disklabel
    c toggle the dos compatibility flag

    Generic
    d delete a partition
    F list free unpartitioned space
    l list known partition types
    n add a new partition
    p print the partition table
    t change a partition type
    v verify the partition table
    i print information about a partition

    Misc
    m print this menu
    u change display/entry units
    x extra functionality (experts only)

    Script
    I load disk layout from sfdisk script file
    O dump disk layout to sfdisk script file

    Save & Exit
    w write table to disk and exit
    q quit without saving changes

    Create a new label
    g create a new empty GPT partition table
    G create a new empty SGI (IRIX) partition table
    o create a new empty DOS partition table
    s create a new empty Sun partition table

    Command (m for help): p

    Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 sectors
    Disk model: VMware Virtual S
    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: 0xf894433b

    Command (m for help): n
    Partition type
    p primary (0 primary, 0 extended, 4 free)
    e extended (container for logical partitions)
    Select (default p): p
    Partition number (1-4, default 1): 1
    First sector (2048-10485759, default 2048):
    Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-10485759, default 10485759):

    Created a new partition 1 of type 'Linux' and of size 5 GiB.

    Command (m for help): p
    Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 sectors
    Disk model: VMware Virtual S
    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: 0xf894433b

    Device Boot Start End Sectors Size Id Type
    /dev/sdb1 2048 10485759 10483712 5G 83 Linux

    Command (m for help): w
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.
  • /dev/sdc执行上述同样操作

  • 都执行完成后,重启服务器

    1
    reboot now
  • 重启完成后,格式化磁盘

    1
    2
    3
    # 将磁盘格式化为ext4格式
    mkfs.ext4 /dev/sdb
    mkfs.ext4 /dev/sdc
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    root@minio-102:/home/holelin# mkfs.ext4 /dev/sdb
    mke2fs 1.45.5 (07-Jan-2020)
    Found a dos partition table in /dev/sdb
    Proceed anyway? (y,N) y
    Creating filesystem with 1310720 4k blocks and 327680 inodes
    Filesystem UUID: 0a13e2ca-b99f-42e5-a593-1d91a40b0a0b
    Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736

    Allocating group tables: done
    Writing inode tables: done
    Creating journal (16384 blocks): done
    Writing superblocks and filesystem accounting information: done

    root@minio-102:/home/holelin# mkfs.ext4 /dev/sdc
    mke2fs 1.45.5 (07-Jan-2020)
    Found a dos partition table in /dev/sdc
    Proceed anyway? (y,N) y
    Creating filesystem with 1310720 4k blocks and 327680 inodes
    Filesystem UUID: 8661df5c-13f9-493b-a5e6-902cd612a613
    Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736

    Allocating group tables: done
    Writing inode tables: done
    Creating journal (16384 blocks): done
    Writing superblocks and filesystem accounting information: done
  • 创建命令将其挂载上去

    1
    2
    3
    root@minio-102:/home/holelin# mkdir -p /opt/bigdata/minio/data{1..2}
    root@minio-102:/home/holelin# mount /dev/sdb /opt/bigdata/minio/data1
    root@minio-102:/home/holelin# mount /dev/sdc /opt/bigdata/minio/data2
  • 查看挂载情况

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    root@minio-102:/opt/bigdata/minio# df -h
    Filesystem Size Used Avail Use% Mounted on
    udev 1.9G 0 1.9G 0% /dev
    tmpfs 391M 1.6M 389M 1% /run
    /dev/mapper/ubuntu--vg-ubuntu--lv 19G 6.3G 12G 36% /
    tmpfs 2.0G 0 2.0G 0% /dev/shm
    tmpfs 5.0M 0 5.0M 0% /run/lock
    tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
    /dev/sda2 2.0G 108M 1.7G 6% /boot
    /dev/loop1 50M 50M 0 100% /snap/snapd/18357
    /dev/loop0 92M 92M 0 100% /snap/lxd/24061
    /dev/loop2 64M 64M 0 100% /snap/core20/1828
    tmpfs 391M 0 391M 0% /run/user/1000
    /dev/sdb 4.9G 24K 4.6G 1% /opt/bigdata/minio/data1
    /dev/sdc 4.9G 24K 4.6G 1% /opt/bigdata/minio/data2
  • (建议)运行命令cp /etc/fstab /etc/fstab.bak备份etc/fstab文件

  • 设置自动挂载

    • 编辑vim /etc/fstab
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    # /etc/fstab: static file system information.
    #
    # Use 'blkid' to print the universally unique identifier for a
    # device; this may be used with UUID= as a more robust way to name devices
    # that works even if disks are added and removed. See fstab(5).
    #
    # <file system> <mount point> <type> <options> <dump> <pass>
    # / was on /dev/ubuntu-vg/ubuntu-lv during curtin installation
    /dev/disk/by-id/dm-uuid-LVM-cGmWUVBv33VTllHitivA9iiCMWt8DSieosTgIHWpLhOULK45fGjBSC1JCjWpx9qR / ext4 defaults 0 1
    # /boot was on /dev/sda2 during curtin installation
    /dev/disk/by-uuid/ddec6c8f-ad72-404f-84f6-0faea3c5b690 /boot ext4 defaults 0 1
    /swap.img none swap sw 0 0
    /dev/sdb /opt/bigdata/minio/data1 ext4 defaults 0 0
    /dev/sdc /opt/bigdata/minio/data2 ext4 defaults 0 0
    • 或者直接运行命令 echo /dev/sdc /opt/bigdata/minio/data2 ext4 defaults 0 0 >> /etc/fstab /etc/fstab写入新分区信息

磁盘阵列(Redundant Arrays of Inexpensive Disks,RAID )

  • 通过一个技术(软件或者硬件),将多个较小的磁盘整合为一个较大的磁盘装置,而这个较大的磁盘功能可不止是存储而已,它还有数据保护的功能.整个RAID由于选择的等级(level)不同,而使得整合后的磁盘具有不同的功能,常见的level有几种:
  • Linear mode(线性模式)
  • RAID-0(交错模式,stripe)
  • RAID-1(映像模式,mirror)
  • RAID-5

/etc/fstab

1
2
3
4
5
6
7
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
  • file system: 例如/dev/cdrom/dev/sdb,除了使⽤设备名,还可以使⽤设备的UUID或设备的卷标签,例如,LABAL=rootUUID=7f91104e-8187-4ccf-8215-6e2e641f32e3

  • mount point: 该字段描述希望的⽂件系统加载的⽬录,对于swap设备,该字段为none

  • type: 定义了该设备上的⽂件系统

    • 系统可⽤⽂件系统 cat /proc/filesystems

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      nodev	sysfs
      nodev tmpfs
      nodev bdev
      nodev proc
      nodev cgroup
      nodev cgroup2
      nodev cpuset
      nodev devtmpfs
      nodev configfs
      nodev debugfs
      nodev tracefs
      nodev securityfs
      nodev sockfs
      nodev bpf
      nodev pipefs
      nodev ramfs
      nodev hugetlbfs
      nodev devpts
      ext3
      ext2
      ext4
      squashfs
      vfat
      nodev ecryptfs
      fuseblk
      nodev fuse
      nodev fusectl
      nodev efivarfs
      nodev mqueue
      nodev resctrl
      nodev pstore
      nodev autofs
      nodev binfmt_misc
      nodev overlay
      nodev aufs
  • options

    选项 含义
    defaults 使⽤默认设置. 等于rw,suid,dev,exec,auto,nouser,async
    rw 挂载为读写权限
    ro 以只读模式加载该⽂件系统
    exec 是⼀个默认设置项,它使在那个分区中的可执⾏的⼆进制⽂件能够执⾏
    noexec ⼆进制⽂件不允许执⾏
    sync 不对该设备的写操作进⾏缓冲处理,这可以防⽌在⾮正常关机时情况下破坏⽂件系统,但是却降低了计算机速度
    async 所有的I/O将以异步⽅式进⾏
    user 允许普通⽤户加载该⽂件系统
    nouser 只允许root⽤户挂载.这是默认设置.
    quota 强制在该⽂件系统上进⾏磁盘定额限制
    noauto 不再使⽤mount -a命令(例如系统启动时)加载该⽂件系统
    noatime/nodiratime 禁⽌更新访问时间
  • dump: 该选项被"dump"命令使⽤来检查⼀个⽂件系统应该以多快频率进⾏转储,若不需要转储就设置该字段为0

  • pass: 该字段被fsck命令⽤来决定在启动时需要被扫描的⽂件系统的顺序,根⽂件系统"/"对应该字段的值应该为1,其他⽂件系统应该为2。若该⽂件系统⽆需在启动时扫描则设置该字段为0.

smartctl

  • SMART (Self-Monitoring, Analysis and Reporting Technology) 是一种内置于存储设备(如硬盘和固态硬盘)中的监控系统,用于检测和报告潜在的硬件故障,以便用户可以在设备完全失败之前采取措施。SMART 技术提供了一组可以监控的属性,这些属性反映了磁盘的健康状况,包括错误率、温度、重新分配的扇区数等等。

SMART 的主要功能

  1. 监控: 持续监控存储设备的运行情况。
  2. 分析: 通过内置算法分析监控数据,判断磁盘健康状况。
  3. 报告: 当检测到潜在问题时,向用户发出警告,建议备份数据并更换硬盘。

常见的 SMART 属性

  • Reallocated Sectors Count: 重新分配的扇区数。这通常是一个重要的故障前兆。
  • Current Pending Sector Count: 当前等待重新分配的扇区数。
  • Power-On Hours: 磁盘通电时间。
  • Temperature: 磁盘温度。
  • Read Error Rate: 读取错误率。
  • Spin Retry Count: 磁盘启动重试次数

示例

1
sudo smartctl -a /dev/sda